Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colour conversions #14

Closed
SymbolixAU opened this issue Sep 9, 2018 · 2 comments

Comments

@SymbolixAU
Copy link
Owner

commented Sep 9, 2018

TODO

  • hex_to_rgb - with and without alpha, both RGB(A) and RRGGBB(AA)
  • rgb_to_hex - with and without alpha, allow vectors & matrix inputs
@SymbolixAU SymbolixAU added this to the v0.2.0 milestone Sep 9, 2018
@SymbolixAU SymbolixAU self-assigned this Oct 9, 2018
@SymbolixAU

This comment has been minimized.

Copy link
Owner Author

commented Oct 9, 2018

new convert_hex_to_rgb() benchmarks well

col <- "#00FF00FF"
col <- rep(col, 1e6)

library(microbenchmark)

microbenchmark(
  cv = { colourvalues:::rcpp_convert_hex_to_rgb_new( col) },
  cv_old = { colourvalues:::rcpp_convert_hex_to_rgb( col ) }, 
  gr = { grDevices::col2rgb(col, alpha = TRUE) },
  times = 10
)

# Unit: milliseconds
#   expr       min        lq     mean    median        uq       max neval
#     cv  30.81213  32.73352  47.4408  35.59811  76.95149  81.37984    10
# cv_old 272.52093 276.65413 290.7468 285.09019 295.67034 327.61521    10
#     gr  36.80980  39.10075  41.6736  41.57528  44.91530  46.51591    10
SymbolixAU added a commit that referenced this issue Oct 9, 2018
SymbolixAU added a commit that referenced this issue Oct 9, 2018
@SymbolixAU

This comment has been minimized.

Copy link
Owner Author

commented Oct 10, 2018

and the other way

rgb2hex <- function(m) grDevices::rgb(m[,1], m[,2], m[,3], m[,4], maxColorValue = 255)

m <- matrix(c(255,170,0,255),ncol = 4)
n <- 1e6
m <- m[rep(1,n),]

r <- rep(255, n)
g <- rep(170, n)
b <- rep(0, n)
a <- rep(255, n)
microbenchmark(
  gr = { rgb2hex(m) },
  gr2 = { rgb(r,g,b,a, maxColorValue = 255) },
  cv = { colourvalues:::rcpp_convert_rgb_to_hex(m) },
  times = 10
)

# Unit: milliseconds
# expr      min       lq      mean    median        uq       max neval
#  gr 92.93735 97.36313 105.60413 100.61244 104.47904 152.06389    10
# gr2 77.65241 80.03476  93.30192  85.64504  90.76205 131.98374    10
#  cv 78.46464 78.81009  83.86777  81.85836  87.48609  94.67922    10
SymbolixAU added a commit that referenced this issue Oct 10, 2018
@SymbolixAU SymbolixAU closed this Oct 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.