Colormap.st
author tm
Fri, 05 Mar 1999 18:05:40 +0100
changeset 2483 6b77b75e74bb
parent 2448 89c338d3412e
child 3265 408fac627dc4
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
     1
"
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
     3
	      All Rights Reserved
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
     4
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    11
"
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    12
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
    13
SequenceableCollection subclass:#Colormap
572
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
    14
	instanceVariableNames:'redVector greenVector blueVector'
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
    15
	classVariableNames:''
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
    16
	poolDictionaries:''
665
843bf13683f5 category change
Claus Gittinger <cg@exept.de>
parents: 637
diff changeset
    17
	category:'Graphics-Images-Support'
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    18
!
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    19
1092
1b6391f333de category rename
Claus Gittinger <cg@exept.de>
parents: 944
diff changeset
    20
!Colormap class methodsFor:'documentation'!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    21
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    22
copyright
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    23
"
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    24
 COPYRIGHT (c) 1994 by Claus Gittinger
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    25
	      All Rights Reserved
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    26
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    27
 This software is furnished under a license and may be used
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    28
 only in accordance with the terms of that license and with the
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    30
 be provided or otherwise made available to, or used by, any
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    31
 other person.  No title to or ownership of the software is
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    32
 hereby transferred.
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    33
"
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    34
!
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    35
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    36
documentation
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    37
"
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    38
    Colormaps are used with images (and Forms) to keep the byte-to-color
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    39
    mapping.
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
    40
    Externally, either colors or pixel values can be accessed.
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    41
    Internally, the values are stored as 3 separate byte-arrays
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    42
    (i.e. individual components can be 0..255).
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
    43
    This was done to avoid overhead due to allocation of many color
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
    44
    instances.
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
    45
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    46
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    47
    [author:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    48
        Claus Gittinger
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    49
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
    50
    [see also:]
603
7e2b1e471427 commentary
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
    51
        Color Image Form
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    52
"
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    53
! !
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    54
1092
1b6391f333de category rename
Claus Gittinger <cg@exept.de>
parents: 944
diff changeset
    55
!Colormap class methodsFor:'instance creation'!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    56
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
    57
fromColors:aColorArray
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    58
    "given a sequenceable collection of colors, return a new instance
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
    59
     of myself"
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
    60
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    61
    ^ self withColors:aColorArray
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    62
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    63
    "
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    64
     Colormap 
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    65
        fromColors:(Array with:Color black
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    66
                          with:Color red
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    67
                          with:Color white)
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    68
    "
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    69
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    70
    "Modified: 25.2.1997 / 19:00:31 / cg"
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    71
!
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    72
2448
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
    73
new:numColors
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
    74
    ^ self withColors:(Array new:numColors withAll:Color black)
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
    75
!
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
    76
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    77
redVector:r greenVector:g blueVector:b
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    78
    "given vectors of red/green/and blue pixelValues,
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    79
     return a new instance of myself.
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    80
     The values must be in the range 0..255."
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    81
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    82
    ^ self new redVector:r greenVector:g blueVector:b
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    83
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    84
    "
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    85
     Colormap 
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    86
        redVector:#[0 127 255]
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    87
        greenVector:#[0 127 255]
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    88
        blueVector:#[0 127 255]
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    89
    "
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    90
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    91
    "Modified: 23.4.1996 / 22:16:00 / cg"
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    92
!
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    93
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    94
withColors:aColorArray
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    95
    "given a sequenceable collection of colors, return a new instance
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    96
     of myself. Renamed from #fromColors: for ST-80 compatibility."
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    97
1378
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
    98
    ^ self new colors:aColorArray
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
    99
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   100
    "
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   101
     Colormap 
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   102
        withColors:(Array with:Color black
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   103
                          with:Color red
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   104
                          with:Color white)
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   105
    "
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   106
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   107
    "Created: 25.2.1997 / 18:59:09 / cg"
1378
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   108
    "Modified: 25.2.1997 / 19:03:08 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   109
! !
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   110
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   111
!Colormap methodsFor:'accessing'!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   112
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   113
at:index 
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   114
    "return the color for a index. 
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   115
     Notice that index range is 1..."
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   116
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   117
    |r g b idx "{ Class: SmallInteger }" |
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   118
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   119
    idx := index.
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   120
    r := redVector at:idx.
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   121
    g := greenVector at:idx.
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   122
    b := blueVector at:idx.
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   123
1351
6d5552229507 checkin from browser
ca
parents: 1092
diff changeset
   124
    ^ Color redByte:r greenByte:g blueByte:b
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   125
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   126
    "Created: 2.5.1996 / 12:21:40 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   127
    "Modified: 8.6.1996 / 14:25:30 / cg"
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   128
!
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   129
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   130
at:index put:aColor
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   131
    "set the color for a index. Return aColor (sigh).
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   132
     Notice that index range is 1..."
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   133
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   134
    |r g b idx "{ Class: SmallInteger }" |
572
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   135
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   136
    r := (aColor red * 255 / 100) rounded.
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   137
    g := (aColor green * 255 / 100) rounded.
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   138
    b := (aColor blue * 255 / 100) rounded.
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   139
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   140
    idx := index.
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   141
    redVector at:idx put:r.
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   142
    greenVector at:idx put:g.
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   143
    blueVector at:idx put:b.
572
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   144
    ^ aColor
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   145
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   146
    "Modified: 2.5.1996 / 17:29:29 / cg"
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   147
!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   148
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   149
blueAt:index
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   150
    "return the blue component for some index.
153
claus
parents: 118
diff changeset
   151
     The returned value is scaled from the internal 0.. 255 to
claus
parents: 118
diff changeset
   152
     a percentage value 0..100"
claus
parents: 118
diff changeset
   153
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   154
    ^ (blueVector at:index) * 100 / 255
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   155
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   156
    "Modified: 2.5.1996 / 17:29:17 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   157
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   158
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   159
colors
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   160
    "ST-80 compatibility: return a collection containing the colors I hold"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   161
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   162
    ^ self asArray
153
claus
parents: 118
diff changeset
   163
!
claus
parents: 118
diff changeset
   164
1378
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   165
colors:aCollectionOfColors
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   166
    "setup the receiver from colors given in a sequenceable collection of colors"
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   167
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   168
    |sz "{Class: SmallInteger }"|
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   169
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   170
    sz := aCollectionOfColors size.
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   171
    redVector := ByteArray new:sz.
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   172
    greenVector := ByteArray new:sz.
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   173
    blueVector := ByteArray new:sz.
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   174
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   175
    1 to:sz do:[:i |
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   176
        |clr r g b|
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   177
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   178
        clr := aCollectionOfColors at:i.
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   179
        clr notNil ifTrue:[
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   180
            redVector at:i put:(clr redByte).
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   181
            greenVector at:i put:(clr greenByte).
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   182
            blueVector at:i put:(clr blueByte).
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   183
        ]
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   184
    ].
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   185
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   186
    "Modified: 25.2.1997 / 19:02:47 / cg"
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   187
!
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   188
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   189
greenAt:index
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   190
    "return the green component for some index.
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   191
     The returned value is scaled from the internal 0.. 255 to
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   192
     a percentage value 0..100"
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   193
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   194
    ^ (greenVector at:index) * 100 / 255
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   195
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   196
    "Modified: 2.5.1996 / 17:29:36 / cg"
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   197
!
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   198
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   199
redAt:index
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   200
    "return the red component for some index.
153
claus
parents: 118
diff changeset
   201
     The returned value is scaled from the internal 0.. 255 to
claus
parents: 118
diff changeset
   202
     a percentage value 0..100"
claus
parents: 118
diff changeset
   203
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   204
    ^ (redVector at:index) * 100 / 255
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   205
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   206
    "Modified: 2.5.1996 / 17:29:44 / cg"
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   207
!
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   208
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   209
size
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   210
    "return the number of colors in the receiver"
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   211
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   212
    ^ redVector size
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   213
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   214
    "Modified: 23.4.1996 / 22:13:43 / cg"
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   215
! !
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   216
1092
1b6391f333de category rename
Claus Gittinger <cg@exept.de>
parents: 944
diff changeset
   217
!Colormap methodsFor:'accessing-internals'!
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   218
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   219
blueVector
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   220
    "return the blueVector"
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   221
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   222
    ^ blueVector
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   223
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   224
    "Modified: 2.5.1996 / 12:44:17 / cg"
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   225
!
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   226
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   227
blueVector:something
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   228
    "set blueVector"
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   229
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   230
    blueVector := something.
153
claus
parents: 118
diff changeset
   231
!
claus
parents: 118
diff changeset
   232
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   233
greenVector
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   234
    "return greenVector"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   235
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   236
    ^ greenVector
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   237
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   238
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   239
greenVector:something
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   240
    "set greenVector"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   241
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   242
    greenVector := something.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   243
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   244
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   245
redVector
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   246
    "return redVector"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   247
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   248
    ^ redVector
153
claus
parents: 118
diff changeset
   249
!
claus
parents: 118
diff changeset
   250
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   251
redVector:something
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   252
    "set redVector"
153
claus
parents: 118
diff changeset
   253
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   254
    redVector := something.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   255
!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   256
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   257
redVector:r greenVector:g blueVector:b
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   258
    "set the red, green and blueVectors"
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   259
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   260
    redVector := r.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   261
    greenVector := g.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   262
    blueVector := b.
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   263
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   264
    "Modified: 23.4.1996 / 22:13:31 / cg"
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   265
! !
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   266
943
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   267
!Colormap methodsFor:'converting'!
917
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   268
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   269
asArray
944
8d100ca5857c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 943
diff changeset
   270
    "return the receiver as an array containing my colors"
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   271
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   272
    |r g b n "{ Class: SmallInteger }" 
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   273
     scale array|
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   274
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   275
    n := redVector size.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   276
    array := Array new:n.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   277
    scale := Color scalingValue / 255.0.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   278
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   279
    1 to:n do:[:idx |
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   280
        r := redVector at:idx.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   281
        g := greenVector at:idx.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   282
        b := blueVector at:idx.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   283
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   284
        array at:idx put:(Color
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   285
                            scaledRed:(r * scale) rounded
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   286
                            scaledGreen:(g * scale) rounded
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   287
                            scaledBlue:(b * scale) rounded)
943
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   288
    ].
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   289
    ^ array
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   290
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   291
    "Created: 11.7.1996 / 20:19:45 / cg"
944
8d100ca5857c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 943
diff changeset
   292
    "Modified: 11.7.1996 / 21:34:16 / cg"
943
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   293
! !
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   294
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   295
!Colormap methodsFor:'copying'!
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   296
2483
6b77b75e74bb checkin from browser
tm
parents: 2448
diff changeset
   297
copyFrom:start to:stop
6b77b75e74bb checkin from browser
tm
parents: 2448
diff changeset
   298
    ^ self class withColors:(self asArray copyFrom:start to:stop)
6b77b75e74bb checkin from browser
tm
parents: 2448
diff changeset
   299
!
6b77b75e74bb checkin from browser
tm
parents: 2448
diff changeset
   300
917
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   301
postCopy
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   302
    redVector := redVector copy.
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   303
    greenVector := greenVector copy.
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   304
    blueVector := blueVector copy.
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   305
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   306
    "Created: 5.7.1996 / 14:52:15 / cg"
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   307
! !
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   308
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   309
!Colormap methodsFor:'misc'!
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   310
2448
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   311
grow:howBig
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   312
    "change the receivers size - not allowed"
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   313
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   314
    howBig == self size ifTrue:[^ self].
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   315
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   316
    ^ self shouldNotImplement
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   317
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   318
!
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   319
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   320
scaleValuesBy:scaleFactor
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   321
    "multiply all values by scaleFactor; finally round to integer.
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   322
     This can be used to brighten/darken an images colormap"
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   323
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   324
    |sz "{ Class: SmallInteger }" |
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   325
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   326
    sz := redVector size.
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   327
    1 to:sz do:[:index |
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   328
        redVector at:index put:((redVector at:index) * scaleFactor) rounded.
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   329
        greenVector at:index put:((greenVector at:index) * scaleFactor) rounded.
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   330
        blueVector at:index put:((blueVector at:index) * scaleFactor) rounded.
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   331
    ]
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   332
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   333
    "Modified: 2.5.1996 / 12:46:07 / cg"
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   334
! !
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   335
1435
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   336
!Colormap methodsFor:'queries'!
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   337
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   338
indexOfPaintNearest: color
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   339
    |minDistance minIndex dist
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   340
     sz "{ Class: SmallInteger }"|
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   341
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   342
    minDistance := (self at:1) deltaFrom:color.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   343
    minIndex := 1.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   344
    sz := self size.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   345
    2 to:sz do:[:idx |
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   346
        dist := (self at:idx) deltaFrom:color.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   347
        dist < minDistance ifTrue:[
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   348
            minDistance := dist.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   349
            minIndex := idx.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   350
        ]
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   351
    ].
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   352
    ^ minIndex
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   353
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   354
    "Created: 6.3.1997 / 15:45:39 / cg"
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   355
! !
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   356
773
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   357
!Colormap methodsFor:'storing'!
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   358
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   359
storeOn:aStream
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   360
    "append a representation to aStream, from which the receiver
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   361
     can be reconstructed"
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   362
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   363
    aStream nextPutAll:'(' , self class name ,' redVector:'.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   364
    redVector storeOn:aStream.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   365
    aStream nextPutAll:' greenVector:'.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   366
    greenVector storeOn:aStream.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   367
    aStream nextPutAll:' blueVector:'.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   368
    blueVector storeOn:aStream.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   369
    aStream nextPutAll:')'
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   370
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   371
    "Created: 30.5.1996 / 16:28:27 / ca"
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   372
    "Modified: 30.5.1996 / 16:32:44 / ca"
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   373
! !
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   374
1092
1b6391f333de category rename
Claus Gittinger <cg@exept.de>
parents: 944
diff changeset
   375
!Colormap class methodsFor:'documentation'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   376
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   377
version
2483
6b77b75e74bb checkin from browser
tm
parents: 2448
diff changeset
   378
    ^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.26 1999-03-05 17:05:40 tm Exp $'
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   379
! !