Colormap.st
author Claus Gittinger <cg@exept.de>
Mon, 06 May 2013 20:26:05 +0200
changeset 6059 cefde51cf073
parent 4794 fee4be15bbd5
child 6150 f986ec057734
permissions -rw-r--r--
class: Colormap comment/format in: #rgbBytesVector:
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
"
3265
408fac627dc4 category change
Claus Gittinger <cg@exept.de>
parents: 2483
diff changeset
    12
"{ Package: 'stx:libview' }"
408fac627dc4 category change
Claus Gittinger <cg@exept.de>
parents: 2483
diff changeset
    13
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
    14
SequenceableCollection subclass:#Colormap
572
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
    15
	instanceVariableNames:'redVector greenVector blueVector'
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
    16
	classVariableNames:''
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
    17
	poolDictionaries:''
665
843bf13683f5 category change
Claus Gittinger <cg@exept.de>
parents: 637
diff changeset
    18
	category:'Graphics-Images-Support'
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    19
!
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    20
1092
1b6391f333de category rename
Claus Gittinger <cg@exept.de>
parents: 944
diff changeset
    21
!Colormap class methodsFor:'documentation'!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    22
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    23
copyright
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    24
"
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    25
 COPYRIGHT (c) 1994 by Claus Gittinger
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    26
	      All Rights Reserved
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    27
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    28
 This software is furnished under a license and may be used
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    33
 hereby transferred.
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    34
"
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    35
!
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    36
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    37
documentation
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    38
"
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    39
    Colormaps are used with images (and Forms) to keep the byte-to-color 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).
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    43
    This was done to avoid overhead due to allocation of many color instances.
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    44
3847
288ab85676aa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3846
diff changeset
    45
    Notice: Colormap is going to be obsoleted, and the functionality will
288ab85676aa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3846
diff changeset
    46
    move to subclasses (MappedPalette etc.)
288ab85676aa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3846
diff changeset
    47
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    48
    [author:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    49
        Claus Gittinger
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    50
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
    51
    [see also:]
603
7e2b1e471427 commentary
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
    52
        Color Image Form
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    53
"
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    54
! !
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    55
1092
1b6391f333de category rename
Claus Gittinger <cg@exept.de>
parents: 944
diff changeset
    56
!Colormap class methodsFor:'instance creation'!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
    57
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
    58
fromColors:aColorArray
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    59
    "given a sequenceable collection of colors, return a new instance of myself.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    60
     Obsolete: use #withColors: for VW compatibility."
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
    61
4176
40b359dfc293 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 3876
diff changeset
    62
    <resource: #obsolete>
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    63
    self obsoleteMethodWarning:'use #withColors:'.
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    64
    ^ self withColors:aColorArray
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    65
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    66
    "
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    67
     Colormap 
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    68
        fromColors:(Array with:Color black
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    69
                          with:Color red
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    70
                          with:Color white)
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
    "Modified: 25.2.1997 / 19:00:31 / cg"
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    74
!
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    75
2448
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
    76
new:numColors
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    77
    "/ ^ self withColors:(Array new:numColors withAll:Color black)
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    78
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
    79
    self == Colormap ifTrue:[
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
    80
        "/ Colormap will be abstract in the near future
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
    81
        self obsoleteFeatureWarning:'please change your code to use a concrete subclass of ColorPalette'.
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
    82
    ].
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
    83
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    84
    ^ self
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    85
        redVector:(ByteArray new:numColors withAll:0)
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    86
        greenVector:(ByteArray new:numColors withAll:0)
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    87
        blueVector:(ByteArray new:numColors withAll:0)
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    88
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    89
    "
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
    90
     MappedPalette new:100
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    91
    "
2448
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
    92
!
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
    93
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
    94
redVector:rV greenVector:gV blueVector:bV
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    95
    "given vectors of red/green/and blue pixelValues,
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    96
     return a new instance of myself.
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    97
     The values must be in the range 0..255."
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
    98
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
    99
    self == Colormap ifTrue:[
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   100
        "/ Colormap will be abstract in the near future
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   101
        self obsoleteFeatureWarning:'please change your code to use a concrete subclass of ColorPalette'.
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   102
    ].
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   103
    ^ self new 
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   104
        redVector:rV 
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   105
        greenVector:gV 
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   106
        blueVector:bV
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   107
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   108
    "
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   109
     MappedPalette
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   110
        redVector:#[0 127 255]
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   111
        greenVector:#[0 127 255]
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   112
        blueVector:#[0 127 255]
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   113
    "
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   114
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   115
    "Modified: 23.4.1996 / 22:16:00 / cg"
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   116
!
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   117
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   118
rgbBytesVector:rgbVector
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   119
    "given a single vector containing r-g-b byte values,
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   120
     return a new instance of myself.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   121
     The values must be in the range 0..255."
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   122
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   123
    |rV gV bV srcIndex nColors|
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   124
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   125
    nColors := rgbVector size // 3.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   126
    rV := ByteArray new:nColors.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   127
    gV := ByteArray new:nColors.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   128
    bV := ByteArray new:nColors.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   129
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   130
    srcIndex := 1.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   131
    1 to:nColors do:[:dstIndex |
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   132
        |r g b|
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   133
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   134
        r := rgbVector at:srcIndex.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   135
        g := rgbVector at:srcIndex+1.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   136
        b := rgbVector at:srcIndex+2.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   137
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   138
        rV at:dstIndex put:r.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   139
        gV at:dstIndex put:g.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   140
        bV at:dstIndex put:b.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   141
        srcIndex := srcIndex + 3.
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   142
    ].
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   143
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   144
    ^ self 
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   145
        redVector:rV 
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   146
        greenVector:gV 
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   147
        blueVector:bV
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   148
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   149
    "
3845
189f7932a76f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3844
diff changeset
   150
     |map|
189f7932a76f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3844
diff changeset
   151
6059
cefde51cf073 class: Colormap
Claus Gittinger <cg@exept.de>
parents: 4794
diff changeset
   152
     map := Colormap rgbBytesVector:#[0 0 0 127 127 127 255 0 0 255 255 255].
3845
189f7932a76f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3844
diff changeset
   153
     map atPixelValue:2    
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   154
    "
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   155
!
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   156
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   157
rgbValueVector:rgbValueVector
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   158
    "given a single vector containing r-g-b pixel-values,
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   159
     return a new instance of myself.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   160
     The values must be of the rgb-form i.e. 16rRRGGBB"
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   161
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   162
    |rV gV bV nColors|
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   163
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   164
    nColors := rgbValueVector size.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   165
    rV := ByteArray new:nColors.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   166
    gV := ByteArray new:nColors.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   167
    bV := ByteArray new:nColors.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   168
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   169
    1 to:nColors do:[:index |
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   170
        |rgb r g b|
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   171
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   172
        rgb := rgbValueVector at:index.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   173
        r := (rgb bitShift:-16) bitAnd:16rFF.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   174
        g := (rgb bitShift:-8) bitAnd:16rFF.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   175
        b := rgb bitAnd:16rFF.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   176
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   177
        rV at:index put:r.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   178
        gV at:index put:g.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   179
        bV at:index put:b.
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   180
    ].
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   181
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   182
    ^ self 
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   183
        redVector:rV 
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   184
        greenVector:gV 
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   185
        blueVector:bV
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   186
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   187
    "
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   188
     |map|
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   189
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   190
     map := Colormap rgbValueVector:#(16r000000 16r7F7F7F 16r800000 16rFFFFFF).
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   191
     map atPixelValue:2    
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   192
    "
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   193
!
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
   194
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   195
withColors:aColorArray
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   196
    "given a sequenceable collection of colors, return a new instance
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   197
     of myself. Renamed from #fromColors: for ST-80 compatibility."
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   198
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   199
    self == Colormap ifTrue:[
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   200
        "/ Colormap will be abstract in the near future
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   201
        self obsoleteFeatureWarning:'please change your code to use a concrete subclass of ColorPalette'.
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   202
    ].
1378
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   203
    ^ self new colors:aColorArray
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   204
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   205
    "
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   206
     MappedPalette
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   207
        withColors:(Array with:Color black
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   208
                          with:Color red
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   209
                          with:Color white)
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   210
    "
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   211
1377
d898f243c3e5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1351
diff changeset
   212
    "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
   213
    "Modified: 25.2.1997 / 19:03:08 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   214
! !
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   215
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   216
!Colormap methodsFor:'accessing'!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   217
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   218
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
   219
    "return the color for a index. 
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   220
     Notice that index range is 1...nColors"
635
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
    |r g b idx "{ Class: SmallInteger }" |
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   223
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   224
    idx := index.
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   225
    r := self redByteAt:idx.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   226
    g := self greenByteAt:idx.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   227
    b := self blueByteAt:idx.
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   228
1351
6d5552229507 checkin from browser
ca
parents: 1092
diff changeset
   229
    ^ 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
   230
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   231
    "Created: 2.5.1996 / 12:21:40 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   232
    "Modified: 8.6.1996 / 14:25:30 / cg"
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   233
!
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   234
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   235
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
   236
    "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
   237
     Notice that index range is 1..."
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   238
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   239
    |r g b idx "{ Class: SmallInteger }" |
572
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   240
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   241
    r := (aColor red * 255 / 100) rounded.
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   242
    g := (aColor green * 255 / 100) rounded.
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   243
    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
   244
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   245
    idx := index.
4794
fee4be15bbd5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
   246
    self redByteAt:idx put:(r max:0).
fee4be15bbd5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
   247
    self greenByteAt:idx put:(g max:0).
fee4be15bbd5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
   248
    self blueByteAt:idx put:(b max:0).
572
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   249
    ^ aColor
b164eb8a3e6e commentary
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   250
4794
fee4be15bbd5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
   251
    "Modified: / 22-07-2007 / 15:28:32 / cg"
118
25e775072a89 *** empty log message ***
claus
parents: 91
diff changeset
   252
!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   253
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   254
atPixelValue:pixelValue 
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   255
    "return the color for a pixelValue. 
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   256
     Notice that pixelValue range is 0...nColors-1"
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   257
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   258
    ^ self at:(pixelValue + 1)
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   259
!
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   260
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   261
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
   262
    "return the blue component for some index.
153
claus
parents: 118
diff changeset
   263
     The returned value is scaled from the internal 0.. 255 to
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   264
     a percentage value 0..100.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   265
     Notice that index range is 1..."
153
claus
parents: 118
diff changeset
   266
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   267
    ^ (self blueByteAt:index) * 100 / 255
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   268
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   269
    "Modified: 2.5.1996 / 17:29:17 / cg"
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   270
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   271
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   272
colors
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   273
    "ST-80 compatibility: return a collection containing the colors I hold"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   274
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   275
    ^ self asArray
153
claus
parents: 118
diff changeset
   276
!
claus
parents: 118
diff changeset
   277
1378
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   278
colors:aCollectionOfColors
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   279
    "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
   280
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   281
    |sz "{Class: SmallInteger }"|
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   282
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   283
    sz := aCollectionOfColors size.
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   284
    redVector := ByteArray new:sz.
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   285
    greenVector := ByteArray new:sz.
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   286
    blueVector := ByteArray new:sz.
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   287
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   288
    1 to:sz do:[:i |
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   289
        |clr r g b|
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   290
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   291
        clr := aCollectionOfColors at:i.
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   292
        clr notNil ifTrue:[
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   293
            redVector at:i put:(clr redByte).
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   294
            greenVector at:i put:(clr greenByte).
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   295
            blueVector at:i put:(clr blueByte).
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   296
        ]
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   297
    ].
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   298
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   299
    "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
   300
!
a83a3522a199 moved #colors: from mappedPalette; use it in #withColors.
Claus Gittinger <cg@exept.de>
parents: 1377
diff changeset
   301
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   302
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
   303
    "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
   304
     The returned value is scaled from the internal 0.. 255 to
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   305
     a percentage value 0..100.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   306
     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
   307
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   308
    ^ (self greenByteAt: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
   309
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   310
    "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
   311
!
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   312
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   313
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
   314
    "return the red component for some index.
153
claus
parents: 118
diff changeset
   315
     The returned value is scaled from the internal 0.. 255 to
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   316
     a percentage value 0..100.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   317
     Notice that index range is 1..."
153
claus
parents: 118
diff changeset
   318
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   319
    ^ (self redByteAt: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
   320
637
08e099c202db oops - had to undo 0-based indexing (some images use arrays as colormap)
Claus Gittinger <cg@exept.de>
parents: 636
diff changeset
   321
    "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
   322
! !
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   323
1092
1b6391f333de category rename
Claus Gittinger <cg@exept.de>
parents: 944
diff changeset
   324
!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
   325
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   326
blueByteAt:index
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   327
    "return the blueByte component for some index.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   328
     The returned value is from the internal 0.. 255"
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   329
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   330
    ^ (blueVector at:index)
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   331
!
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   332
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   333
blueByteAt:index put:anInteger
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   334
    "change the internal blueByte component for some index.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   335
     The argument, anInteger should be from the internal 0.. 255.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   336
     Notice that index range is 1..."
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   337
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   338
    ^ blueVector at:index put:anInteger
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   339
!
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   340
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   341
blueVector
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   342
    "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
   343
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   344
    ^ blueVector
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   345
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   346
    "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
   347
!
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   348
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   349
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
   350
    "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
   351
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   352
    blueVector := something.
153
claus
parents: 118
diff changeset
   353
!
claus
parents: 118
diff changeset
   354
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   355
greenByteAt:index
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   356
    "return the greenByte component for some index.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   357
     The returned value is from the internal 0.. 255"
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   358
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   359
    ^ (greenVector at:index)
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   360
!
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   361
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   362
greenByteAt:index put:anInteger
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   363
    "change the internal greenByte component for some index.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   364
     The argument, anInteger should be from the internal 0.. 255.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   365
     Notice that index range is 1..."
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   366
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   367
    ^ greenVector at:index put:anInteger
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   368
!
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   369
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   370
greenVector
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   371
    "return greenVector"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   372
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   373
    ^ greenVector
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   374
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   375
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   376
greenVector:something
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   377
    "set greenVector"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   378
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   379
    greenVector := something.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   380
!
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   381
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   382
redByteAt:index
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   383
    "return the redByte component for some index.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   384
     The returned value is from the internal 0.. 255"
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   385
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   386
    ^ (redVector at:index)
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   387
!
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   388
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   389
redByteAt:index put:anInteger
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   390
    "change the internal redByte component for some index.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   391
     The argument, anInteger should be from the internal 0.. 255.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   392
     Notice that index range is 1..."
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   393
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   394
    ^ redVector at:index put:anInteger
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   395
!
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   396
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   397
redVector
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   398
    "return redVector"
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   399
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   400
    ^ redVector
153
claus
parents: 118
diff changeset
   401
!
claus
parents: 118
diff changeset
   402
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   403
redVector:something
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   404
    "set redVector"
153
claus
parents: 118
diff changeset
   405
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   406
    redVector := something.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   407
!
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   408
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   409
redVector:r greenVector:g blueVector:b
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   410
    "set the red, green and blueVectors"
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   411
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   412
    redVector := r.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   413
    greenVector := g.
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   414
    blueVector := b.
602
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   415
f4827cf7d3f9 commentary
Claus Gittinger <cg@exept.de>
parents: 572
diff changeset
   416
    "Modified: 23.4.1996 / 22:13:31 / cg"
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   417
! !
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   418
943
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   419
!Colormap methodsFor:'converting'!
917
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   420
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   421
asArray
944
8d100ca5857c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 943
diff changeset
   422
    "return the receiver as an array containing my colors"
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   423
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   424
    |r g b n "{ Class: SmallInteger }" 
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   425
     scale array|
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   426
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   427
    n := self size.
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   428
    array := Array new:n.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   429
    scale := Color scalingValue / 255.0.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   430
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   431
    1 to:n do:[:idx |
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   432
        r := self redByteAt:idx.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   433
        g := self greenByteAt:idx.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   434
        b := self blueByteAt:idx.
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   435
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   436
        array at:idx put:(Color
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   437
                            scaledRed:(r * scale) rounded
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   438
                            scaledGreen:(g * scale) rounded
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   439
                            scaledBlue:(b * scale) rounded)
943
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   440
    ].
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   441
    ^ array
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   442
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   443
    "Created: 11.7.1996 / 20:19:45 / cg"
944
8d100ca5857c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 943
diff changeset
   444
    "Modified: 11.7.1996 / 21:34:16 / cg"
943
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   445
! !
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   446
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   447
!Colormap methodsFor:'copying'!
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   448
2483
6b77b75e74bb checkin from browser
tm
parents: 2448
diff changeset
   449
copyFrom:start to:stop
3844
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   450
    ^ self class 
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   451
        redVector:(redVector copyFrom:start to:stop)
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   452
        greenVector:(greenVector copyFrom:start to:stop)
6640f9dd4b9e code cleanup
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   453
        blueVector:(blueVector copyFrom:start to:stop)
2483
6b77b75e74bb checkin from browser
tm
parents: 2448
diff changeset
   454
!
6b77b75e74bb checkin from browser
tm
parents: 2448
diff changeset
   455
917
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   456
postCopy
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   457
    redVector := redVector copy.
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   458
    greenVector := greenVector copy.
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   459
    blueVector := blueVector copy.
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   460
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   461
    "Created: 5.7.1996 / 14:52:15 / cg"
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   462
! !
d0ab9a4e0344 postCopt must copy the vectors
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   463
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   464
!Colormap methodsFor:'misc'!
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   465
2448
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   466
grow:howBig
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   467
    "change the receivers size"
2448
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   468
3271
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   469
    |t|
2448
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   470
3271
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   471
    howBig == self size ifTrue:[^ self].
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   472
    redVector isNil ifTrue:[
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   473
        redVector := ByteArray new:howBig.
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   474
        greenVector := ByteArray new:howBig.
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   475
        blueVector := ByteArray new:howBig.
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   476
        ^ self
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   477
    ].
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   478
    t := redVector. redVector := ByteArray new:howBig. redVector replaceFrom:1 to:t size with:t startingAt:1.
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   479
    t := greenVector. greenVector := ByteArray new:howBig. greenVector replaceFrom:1 to:t size with:t startingAt:1.
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   480
    t := blueVector. blueVector := ByteArray new:howBig. blueVector replaceFrom:1 to:t size with:t startingAt:1.
51d0adbc1aa0 support grow
Claus Gittinger <cg@exept.de>
parents: 3265
diff changeset
   481
    ^ self
2448
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   482
!
89c338d3412e more for collection-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
   483
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   484
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
   485
    "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
   486
     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
   487
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   488
    |sz "{ Class: SmallInteger }" |
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   489
635
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   490
    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
   491
    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
   492
        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
   493
        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
   494
        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
   495
    ]
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   496
1e1c3f870ba8 colorMap is now 0-index based (more compatibility with ST-80's Palette)
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   497
    "Modified: 2.5.1996 / 12:46:07 / cg"
91
03c73c3b1d57 Initial revision
claus
parents:
diff changeset
   498
! !
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   499
3276
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   500
!Colormap methodsFor:'printing & storing'!
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   501
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   502
storeOn:aStream
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   503
    "append a representation to aStream, from which the receiver
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   504
     can be reconstructed"
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   505
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   506
    aStream nextPutAll:'(' , self class name ,' redVector:'.
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   507
    redVector storeOn:aStream.
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   508
    aStream nextPutAll:' greenVector:'.
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   509
    greenVector storeOn:aStream.
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   510
    aStream nextPutAll:' blueVector:'.
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   511
    blueVector storeOn:aStream.
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   512
    aStream nextPutAll:')'
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   513
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   514
    "Created: 30.5.1996 / 16:28:27 / ca"
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   515
    "Modified: 30.5.1996 / 16:32:44 / ca"
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   516
! !
9ed39f7e7282 category change
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
   517
1435
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   518
!Colormap methodsFor:'queries'!
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   519
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   520
indexOfPaintNearest: color
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   521
    |minDistance minIndex dist
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   522
     sz "{ Class: SmallInteger }"|
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   523
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   524
    minDistance := (self at:1) deltaFrom:color.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   525
    minIndex := 1.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   526
    sz := self size.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   527
    2 to:sz do:[:idx |
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   528
        dist := (self at:idx) deltaFrom:color.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   529
        dist < minDistance ifTrue:[
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   530
            minDistance := dist.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   531
            minIndex := idx.
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   532
        ]
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   533
    ].
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   534
    ^ minIndex
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   535
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   536
    "Created: 6.3.1997 / 15:45:39 / cg"
3265
408fac627dc4 category change
Claus Gittinger <cg@exept.de>
parents: 2483
diff changeset
   537
!
408fac627dc4 category change
Claus Gittinger <cg@exept.de>
parents: 2483
diff changeset
   538
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   539
isFixedPalette
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   540
    ^ false
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   541
!
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   542
3840
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   543
isGreyscaleColormap
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   544
    "return true, if the receiver is actually a greymap.
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   545
     Could be used to convert images as read from imageFiles
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   546
     (for example, GIF-files) automatically to greyScale (which is not yet done)."
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   547
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   548
    |sz "{ Class: SmallInteger }"
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   549
     redVal|
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   550
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   551
    sz := self size.
3840
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   552
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   553
    1 to:sz do:[:i |
4185
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   554
        redVal := self redByteAt:i.
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   555
        redVal ~~ (self greenByteAt:i) ifTrue:[^ false].
cc96d1c1e28c fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4176
diff changeset
   556
        redVal ~~ (self blueByteAt:i) ifTrue:[^ false].
3840
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   557
    ].
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   558
    ^ true
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   559
!
5121ec4d4955 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   560
3265
408fac627dc4 category change
Claus Gittinger <cg@exept.de>
parents: 2483
diff changeset
   561
size
408fac627dc4 category change
Claus Gittinger <cg@exept.de>
parents: 2483
diff changeset
   562
    "return the number of colors in the receiver"
408fac627dc4 category change
Claus Gittinger <cg@exept.de>
parents: 2483
diff changeset
   563
408fac627dc4 category change
Claus Gittinger <cg@exept.de>
parents: 2483
diff changeset
   564
    ^ redVector size
408fac627dc4 category change
Claus Gittinger <cg@exept.de>
parents: 2483
diff changeset
   565
408fac627dc4 category change
Claus Gittinger <cg@exept.de>
parents: 2483
diff changeset
   566
    "Modified: 23.4.1996 / 22:13:43 / cg"
1435
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   567
! !
b6c31a44424a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1378
diff changeset
   568
1092
1b6391f333de category rename
Claus Gittinger <cg@exept.de>
parents: 944
diff changeset
   569
!Colormap class methodsFor:'documentation'!
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   570
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   571
version
6059
cefde51cf073 class: Colormap
Claus Gittinger <cg@exept.de>
parents: 4794
diff changeset
   572
    ^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.40 2013-05-06 18:26:05 cg Exp $'
285
1effedd62f30 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   573
! !
6059
cefde51cf073 class: Colormap
Claus Gittinger <cg@exept.de>
parents: 4794
diff changeset
   574