The R Project SVN R

Rev

Rev 61153 | Rev 75868 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61153 Rev 61168
Line 64... Line 64...
64
                 green = c(0.2900, 0.6000),
64
                 green = c(0.2900, 0.6000),
65
                 blue =  c(0.1500, 0.0600),
65
                 blue =  c(0.1500, 0.0600),
66
                 name = "PAL/SECAM RGB"))
66
                 name = "PAL/SECAM RGB"))
67
 
67
 
68
## converter for sRGB in #rrggbb format
68
## converter for sRGB in #rrggbb format
69
hexcolor <- colorConverter(toXYZ = function(hex,...) {
69
hexcolor <- colorConverter(toXYZ = function(hex, ...) {
70
                            rgb <- t(col2rgb(hex))/255
70
                            rgb <- t(col2rgb(hex))/255
71
                            colorspaces$sRGB$toXYZ(rgb, ...) },
71
                            colorspaces$sRGB$toXYZ(rgb, ...) },
72
                           fromXYZ = function(xyz,...) {
72
                           fromXYZ = function(xyz, ...) {
73
                              rgb <- colorspaces$sRGB$fromXYZ(xyz, ..)
73
                              rgb <- colorspaces$sRGB$fromXYZ(xyz, ..)
74
                              rgb <- round(rgb,5)
74
                              rgb <- round(rgb, 5)
75
                              if (min(rgb) < 0 || max(rgb) > 1)
75
                              if (min(rgb) < 0 || max(rgb) > 1)
76
                                   as.character(NA)
76
                                   as.character(NA)
77
                              else rgb(rgb[1], rgb[2], rgb[3])},
77
                              else rgb(rgb[1], rgb[2], rgb[3])},
78
                           white = "D65", name = "#rrggbb")
78
                           white = "D65", name = "#rrggbb")
79
 
79
 
80
(cols <- t(col2rgb(palette())))
80
(cols <- t(col2rgb(palette())))
81
zapsmall(luv <- convertColor(cols,from = "sRGB", to = "Luv", scale.in = 255))
81
zapsmall(luv <- convertColor(cols, from = "sRGB", to = "Luv", scale.in = 255))
82
(hex <- convertColor(luv, from = "Luv",  to = hexcolor, scale.out = NULL))
82
(hex <- convertColor(luv, from = "Luv",  to = hexcolor, scale.out = NULL))
83
 
83
 
84
## must make hex a matrix before using it
84
## must make hex a matrix before using it
85
(cc <- round(convertColor(as.matrix(hex), from = hexcolor, to = "sRGB",
85
(cc <- round(convertColor(as.matrix(hex), from = hexcolor, to = "sRGB",
86
                          scale.in = NULL, scale.out = 255)))
86
                          scale.in = NULL, scale.out = 255)))