Colormap.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Feb 1997 19:00:42 +0100
changeset 1377 d898f243c3e5
parent 1351 6d5552229507
child 1378 a83a3522a199
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
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    73
redVector:r greenVector:g blueVector:b
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    74
    "given vectors of red/green/and blue pixelValues,
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    75
     return a new instance of myself.
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    76
     The values must be in the range 0..255."
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    77
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    78
    ^ self new redVector:r greenVector:g blueVector:b
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    79
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    80
    "
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    81
     Colormap 
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    82
        redVector:#[0 127 255]
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    83
        greenVector:#[0 127 255]
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    84
        blueVector:#[0 127 255]
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    85
    "
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    86
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    87
    "Modified: 23.4.1996 / 22:16:00 / cg"
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    88
!
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
withColors:aColorArray
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    91
    "given a sequenceable collection of colors, return a new instance
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    92
     of myself. Renamed from #fromColors: for ST-80 compatibility."
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    93
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
    94
    |n rV gV bV|
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
    95
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
    96
    n := aColorArray size.
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
    97
    rV := ByteArray new:n.
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
    98
    gV := ByteArray new:n.
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
    99
    bV := ByteArray new:n.
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   100
    1 to:n do:[:i |
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   101
        |clr|
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   102
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   103
        clr := aColorArray at:i.
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   104
        rV at:i put:(clr red * 255 / 100) rounded.
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   105
        bV at:i put:(clr green * 255 / 100) rounded.
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   106
        gV at:i put:(clr blue * 255 / 100) rounded.
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   107
    ].
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   108
    ^ self new redVector:rV greenVector:gV blueVector:bV
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   109
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   110
    "
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   111
     Colormap 
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   112
        withColors:(Array with:Color black
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   113
                          with:Color red
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   114
                          with:Color white)
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   115
    "
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   116
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   117
    "Created: 25.2.1997 / 18:59:09 / cg"
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   118
    "Modified: 25.2.1997 / 19:00:35 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   119
! !
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   120
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   121
!Colormap methodsFor:'accessing'!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   122
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   123
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
   124
    "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
   125
     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
   126
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   127
    |r g b idx "{ Class: SmallInteger }" |
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   128
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   129
    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
   130
    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
   131
    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
   132
    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
   133
1351
6d5552229507 checkin from browser
ca
parents: 1092
diff changeset
   134
    ^ 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
   135
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   136
    "Created: 2.5.1996 / 12:21:40 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   137
    "Modified: 8.6.1996 / 14:25:30 / cg"
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   138
!
03c73c3b1d57 Initial revision
claus
parents:
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
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
   141
    "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
   142
     Notice that index range is 1..."
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   143
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   144
    |r g b idx "{ Class: SmallInteger }" |
572
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   145
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   146
    r := (aColor red * 255 / 100) rounded.
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   147
    g := (aColor green * 255 / 100) rounded.
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   148
    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
   149
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   150
    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
   151
    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
   152
    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
   153
    blueVector at:idx put:b.
572
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   154
    ^ aColor
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
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:29 / cg"
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   157
!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   158
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   159
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
   160
    "return the blue component for some index.
153
claus
parents: 118
diff changeset
   161
     The returned value is scaled from the internal 0.. 255 to
claus
parents: 118
diff changeset
   162
     a percentage value 0..100"
claus
parents: 118
diff changeset
   163
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   164
    ^ (blueVector at:index) * 100 / 255
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   165
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   166
    "Modified: 2.5.1996 / 17:29:17 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   167
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   168
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   169
colors
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   170
    "ST-80 compatibility: return a collection containing the colors I hold"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   171
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   172
    ^ self asArray
153
claus
parents: 118
diff changeset
   173
!
claus
parents: 118
diff changeset
   174
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   175
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
   176
    "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
   177
     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
   178
     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
   179
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   180
    ^ (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
   181
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   182
    "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
   183
!
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   184
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   185
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
   186
    "return the red component for some index.
153
claus
parents: 118
diff changeset
   187
     The returned value is scaled from the internal 0.. 255 to
claus
parents: 118
diff changeset
   188
     a percentage value 0..100"
claus
parents: 118
diff changeset
   189
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   190
    ^ (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
   191
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   192
    "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
   193
!
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   194
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   195
size
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   196
    "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
   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
    ^ 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
   199
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   200
    "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
   201
! !
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   202
1092
1b6391f333de category rename
Claus Gittinger <cg@exept.de>
parents: 944
diff changeset
   203
!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
   204
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   205
blueVector
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   206
    "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
   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
    ^ blueVector
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   209
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   210
    "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
   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
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   213
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
   214
    "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
   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
    blueVector := something.
153
claus
parents: 118
diff changeset
   217
!
claus
parents: 118
diff changeset
   218
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   219
greenVector
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   220
    "return greenVector"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   221
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   222
    ^ greenVector
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   223
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   224
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   225
greenVector:something
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   226
    "set greenVector"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   227
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   228
    greenVector := something.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   229
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   230
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   231
redVector
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   232
    "return redVector"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   233
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   234
    ^ redVector
153
claus
parents: 118
diff changeset
   235
!
claus
parents: 118
diff changeset
   236
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   237
redVector:something
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   238
    "set redVector"
153
claus
parents: 118
diff changeset
   239
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   240
    redVector := something.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   241
!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   242
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   243
redVector:r greenVector:g blueVector:b
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   244
    "set the red, green and blueVectors"
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   245
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   246
    redVector := r.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   247
    greenVector := g.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   248
    blueVector := b.
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   249
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   250
    "Modified: 23.4.1996 / 22:13:31 / cg"
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   251
! !
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   252
943
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   253
!Colormap methodsFor:'converting'!
917
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   254
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   255
asArray
944
8d100ca5857c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 943
diff changeset
   256
    "return the receiver as an array containing my colors"
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   257
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   258
    |r g b n "{ Class: SmallInteger }" 
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   259
     scale array|
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   260
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   261
    n := redVector size.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   262
    array := Array new:n.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   263
    scale := Color scalingValue / 255.0.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   264
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   265
    1 to:n do:[:idx |
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   266
        r := redVector at:idx.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   267
        g := greenVector at:idx.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   268
        b := blueVector at:idx.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   269
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   270
        array at:idx put:(Color
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   271
                            scaledRed:(r * scale) rounded
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   272
                            scaledGreen:(g * scale) rounded
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   273
                            scaledBlue:(b * scale) rounded)
943
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   274
    ].
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   275
    ^ array
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   276
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   277
    "Created: 11.7.1996 / 20:19:45 / cg"
944
8d100ca5857c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 943
diff changeset
   278
    "Modified: 11.7.1996 / 21:34:16 / cg"
943
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   279
! !
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   280
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   281
!Colormap methodsFor:'copying'!
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   282
917
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   283
postCopy
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   284
    redVector := redVector copy.
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   285
    greenVector := greenVector copy.
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   286
    blueVector := blueVector copy.
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   287
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   288
    "Created: 5.7.1996 / 14:52:15 / cg"
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   289
! !
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   290
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   291
!Colormap methodsFor:'misc'!
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   292
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   293
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
   294
    "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
   295
     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
   296
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   297
    |sz "{ Class: SmallInteger }" |
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   298
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   299
    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
   300
    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
   301
        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
   302
        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
   303
        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
   304
    ]
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   305
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   306
    "Modified: 2.5.1996 / 12:46:07 / cg"
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   307
! !
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   308
773
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   309
!Colormap methodsFor:'storing'!
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   310
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   311
storeOn:aStream
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   312
    "append a representation to aStream, from which the receiver
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   313
     can be reconstructed"
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   314
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   315
    aStream nextPutAll:'(' , self class name ,' redVector:'.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   316
    redVector storeOn:aStream.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   317
    aStream nextPutAll:' greenVector:'.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   318
    greenVector storeOn:aStream.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   319
    aStream nextPutAll:' blueVector:'.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   320
    blueVector storeOn:aStream.
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   321
    aStream nextPutAll:')'
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   322
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   323
    "Created: 30.5.1996 / 16:28:27 / ca"
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   324
    "Modified: 30.5.1996 / 16:32:44 / ca"
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   325
! !
a06487b33240 checkin from browser
ca
parents: 665
diff changeset
   326
1092
1b6391f333de category rename
Claus Gittinger <cg@exept.de>
parents: 944
diff changeset
   327
!Colormap class methodsFor:'documentation'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   328
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   329
version
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   330
    ^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.22 1997-02-25 18:00:42 cg Exp $'
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   331
! !