Image.st
author Claus Gittinger <cg@exept.de>
Tue, 28 May 1996 21:12:57 +0200
changeset 748 818c6312acd1
parent 746 f5479d603f64
child 757 6c7dc7e05e93
permissions -rw-r--r--
grey vs. gray
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     1
"
6
7ee0cfde237d *** empty log message ***
claus
parents: 5
diff changeset
     2
 COPYRIGHT (c) 1991 by Claus Gittinger
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
     3
	      All Rights Reserved
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     4
48194c26a46c Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
48194c26a46c Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
48194c26a46c Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
48194c26a46c Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
48194c26a46c Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
48194c26a46c Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
48194c26a46c Initial revision
claus
parents:
diff changeset
    11
"
48194c26a46c Initial revision
claus
parents:
diff changeset
    12
48194c26a46c Initial revision
claus
parents:
diff changeset
    13
Object subclass:#Image
306
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
    14
	instanceVariableNames:'bytes width height bitsPerSample samplesPerPixel colorMap
305
4ece2bdf1011 handle StaticColor visual (OS/2 server has this)
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
    15
		photometric device deviceForm monoDeviceForm fullColorDeviceForm'
306
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
    16
	classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors
305
4ece2bdf1011 handle StaticColor visual (OS/2 server has this)
Claus Gittinger <cg@exept.de>
parents: 286
diff changeset
    17
		CollectGarbageWhenRunningOutOfColors FileFormats'
306
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
    18
	poolDictionaries:''
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
    19
	category:'Graphics-Images'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    20
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    21
48194c26a46c Initial revision
claus
parents:
diff changeset
    22
!Image class methodsFor:'documentation'!
48194c26a46c Initial revision
claus
parents:
diff changeset
    23
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    24
copyright
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    25
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    26
 COPYRIGHT (c) 1991 by Claus Gittinger
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
    27
	      All Rights Reserved
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    28
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    29
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    30
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    32
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    33
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    34
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    35
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    36
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    37
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    38
documentation
48194c26a46c Initial revision
claus
parents:
diff changeset
    39
"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    40
    this class provides (some time in the future) representation
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    41
    for all kinds of images (monochrome, greyscale and color)
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    42
    and will finally replace Form. 
622
565e2301c064 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    43
    For now (only ;-) depths of 1, 2, 4, 8, 16 and 24 are supported.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    44
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    45
    An Image keeps all of its information in a device independent way, 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    46
    but may be associated to a device. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    47
    The data held keeps all information which was originally present, 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    48
    even if the display-device has lower resolution.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    49
    Therefore, it is possible to process and manipulate images without loosing 
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    50
    color information - even on low color resolution displays.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    51
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    52
    Usually, you get a device specific representation of the image by
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    53
    sending the 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    54
        'on:aDevice' 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    55
    message to it, which will create a (possibly dithered) device-form, 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    56
    representing the image using the currently available colors.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    57
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    58
    In rare cases, an explicit monochrome representation of the image is needed 
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    59
    (X servers take monochrome icons only), this can be created by sending
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    60
    it the message 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    61
        'monochromeOn:aDevice'.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    62
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    63
    Also, it is planned to generate another hi-color resolution version,
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    64
    which uses its own colormap and allows the use of all 256 colors on an 8bit display 
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    65
    (this is not currently implemented).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    66
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    67
    An images pixel interpretation is controlled by the photometric instance variable
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    68
    and (if that is #palette) a colorMap.
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    69
    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
    70
    (and using specialized colorMaps for b&w / greyScale images).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    71
    This may change in future versions for more application compatibility.
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    72
 
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    73
    To convert pictures from/to external file-formats, image readers are used
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    74
    which have the file-format knowledge built in. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    75
    There are readers for most common formats available 
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    76
    (see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    77
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    78
    File formats are handled by subclasses of ImageReader, which understand
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    79
    a specific format. You can add more readers, by adding an association
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    80
    such as ('.jpg' -> JPEGReader) to the class variable 'FileFormats' 
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    81
    (see the classes #initialize method, which dsets up some default, and the
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    82
    patches/display.rc files, which add more).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    83
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    84
    Some algorithms used here (especially dithering & color allocation) are
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    85
    experimental and far from being perfect (some are very slow). 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    86
    For now, the most common cases have been optimized and perform reasonably
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    87
    fast - however, with uncommon depth/visualType combinations, you may
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    88
    run into slower fallback methods ...
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    89
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    90
    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
    91
    (may) be done in the future if there is a demand for it ...
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    92
    Dithering can be controlled by the DitherAlgorithm classVariable:
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
    93
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    94
       DitherAlgorithm:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    95
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    96
       nil                  a simple threshold algorithm
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    97
                            (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    98
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    99
       #pattern             patterned dither
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   100
                            (for p, take dithered color to fill pixel;
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   101
                             uses dithering in color-class)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   102
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   103
       #error               error diffusion dither (Floyd-Steinberg)
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   104
                            planned - not yet implemented.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   105
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   106
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   107
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   108
    [instance variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   109
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   110
        width               <Integer>       the width in pixels
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   111
        height              <Integer>       the height in pixels
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   112
        bytes               <ByteArray>     the full image information
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   113
        photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   114
        samplesPerPixel     <Integer>       the number of planes
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   115
        bitsPerSample       <Array>         the number of bits per plane
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   116
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   117
        colorMap            <Array>         only if photometric is #pseudocolor;
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   118
                                            maps pixel values to r/g/b values.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   119
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   120
        device              <Workstation>   the device on which deviceForm,
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   121
                                            monoDeviceForm and lowResDeviceForm are
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   122
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   123
        deviceForm          <Form>          the device form which gives the best
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   124
                                            possible aproximation of the image on
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   125
                                            device using standard colors.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   126
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   127
        monoDeviceForm      <Form>          the device form which gives a monochrome
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   128
                                            aproximation of the image on device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   129
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   130
        fullColorDeviceForm <Form>          the device form which gives the best
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   131
                                            possible aproximation of the image on
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   132
                                            device using private colors.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   133
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   134
    [class variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   135
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   136
        Lobby               <Registry>      keeps track of known images
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   137
                                            (for resource freeing with garbage collector)
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   138
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   139
        DitherAlgorithm     <Symbol>        defines how to dither
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   140
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   141
        NumberOfDitherColors <Integer>      defines, how many dither colors to use
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   142
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   143
        FileFormats         <Dictionary>    associates filename extensions to
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   144
                                            image reader classes (now set-up in startup-file)
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   145
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   146
        CollectGarbageWhenRunningOutOfColors
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   147
                            <Boolean>       if true, and we run out of available
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   148
                                            device colors during creation of a
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   149
                                            device image, collect garbage for
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   150
                                            possible image reclamation.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   151
                                            If false, proceed immediately.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   152
                                            Default is true.
158
claus
parents: 157
diff changeset
   153
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   154
    todo:
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   155
        there is currently no mask stored/available in the image itself; currently masks
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   156
        have to be stored as separate bitmaps. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   157
        (which is bad for image-file formats, which provide a mask)
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   158
        Thus, currently, all images are completely opaque.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   159
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   160
    [See also:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   161
        Form Icon ImageReader
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   162
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   163
    [author:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   164
        Claus Gittinger
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   165
"
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   166
!
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   167
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   168
examples
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   169
"
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   170
    reading from a file (many formats are supported):
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   171
                                                                        [exBegin]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   172
        (Image fromFile:'bitmaps/claus.gif') inspect
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   173
                                                                        [exEnd]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   174
                                                                        [exBegin]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   175
        (Image fromFile:'bitmaps/SmalltalkX.xbm') inspect
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   176
                                                                        [exEnd]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   177
                                                                        [exBegin]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   178
        (Image fromFile:'bitmaps/okSmily_up.bmp') inspect
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   179
                                                                        [exEnd]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   180
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   181
    storing (only a few formats are currently supported):
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   182
                                                                        [exBegin]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   183
        |img|
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   184
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   185
        img := Image fromFile:'bitmaps/okSmily_up.bmp'.
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   186
        img saveOn:'myImage.tiff'.
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   187
        (Image fromFile:'myImage.tiff') inspect
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   188
                                                                        [exEnd]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   189
    magnifying (any factor):
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   190
                                                                        [exBegin]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   191
        ((Image fromFile:'bitmaps/claus.gif') 
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   192
            magnifiedTo:(48@48))
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   193
                inspect
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   194
                                                                        [exEnd]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   195
                                                                        [exBegin]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   196
        ((Image fromFile:'bitmaps/claus.gif') 
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   197
            magnifiedBy:0.7)
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   198
                inspect
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   199
                                                                        [exEnd]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   200
    rotating (currently, only multiples of 90 degrees are supported):
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   201
                                                                        [exBegin]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   202
        ((Image fromFile:'bitmaps/claus.gif') 
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   203
            rotated:90)
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   204
                inspect
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   205
                                                                        [exEnd]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   206
                                                                        [exBegin]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   207
        (((Image fromFile:'bitmaps/claus.gif') 
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   208
            magnifiedBy:0.3@0.7) rotated:270)
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   209
                inspect
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   210
                                                                        [exEnd]
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   211
"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   212
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   213
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   214
!Image class methodsFor:'initialization'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   215
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   216
fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   217
    "return the collection of supported file formats.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   218
     The returned dictionary maps file-extensions to image reader classes."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   219
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   220
    FileFormats isNil ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   221
	self initializeFileFormatTable
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   222
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   223
    ^ FileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   224
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   225
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   226
     Image fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   227
    "
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   228
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   229
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   230
flushDeviceImages
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   231
    "simply unassign all pictures from their device"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   232
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   233
    Lobby do:[:anImage |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   234
	anImage restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   235
    ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   236
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   237
48194c26a46c Initial revision
claus
parents:
diff changeset
   238
initialize
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   239
    "initialize class constants"
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   240
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   241
    "setup tracker of known pictures"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   242
    Lobby isNil ifTrue:[
748
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   243
        Lobby := Registry new.
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   244
        ObjectMemory addDependent:self.
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   245
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   246
        "define algorithm to use for dithering - currently only nil or #pattern supported"
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   247
        DitherAlgorithm := #pattern.   "will be changed to error as soon as implemented"
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   248
        (Display notNil and:[Display hasGrayscales]) ifFalse:[
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   249
            NumberOfDitherColors := 64
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   250
        ] ifTrue:[
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   251
            "as far as I remember, this is about the number of grey values, the eye can distinguish"
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   252
            NumberOfDitherColors := 100
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   253
        ].
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   254
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   255
        "define reader classes"
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   256
        FileFormats isNil ifTrue:[
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   257
            self initializeFileFormatTable
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   258
        ].
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   259
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   260
        CollectGarbageWhenRunningOutOfColors := false
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
   261
    ]
748
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   262
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   263
    "Modified: 28.5.1996 / 21:12:30 / cg"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   264
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   265
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   266
initializeFileFormatTable
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   267
    "initialize a default table to map from file extension to reader class.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   268
     The mapping here is a default needed for proper operation of ST/X;
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   269
     see the 'smalltalk.rc' startup file for a real (full) map."
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   270
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   271
    FileFormats := Dictionary new.
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   272
    FileFormats at:'.xbm'  put:XBMReader.
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   273
    FileFormats at:'.tiff' put:TIFFReader.
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   274
    FileFormats at:'.gif'  put:GIFReader.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   275
"/    FileFormats at:'.img'  put:IMGReader.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   276
"/    FileFormats at:'.icon' put:SunRasterReader.
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   277
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   278
    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   279
     Image initializeFileFormatTable
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   280
    "
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   281
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   282
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   283
update:something
48194c26a46c Initial revision
claus
parents:
diff changeset
   284
    "flush all device specific stuff when restarted from a snapshot"
48194c26a46c Initial revision
claus
parents:
diff changeset
   285
48194c26a46c Initial revision
claus
parents:
diff changeset
   286
    (something == #restarted) ifTrue:[
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   287
	self flushDeviceImages
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   288
    ]
48194c26a46c Initial revision
claus
parents:
diff changeset
   289
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   290
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   291
!Image class methodsFor:'instance creation'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   292
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   293
extent:ext depth:d bits:bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   294
    "ST-80 compatibility; assume 32-bit padding"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   295
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   296
    ^ self extent:ext depth:d bits:bits pad:32
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   297
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   298
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   299
extent:ext depth:d bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   300
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   301
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   302
    ^ self width:ext x height:ext y depth:d fromArray:bits pad:padding
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   303
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   304
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   305
extent:ext depth:d palette:aColormap bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   306
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   307
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   308
    ^ self width:ext x height:ext y depth:d fromArray:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   309
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   310
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   311
extent:ext fromArray:bits offset:offset
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   312
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   313
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   314
    ^ self width:ext x height:ext y fromArray:bits
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   315
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   316
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   317
fromForm:aForm
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   318
    "create & return an Image given a form"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   319
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   320
    |cls|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   321
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   322
    cls := self.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   323
    cls == Image ifTrue:[
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   324
	cls := self implementorForDepth:aForm depth
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   325
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   326
    ^ (cls new) fromForm:aForm.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   327
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   328
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   329
     |f|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   330
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   331
     f := Form width:16 height:16.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   332
     f clear.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   333
     f displayLineFromX:0 y:0 toX:15 y:15.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   334
     f inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   335
     (Image fromForm:f) inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   336
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   337
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   338
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   339
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   340
    "create & return an Image given another image. This can be used to
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   341
     convert an image to another depth."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   342
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   343
    (self == Image or:[anImage class == self]) ifTrue:[^ anImage].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   344
    ^ self new fromImage:anImage.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   345
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   346
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   347
     |i1 i8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   348
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   349
     i1 := Image fromFile:'bitmaps/SBrowser.xbm'.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   350
     i8 := Depth8Image fromImage:i1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   351
     i8 inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   352
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   353
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   354
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   355
fromSubImage:anImage in:aRectangle
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   356
    "create & return an Image from a rectangular area in another image. 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   357
     This can also be used to get a subimage in another depth."
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   358
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   359
    ^ self new fromSubImage:anImage in:aRectangle.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   360
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   361
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   362
     |i1 i8|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   363
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   364
     i1 := Image fromFile:'bitmaps/garfield.gif'.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   365
     i8 := Depth8Image fromSubImage:i1 in:(0@0 corner:20@20).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   366
     i8 inspect
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   367
    "
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   368
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   369
     |i1 i8|
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   370
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   371
     i1 := Image fromFile:'bitmaps/claus.gif'.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   372
     i8 := Depth8Image fromSubImage:i1 in:(70@50 extent:50@50).
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   373
     i8 inspect
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   374
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   375
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   376
    "Created: 20.9.1995 / 01:05:43 / claus"
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   377
    "Modified: 7.5.1996 / 19:28:17 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   378
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   379
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   380
new
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   381
    "create a new image. Redefined to set the photometric to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   382
     greyScale with black being 0 as default."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   383
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   384
    ^ super new photometric:#blackIs0
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   385
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   386
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   387
width:w height:h
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   388
    "create a new image, given width, height. Assume a depth of 1."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   389
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   390
    |cls|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   391
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   392
    cls := self.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   393
    cls == Image ifTrue:[
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   394
	cls := self implementorForDepth:1
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   395
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   396
    ^ cls new width:w height:h depth:1 
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   397
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   398
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   399
width:w height:h depth:d
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   400
    "create a new image, given width, height and depth"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   401
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   402
    ^ (self implementorForDepth:d) new
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   403
	width:w height:h depth:d
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   404
!
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   405
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   406
width:w height:h depth:d fromArray:pixelData
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   407
    "create a new image, given width, height, depth and data.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   408
     Data must be a ByteArray containing correctly aligned bits for the specified
134
claus
parents: 132
diff changeset
   409
     depth (8-bit padded)."
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   410
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   411
    ^ (self implementorForDepth:d) new width:w height:h depth:d fromArray:pixelData
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   412
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   413
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   414
     Image width:8 
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   415
	   height:8
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   416
	   depth:1
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   417
	   fromArray:#[2r11001100
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   418
		       2r00110011
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   419
		       2r11001100
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   420
		       2r00110011
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   421
		       2r11001100
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   422
		       2r00110011
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   423
		       2r11001100
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   424
		       2r00110011].
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   425
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   426
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   427
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   428
     Image width:8 
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   429
	   height:8
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   430
	   depth:2 
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   431
	   fromArray:#[4r1100 4r1100
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   432
		       4r0011 4r0011
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   433
		       4r1100 4r1100
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   434
		       4r0011 4r0011
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   435
		       4r1100 4r1100
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   436
		       4r0011 4r0011
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   437
		       4r1100 4r1100
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   438
		       4r0011 4r0011].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   439
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   440
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   441
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   442
     Image width:8 
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   443
	   height:8
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   444
	   depth:4 
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   445
	   fromArray:#[4r0001 4r0001
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   446
		       4r0011 4r0011
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   447
		       4r1100 4r1100
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   448
		       4r0011 4r0011
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   449
		       4r1100 4r1100
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   450
		       4r0011 4r0011
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   451
		       4r1100 4r1100
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   452
		       4r0011 4r0011].
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   453
    "
132
claus
parents: 125
diff changeset
   454
!
claus
parents: 125
diff changeset
   455
134
claus
parents: 132
diff changeset
   456
width:w height:h depth:d fromArray:pixelData pad:padding
claus
parents: 132
diff changeset
   457
    "create a new image, given width, height, depth and data.
claus
parents: 132
diff changeset
   458
     Data must be a ByteArray containing correctly aligned bits for the specified
claus
parents: 132
diff changeset
   459
     depth."
claus
parents: 132
diff changeset
   460
claus
parents: 132
diff changeset
   461
    |img newBits srcRowBytes dstRowBytes srcIndex dstIndex|
claus
parents: 132
diff changeset
   462
claus
parents: 132
diff changeset
   463
    img := (self implementorForDepth:d) new width:w height:h depth:d .
claus
parents: 132
diff changeset
   464
claus
parents: 132
diff changeset
   465
    padding ~~ 8 ifTrue:[
claus
parents: 132
diff changeset
   466
	"must repad; ST/X uses byte padding, while ST-80 uses longword
claus
parents: 132
diff changeset
   467
	 padding. This is stupid, and may be changed in ST/X with future versions.
claus
parents: 132
diff changeset
   468
	"
claus
parents: 132
diff changeset
   469
	dstRowBytes := img bytesPerRow.
144
claus
parents: 134
diff changeset
   470
	srcRowBytes := ((w * d + padding - 1) bitShift:-5) bitShift:2.
134
claus
parents: 132
diff changeset
   471
claus
parents: 132
diff changeset
   472
	newBits := ByteArray new:(dstRowBytes * h).
claus
parents: 132
diff changeset
   473
	srcIndex := 1.
claus
parents: 132
diff changeset
   474
	dstIndex := 1.
claus
parents: 132
diff changeset
   475
claus
parents: 132
diff changeset
   476
	1 to:h do:[:row |
claus
parents: 132
diff changeset
   477
	    newBits replaceFrom:dstIndex 
claus
parents: 132
diff changeset
   478
			     to:(dstIndex + dstRowBytes - 1)
claus
parents: 132
diff changeset
   479
			   with:pixelData
claus
parents: 132
diff changeset
   480
		     startingAt:srcIndex.
claus
parents: 132
diff changeset
   481
	    srcIndex := srcIndex + srcRowBytes.
claus
parents: 132
diff changeset
   482
	    dstIndex := dstIndex + dstRowBytes.
claus
parents: 132
diff changeset
   483
	].
claus
parents: 132
diff changeset
   484
    ] ifFalse:[
claus
parents: 132
diff changeset
   485
	newBits := pixelData
claus
parents: 132
diff changeset
   486
    ].
claus
parents: 132
diff changeset
   487
    img bits:newBits.
claus
parents: 132
diff changeset
   488
    ^ img
claus
parents: 132
diff changeset
   489
!
claus
parents: 132
diff changeset
   490
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   491
width:w height:h fromArray:anArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   492
    "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
   493
     receiving class is Image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   494
     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
   495
     (i.e. 8 bits per byte)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   496
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   497
    |cls d|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   498
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   499
    cls := self.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   500
    cls == Image ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   501
	cls := self implementorForDepth:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   502
	d := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   503
    ] ifFalse:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   504
	d := cls imageDepth
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   505
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   506
    ^ cls new width:w height:h depth:d fromArray:anArray
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   507
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   508
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   509
     Image width:8 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   510
	   height:8 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   511
	   fromArray:#[2r11001100
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   512
		       2r00110011
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   513
		       2r11001100
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   514
		       2r00110011
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   515
		       2r11001100
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   516
		       2r00110011
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   517
		       2r11001100
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   518
		       2r00110011].
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   519
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   520
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   521
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   522
!Image class methodsFor:'file reading'!
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   523
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   524
fromFile:aFileName
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   525
    "read an image from a file - this methods tries to find
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   526
     out the file format itself (by the extension and by contents)
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   527
     and lets the appropriate reader read the file."
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   528
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   529
    |image name nm inStream suffixLen|
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   530
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   531
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   532
     before trying each reader, check if file is readable
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   533
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   534
    name := aFileName.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   535
    inStream := Smalltalk systemFileStreamFor:name.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   536
    inStream isNil ifTrue:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   537
        inStream := Smalltalk bitmapFileStreamFor:name.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   538
        inStream isNil ifTrue:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   539
            ('IMAGE: ' , aFileName , ' does not exist or is not readable') infoPrintNL.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   540
            ^ nil
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   541
        ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   542
        name := 'bitmaps/' , name.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   543
    ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   544
    inStream close.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   545
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   546
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   547
     get the imageReader class from the files extension
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   548
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   549
    nm := name.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   550
    (name endsWith:'.Z') ifTrue:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   551
        suffixLen := 2
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   552
    ] ifFalse:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   553
        (name endsWith:'.gz') ifTrue:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   554
            suffixLen := 3
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   555
        ] ifFalse:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   556
            suffixLen := 0
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   557
        ]
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   558
    ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   559
    suffixLen ~~ 0 ifTrue:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   560
        nm := name copyWithoutLast:suffixLen
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   561
    ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   562
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   563
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   564
     ask the corresponding readerclass first
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   565
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   566
    FileFormats keysAndValuesDo:[:suffix :readerClass |
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   567
        (nm endsWith:suffix) ifTrue:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   568
            readerClass notNil ifTrue:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   569
                image := readerClass fromFile:name.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   570
                image notNil ifTrue:[^ image].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   571
            ]
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   572
        ]
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   573
    ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   574
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   575
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   576
     no known extension - ask all readers if they know
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   577
     this format ...
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   578
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   579
    FileFormats do:[:readerClass |
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   580
        readerClass notNil ifTrue:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   581
            (readerClass isValidImageFile:name) ifTrue:[
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   582
                ^ readerClass fromFile:name 
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   583
            ]
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   584
        ]
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   585
    ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   586
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   587
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   588
     nope - unknown format
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   589
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   590
    'IMAGE: unknown image file format: ' infoPrint. aFileName infoPrintNL.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   591
    ^ nil
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   592
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   593
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   594
     Image fromFile:'bitmaps/dano.tiff'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   595
     Image fromFile:'bitmaps/test.fax'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   596
     Image fromFile:'bitmaps/voice.tiff'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   597
     Image fromFile:'voice.tiff'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   598
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   599
     Image fromFile:'../fileIn/bitmaps/claus.gif'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   600
     Image fromFile:'../fileIn/bitmaps/garfield.gif'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   601
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   602
     Image fromFile:'../fileIn/bitmaps/founders.im8'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   603
     Image fromFile:'../goodies/faces/next.com/steve.face'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   604
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   605
     Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   606
     Image fromFile:'bitmaps/globe1.xbm'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   607
     Image fromFile:'bitmaps/globe1.xbm.Z'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   608
     Image fromFile:'bitmaps/hello_world.icon'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   609
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   610
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   611
    "Modified: 7.3.1996 / 19:18:13 / cg"
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   612
! !
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   613
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   614
!Image class methodsFor:'misc'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   615
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   616
dither:aSymbol
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   617
    "define how to dither - #pattern, #error or none;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   618
     error diffusion dithering is currently not implemented,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   619
     pattern dither is currently very slow."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   620
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   621
    DitherAlgorithm := aSymbol
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   622
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   623
    "Image dither:#pattern"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   624
    "Image dither:#error"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   625
    "Image dither:nil"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   626
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   627
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   628
numberOfDitherColors:n
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   629
    "define how many colors (i.e. patterns) to use when
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   630
     doing a pattern dither"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   631
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   632
    NumberOfDitherColors := n
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   633
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   634
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   635
!Image class methodsFor:'queries'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   636
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   637
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   638
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   639
     this class.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   640
     Must be redefined in concrete subclasses"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   641
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   642
    ^ self shouldNotImplement
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   643
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   644
    "Modified: 20.4.1996 / 23:40:41 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   645
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   646
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
   647
implementorForDepth:depth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   648
    "return the class, which best implements images of depth"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   649
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   650
    depth == 1 ifTrue:[^ Depth1Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   651
    depth == 2 ifTrue:[^ Depth2Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   652
    depth == 4 ifTrue:[^ Depth4Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   653
    depth == 8 ifTrue:[^ Depth8Image].
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
   654
    depth == 15 ifTrue:[^ Depth16Image].  "/ kludge for 15bit XFree
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   655
    depth == 16 ifTrue:[^ Depth16Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   656
    depth == 24 ifTrue:[^ Depth24Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   657
    ^ self
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   658
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   659
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   660
!Image class methodsFor:'screen capture'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   661
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   662
fromScreen
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   663
    "return an image of the full screen"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   664
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   665
    |display|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   666
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   667
    display := Screen current.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   668
    ^ self fromScreen:(0@0 corner:(display width @ display height))
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   669
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   670
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   671
     Image fromScreen
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   672
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   673
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   674
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   675
fromScreen:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   676
    "return an image of a part of the screen"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   677
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   678
    ^ self fromScreen:aRectangle on:Screen current 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   679
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   680
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   681
     Image fromScreen:(0@0 corner:100@100)
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   682
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   683
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   684
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   685
fromScreen:aRectangle on:aDisplay
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   686
    "return an image of a part of the screen, which may be on
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   687
     another Display."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   688
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   689
    |depth vis img|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   690
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   691
    depth := aDisplay depth.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   692
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   693
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   694
    "/ 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
   695
    "/ (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
   696
    "/  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
   697
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   698
    vis := aDisplay visualType.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   699
    (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   700
	depth > 8 ifTrue:[
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   701
	    depth := 24.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   702
	]
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   703
    ].
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   704
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   705
    img := (self implementorForDepth: depth) new.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   706
    ^ img fromScreen:aRectangle on:aDisplay
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   707
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   708
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   709
     Image fromScreen:(0@0 corner:100@100)
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   710
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   711
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   712
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   713
fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   714
    "return an image of a part of the screen; 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   715
     let user specify screen area."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   716
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   717
    ^ self fromScreen:(Rectangle fromUser)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   718
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   719
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   720
     Image fromScreenArea
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   721
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   722
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   723
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   724
fromUser
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   725
    "return an image of a part of the screen; let user specify screen area.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   726
     Same as fromScreenArea, for ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   727
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   728
    ^ self fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   729
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   730
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   731
     Image fromUser
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   732
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   733
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   734
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   735
fromView:aView
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   736
    "return an image taken from a views contents as currently
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   737
     on the screen. The returned image has the same depth and photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   738
     as the Display. Notice, that for invisible or partial covered
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   739
     views, the returned Image is NOT correct. You may want to raise
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   740
     the view before using this method."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   741
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   742
    |org dev|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   743
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
   744
    dev := aView graphicsDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   745
    org := dev translatePoint:(0@0)
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
   746
                         from:(aView id)
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
   747
                           to:dev rootWindowId.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   748
    ^ self fromScreen:(org extent:aView extent) on:dev
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   749
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   750
    "
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   751
     Image fromView:(NewLauncher allInstances first topView)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   752
     Image fromView:(SystemBrowser allInstances first topView)
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   753
    "
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
   754
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
   755
    "Modified: 28.5.1996 / 20:23:32 / cg"
157
claus
parents: 154
diff changeset
   756
! !
claus
parents: 154
diff changeset
   757
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   758
!Image methodsFor:'accessing'!
48194c26a46c Initial revision
claus
parents:
diff changeset
   759
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   760
bitsPerSample
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   761
    "return the number of bits per sample.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   762
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   763
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   764
    ^ bitsPerSample
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   765
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   766
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   767
colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   768
    "return the colormap"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   769
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   770
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   771
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   772
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   773
colorMap:anArrayOfArrays
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   774
    "set the colorMap"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   775
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   776
    colorMap := anArrayOfArrays.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   777
    photometric isNil ifTrue:[photometric := #palette].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   778
    deviceForm notNil ifTrue:[self release]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   779
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   780
    "Modified: 31.8.1995 / 03:05:59 / claus"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   781
    "Modified: 23.4.1996 / 10:57:32 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   782
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   783
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   784
depth
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   785
    "return the depth of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   786
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   787
    ^ self bitsPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   788
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   789
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   790
device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   791
    "return the device, the receiver is associated with.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   792
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   793
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   794
    ^ device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   795
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   796
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   797
extent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   798
    "return the images extent"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   799
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   800
    ^ width@height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   801
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   802
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   803
fullColorId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   804
    "return the id of the full color image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   805
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   806
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   807
    fullColorDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   808
    ^ fullColorDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   809
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   810
728
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   811
graphicsDevice
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   812
    "same as #device - for ST-80 compatibility"
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   813
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   814
    ^ device
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   815
!
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
   816
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   817
height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   818
    "return the height of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   819
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   820
    ^ height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   821
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   822
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   823
id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   824
    "return the id of the image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   825
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   826
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   827
    deviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   828
    ^ deviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   829
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   830
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   831
monochromeId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   832
    "return the id of the monochrome image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   833
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   834
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   835
    monoDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   836
    ^ monoDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   837
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   838
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   839
palette 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   840
    "return the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   841
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   842
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   843
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   844
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   845
palette:aColormap 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   846
    "set the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   847
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   848
    colorMap := aColormap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   849
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   850
    "Created: 1.2.1996 / 15:09:25 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   851
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   852
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   853
photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   854
    "return the photometric, a symbol such as #palette, #rgb etc."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   855
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   856
    ^ photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   857
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   858
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   859
samplesPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   860
    "return the number of samples per pixel in the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   861
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   862
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   863
    ^ samplesPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   864
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   865
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   866
width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   867
    "return the width of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   868
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   869
    ^ width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   870
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   871
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   872
!Image methodsFor:'accessing - pixels'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   873
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   874
at:aPoint
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   875
    "retrieve the pixel at aPoint; return a color.
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   876
     Pixels start at 0@0 for upper left pixel, end at
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   877
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   878
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   879
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   880
     (it is meant to access individual pixels - for example, in a bitmap editor)"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   881
48194c26a46c Initial revision
claus
parents:
diff changeset
   882
    ^ self atX:aPoint x y:aPoint y
48194c26a46c Initial revision
claus
parents:
diff changeset
   883
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   884
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   885
at:aPoint put:aColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   886
    "set the pixel at aPoint to aColor.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   887
     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
   888
     (width-1)@(height-1) for lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   889
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   890
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   891
     (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
   892
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   893
    ^ self atX:aPoint x y:aPoint y put:aColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   894
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   895
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   896
atPoint:aPoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   897
    "ST-80 compatibility: return the pixelValue at:aPoint."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   898
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   899
    ^ self valueAtX:aPoint x y:aPoint y
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   900
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   901
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   902
atX:x y:y
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   903
    "retrieve a pixel at x/y; return a color.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   904
     Pixels start at 0@0 for upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   905
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   906
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   907
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   908
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   909
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   910
    |pixel maxPixel r g b|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   911
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   912
    pixel := self valueAtX:x y:y.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   913
    photometric == #blackIs0 ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   914
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   915
        ^ Color gray:(pixel * (100 / maxPixel)).
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   916
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   917
    photometric == #whiteIs0 ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   918
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   919
        ^ Color gray:100 - (pixel * (100 / maxPixel)).
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   920
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   921
    photometric == #palette ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   922
        ^ colorMap at:(pixel + 1)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   923
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   924
    photometric == #rgb ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   925
        r := (pixel bitShift:16) bitAnd:16rFF.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   926
        g := (pixel bitShift:8) bitAnd:16rFF.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   927
        b := pixel bitAnd:16rFF.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   928
        ^ Color red:r / 255 * 100
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   929
              green:g / 255 * 100
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   930
               blue:b / 255 * 100
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   931
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   932
    self error:'invalid photometric'
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   933
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
   934
    "Modified: 28.5.1996 / 20:54:59 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   935
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   936
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   937
atX:x y:y put:aColor
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   938
    "set the pixel at x/y to aColor.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   939
     Pixels start at 0@0 for the upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   940
     (width-1)@(height-1) for the lower right pixel.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   941
     This method checks if the color can be stored in the image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   942
     (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
   943
     You should not use this method for image-processing, it is very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   944
     (it is meant to access individual pixels - for example, in a bitmap editor)"
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   945
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   946
    |pixel maxPixel|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   947
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   948
    photometric == #whiteIs0 ifTrue:[
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   949
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   950
	pixel := maxPixel - (aColor brightness * maxPixel) rounded.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   951
    ] ifFalse:[
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   952
	photometric == #blackIs0 ifTrue:[
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   953
	    maxPixel := (1 bitShift:self bitsPerPixel) - 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   954
	    pixel := (aColor brightness * maxPixel) rounded.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   955
	] ifFalse:[
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   956
	    photometric ~~ #palette ifTrue:[
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   957
		self error:'format not supported'.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   958
		^ nil
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   959
	    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   960
	    pixel := colorMap indexOf:aColor.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   961
	    pixel == 0 ifTrue:[
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   962
		"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   963
		 the color to be stored is not in the images colormap
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   964
		"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   965
		self error:'invalid color'
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   966
	    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   967
	    pixel := pixel - 1
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   968
	]
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   969
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   970
    self atX:x y:y putValue:pixel.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   971
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
   972
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   973
atX:x y:y putValue:aPixelValue
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   974
    "set the pixel at x/y to aPixelValue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   975
     The interpretation of the pixelValue depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   976
     and the colormap. (see also: Image>>atX:y:put:)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   977
     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
   978
     (width-1) @ (height-1) for the lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   979
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   980
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   981
     (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
   982
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   983
    ^ self subclassResponsibility
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   984
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   985
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   986
bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   987
    "return the raw image data; depending on the photometric,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   988
     this has to be interpreted as monochrome, greyscale,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   989
     palette or rgb data. It is also packed to be dense, so
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   990
     a 4 bitPerSample palette image will store 2 pixels per byte."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   991
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   992
    ^ bytes
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   993
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   994
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   995
data
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   996
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   997
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   998
    ^ bytes
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   999
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1000
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1001
data:aByteArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1002
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1003
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1004
    bytes := aByteArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1005
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1006
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1007
valueAt:aPoint
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1008
    "retrieve the pixelValue at aPoint; return an integer number.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1009
     Pixels start at 0@0 for upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1010
     width-1@height-1 for lower right pixel.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1011
     The returned numbers interpretation depends on the photometric
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1012
     and the colormap. (see also Image>>at: and Image>>atX:y:)
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  1013
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1014
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1015
     (it is meant to access individual pixels - for example, in a bitmap editor)"
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1016
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1017
    ^ self valueAtX:aPoint x y:aPoint y
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1018
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1019
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1020
valueAtX:x y:y
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1021
    "retrieve the pixelValue at aPoint; return an integer number.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1022
     Pixels start at 0/0 for upper left pixel, and end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1023
     width-1@height-1 for lower right pixel.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1024
     The returned numbers interpretation depends on the photometric
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1025
     and the colormap. (see also Image>>at: and Image>>atX:y:)
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1026
     You should not use this method for image-processing of
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1027
     big images, its very slow ... 
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1028
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  1029
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  1030
    ^ self subclassResponsibility
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1031
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1032
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1033
!Image methodsFor:'accessing - private'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1034
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1035
bits:aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1036
    "set the raw data.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1037
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1038
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1039
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1040
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1041
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1042
    bytes := aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1043
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1044
    "Modified: 23.4.1996 / 11:08:28 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  1045
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  1046
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1047
bitsPerSample:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1048
    "set the number of bits per sample. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1049
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1050
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1051
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1052
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1053
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1054
    bitsPerSample := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1055
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1056
    "Modified: 23.4.1996 / 11:08:31 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1057
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1058
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1059
depth:d
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1060
    "set the depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1061
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1062
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1063
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1064
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1065
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1066
    d == 24 ifTrue:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1067
        samplesPerPixel := 3.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1068
        bitsPerSample := #(8 8 8)
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1069
    ] ifFalse:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1070
        samplesPerPixel := 1.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1071
        bitsPerSample := Array with:d 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1072
    ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1073
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1074
    "Modified: 23.4.1996 / 11:08:34 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1075
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1076
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1077
extent:anExtent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1078
    "set the images extent.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1079
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1080
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1081
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1082
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1083
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1084
    width := anExtent x.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1085
    height := anExtent y
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1086
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1087
    "Modified: 23.4.1996 / 11:08:38 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1088
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1089
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1090
height:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1091
    "set the height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1092
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1093
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1094
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1095
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1096
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1097
    height := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1098
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1099
    "Modified: 23.4.1996 / 11:08:40 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1100
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1101
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1102
photometric:aSymbol
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1103
    "set the photometric interpretation of the pixel values.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1104
     The argument, aSymbol is one of:
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1105
        #blackIs0, #whiteIs0, #palette, #rgb
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1106
     See TIFF documentation, from which the photometric concept is borrowed.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1107
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1108
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1109
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1110
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1111
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1112
    photometric := aSymbol
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1113
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1114
    "Modified: 23.4.1996 / 11:08:08 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1115
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1116
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1117
samplesPerPixel:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1118
    "set the array of samples per pixel.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1119
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1120
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1121
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1122
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1123
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1124
    samplesPerPixel := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1125
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1126
    "Modified: 23.4.1996 / 11:08:45 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1127
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1128
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1129
width:aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1130
    "set the width of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1131
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1132
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1133
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1134
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1135
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1136
    width := aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1137
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1138
    "Modified: 23.4.1996 / 11:08:48 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  1139
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  1140
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1141
width:w height:h 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1142
    "set the width and height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1143
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1144
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1145
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1146
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1147
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1148
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1149
    height := h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1150
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1151
    "Modified: 23.4.1996 / 11:08:53 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1152
!
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  1153
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1154
width:w height:h depth:d
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1155
    "set the width, height and depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1156
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1157
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1158
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1159
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1160
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1161
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1162
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1163
    self depth:d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1164
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1165
    "Modified: 23.4.1996 / 11:08:56 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1166
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1167
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1168
width:w height:h depth:d fromArray:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1169
    "set the width, height, depth and pixels of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1170
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1171
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1172
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1173
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1174
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1175
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1176
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1177
    self depth:d.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1178
    bytes := bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1179
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1180
    "Modified: 23.4.1996 / 11:08:59 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1181
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1182
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1183
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
  1184
    "set all relevant internal state of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1185
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1186
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1187
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1188
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1189
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1190
    width := w.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1191
    height := h.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1192
    photometric := p.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1193
    samplesPerPixel := spp.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1194
    bitsPerSample := bps.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1195
    colorMap := cm.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1196
    bytes := pixels.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1197
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1198
    "Created: 23.4.1996 / 11:06:40 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1199
    "Modified: 23.4.1996 / 11:09:02 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1200
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  1201
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1202
!Image methodsFor:'binary storage'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1203
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1204
readBinaryContentsFrom: stream manager: manager
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1205
    "read a binary representation of an image from stream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1206
     Redefined to flush any device data."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1207
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1208
    super readBinaryContentsFrom: stream manager: manager.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1209
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1210
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1211
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1212
    fullColorDeviceForm := nil.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1213
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1214
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1215
storeBinaryDefinitionOn: stream manager: manager
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1216
    "store a binary representation of the receiver on stream.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1217
     This is an internal interface for binary storage mechanism.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1218
     Redefined to not store the device form (which is recreated at
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1219
     load time anyway)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1220
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1221
    |tDevice tDeviceForm tMonoDeviceForm tFullColorDeviceForm|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1222
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1223
    tDevice := device.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1224
    tDeviceForm := deviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1225
    tMonoDeviceForm := monoDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1226
    tFullColorDeviceForm := fullColorDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1227
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1228
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1229
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1230
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1231
    fullColorDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1232
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1233
    super storeBinaryDefinitionOn: stream manager: manager.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1234
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1235
    device := tDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1236
    deviceForm := tDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1237
    monoDeviceForm := tMonoDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1238
    fullColorDeviceForm := tFullColorDeviceForm.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1239
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1240
    "Modified: 23.4.1996 / 09:30:50 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1241
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  1242
48194c26a46c Initial revision
claus
parents:
diff changeset
  1243
!Image methodsFor:'converting'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1244
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1245
asCachedImage
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1246
    "return the receiver associated to the current screens device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1247
     For ST-80 compatibility 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1248
     (ST/X uses Image for both device- and nonDevice-images)"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1249
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1250
    ^ self on:Screen current
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1251
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1252
    "Modified: 23.4.1996 / 11:10:32 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1253
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1254
48194c26a46c Initial revision
claus
parents:
diff changeset
  1255
asFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1256
    "get a device form, with best possible approximation.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1257
     remember it in case someone asks again."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1258
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1259
    |form|
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1260
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1261
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1262
48194c26a46c Initial revision
claus
parents:
diff changeset
  1263
    (photometric == #palette) ifTrue:[
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1264
	form := self paletteImageAsFormOn:aDevice
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1265
    ] ifFalse:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1266
	(photometric == #rgb) ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1267
	    form := self rgbImageAsFormOn:aDevice
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1268
	] ifFalse:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1269
	    form := self greyImageAsFormOn:aDevice
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1270
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1271
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  1272
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1273
    (device isNil or:[aDevice == device]) ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1274
	"remember this form in the receiver ..."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1275
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1276
	form notNil ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1277
	    deviceForm := form.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1278
	    device isNil ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1279
		device := aDevice.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1280
		Lobby register:self
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1281
	    ] ifFalse:[
162
claus
parents: 158
diff changeset
  1282
		Lobby registerChange:self
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1283
	    ].
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1284
	    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1285
	     can save space, by not keeping the images data-bits
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1286
	     twice (here and in the device form)
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1287
	    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1288
	    form forgetBits
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1289
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1290
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  1291
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1292
    ^ form
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1293
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1294
48194c26a46c Initial revision
claus
parents:
diff changeset
  1295
asMonochromeFormOn:aDevice
48194c26a46c Initial revision
claus
parents:
diff changeset
  1296
    "get a monochrome device form"
48194c26a46c Initial revision
claus
parents:
diff changeset
  1297
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1298
    |form|
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1299
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1300
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm].
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1301
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1302
    (photometric == #palette) ifTrue:[
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1303
	form := self paletteImageAsMonoFormOn:aDevice
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1304
    ] ifFalse:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1305
	(photometric == #rgb) ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1306
	    form := self rgbImageAsMonoFormOn:aDevice
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1307
	] ifFalse:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1308
	    form := self greyImageAsMonoFormOn:aDevice
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1309
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1310
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  1311
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1312
    (device isNil or:[aDevice == device]) ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1313
	"remember this form in the receiver ..."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1314
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1315
	form notNil ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1316
	    monoDeviceForm := form.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1317
	    device isNil ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1318
		device := aDevice.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1319
		Lobby register:self
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1320
	    ] ifFalse:[
162
claus
parents: 158
diff changeset
  1321
		Lobby registerChange:self
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1322
	    ].
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1323
	    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1324
	     can save space, by not keeping the images data-bits
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1325
	     twice (here and in the device form)
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1326
	    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1327
	    form forgetBits
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1328
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1329
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  1330
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1331
    ^ form
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1332
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1333
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1334
fromForm:aForm
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1335
    "setup the receiver from a form"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1336
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1337
    |map c0 c1|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1338
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1339
    width := aForm width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1340
    height := aForm height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1341
    bytes := aForm bits.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1342
    bitsPerSample := self bitsPerSample.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1343
    samplesPerPixel := self samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1344
    map := aForm colorMap.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1345
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1346
    aForm depth == 1 ifTrue:[
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1347
        map isNil ifTrue:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1348
            photometric := #whiteIs0
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1349
        ] ifFalse:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1350
            c0 := map at:1.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1351
            c1 := map at:2.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1352
            ((c0 = Color white)
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1353
            and:[c1 = Color black]) ifTrue:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1354
                photometric := #whiteIs0
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1355
            ] ifFalse:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1356
                ((c0 = Color black)
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1357
                and:[c1 = Color white]) ifTrue:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1358
                    photometric := #blackIs0
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1359
                ] ifFalse:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1360
                    photometric := #palette.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1361
                    colorMap := Array with:c0 with:c1.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1362
                ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1363
            ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1364
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1365
    ] ifFalse:[
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1366
        map notNil ifTrue:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1367
            photometric := #palette.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1368
            colorMap := map copy.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1369
        ] ifFalse:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1370
            "
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1371
             photometric stays at default
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1372
             (which is rgb for d24, greyscale for others)
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1373
            "
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1374
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1375
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1376
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1377
    "Modified: 23.4.1996 / 11:11:00 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1378
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1379
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1380
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1381
    "setup the receiver from another image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1382
     Color precision may be lost, if conversion is from a higher depth
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1383
     image. 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1384
     WARNING:
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1385
     This implementation is a slow fallback (the loop over the
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1386
     source pixels is very slow). If this method is used heavily, you
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1387
     may want to redefine it in concrete subclasses for common source images."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1388
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1389
    width := anImage width.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1390
    height := anImage height.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1391
    bytes := ByteArray uninitializedNew:(self bytesPerRow * height).
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1392
    bitsPerSample := self bitsPerSample.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1393
    samplesPerPixel := self samplesPerPixel.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1394
    self colormapFromImage:anImage.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1395
    anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr |
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1396
	self atX:x y:y put:clr
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1397
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1398
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1399
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1400
     |i i2 i4 i8 i24|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1401
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1402
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1403
     i inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1404
     i2 := Depth2Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1405
     i2 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1406
     i4 := Depth4Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1407
     i4 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1408
     i8 := Depth8Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1409
     i8 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1410
     i24 := Depth24Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1411
     i24 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1412
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1413
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1414
    "Created: 20.9.1995 / 00:59:03 / claus"
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1415
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1416
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1417
fromSubImage:anImage in:aRectangle
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1418
    "setup the receiver from another image, extracting a rectangular
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1419
     area. Color precision may be lost, if conversion is from a higher depth
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1420
     image. 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1421
     WARNING:
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1422
     This implementation is a slow fallback (the loop over the
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1423
     source pixels is very slow). If this method is used heavily, you
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1424
     may want to redefine it in concrete subclasses for the common case of
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1425
     of creating a subImage with the same depth & palette."
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1426
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1427
    |x0 y0|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1428
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1429
    width := aRectangle width + 1.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1430
    height := aRectangle height + 1.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1431
    bytes := ByteArray uninitializedNew:(self bytesPerRow * height).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1432
    bitsPerSample := self bitsPerSample.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1433
    samplesPerPixel := self samplesPerPixel.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1434
    self colormapFromImage:anImage.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1435
    x0 := aRectangle left.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1436
    y0 := aRectangle top.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1437
    ((photometric == anImage photometric)
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1438
    and:[self bitsPerPixel == anImage bitsPerPixel
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1439
    and:[colorMap = anImage colorMap]]) ifTrue:[
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1440
	"/ can do it by value
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1441
	anImage valuesFromX:x0  y:y0 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1442
			toX:aRectangle right y:aRectangle bottom 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1443
			 do:[:x :y :pixelValue |
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1444
	    self atX:x-x0 y:y-y0 putValue:pixelValue.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1445
	]
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1446
    ] ifFalse:[
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1447
	"/ must do it by colors
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1448
	anImage colorsFromX:x0  y:y0 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1449
			toX:aRectangle right y:aRectangle bottom 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1450
			 do:[:x :y :clr |
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1451
	    self atX:x-x0 y:y-y0 put:clr.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1452
	]
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1453
    ].
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1454
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1455
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1456
     |i i2 i4 i8 i24|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1457
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1458
     i := Image fromFile:'bitmaps/garfield.gif'.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1459
     i inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1460
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1461
     i4 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1462
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1463
     i8 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1464
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1465
     i24 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1466
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1467
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1468
    "Created: 20.9.1995 / 01:06:02 / claus"
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1469
    "Modified: 20.9.1995 / 10:15:37 / claus"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1470
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1471
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1472
monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1473
    "return a monochrome device image of the receiver for aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1474
     (monochrome, even if device supports colors)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1475
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1476
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1477
    (device notNil and:[aDevice ~~ device]) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1478
	"oops, I am already accociated to another device
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1479
	 - need a copy ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1480
	"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1481
	^ self copy monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1482
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1483
    monoDeviceForm := self asMonochromeFormOn:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1484
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1485
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1486
on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1487
    "return an image with the same pixels as the receiver, but
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1488
     associated to aDevice. If the receiver is not yet bound to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1489
     a device, this will be the receiver. Otherwise, a new image
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1490
     is returned."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1491
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1492
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1493
    (device notNil and:[aDevice ~~ device]) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1494
	"oops, I am already accociated to another device
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1495
	 - need a copy ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1496
	"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1497
	^ self copy on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1498
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1499
    deviceForm := self asFormOn:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1500
    device := aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1501
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1502
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1503
!Image methodsFor:'converting greyscale images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1504
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1505
greyImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1506
    "return a thresholded grey-deviceForm from the grey image."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1507
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1508
    |pictureDepth nPlanes f|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1509
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1510
    nPlanes := samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1511
    (nPlanes == 2) ifTrue:[
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1512
	'IMAGE: alpha plane ignored' errorPrintNL.
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1513
	nPlanes := 1
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1514
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1515
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1516
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1517
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1518
    "monochrome is very easy ..."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1519
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1520
    (pictureDepth == 1) ifTrue:[
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1521
	^ Form width:width height:height fromArray:bytes on:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1522
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1523
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1524
    (aDevice visualType == #StaticGray) ifTrue:[
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1525
	(aDevice depth == pictureDepth) ifTrue:[
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1526
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1527
	    "greyscale is easy, if the depths match"
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1528
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1529
	    f := Form width:width height:height depth:pictureDepth on:aDevice.
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1530
	    f isNil ifTrue:[^ nil].
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1531
	    f initGC.
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1532
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1533
	    "if device has white at the opposite corner ..."
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1534
	    ((aDevice blackpixel == 0) == (photometric == #blackIs0)) ifFalse:[
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1535
		"have to invert bits"
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1536
		f function:#copyInverted
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1537
	    ].
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1538
	    aDevice drawBits:bytes depth:pictureDepth width:width height:height
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1539
			    x:0 y:0
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1540
			 into:(f id)
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1541
			    x:0 y:0 width:width height:height with:(f gcId).
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1542
	    ^ f
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1543
	].
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1544
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1545
	"the image has more greylevels than the display - dither"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1546
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1547
"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1548
coming soon ...
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1549
	DitherAlgorithm == #error ifTrue:[
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1550
	    ^ self greyImageAsErrorDitheredGreyFormOn:aDevice
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1551
	].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1552
"
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1553
	DitherAlgorithm == #pattern ifTrue:[
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1554
	    ^ self greyImageAsPatternDitheredGreyFormOn:aDevice
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1555
	].
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1556
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1557
	"no dither, simply cut off information"
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1558
	(aDevice depth == 1) ifTrue:[
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1559
	    "for monochrome, there is a special method to do this"
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1560
	    ^ self greyImageAsMonoFormOn:aDevice
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1561
	].
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1562
	"the general case, will take as many bits from the image
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1563
	 as possible for the device"
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1564
	^ self greyImageAsGreyFormOn:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1565
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1566
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1567
306
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  1568
    (aDevice visualType == #PseudoColor 
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  1569
    or:[aDevice visualType == #GrayScale
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  1570
    or:[aDevice visualType == #StaticColor]]) ifTrue:[
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1571
	^ self greyImageAsPseudoFormOn:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1572
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1573
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1574
    (aDevice visualType == #TrueColor) ifTrue:[
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1575
	^ self greyImageAsTrueColorFormOn:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1576
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1577
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1578
    self error:'cannot convert this format'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1579
    ^ nil
306
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  1580
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  1581
    "Modified: 11.12.1995 / 18:55:01 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1582
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1583
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1584
greyImageAsGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1585
    "return an 8-bit Form from the grey image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1586
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1587
    |wideBits pictureDepth f map nplanes ncells
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1588
     inverse 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1589
     mapSize  "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1590
     oldValue "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1591
     newValue "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1592
     shift    "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1593
     shift2   "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1594
     shift3   "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1595
     shift4   "{ Class: SmallInteger }" |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1596
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1597
    (aDevice depth == 8) ifFalse:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1598
	'IMAGE: non-8 plane displays not supported' errorPrintNL.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1599
	^ self greyImageAsMonoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1600
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1601
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1602
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1603
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1604
    wideBits := ByteArray uninitializedNew:(width * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1605
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1606
    map := ByteArray uninitializedNew:(1 bitShift:pictureDepth).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1607
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1608
    "find the real number of server-planes"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1609
    nplanes := 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1610
    ncells := 256.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1611
    [aDevice ncells < ncells] whileTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1612
	nplanes := nplanes - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1613
	ncells := ncells // 2
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1614
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1615
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1616
    "prepare translation table"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1617
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1618
    shift := nplanes - pictureDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1619
    shift2 := shift - pictureDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1620
    shift3 := shift2 - pictureDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1621
    shift4 := shift3 - pictureDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1622
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1623
    inverse := aDevice blackpixel ~~ 0.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1624
    photometric == #blackIs0 ifFalse:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1625
	inverse := inverse not
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1626
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1627
    mapSize := map size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1628
    1 to:mapSize do:[:index |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1629
	oldValue := index - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1630
	newValue := oldValue bitShift:shift.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1631
	newValue := newValue bitOr:(oldValue bitShift:shift2).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1632
	newValue := newValue bitOr:(oldValue bitShift:shift3).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1633
	newValue := newValue bitOr:(oldValue bitShift:shift4).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1634
	inverse ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1635
	    map at:(map size - index + 1) put:newValue
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1636
	] ifFalse:[
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1637
	    map at:index put:newValue
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1638
	]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1639
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1640
    bytes expandPixels:pictureDepth
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1641
		width:width 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1642
	       height:height
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1643
		 into:wideBits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1644
	      mapping:map.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1645
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1646
    f := Form width:width height:height depth:8 on:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1647
    f isNil ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1648
    f initGC.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1649
    aDevice drawBits:wideBits depth:8 width:width height:height
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1650
		       x:0 y:0
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1651
		    into:(f id) x:0 y:0 width:width height:height with:(f gcId).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1652
    ^ f
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1653
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1654
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1655
greyImageAsMonoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1656
    "return a (thresholded) monochrome Form from the image."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1657
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1658
    ^ self subclassResponsibility
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1659
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1660
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1661
greyImageAsPatternDitheredGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1662
    "return a dithered greyForm from the grey image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1663
     Works for any source/destination depths, but very very slow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1664
     since each pixel is processed individually.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1665
     Usually redefined by subclasses for more performance"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1666
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1667
    |f last      
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1668
     x0            "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1669
     w             "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1670
     h             "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1671
     run           "{Class: SmallInteger }" |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1672
694
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1673
    Transcript showCR:'slow dithering ..'. Transcript endEntry.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1674
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1675
    w := width - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1676
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1677
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1678
    "draw each pixel using dither color (let others do the dithering)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1679
     although the code is simple, its very slow"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1680
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1681
    f := Form width:width height:height depth:aDevice depth on:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1682
    f isNil ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1683
    f initGC.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1684
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1685
    0 to:h do:[:dstY |
694
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1686
        x0 := 0.
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1687
        run := 0.
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1688
        last := nil.
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1689
        self atY:dstY from:0 to:w do:[:x :srcColor |
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1690
            |dstColor|
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1691
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1692
            srcColor ~~ last ifTrue:[
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1693
                (run ~~ 0) ifTrue:[
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1694
                    f fillRectangleX:x0 y:dstY width:run height:1.
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1695
                ].
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1696
                run := 0.
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1697
                dstColor := Color gray:(srcColor grayIntensity).
694
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1698
                f paint:dstColor.
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1699
                last := srcColor.
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1700
                x0 := x
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1701
            ].
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1702
            run := run + 1
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1703
        ].
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1704
        f fillRectangleX:x0 y:dstY width:run height:1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1705
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1706
    ^ f
694
f6c8fc8419bd showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1707
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1708
    "Modified: 28.5.1996 / 20:55:02 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1709
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1710
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1711
greyImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1712
    "return an 8-bit pseudo Form from the grey image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1713
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1714
    |wideBits pictureDepth f map  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1715
     colorMap usedColors nUsed aColor 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1716
     nColors "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1717
     range id|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1718
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1719
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1720
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1721
    (#(2 4 8) includes:pictureDepth) ifFalse:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1722
        self error:'currently only depth-2, 4 or 8 supported'.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1723
        ^ nil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1724
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1725
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1726
    wideBits := ByteArray uninitializedNew:(width * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1727
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1728
    (pictureDepth == 8) ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1729
        "for 8bits, we scan for used colors first;
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1730
         to avoid allocating too many colors"
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1731
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1732
        usedColors := bytes usedValues.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1733
        nUsed := usedColors max + 1.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1734
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1735
        colorMap := Array new:nUsed.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1736
        photometric == #blackIs0 ifTrue:[
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1737
            usedColors do:[:grey |
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1738
                colorMap at:(grey + 1) put:(Color gray:(100.0 / 256.0 * grey))
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1739
            ]
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1740
        ] ifFalse:[
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1741
            usedColors do:[:grey |
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1742
                colorMap at:(grey + 1) put:(Color gray:(100 - (100.0 / 256.0 * grey)))
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1743
            ]
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1744
        ]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1745
    ] ifFalse:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1746
        nColors := (1 bitShift:pictureDepth).
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1747
        colorMap := Array new:nColors.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1748
        range := 100 / (nColors - 1) asFloat.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1749
        photometric == #blackIs0 ifTrue:[
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1750
            1 to:nColors do:[:i |
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1751
                colorMap at:i put:(Color gray:(i - 1) * range).
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1752
            ].
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1753
        ] ifFalse:[
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1754
            1 to:nColors do:[:i |
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1755
                colorMap at:(nColors - i + 1) put:(Color gray:(i - 1) * range).
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1756
            ].
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1757
        ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1758
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1759
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1760
    "XXX should reduce 8->6->4->2 planes, if not all colors could be allocated"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1761
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1762
    "setup the translation map"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1763
    map := ByteArray uninitializedNew:256.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1764
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1765
    1 to:nColors do:[:i |
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1766
        aColor := colorMap at:i.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1767
        aColor notNil ifTrue:[
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1768
            aColor := aColor on:aDevice.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1769
            colorMap at:i put:aColor.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1770
            id := aColor colorId.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1771
            id notNil ifTrue:[
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1772
                map at:i put:id
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1773
            ] ifFalse:[
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1774
                map at:i put:0
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1775
            ]
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1776
        ]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1777
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1778
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1779
    "expand & translate"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1780
    bytes expandPixels:pictureDepth
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1781
                width:width 
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1782
               height:height
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1783
                 into:wideBits
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1784
              mapping:map.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1785
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1786
    f := Form width:width height:height depth:8 on:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1787
    f isNil ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1788
    f colorMap:colorMap. 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1789
    f initGC.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1790
    aDevice drawBits:wideBits depth:8 width:width height:height
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1791
                       x:0 y:0
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1792
                    into:(f id) x:0 y:0 width:width height:height with:(f gcId).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1793
    ^ f
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1794
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  1795
    "Modified: 28.5.1996 / 20:55:57 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1796
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1797
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1798
greyImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1799
    "return a true-color device-form for the grey-image receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1800
     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
  1801
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1802
    |depth  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1803
     myDepth "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1804
     nColors "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1805
     colorValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1806
     scaleDown scaleRed scaleGreen scaleBlue redShift blueShift greenShift
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1807
     form imageBitsdestIndex 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1808
     bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits destIndex
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1809
     nPixels|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1810
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1811
    "/ this is a slow fallback method; this ought to be
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1812
    "/ redefined in DepthxImage for more performance.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1813
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1814
    depth := aDevice depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1815
    myDepth := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1816
    myDepth > 12 ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1817
	self error:'unsupported trueColor depth in greyImageAsTrueColorFormOn:'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1818
	^ nil
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1819
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  1820
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1821
    "/ compute scale to map from my pixels into devices range
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1822
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1823
    scaleDown := 1 bitShift:myDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1824
    scaleRed := (1 bitShift:aDevice bitsRed).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1825
    scaleGreen := (1 bitShift:aDevice bitsGreen).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1826
    scaleBlue := (1 bitShift:aDevice bitsBlue).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1827
    redShift := aDevice shiftRed.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1828
    greenShift := aDevice shiftGreen.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1829
    blueShift := aDevice shiftBlue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1830
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1831
    nColors := (1 bitShift:myDepth).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1832
    colorValues := Array new:nColors.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1833
    1 to:nColors do:[:i |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1834
	|v gv bv rv nv|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1835
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1836
	"/ scale down to 0..1
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1837
	v := (i-1) / scaleDown.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1838
	rv := (v * scaleRed) rounded.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1839
	gv := (v * scaleGreen) rounded.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1840
	bv := (v * scaleBlue) rounded.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1841
	nv := rv bitShift:redShift.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1842
	nv := nv bitOr:(gv bitShift:greenShift).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1843
	nv := nv bitOr:(bv bitShift:blueShift).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1844
	colorValues at:i put:nv
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1845
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1846
    photometric == #whiteIs0 ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1847
	"/ reverse the order; 0 is brightest
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1848
	colorValues reverse
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1849
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1850
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1851
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  1852
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  1853
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1854
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1855
    "/ for now, only support some depths
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1856
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1857
    usedDeviceBitsPerPixel == 16 ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1858
	imageBits := ByteArray uninitializedNew:(width * height * 2).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1859
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1860
	"/ now, walk over the image and replace
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1861
	"/ colorMap indices by color values in the bits array
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1862
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1863
	destIndex := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1864
	0 to:height-1 do:[:y |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1865
	    0 to:width-1 do:[:x |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1866
		|greyValue|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1867
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1868
		greyValue := self valueAtX:x y:y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1869
		imageBits wordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1870
		destIndex := destIndex + 2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1871
	    ]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1872
	]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1873
    ] ifFalse:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1874
	usedDeviceBitsPerPixel == 32 ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1875
	    imageBits := ByteArray uninitializedNew:(width * height * 4).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1876
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1877
	    "/ now, walk over the image and replace
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1878
	    "/ colorMap indices by color values in the bits array
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1879
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1880
	    destIndex := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1881
	    0 to:height-1 do:[:y |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1882
		0 to:width-1 do:[:x |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1883
		    |greyValue|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1884
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1885
		    greyValue := self valueAtX:x y:y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1886
		    imageBits doubleWordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1887
		    destIndex := destIndex + 4.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1888
		]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1889
	    ]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1890
	]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1891
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1892
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1893
    imageBits isNil ifTrue:[            
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1894
	'IMAGE: unimplemented trueColor depth on greyImageAsTrueColorFormOn:' errorPrintNL.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1895
	^ self paletteImageAsMonoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1896
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1897
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1898
    form :=
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1899
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1900
    form isNil ifTrue:[^ nil].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1901
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1902
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1903
    form 
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1904
	copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1905
	       width:width height:height 
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1906
		   x:0 y:0 toX:0 y:0. 
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1907
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1908
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1909
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1910
    "Created: 20.10.1995 / 22:05:10 / cg"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1911
    "Modified: 21.10.1995 / 19:30:37 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1912
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  1913
48194c26a46c Initial revision
claus
parents:
diff changeset
  1914
!Image methodsFor:'converting palette images'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1915
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1916
paletteImageAs2PlaneFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1917
    "return a 2-bit grey-deviceForm from the palette image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1918
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1919
    ^ self subclassResponsibility
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1920
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1921
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1922
paletteImageAsFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1923
    "return a device-form for the palette-image receiver"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1924
380
c5ffc6d48a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
  1925
    |type ddepth|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1926
379
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1927
    (ddepth := aDevice depth) == 1 ifTrue:[
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1928
	^ self paletteImageAsMonoFormOn:aDevice
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1929
    ].
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  1930
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1931
    ((type := aDevice visualType) == #StaticGray) ifTrue:[
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1932
	ddepth == 8 ifTrue:[
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1933
	    ^ self paletteImageAsGreyFormOn:aDevice
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1934
	].
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1935
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1936
	DitherAlgorithm == #pattern ifTrue:[
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1937
	    ^ self paletteImageAsPatternDitheredGreyFormOn:aDevice
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1938
	].
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1939
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1940
	ddepth == 2 ifTrue:[
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1941
	    ^ self paletteImageAs2PlaneFormOn:aDevice
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1942
	].
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1943
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1944
	^ self paletteImageAsMonoFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1945
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1946
    (type == #TrueColor) ifTrue:[
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1947
	^ self paletteImageAsTrueColorFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1948
    ].
306
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  1949
    (type == #PseudoColor) ifTrue:[
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1950
	^ self paletteImageAsPseudoFormOn:aDevice
306
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  1951
    ].
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  1952
    (type == #StaticColor) ifTrue:[
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
  1953
	^ self paletteImageAsPseudoFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1954
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1955
    "/ dump fallback: every device should implement b&w images ...
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  1956
    ^ self paletteImageAsMonoFormOn:aDevice
306
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  1957
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
  1958
    "Modified: 11.12.1995 / 16:34:52 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1959
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1960
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1961
paletteImageAsGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1962
    "return an 8-bit grey-deviceForm from the palette image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1963
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1964
    ^ self subclassResponsibility
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1965
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1966
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1967
paletteImageAsMonoFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1968
    "return a 1-bit mono-deviceForm from the palette image"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1969
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  1970
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1971
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1972
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1973
paletteImageAsPatternDitheredGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1974
    "return a dithered grey-deviceForm from the palette image."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1975
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  1976
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1977
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1978
48194c26a46c Initial revision
claus
parents:
diff changeset
  1979
paletteImageAsPseudoFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  1980
    "return a pseudo-deviceForm from the palette image."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1981
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1982
    |tempImage d temp8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1983
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1984
    d := self depth.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1985
    (#(1 2 4 8) includes:d) ifTrue:[ 
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1986
	"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1987
	 fallback code for some depth's:
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1988
	 create a temporary Depth8Image and use its conversion method
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1989
	"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1990
	temp8 := ByteArray uninitializedNew:(width * height).
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1991
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1992
	bytes expandPixels:d      
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1993
		     width:width 
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1994
		   height:height
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1995
		     into:temp8
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1996
		  mapping:nil.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1997
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1998
	tempImage := Image width:width height:height depth:8 fromArray:temp8.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1999
	tempImage colorMap:colorMap.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2000
	^ tempImage paletteImageAsPseudoFormOn:aDevice
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2001
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2002
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2003
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2004
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2005
paletteImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2006
    "return a true-color device-form for the palette-image receiver."
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2007
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2008
    |depth 
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2009
     myDepth "{ Class: SmallInteger }"
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2010
     nColors "{ Class: SmallInteger }"
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2011
     colorValues 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2012
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
194
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2013
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel 
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2014
     destIndex ok|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2015
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2016
    "/ this is a slow fallback method; this ought to be
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2017
    "/ redefined in DepthxImage for more performance.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2018
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2019
    depth := aDevice depth.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2020
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2021
    myDepth > 12 ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2022
	'IMAGE: depth > 12 not supported' errorPrintNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2023
	^ nil
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2024
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2025
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2026
    "/ gather r/g/b values for all colors in the map ...
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2027
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2028
    nColors := colorMap size.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2029
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2030
    "/ precompute scales to map from 0..100 into devices range
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2031
    "/ (this may be different for the individual components)
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2032
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2033
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2034
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2035
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2036
    redShift := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2037
    greenShift := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2038
    blueShift := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2039
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2040
    colorValues := Array uninitializedNew:nColors.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2041
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2042
    1 to:nColors do:[:index |
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2043
	|clr rv gv bv v "{ Class: SmallInteger }" |
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2044
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2045
	clr := colorMap at:index.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2046
	clr notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2047
	    rv := (clr red * scaleRed) rounded.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2048
	    gv := (clr green * scaleGreen) rounded.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2049
	    bv := (clr blue * scaleBlue) rounded.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2050
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2051
	    v := rv bitShift:redShift.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2052
	    v := v bitOr:(gv bitShift:greenShift).
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2053
	    v := v bitOr:(bv bitShift:blueShift).
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2054
	    colorValues at:index put:v.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2055
"/ clr print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2056
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2057
"/ ' -> ' print. v printNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2058
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2059
	]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2060
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2061
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2062
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  2063
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  2064
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2065
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2066
    "/ for now, only support some depths
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2067
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2068
    usedDeviceBitsPerPixel == 16 ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2069
	imageBits := ByteArray uninitializedNew:(width * height * 2).
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2070
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2071
	"/ now, walk over the image and replace
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2072
	"/ colorMap indices by color values in the bits array
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2073
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2074
	ok := false.
194
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2075
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2076
%{      /* OPTIONAL */
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2077
	if (__bothSmallInteger(_INST(height), _INST(width))
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2078
	 && __isArray(colorValues)
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2079
	 && __isByteArray(_INST(bytes))
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2080
	 && (myDepth == __MKSMALLINT(8))
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2081
	 && __isByteArray(imageBits)) {
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2082
	    int x, y, w, h, nPix;
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2083
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2084
	    unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2085
	    char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2086
	    OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2087
194
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2088
	    w = __intVal(_INST(width));
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2089
	    h = __intVal(_INST(height));
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2090
	    nPix = w * h;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2091
	    while (nPix > 0) {
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2092
		unsigned idx, v;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2093
		OBJ clr;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2094
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2095
		idx = *srcPtr;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2096
		clr = ap[idx];
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2097
		v = __intVal(clr);
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2098
#ifdef MSBFIRST
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2099
		((short *)dstPtr)[0] = v;
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2100
#else
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2101
		dstPtr[0] = (v>>8) & 0xFF;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2102
		dstPtr[1] = (v) & 0xFF;
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2103
#endif
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2104
		dstPtr += 2;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2105
		srcPtr += 1;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2106
		nPix--;
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2107
	    }
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2108
	    ok = true;
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2109
	}
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2110
%}.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2111
	ok ifFalse:[
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2112
	    "/ this fallback is only executed if some type is not
194
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2113
	    "/ what the primitive expects (for example, if the bytes-instvar
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2114
	    "/ is not a ByteArray) 
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2115
	    "/ or (more important) the source depth is not 8.
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2116
	    "/ The code below uses the (depth independent) but slower
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2117
	    "/ #valueAtX:y: to fetch pixel values.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2118
	    destIndex := 1.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2119
	    0 to:height-1 do:[:y |
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2120
		0 to:width-1 do:[:x |
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2121
		    |colorIndex|
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2122
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2123
		    colorIndex := self valueAtX:x y:y.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2124
		    imageBits wordAt:destIndex put:(colorValues at:colorIndex + 1) MSB:true.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2125
		    destIndex := destIndex + 2.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2126
		]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2127
	    ]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2128
	]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2129
    ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2130
	usedDeviceBitsPerPixel == 32 ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2131
	    imageBits := ByteArray uninitializedNew:(width * height * 4).
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2132
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2133
	    "/ now, walk over the image and replace
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2134
	    "/ colorMap indices by color values in the bits array
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2135
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2136
	    ok := false.
194
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2137
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2138
%{          /* OPTIONAL */
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2139
	    if (__bothSmallInteger(_INST(height), _INST(width))
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2140
	     && __isArray(colorValues)
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2141
	     && __isByteArray(_INST(bytes))
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2142
	     && (myDepth == __MKSMALLINT(8))
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2143
	     && __isByteArray(imageBits)) {
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2144
		int x, y, w, h, nPix;
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2145
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2146
		unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2147
		char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2148
		OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2149
194
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2150
		w = __intVal(_INST(width));
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2151
		h = __intVal(_INST(height));
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2152
		nPix = w * h;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2153
		while (nPix > 0) {
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2154
		    unsigned idx, v;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2155
		    OBJ clr;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2156
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2157
		    idx = *srcPtr;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2158
		    clr = ap[idx];
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2159
		    v = __intVal(clr);
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2160
#ifdef MSBFIRST
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2161
		    ((long *)dstPtr)[0] = v;
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2162
#else
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2163
		    dstPtr[0] = (v>>24) & 0xFF;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2164
		    dstPtr[1] = (v>>16) & 0xFF;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2165
		    dstPtr[2] = (v>>8) & 0xFF;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2166
		    dstPtr[3] = (v) & 0xFF;
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2167
#endif
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2168
		    dstPtr += 4;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2169
		    srcPtr += 1;
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2170
		    nPix--;
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2171
		}
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2172
		ok = true;
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2173
	    }
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2174
%}.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2175
	    ok ifFalse:[
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2176
		"/ this fallback is only executed if some type is not
194
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2177
		"/ what the primitive expects (for example, if the bytes-instvar
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2178
		"/ is not a ByteArray) 
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2179
		"/ or (more important) the source depth is not 8.
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2180
		"/ The code below uses the (depth independent) but slower
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  2181
		"/ #valueAtX:y: to fetch pixel values.
194
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  2182
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2183
		destIndex := 1.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2184
		0 to:height-1 do:[:y |
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2185
		    0 to:width-1 do:[:x |
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2186
			|colorIndex|
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2187
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2188
			colorIndex := self valueAtX:x y:y.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2189
			imageBits doubleWordAt:destIndex put:(colorValues at:colorIndex + 1) MSB:true.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2190
			destIndex := destIndex + 4.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2191
		    ]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2192
		]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2193
	    ]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2194
	]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2195
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2196
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2197
    imageBits isNil ifTrue:[            
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2198
	'IMAGE: unimplemented trueColor depth in paletteImageAsTrueColorFormOn:' errorPrintNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2199
	^ self paletteImageAsMonoFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2200
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2201
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2202
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2203
    form isNil ifTrue:[^ nil].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2204
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2205
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2206
    form 
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2207
	copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth 
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2208
	       width:width height:height 
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2209
		   x:0 y:0 toX:0 y:0. 
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2210
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2211
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2212
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2213
    "Created: 20.10.1995 / 22:05:10 / cg"
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2214
    "Modified: 21.10.1995 / 19:30:26 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2215
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  2216
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2217
!Image methodsFor:'converting rgb images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2218
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2219
rgbImageAs2PlaneFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2220
    "return a 2-bit device form for aDevice from the rgb picture,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2221
     using a threshold algorithm. 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2222
     (i.e. grey value < 0.25 -> black // 0.25..0.5 -> darkgrey //
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2223
      0.5 .. 0.75 -> lightgrey // > 0.75 -> white)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2224
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2225
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2226
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2227
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2228
rgbImageAs8BitGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2229
    "return an 8-bit greyForm from the rgb picture"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2230
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2231
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2232
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2233
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2234
rgbImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2235
    "convert am rgb image to a device-form on aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2236
     Return the device-form."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2237
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2238
    |visual|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2239
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2240
    visual := aDevice visualType.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2241
    (visual == #StaticGray) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2242
	^ self rgbImageAsGreyFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2243
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2244
    (visual == #TrueColor) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2245
	^ self rgbImageAsTrueColorFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2246
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2247
    ^ self rgbImageAsPseudoFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2248
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2249
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2250
rgbImageAsGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2251
    "convert an rgb image to a grey device-form on aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2252
     (for greyscale displays)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2253
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2254
    |deviceDepth|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2255
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2256
    deviceDepth := aDevice depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2257
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2258
    "I have specially tuned methods for monochrome"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2259
    (deviceDepth == 1) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2260
	DitherAlgorithm == #error ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2261
	    ^ self rgbImageAsErrorDitheredGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2262
	].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2263
	DitherAlgorithm == #pattern ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2264
	    ^ self rgbImageAsPatternDitheredGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2265
	].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2266
	^ self rgbImageAsMonoFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2267
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  2268
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2269
    "and for 2plane greyscale (i.e. NeXTs)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2270
    (deviceDepth == 2) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2271
	DitherAlgorithm == #error  ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2272
	    ^ self rgbImageAsErrorDitheredGreyFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2273
	].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2274
	DitherAlgorithm == #pattern  ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2275
	    ^ self rgbImageAsPatternDitheredGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2276
	].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2277
	^ self rgbImageAs2PlaneFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2278
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  2279
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2280
    (deviceDepth == 8) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2281
	^ self rgbImageAs8BitGreyFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2282
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  2283
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2284
    "mhmh need another converter ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2285
     till then we do:"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2286
    DitherAlgorithm == #error  ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2287
	^ self rgbImageAsErrorDitheredGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2288
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2289
    DitherAlgorithm == #pattern  ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2290
	^ self rgbImageAsPatternDitheredGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2291
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2292
    ^ self rgbImageAsMonoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2293
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2294
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2295
rgbImageAsMonoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2296
    "return a 1-bit monochrome form for aDevice from the rgb picture,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2297
     using a threshold algorithm. 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2298
     (i.e. grey value < 0.5 -> black, grey value >= 0.5 -> white)."
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
    ^ self subclassResponsibility
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2301
!
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2302
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2303
rgbImageAsPatternDitheredGreyFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2304
    "return a dithered greyForm for aDevice from the palette picture.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2305
     works for any destination depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2306
     A slow algorithm, using draw into the form (which indirectly does
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2307
     the dither) - should be rewritten."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2308
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2309
    ^ self subclassResponsibility
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2310
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2311
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2312
rgbImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2313
    "return a pseudocolor form from the rgb-picture"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2314
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2315
    ^ self subclassResponsibility
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2316
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2317
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2318
rgbImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2319
    "return a truecolor form from the rgb-picture."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2320
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2321
    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel depth
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2322
     form|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2323
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2324
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  2325
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  2326
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2327
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  2328
    "/ kludge for 15bit XFree servers (should return 16 here - does not)
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  2329
    usedDeviceBitsPerPixel == 15 ifTrue:[
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  2330
	usedDeviceBitsPerPixel := 16
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  2331
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  2332
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2333
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2334
    "/ only the trivial case, where the depths match
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2335
    "/ is handled here; conversions are supposed to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2336
    "/ be done in concrete subclasses (see D24Image)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2337
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2338
    self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2339
	'IMAGE: unimplemented trueColor depth in rgbImageAsTrueColorFormOn:' errorPrintNL.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2340
	^ self rgbImageAsMonoFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2341
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2342
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2343
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2344
    form isNil ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2345
	'IMAGE: display bitmap creation failed' errorPrintNL.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2346
	^ nil
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2347
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2348
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2349
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2350
    form 
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2351
	copyBitsFrom:bytes bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2352
	       width:width height:height 
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2353
		   x:0 y:0 toX:0 y:0. 
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2354
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2355
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  2356
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2357
    "Modified: 21.10.1995 / 19:30:11 / cg"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2358
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2359
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2360
!Image methodsFor:'copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2361
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2362
postCopy
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2363
    "redefined to also copy the pixels and the colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2364
     and clear out any device handles in the copy."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2365
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2366
    bytes := bytes copy.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2367
    colorMap := colorMap deepCopy.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2368
    device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2369
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2370
    "Modified: 23.4.1996 / 11:12:03 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2371
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2372
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2373
!Image methodsFor:'displaying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2374
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2375
displayOn:aGC at:aPoint
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2376
    "draw the receiver in the graphicsContext, aGC.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2377
     Smalltalk-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2378
672
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2379
    self displayOn:aGC x:aPoint x y:aPoint y.
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2380
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2381
    "Modified: 12.5.1996 / 20:16:38 / cg"
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2382
!
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2383
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2384
displayOn:aGC x:x y:y
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2385
    "draw the receiver in the graphicsContext, aGC.
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2386
     Smalltalk-80 compatibility"
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2387
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2388
    aGC displayForm:self x:x y:y.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2389
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2390
    "Modified: 23.4.1996 / 11:12:31 / cg"
672
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2391
    "Created: 12.5.1996 / 20:14:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2392
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2393
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2394
!Image methodsFor:'enumerating'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2395
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2396
atY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2397
    "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
  2398
     The block is passed the color at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2399
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2400
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2401
     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
  2402
     and also the color allocation)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2403
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2404
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2405
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2406
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2407
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2408
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2409
    xStart to:xEnd do:[:xRun |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2410
	aBlock value:(self atX:xRun y:y)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2411
    ]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2412
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2413
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2414
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2415
    "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
  2416
     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
  2417
     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
  2418
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2419
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2420
     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
  2421
     and especially, the color allocations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2422
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2423
    |xS "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2424
     xE "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2425
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2426
    xS := xStart.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2427
    xE := xEnd.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2428
    yStart to:yEnd do:[:yRun |    
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2429
	self atY:yRun from:xStart to:xEnd do:[:xRun :color |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2430
	    aBlock value:xRun value:yRun value:color 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2431
	]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2432
    ]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2433
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2434
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2435
valueAtY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2436
    "perform aBlock for each pixelValue from x1 to x2 in row y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2437
     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
  2438
     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
  2439
     (see also Image>>atY:from:to:do:).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2440
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2441
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2442
     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
  2443
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2444
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2445
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2446
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2447
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2448
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2449
    xStart to:xEnd do:[:xRun |
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2450
        aBlock value:xRun value:(self valueAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2451
    ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2452
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2453
    "Modified: 17.5.1996 / 12:03:59 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2454
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2455
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2456
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2457
    "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
  2458
     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
  2459
     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
  2460
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2461
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2462
     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
  2463
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2464
    |xS "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2465
     xE "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2466
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2467
    xS := xStart.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2468
    xE := xEnd.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2469
    yStart to:yEnd do:[:yRun |    
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2470
	self valueAtY:yRun from:xStart to:xEnd do:[:xRun :pixel |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2471
	    aBlock value:xRun value:yRun value:pixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2472
	]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2473
    ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2474
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  2475
48194c26a46c Initial revision
claus
parents:
diff changeset
  2476
!Image methodsFor:'image manipulations'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2477
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2478
colorMapProcessing:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2479
    "a helper for all kinds of colormap manipulations.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2480
     The argument, aBlock is called for every colormap entry, 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2481
     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
  2482
     This will fail for non-palette images.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2483
     See examples in Image>>copyWithColorMapProcessing:"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2484
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2485
    |nColors "{ Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2486
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2487
    colorMap isNil ifTrue:[
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2488
        ^ self error:'image has no colormap'
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2489
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2490
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2491
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2492
    1 to:nColors do:[:index |
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2493
        |clr|
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2494
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2495
        clr := colorMap at:index.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2496
        clr notNil ifTrue:[
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2497
            colorMap at:index put:(aBlock value:clr)
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2498
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2499
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2500
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2501
    "Modified: 23.4.1996 / 11:13:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2502
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2503
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2504
copyWithColorMapProcessing:aBlock
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2505
    "a helper to create & return new images based on the receiver with
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2506
     some colorMap processing. The receiver is copied, and the copied images
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2507
     colormap is modified by replacing entries with the result of the processing block,
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2508
     which is called with the original color values. The block is supposed to return
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2509
     a color."
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2510
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2511
    |newImage|
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2512
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2513
    newImage := self copy.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2514
    newImage colorMap isNil ifTrue:[
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2515
	self error:'no colormap in image'.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2516
	^ nil
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2517
    ].
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2518
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2519
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2520
     the code below manipulates the colormap.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2521
     For non-palette images, special code is required
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2522
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2523
    newImage colorMapProcessing:aBlock.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2524
    ^ newImage
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2525
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2526
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2527
     leave red component only:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2528
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2529
     (Image fromFile:'bitmaps/claus.gif') 
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2530
	copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0] 
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2531
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2532
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2533
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2534
     make it reddish:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2535
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2536
     (Image fromFile:'bitmaps/claus.gif') 
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2537
	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
  2538
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2539
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2540
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2541
     invert:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2542
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2543
     (Image fromFile:'bitmaps/claus.gif') 
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2544
	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
  2545
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2546
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2547
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2548
     lighter:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2549
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2550
     (Image fromFile:'bitmaps/claus.gif') 
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2551
	copyWithColorMapProcessing:[:clr | |r g b|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2552
						r := clr red.  g := clr green.  b := clr blue.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2553
						Color red:(r + (100-r//2)) 
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2554
						      green:(g + (100-g//2)) 
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2555
						      blue:(b + (100-b//2))]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2556
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2557
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2558
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2559
     darker:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2560
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2561
     (Image fromFile:'bitmaps/claus.gif') 
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2562
	copyWithColorMapProcessing:[:clr | Color red:(clr red//2) green:(clr green // 2) blue:(clr blue // 2)] 
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2563
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2564
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2565
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2566
darkened
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2567
    "return a new image which is slightly darker than the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2568
     The receiver must be a palette image (currently).
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2569
     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
  2570
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2571
     ^ self 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2572
        copyWithColorMapProcessing:[:clr | 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2573
                Color red:(clr red // 2) 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2574
                    green:(clr green // 2) 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2575
                     blue:(clr blue // 2)] 
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2576
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2577
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2578
     (Image fromFile:'bitmaps/claus.gif') inspect
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2579
     (Image fromFile:'bitmaps/claus.gif') darkened inspect
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2580
    "
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2581
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2582
    "Modified: 23.4.1996 / 11:14:34 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2583
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2584
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2585
flipHorizontal
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2586
    "inplace horizontal flip"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2587
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2588
    |w  "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2589
     h  "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2590
     c2 "{Class: SmallInteger }" 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2591
     value |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2592
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2593
    w := width - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2594
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2595
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2596
    0 to:h do:[:row |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2597
	c2 := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2598
	0 to:(w // 2) do:[:col |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2599
	    value := self valueAtX:col y:row.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2600
	    self atX:col y:row putValue:(self valueAtX:c2 y:row).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2601
	    self atX:c2 y:row putValue:value.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2602
	    c2 := c2 - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2603
	]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2604
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2605
    "flush device info"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2606
    self restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2607
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2608
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2609
flipVertical
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2610
    "inplace vertical flip"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2611
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2612
    |h           "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2613
     bytesPerRow "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2614
     buffer 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2615
     indexLow    "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2616
     indexHi     "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2617
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2618
    bytesPerRow := self bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2619
    buffer := ByteArray new:bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2620
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2621
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2622
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2623
    indexLow := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2624
    indexHi := bytesPerRow * h + 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2625
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2626
    0 to:(h // 2) do:[:row |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2627
	buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2628
	bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2629
	bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2630
	indexLow := indexLow + bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2631
	indexHi := indexHi - bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2632
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2633
    "flush device info"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2634
    self restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2635
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2636
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2637
hardMagnifiedBy:scalePoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2638
    "return a new image magnified by scalePoint, aPoint.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2639
     This is the general magnification method, handling non-integral values.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2640
     It is slower than the integral magnification method."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2641
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2642
    |mX        
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2643
     mY        
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2644
     newWidth  "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2645
     newHeight "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2646
     w         "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2647
     h         "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2648
     newImage newBits bitsPerPixel newBytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2649
     value srcRow|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2650
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2651
    mX := scalePoint x.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2652
    mY := scalePoint y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2653
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2654
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2655
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2656
    newWidth := (width * mX) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2657
    newHeight := (height * mY) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2658
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2659
    bitsPerPixel := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2660
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2661
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2662
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2663
    newImage := self species new.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2664
    newImage bits:newBits.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2665
    newImage width:newWidth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2666
    newImage height:newHeight.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2667
    newImage photometric:photometric.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2668
    newImage samplesPerPixel:samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2669
    newImage bitsPerSample:bitsPerSample.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2670
    newImage colorMap:colorMap copy.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2671
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2672
    "walk over destination image fetching pixels from source image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2673
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2674
    w := newWidth - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2675
    h := newHeight - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2676
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2677
    0 to:h do:[:row |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2678
	srcRow := (row // mY).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2679
	0 to:w do:[:col |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2680
	    value := self valueAtX:(col // mX) y:srcRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2681
	    newImage atX:col y:row putValue:value.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2682
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2683
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2684
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2685
    ^ newImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2686
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2687
    "((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2688
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2689
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2690
hardRotated:degrees
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2691
    "raise an error - rotation by arbitrary angles is not yet implemented"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2692
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2693
    self error:'not yet implemented'
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2694
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2695
    "Modified: 23.4.1996 / 11:15:33 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2696
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2697
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  2698
lightened
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2699
    "return a new image which is slightly brighter than the receiver.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2700
     The receiver must be a palette image (currently).
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2701
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  2702
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2703
     ^ self 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2704
        copyWithColorMapProcessing:[:clr | |r g b|
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2705
                                           r := clr red. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2706
                                           g := clr green. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2707
                                           b := clr blue.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2708
                                           Color red:(r + (100-r//2)) 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2709
                                                 green:(g + (100-g//2))
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2710
                                                 blue:(b + (100-b//2))]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2711
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2712
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2713
     (Image fromFile:'bitmaps/claus.gif') inspect
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2714
     (Image fromFile:'bitmaps/claus.gif') lightened inspect
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2715
     (Image fromFile:'bitmaps/claus.gif') darkened inspect
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2716
     (Image fromFile:'bitmaps/claus.gif') darkened darkened inspect
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2717
    "
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2718
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2719
    "Modified: 23.4.1996 / 11:14:41 / cg"
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  2720
!
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  2721
134
claus
parents: 132
diff changeset
  2722
magnifiedBy:scale
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2723
    "return a new image magnified by scalePoint, aPoint.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2724
     If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:'
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2725
     while simple (integral) magnifications are handled here."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2726
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2727
    |scalePoint mX mY
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2728
     magX      "{ Class: SmallInteger }"   "new version of stc can find this out itself..."
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2729
     magY      "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2730
     srcOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2731
     dstOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2732
     w         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2733
     h         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2734
     first
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2735
     newWidth newHeight newImage newBits 
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2736
     bitsPerPixel newBytesPerRow oldBytesPerRow|
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2737
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2738
    scalePoint := scale asPoint.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2739
    mX := scalePoint asPoint x.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2740
    mY := scalePoint asPoint y.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2741
    ((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2742
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
48194c26a46c Initial revision
claus
parents:
diff changeset
  2743
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2744
    ((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[
134
claus
parents: 132
diff changeset
  2745
	^ self hardMagnifiedBy:scalePoint
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2746
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  2747
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2748
    bitsPerPixel := self depth.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2749
    oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
  2750
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2751
    w := width.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2752
    h := height.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2753
    magX := mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2754
    magY := mY.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2755
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2756
    newWidth := w * mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2757
    newHeight := h * mY.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2758
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
  2759
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
48194c26a46c Initial revision
claus
parents:
diff changeset
  2760
48194c26a46c Initial revision
claus
parents:
diff changeset
  2761
    newImage := self species new.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2762
    newImage bits:newBits.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2763
    newImage width:newWidth.
48194c26a46c Initial revision
claus
parents:
diff changeset
  2764
    newImage height:newHeight.
48194c26a46c Initial revision
claus
parents:
diff changeset
  2765
    newImage photometric:photometric.
48194c26a46c Initial revision
claus
parents:
diff changeset
  2766
    newImage samplesPerPixel:samplesPerPixel.
48194c26a46c Initial revision
claus
parents:
diff changeset
  2767
    newImage bitsPerSample:bitsPerSample.
48194c26a46c Initial revision
claus
parents:
diff changeset
  2768
    newImage colorMap:colorMap copy.
48194c26a46c Initial revision
claus
parents:
diff changeset
  2769
48194c26a46c Initial revision
claus
parents:
diff changeset
  2770
    mX = 1 ifTrue:[
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2771
	"expand rows only"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2772
	srcOffset := 1.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2773
	dstOffset := 1.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2774
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2775
	1 to:h do:[:row |
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2776
	    1 to:mY do:[:i |
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2777
		newBits replaceFrom:dstOffset 
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2778
			to:(dstOffset + oldBytesPerRow - 1)
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2779
			with:bytes 
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2780
			startingAt:srcOffset.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2781
		dstOffset := dstOffset + newBytesPerRow
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2782
	    ].
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2783
	    srcOffset := srcOffset + oldBytesPerRow.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2784
	].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2785
    ] ifFalse:[
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2786
	"expand cols"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2787
	(mX > 1) ifTrue:[
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2788
	    dstOffset := 1.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2789
	    srcOffset := 1.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2790
	    1 to:h do:[:row |
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2791
		self magnifyRowFrom:bytes 
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2792
		     offset:srcOffset  
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2793
		     into:newBits 
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2794
		     offset:dstOffset 
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2795
		     factor:mX.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2796
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2797
		first := dstOffset.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2798
		dstOffset := dstOffset + newBytesPerRow.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2799
		" and copy for row expansion "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2800
		2 to:mY do:[:i |
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2801
		    newBits replaceFrom:dstOffset 
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2802
			    to:(dstOffset + newBytesPerRow - 1)
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2803
			    with:newBits 
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2804
			    startingAt:first.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2805
		    dstOffset := dstOffset + newBytesPerRow
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2806
		].
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2807
		srcOffset := srcOffset + oldBytesPerRow.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2808
	    ].
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  2809
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2810
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  2811
    ^ newImage
48194c26a46c Initial revision
claus
parents:
diff changeset
  2812
134
claus
parents: 132
diff changeset
  2813
    "((Image fromFile:'bitmaps/claus.gif') magnifiedBy:1@2)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2814
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2815
154
claus
parents: 153
diff changeset
  2816
magnifiedPreservingRatioTo:anExtent 
claus
parents: 153
diff changeset
  2817
    "return a new image magnified to fit into anExtent,
claus
parents: 153
diff changeset
  2818
     preserving the receivers width/height ratio.
claus
parents: 153
diff changeset
  2819
     (i.e. not distorting the image).
claus
parents: 153
diff changeset
  2820
     See also #magnifiedTo: and #magnifiedBy:"
claus
parents: 153
diff changeset
  2821
claus
parents: 153
diff changeset
  2822
    |rX rY|
claus
parents: 153
diff changeset
  2823
claus
parents: 153
diff changeset
  2824
    rX := anExtent x / self width.
claus
parents: 153
diff changeset
  2825
    rY := anExtent y / self height.
claus
parents: 153
diff changeset
  2826
    ^ self magnifiedBy:(rX min:rY)
claus
parents: 153
diff changeset
  2827
claus
parents: 153
diff changeset
  2828
    "
claus
parents: 153
diff changeset
  2829
     ((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100)
claus
parents: 153
diff changeset
  2830
claus
parents: 153
diff changeset
  2831
    in contrast to:
claus
parents: 153
diff changeset
  2832
claus
parents: 153
diff changeset
  2833
     ((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100)
claus
parents: 153
diff changeset
  2834
    "
claus
parents: 153
diff changeset
  2835
!
claus
parents: 153
diff changeset
  2836
134
claus
parents: 132
diff changeset
  2837
magnifiedTo:anExtent 
154
claus
parents: 153
diff changeset
  2838
    "return a new image magnified to have the size specified by extent.
claus
parents: 153
diff changeset
  2839
     This may distort the image if the arguments ratio is not the images ratio.
claus
parents: 153
diff changeset
  2840
     See also #magnifiedPreservingRatioTo: and #magnifiedBy:"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2841
134
claus
parents: 132
diff changeset
  2842
    ^ self magnifiedBy:(anExtent / self extent)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2843
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2844
    "
134
claus
parents: 132
diff changeset
  2845
     ((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100)
154
claus
parents: 153
diff changeset
  2846
claus
parents: 153
diff changeset
  2847
    in contrast to:
claus
parents: 153
diff changeset
  2848
claus
parents: 153
diff changeset
  2849
     ((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2850
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2851
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2852
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2853
rotated:degrees
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2854
    "return a new image from the old one, by rotating the image
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2855
     degrees clockwise. 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2856
     CAVEAT: Currently, only rotation by a multiple of 90 degrees is implemented."
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2857
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2858
    |w  "{Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2859
     h  "{Class: SmallInteger }"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2860
     c2 "{Class: SmallInteger }" 
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2861
     r2 "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2862
     nW "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2863
     nH "{Class: SmallInteger }"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  2864
     newImage newBits newBytesPerRow d|
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2865
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2866
    d := degrees.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2867
    [d < 0] whileTrue:[d := d + 360].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2868
    d >= 360 ifTrue:[d := d \\ 360].
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2869
    d := d truncated.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2870
    d == 0 ifTrue:[^ self].
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2871
    ((d ~~ 90) and:[(d ~~ 270) and:[d ~~ 180]]) ifTrue:[
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2872
        ^ self hardRotated:d
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2873
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2874
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2875
    d == 180 ifTrue:[
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2876
        nW := width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2877
        nH := height.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2878
    ] ifFalse:[
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2879
        nW := height.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2880
        nH := width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2881
    ].
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2882
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2883
    newBytesPerRow := ((nW * self depth) + 7) // 8.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2884
    newBits := ByteArray uninitializedNew:(newBytesPerRow * nH).
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2885
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2886
    newImage := self species new.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2887
    newImage bits:newBits.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2888
    newImage width:nW.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2889
    newImage height:nH.
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2890
    newImage photometric:photometric.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2891
    newImage samplesPerPixel:samplesPerPixel.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2892
    newImage bitsPerSample:bitsPerSample.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2893
    newImage colorMap:colorMap copy.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2894
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2895
    w := width - 1.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2896
    h := height - 1.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2897
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2898
    d == 90 ifTrue:[
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2899
        0 to:h do:[:row |
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2900
            c2 := h-row.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2901
            self valueAtY:row from:0 to:w do:[:col :pixel |
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2902
                newImage atX:c2 y:col putValue:pixel.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2903
            ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2904
"/            0 to:w do:[:col |
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2905
"/                newImage atX:c2 y:col putValue:(self valueAtX:col y:row).
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2906
"/            ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2907
        ]
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2908
    ].
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2909
    d == 180 ifTrue:[
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2910
        0 to:h do:[:row |
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2911
            r2 := h - row.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2912
            self valueAtY:row from:0 to:w do:[:col :pixel |
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2913
                newImage atX:(w-col) y:r2 putValue:pixel.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2914
            ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2915
"/            0 to:w do:[:col |
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2916
"/                newImage atX:(w-col) y:r2 putValue:(self valueAtX:col y:row).
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2917
"/            ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2918
        ]
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  2919
    ].
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2920
    d == 270 ifTrue:[
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2921
        0 to:h do:[:row |
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2922
            self valueAtY:row from:0 to:w do:[:col :pixel |
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2923
                newImage atX:row y:(w-col) putValue:pixel.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2924
            ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2925
"/            0 to:w do:[:col |
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2926
"/                newImage atX:row y:(w-col) putValue:(self valueAtX:col y:row).
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2927
"/            ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2928
        ]
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2929
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  2930
    ^ newImage
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2931
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2932
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2933
     |i|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2934
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2935
     i := Image fromFile:'claus.gif'.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2936
     i inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2937
     (i rotated:90) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2938
     (i rotated:180) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2939
     (i rotated:270) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2940
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2941
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2942
    "Modified: 17.5.1996 / 12:06:34 / cg"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2943
!
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2944
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2945
withPixelFunctionApplied:pixelFunctionBlock
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2946
    "return a new image from the old one, by applying a pixel processor
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2947
     (read `Behond photography, by Gerard J. Holzmann;
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2948
           ISBM 0-13-074410-7)
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2949
     See blurred / oilPointed as examples ...)"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2950
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2951
    |w  "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2952
     h  "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2953
     newImage newBits newBytesPerRow d|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2954
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2955
    newBytesPerRow := ((width * self depth) + 7) // 8.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2956
    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2957
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2958
    newImage := self species new.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2959
    newImage bits:newBits.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2960
    newImage width:width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2961
    newImage height:height.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2962
    newImage photometric:photometric.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2963
    newImage samplesPerPixel:samplesPerPixel.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2964
    newImage bitsPerSample:bitsPerSample.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2965
    newImage colorMap:colorMap copy.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2966
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2967
    w := width - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2968
    h := height - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2969
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2970
    0 to:h do:[:y |
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2971
        0 to:w do:[:x |
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2972
            newImage atX:x y:y put:(pixelFunctionBlock
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2973
                                                value:self
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2974
                                                value:x
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2975
                                                value:y)
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2976
        ]
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2977
    ].
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2978
    ^ newImage
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2979
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2980
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2981
     |i|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2982
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2983
     i := Image fromFile:'claus.gif'.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2984
     i inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2985
     (i withPixelFunctionApplied:[:oldImage :x :y |
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2986
                        ((x between:100 and:200) 
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2987
                        and:[y between:100 and:200]) ifTrue:[
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2988
                            oldImage atX:x y:y
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2989
                        ] ifFalse:[
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2990
                            Color black.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2991
                        ]
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2992
                     ]) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2993
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2994
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  2995
    "Modified: 17.5.1996 / 12:31:44 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2996
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2997
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2998
!Image methodsFor:'inspecting'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2999
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3000
inspectorClass
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3001
    "redefined to launch an ImageInspector
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3002
     (instead of the default InspectorView)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3003
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3004
    ^ ImageInspectorView
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3005
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3006
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3007
!Image methodsFor:'instance release'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3008
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3009
disposed
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3010
    "some Image has been collected - nothing to do"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  3011
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  3012
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3013
release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3014
    "release device resources"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3015
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3016
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3017
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3018
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3019
    fullColorDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3020
    Lobby unregister:self
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  3021
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  3022
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3023
restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3024
    "flush device specifics after a snapin or binary restore"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3025
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3026
    self release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3027
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3028
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3029
!Image methodsFor:'obsolete'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3030
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3031
magnifyBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3032
    "obsolete: has been renamed to magnifiedBy: for ST-80 compatibility
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3033
     and name consistency ..."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3034
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3035
    self obsoleteMethodWarning.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3036
    ^ self magnifiedBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3037
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3038
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3039
!Image methodsFor:'pixel copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3040
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3041
copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3042
    "replace a rectangulat area by pixels from another image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3043
     WARNING:
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3044
     This implementation is a slow fallback (the loop over the
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3045
     source pixels is very slow). If this method is used heavily, you
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3046
     may want to redefine it in concrete subclasses for the common case of
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3047
     of copying from an Image with the same depth & palette."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3048
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3049
    |dX dY|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3050
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3051
    dX := srcX-dstX.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3052
    dY := srcY-dstY.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3053
    ((photometric == anImage photometric)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3054
     and:[self bitsPerPixel == anImage bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3055
     and:[colorMap = anImage colorMap]]) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3056
	"/ can loop over values
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3057
	anImage valuesFromX:srcX  y:srcY 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3058
			toX:srcX+w-1 y:srcY+h-1  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3059
			 do:[:x :y :pixelValue |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3060
	    self atX:x-dX y:y-dY putValue:pixelValue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3061
	]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3062
    ] ifFalse:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3063
	"/ must loop over colors
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3064
	anImage colorsFromX:srcX  y:srcY 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3065
			toX:srcX+w-1 y:srcY+h-1  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3066
			 do:[:x :y :clr |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3067
	    self atX:x-dX y:y-dY put:clr.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3068
	]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3069
    ]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3070
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3071
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3072
     |i1 i8 i4|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3073
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3074
     i8 := Image fromFile:'bitmaps/garfield.gif'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3075
     i8 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3076
     i1 := Image fromFile:'bitmaps/SBrowser.xbm'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3077
     i1 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3078
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3079
     i4 := Depth4Image fromImage:i8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3080
     i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:30 height:30.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3081
     i4 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3082
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3083
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3084
    "Created: 20.9.1995 / 10:14:01 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3085
    "Modified: 20.9.1995 / 10:25:31 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3086
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3087
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3088
subImageIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3089
    "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
  3090
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3091
    ^ self class fromSubImage:self in:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3092
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3093
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3094
     |i|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3095
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3096
     i := Image fromFile:'bitmaps/garfield.gif'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3097
     i inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3098
     (i subImageIn:(300@160 corner:340@200)) inspect
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3099
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3100
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3101
    "Created: 20.9.1995 / 01:24:20 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3102
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3103
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3104
!Image methodsFor:'printing & storing'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3105
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3106
storeOn:aStream
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3107
    "append a printed representation of the receiver to aStream,
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3108
     from which a copy of it can be reconstructed."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3109
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3110
    aStream nextPutAll:'(' , self class name , ' new)'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3111
    aStream nextPutAll:' width: '. width storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3112
    aStream nextPutAll:'; height: '. height storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3113
    aStream nextPutAll:'; photometric:('. photometric storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3114
    aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3115
    aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream. 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3116
    aStream nextPutAll:'); bits:('. bytes storeOn:aStream. aStream nextPutAll:') '.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3117
    colorMap notNil ifTrue:[
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3118
        aStream nextPutAll:'; colorMap:('.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3119
        colorMap storeOn:aStream.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3120
        aStream nextPutAll:')'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3121
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3122
    aStream nextPutAll:'; yourself'
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3123
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3124
    "Modified: 23.4.1996 / 11:18:05 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3125
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  3126
48194c26a46c Initial revision
claus
parents:
diff changeset
  3127
!Image methodsFor:'private'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3128
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3129
bestSupportedImageFormatFor:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3130
    "scan through the image formats as supported by aDevice,
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3131
     and return the best to use when the receiver is to be represented
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3132
     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
  3133
     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
  3134
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3135
    |bestDeviceDepth bestDeviceBitsPerPixel bestInfo maxInfo myDepth maxDepth maxBitsPerPixel |
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3136
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3137
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3138
    maxBitsPerPixel := 0.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3139
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3140
    aDevice supportedImageFormats do:[:entry |
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3141
	|deviceImageDepth deviceImageBitsPerPixel|
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3142
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3143
	deviceImageDepth := entry at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3144
	deviceImageBitsPerPixel := entry at:#bitsPerPixel.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3145
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3146
	deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3147
	    maxInfo := entry.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3148
"/            maxBitsPerPixel := deviceImageBitsPerPixel.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3149
"/            maxDepth := deviceImageDepth.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3150
	].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3151
	deviceImageDepth >= myDepth ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3152
	    deviceImageDepth == myDepth ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3153
		"/ take the better one ...
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3154
		(bestDeviceDepth isNil
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3155
		 or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth)
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3156
		    and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3157
		    bestInfo := entry.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3158
		    bestDeviceDepth := deviceImageDepth.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3159
		    bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3160
		]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3161
	    ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3162
		"/ take the next-larger depth
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3163
		(bestDeviceDepth isNil
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3164
		 or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3165
		    bestInfo := entry.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3166
		    bestDeviceDepth := deviceImageDepth.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3167
		    bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3168
		]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3169
	    ]    
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3170
	].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3171
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3172
    bestDeviceDepth isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3173
	maxBitsPerPixel == 0 ifTrue:[
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3174
	    "/
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3175
	    "/ oops - nothing appropriate
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3176
	    "/
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3177
	    bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3178
	    bestInfo := IdentityDictionary new.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3179
	    bestInfo at:#depth put:bestDeviceDepth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3180
	    bestInfo at:#bitsPerPixel put:bestDeviceDepth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3181
	    bestInfo at:#padding put:32.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3182
	] ifFalse:[
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3183
	    bestInfo := maxInfo.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3184
	]
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3185
    ].
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3186
    ^ bestInfo
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  3187
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  3188
    "Modified: 21.10.1995 / 03:52:45 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3189
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3190
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3191
colormapFromImage:anImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3192
    "setup the receivers colormap from another image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3193
     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
  3194
     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
  3195
     for fromImage:/fromSubImake:"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3196
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3197
    samplesPerPixel == 3 ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3198
	photometric := #rgb
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3199
    ] ifFalse:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3200
	photometric := anImage photometric.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3201
	photometric == #palette ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3202
	    colorMap := anImage colorMap copy.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3203
	    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3204
	     must compress the colormap, if source image has higher depth
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3205
	     than myself. 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3206
	    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3207
	    anImage bitsPerPixel > self bitsPerPixel ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3208
		"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3209
		 get used colors are extracted into our colorMap
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3210
		 (the at-put below will set the pixelValue according the
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3211
		 new colorIndex
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3212
		"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3213
		colorMap := anImage usedColors asArray.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3214
		colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3215
		    'IMAGE: possibly too many colors in image' errorPrintNL
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3216
		]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3217
	    ]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3218
	]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3219
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3220
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3221
    "Created: 20.9.1995 / 00:58:42 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3222
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3223
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3224
magnifyRowFrom:srcBytes offset:srcStart pixels:oldPixels 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3225
	  into:dstBytes offset:dstStart factor:mX
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3226
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3227
    "magnify a single pixel row - can only magnify by integer factors,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3228
     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
  3229
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3230
    ^ self subclassResponsibility
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3231
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3232
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3233
!Image methodsFor:'queries'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3234
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3235
averageColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3236
    "return the average color of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3237
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3238
     (i.e. to compute shadow & light colors for viewBackgrounds).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3239
     Notice, that for the above purpose, it is usually ok to process 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3240
     a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3241
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3242
    ^ self averageColorIn:(0@0 corner:(width-1)@(height-1))
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3243
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3244
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3245
averageColorIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3246
    "return the images average color in an area.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3247
     The implementation below is slow - so you may want to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3248
     create tuned versions for DepthXImage if you plan to do
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3249
     heavy image processing ... 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3250
     (also, creating tuned versions of the enumeration messages helps a lot)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3251
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3252
    |x0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3253
     y0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3254
     x1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3255
     y1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3256
     sumRed sumGreen sumBlue n|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3257
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3258
    sumRed := sumGreen := sumBlue := 0.    
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3259
    y0 := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3260
    y1 := aRectangle bottom.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3261
    x0 := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3262
    x1 := aRectangle right.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3263
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3264
    self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3265
       sumRed := sumRed + colorAtXY red.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3266
       sumGreen := sumGreen + colorAtXY green.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3267
       sumBlue := sumBlue + colorAtXY blue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3268
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3269
    n := (x1 - x0 + 1) * (y1 - y0 + 1).    
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3270
    ^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3271
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3272
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3273
bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3274
    "return the number of bits per pixel"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3275
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3276
    ^ (bitsPerSample inject:0 into:[:sum :i | sum + i])
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3277
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3278
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3279
bitsPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3280
    "return the number of bits in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3281
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3282
    ^  width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3283
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3284
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  3285
bounds
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  3286
    "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
  3287
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  3288
    ^ 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
  3289
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  3290
    "Created: 13.5.1996 / 10:27:06 / cg"
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  3291
!
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  3292
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3293
brightness
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3294
    "return the brightness of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3295
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3296
     (i.e. to compute shadow & light colors for viewBackgrounds).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3297
     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
  3298
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3299
    ^ (self averageColorIn:(0@0 corner:7@7)) brightness
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3300
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3301
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3302
bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3303
    "return the number of bytes in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3304
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3305
    |bitsPerRow bytesPerRow|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3306
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3307
    bitsPerRow := width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3308
    bytesPerRow := bitsPerRow // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3309
    ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3310
	bytesPerRow := bytesPerRow + 1
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3311
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3312
    ^ bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3313
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3314
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3315
heightOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3316
    "return my height, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3317
     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
  3318
     return the pixel-height"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3319
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  3320
    ^ height
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3321
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3322
    "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
  3323
    "Modified: 13.5.1996 / 10:26:36 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3324
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3325
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3326
isImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3327
    "return true, if the receiver is some kind of image;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3328
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3329
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3330
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3331
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3332
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3333
isImageOrForm
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3334
    "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
  3335
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3336
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3337
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3338
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3339
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3340
usedColors
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3341
    "return a collection of colors used in the receiver."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3342
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3343
    |usedValues max|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3344
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3345
    usedValues := self usedValues asArray.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3346
    photometric ~~ #palette ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3347
        max := (1 bitShift:self depth) - 1.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3348
        ^ usedValues collect:[:val | (Color gray:(100 * val / max ))]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3349
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3350
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3351
    ^ usedValues collect:[:val | (colorMap at:val+1)]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3352
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3353
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3354
     (Image fromFile:'bitmaps/garfield.gif') usedColors
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3355
     (Image fromFile:'bitmaps/SBrowser.xbm') usedColors
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3356
     (Image fromFile:'ttt.tiff') usedColors  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3357
    "
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3358
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3359
    "Modified: 28.5.1996 / 20:55:10 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3360
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3361
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3362
usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3363
    "return a collection of color values used in the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3364
     Notice, that the interpretation of the pixels depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3365
     of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3366
     This is a general and therefore slow implementation; subclasses
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3367
     may want to redefine this method for more performance."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3368
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3369
    |set|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3370
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3371
    set := IdentitySet new.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3372
    self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3373
	set add:pixel 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3374
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3375
    ^ set
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3376
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3377
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3378
     (Image fromFile:'bitmaps/garfield.gif') usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3379
     (Image fromFile:'bitmaps/SBrowser.xbm') usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3380
     (Image fromFile:'ttt.tiff') usedValues  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3381
    "
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3382
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3383
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3384
widthOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3385
    "return my width, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3386
     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
  3387
     return the pixel-width"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3388
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  3389
    ^ width
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3390
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  3391
    "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
  3392
    "Modified: 13.5.1996 / 10:26:42 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3393
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3394
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3395
!Image methodsFor:'saving on file'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3396
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3397
saveOn:aFileName
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3398
    "save the image in a aFileName. The suffix of the filename
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3399
     controls the format. Currently, not all formats may be supported
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3400
     (see ImageReader subclasses implementing save:onFile:)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3401
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3402
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3403
     from the extension, get the imageReader class
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3404
     (which should know how to write images as well)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3405
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3406
    FileFormats associationsDo:[:a |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3407
	(aFileName endsWith:(a key)) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3408
	    ^ (a value) save:self onFile:aFileName
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3409
	]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3410
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3411
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3412
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3413
     no known extension - could ask user for the format here.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3414
     currently default to tiff format.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3415
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3416
    'IMAGE: unknown extension - cannot figure out format - using tiff' errorPrintNL.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3417
    ^ self saveOn:aFileName using:TIFFReader
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3418
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3419
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3420
saveOn:aFileName using:readerClass
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3421
    "save the receiver using the representation class"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3422
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3423
    readerClass save:self onFile:aFileName
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3424
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3425
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3426
     anImage saveOn:'myImage' using:TIFFReader
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3427
     anImage saveOn:'myImage' using:XBMReader
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3428
    "
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3429
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3430
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3431
!Image methodsFor:'screen capture'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3432
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3433
fromScreen:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3434
    "read an image from the display screen"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3435
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3436
    ^ self fromScreen:aRectangle on:Screen current
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3437
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3438
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3439
fromScreen:aRectangle on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3440
    "read an image from aDevices display screen.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3441
     Since I have no other displays, only the MonoChrome, StaticGrey 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3442
     and PseudoColor cases have been tested ... 
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3443
     (especially True- and DirectColor may be wrong).
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3444
     Late note: 24bit rgb now also works."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3445
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3446
    |depth visType 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3447
     x        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3448
     y        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3449
     w        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3450
     h        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3451
     dstIndex "{ Class: SmallInteger }" 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3452
     srcIndex "{ Class: SmallInteger }" 
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3453
     srcRow   "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3454
     dstRow   "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3455
     inData tmpData usedPixels mapSize 
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3456
     map bitsPerPixel bytesPerLine byteOrder spaceBitsPerPixel
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3457
     info bitsPerPixelIn bytesPerLineIn curs cid rootView
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3458
     maskR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3459
     maskG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3460
     maskB "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3461
     shR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3462
     shG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3463
     shB "{ Class: SmallInteger }"
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  3464
     shR2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  3465
     shG2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  3466
     shB2 "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3467
     r "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3468
     g "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3469
     b "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3470
     word|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3471
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3472
    curs := Cursor sourceForm:(Form fromFile:'Camera.xbm')
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3473
                     maskForm:(Form fromFile:'Camera_m.xbm')
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3474
                      hotSpot:16@16.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3475
    curs notNil ifTrue:[
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3476
        cid := (curs on:aDevice) id
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3477
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3478
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3479
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3480
     get some attributes of the display device
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3481
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3482
    visType := aDevice visualType.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3483
    depth := aDevice depth.
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3484
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3485
    "/ kludge for 15bit XFree server
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3486
    depth == 15 ifTrue:[
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3487
        depth := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3488
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3489
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3490
    (visType == #StaticGray) ifTrue:[
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3491
        (aDevice blackpixel == 0) ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3492
            photometric := #blackIs0
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3493
        ] ifFalse:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3494
            photometric := #whiteIs0
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3495
        ].
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3496
        samplesPerPixel := 1.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3497
        bitsPerPixel := depth.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3498
        bitsPerSample := Array with:bitsPerPixel.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3499
    ] ifFalse:[
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3500
        ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3501
            photometric := #palette.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3502
            samplesPerPixel := 1.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3503
            bitsPerPixel := depth.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3504
            bitsPerSample := Array with:bitsPerPixel.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3505
        ] ifFalse:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3506
            ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3507
                photometric := #rgb.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3508
                samplesPerPixel := 3.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  3509
"/                bitsPerPixel := depth.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  3510
"/                bitsPerSample := Array with:aDevice bitsRed
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  3511
"/                                       with:aDevice bitsGreen
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  3512
"/                                       with:aDevice bitsBlue
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3513
                bitsPerPixel := 24.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3514
                bitsPerSample := #(8 8 8).
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3515
            ] ifFalse:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3516
                self error:'screen visual not supported'.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3517
                ^ nil
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3518
            ]
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3519
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3520
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3521
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3522
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3523
     dont know yet, how the display pads; assume worst case, 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3524
     offering enough space for 32 bit padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3525
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3526
    w := width := aRectangle width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3527
    h := height := aRectangle height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3528
    x := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3529
    y := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3530
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3531
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3532
     a kludge: we dont know in advance how much we are going to need
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3533
     (its too late when info is present ...)
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3534
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3535
    spaceBitsPerPixel := bitsPerPixel.
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3536
    (bitsPerPixel > 8) ifTrue:[
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3537
        spaceBitsPerPixel := 16.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3538
        (bitsPerPixel > 16) ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3539
            spaceBitsPerPixel := 32.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3540
            (bitsPerPixel > 32) ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3541
                spaceBitsPerPixel := bitsPerPixel.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3542
            ]
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3543
        ]
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3544
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3545
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3546
    bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3547
    inData := ByteArray uninitializedNew:(bytesPerLine * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3548
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3549
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3550
     actually have to grabServer ... but thats not yet available
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3551
    "
728
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  3552
    rootView := aDevice rootView.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3553
    aDevice setActivePointerGrab:rootView.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3554
    aDevice grabPointerIn:rootView id
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3555
               withCursor:cid pointerMode:#async keyboardMode:#sync confineTo:nil.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3556
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3557
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3558
     get the pixels
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3559
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3560
    info := aDevice getBitsFrom:rootView id x:x y:y width:w height:h into:inData. 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3561
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3562
    "
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
  3563
     check if byteorder is what I like (msbFirst)
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
  3564
    "
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3565
    byteOrder := info at:#byteOrder.
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3566
    bitsPerPixelIn := info at:#bitsPerPixel.
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3567
    byteOrder ~~ #msbFirst ifTrue:[
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3568
        bitsPerPixelIn == 16 ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3569
            "/ must swap bytes
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3570
            inData swapBytes
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3571
        ] ifFalse:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3572
            bitsPerPixelIn == 32 ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3573
                "/ must swap longs
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3574
                inData swapLongs
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3575
            ]
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3576
        ]
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
  3577
    ].
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
  3578
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
  3579
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3580
     check, if the devices padding is different ..
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3581
     or if the bitsPerPixels are different
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3582
    "
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3583
    bytesPerLineIn := (info at:#bytesPerLine).                    "what I got"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3584
    bytesPerLine := (w * bitsPerPixel + 7) // 8.                  "what I want"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3585
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3586
    ((bytesPerLine ~~ bytesPerLineIn) 
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3587
    or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3588
        tmpData := inData.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3589
        inData := ByteArray uninitializedNew:(bytesPerLine * height).
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3590
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3591
        srcRow := 1.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3592
        dstRow := 1.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3593
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3594
        bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3595
            "/ for now, only 32 -> 24 is supported
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3596
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3597
            maskR := (1 bitShift:aDevice bitsRed) - 1.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3598
            maskG := (1 bitShift:aDevice bitsGreen) - 1.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3599
            maskB := (1 bitShift:aDevice bitsBlue) - 1.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3600
            shR := aDevice shiftRed negated.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3601
            shG := aDevice shiftGreen negated.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3602
            shB := aDevice shiftBlue negated.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3603
            shR2 := (8 - aDevice bitsRed).
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3604
            shG2 := (8 - aDevice bitsGreen).
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3605
            shB2 := (8 - aDevice bitsBlue).
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3606
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3607
            ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3608
                "/ 'reformatting 32->24...' printNL.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3609
                1 to:h do:[:hi |
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3610
                    srcIndex := srcRow.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3611
                    dstIndex := dstRow.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3612
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3613
                    1 to:w do:[:wi |
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3614
                        word := tmpData doubleWordAt:srcIndex MSB:true.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3615
                        r := (word bitShift:shR) bitAnd:maskR.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3616
                        g := (word bitShift:shG) bitAnd:maskG.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3617
                        b := (word bitShift:shB) bitAnd:maskB.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3618
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3619
                        inData at:dstIndex   put:r.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3620
                        inData at:dstIndex+1 put:g.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3621
                        inData at:dstIndex+2 put:b.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3622
                        srcIndex := srcIndex + 4.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3623
                        dstIndex := dstIndex + 3.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3624
                    ].
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3625
                    dstRow := dstRow + bytesPerLine.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3626
                    srcRow := srcRow + bytesPerLineIn
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3627
                ]
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3628
            ] ifFalse:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3629
                ((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3630
                    "/ 'reformatting 16->24...' printNL.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3631
                    1 to:h do:[:hi |
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3632
                        srcIndex := srcRow.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3633
                        dstIndex := dstRow.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3634
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3635
                        1 to:w do:[:wi |
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3636
                            word := tmpData wordAt:srcIndex MSB:true.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3637
                            r := (word bitShift:shR) bitAnd:maskR.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3638
                            g := (word bitShift:shG) bitAnd:maskG.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3639
                            b := (word bitShift:shB) bitAnd:maskB.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3640
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3641
                            inData at:dstIndex   put:(r bitShift:shR2).
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3642
                            inData at:dstIndex+1 put:(g bitShift:shG2).
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3643
                            inData at:dstIndex+2 put:(b bitShift:shB2).
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3644
                            srcIndex := srcIndex + 2.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3645
                            dstIndex := dstIndex + 3.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3646
                        ].
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3647
                        dstRow := dstRow + bytesPerLine.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3648
                        srcRow := srcRow + bytesPerLineIn
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3649
                    ]
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3650
                ] ifFalse:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3651
                    ('IMAGE: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3652
                                                        bitsPerPixel printString) errorPrintNL.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3653
                    ^ nil
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3654
                ]
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3655
            ].
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3656
        ] ifFalse:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3657
            "
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3658
             repad in the buffer
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3659
            "
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3660
            1 to:h do:[:hi |
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3661
                inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3662
                              with:tmpData startingAt:srcRow.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3663
                dstRow := dstRow + bytesPerLine.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3664
                srcRow := srcRow + bytesPerLineIn
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3665
            ]
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3666
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3667
    ] ifFalse:[
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3668
        (bytesPerLine * height) ~~ inData size ifTrue:[
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3669
            tmpData := inData.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3670
            inData := ByteArray uninitializedNew:(bytesPerLine * height).
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3671
            inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3672
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3673
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3674
    bytes := inData.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3675
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3676
    "info printNL."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3677
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3678
    ((visType == #StaticGray) 
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3679
    or:[visType == #TrueColor
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  3680
    or:[visType == #DirectColor]]) ifTrue:[
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3681
        "
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3682
         were done, the pixel values are the rgb/grey values
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3683
        "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3684
    ] ifFalse:[
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3685
        "
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3686
         what we have now are the color numbers - still need the r/g/b values.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3687
         find out, which colors are in the picture
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3688
        "
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3689
        usedPixels := inData usedValues.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3690
        mapSize := usedPixels max + 1.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3691
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3692
        "get the palette"
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3693
        map := Array new:mapSize.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3694
        usedPixels do:[:colorIndex |
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3695
            |i|
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3696
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3697
            i := colorIndex + 1.
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3698
            aDevice getRGBFrom:colorIndex into:[:r :g :b |
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3699
                map at:i put:(Color red:r green:g blue:b)
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3700
            ]
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3701
        ].
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3702
        colorMap := map.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3703
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3704
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3705
    aDevice ungrabPointer.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3706
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3707
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3708
     (Image new) fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3709
     (Image new) fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3710
    "
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  3711
518
f76da6242336 nicer message
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
  3712
    "Modified: 7.3.1996 / 19:17:33 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3713
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3714
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3715
!Image class methodsFor:'documentation'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3716
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3717
version
748
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  3718
    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.76 1996-05-28 19:12:57 cg Exp $'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  3719
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3720
Image initialize!