farver

High Performance Colourspace Manipulation in R

https://github.com/thomasp85/farver

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.9%) to scientific vocabulary

Keywords

color-conversion rstats
Last synced: 10 months ago · JSON representation

Repository

High Performance Colourspace Manipulation in R

Basic Info
Statistics
  • Stars: 140
  • Watchers: 6
  • Forks: 14
  • Open Issues: 14
  • Releases: 7
Topics
color-conversion rstats
Created over 8 years ago · Last pushed about 2 years ago
Metadata Files
Readme License Code of conduct

README.Rmd

---
output: github_document
---



# farver 


[![R-CMD-check](https://github.com/thomasp85/farver/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/thomasp85/farver/actions/workflows/R-CMD-check.yaml)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version-ago/farver)](https://cran.r-project.org/package=farver)
[![CRAN_Download_Badge](http://cranlogs.r-pkg.org/badges/farver)](https://cran.r-project.org/package=farver)
[![Codecov test coverage](https://codecov.io/gh/thomasp85/farver/branch/main/graph/badge.svg)](https://app.codecov.io/gh/thomasp85/farver?branch=main)


```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)
```

The goal of farver is to provide very fast, vectorised functions for 
conversion of colours between different colour spaces, colour comparisons 
(distance between colours), encoding/decoding, and channel manipulation in 
colour strings. To this end it provides an interface to a modified 
version of the [ColorSpace](https://github.com/berendeanicolae/ColorSpace) C++ 
library developed by Berendea Nicolae.

## Installation
farver can be installed from CRAN using `install.packages('farver')`. The 
development version can be installed from Github using `devtools`:

```{r, eval=FALSE}
# install.packages('devtools')
devtools::install_github('thomasp85/farver')
```

## Use
farver provides an alternative to the `grDevices::rgb()` and 
`grDevices::col2rgb()` for encoding and decoding colours strings. The farver 
functions are superficially equivalent but provides a uniform output format, and
the option to encode and decode directly from/to other colour spaces.

```{r}
library(farver)

codes <- rainbow(10)
codes

spectrum <- decode_colour(codes)
spectrum

encode_colour(spectrum)
```

It also provides an alternative to `grDevices::convertColor()` to switch between
colours spaces. If the origin is a colour string it is possible to decode 
directly into the given colour space. Conversely, if the endpoint is a colour
string it is also possible to encode directly from a given colour space.

```{r}
spectrum_lab <- convert_colour(spectrum, 'rgb', 'lab')
spectrum_lab

decode_colour(codes, to = 'lab')

encode_colour(spectrum_lab, from = 'lab')
```

If colours are given as strings, manipulation of channels will normally require
decoding, conversion to the correct colour space, manipulation of the given 
channel, converting back to rgb and the encoding to string. farver provides a
range of functions that allow you to change any channel in the supported spaces
directly in colour strings:

```{r}
# Add a value to the channel
add_to_channel(codes, channel = 'l', value = 1:10, space = 'lab')

# Set a channel to a specific value
set_channel(codes, 'alpha', c(0.3, 0.7))

# Limit a channel to a given value
cap_channel(codes, 'r', 200)
```

Lastly, farver also provides utilities for calculating the distance between
colours, based on a range of different measures

```{r}
spectrum2 <- t(col2rgb(heat.colors(10)))

compare_colour(spectrum, spectrum2, 'rgb', method = 'cie2000')[1:6, 1:6]
```

## Supported colour spaces
`farver` currently supports the following colour spaces:

- CMY
- CMYK
- HSL
- HSB
- HSV
- CIE L*AB
- Hunter LAB
- OK LAB
- LCH(ab)
- LCH(uv)
- LCH(OK)
- LUV
- RGB
- XYZ
- YXY

## Supported distance measures
`farver` supports the following colour distance metrics

- Euclidean
- CIE1976
- CIE94
- CIE2000
- CMC

## White References
`farver` allows you to set the white point for relative colour spaces, either
based on a standard illuminant (A-F series supported) or by specifying 
chromaticity coordinates or tristimulus values directly

## Benchmark
`farver` is faster than its `grDevices` counterpart but less so than it was at 
its first release, as the colour conversion in grDevices has been improved 
since.

```{r, message=FALSE}
library(ggplot2)
test <- matrix(runif(300000, min = 0, max = 255), ncol = 3)
timing <- bench::mark(
  farver = convert_colour(test, 'rgb', 'lab'),
  grDevices = convertColor(test, 'sRGB', 'Lab', scale.in = 255), 
  check = FALSE,
  min_iterations = 100
)
plot(timing, type = 'ridge')
```

Still, if the start- and/or endpoint are colour strings the ability
to decode and encode directly from/to any colour space will give a huge speed 
up.

```{r, message=FALSE}
colour_strings <- colours()
timing <- bench::mark(
  farver = decode_colour(colour_strings, to = 'lab'),
  grDevices = convertColor(t(col2rgb(colour_strings)), 'sRGB', 'Lab', scale.in = 255), 
  check = FALSE,
  min_iterations = 100
)
plot(timing, type = 'ridge')
```

## Code of Conduct
Please note that the 'farver' project is released with a
[Contributor Code of Conduct](https://farver.data-imaginist.com/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.

Owner

  • Name: Thomas Lin Pedersen
  • Login: thomasp85
  • Kind: user
  • Location: Copenhagen
  • Company: @posit-pbc, part of @tidyverse team

Maker of tools focusing on data science and data visualisation

GitHub Events

Total
  • Issues event: 1
  • Watch event: 11
  • Issue comment event: 4
Last Year
  • Issues event: 1
  • Watch event: 11
  • Issue comment event: 4

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 130
  • Total Committers: 5
  • Avg Commits per committer: 26.0
  • Development Distribution Score (DDS): 0.038
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Thomas Lin Pedersen t****5@g****m 125
Emil Hvitfeldt e****t@g****m 2
Michael Sumner m****r@g****m 1
Kirill Müller k****r 1
Romain François r****n@t****r 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 39
  • Total pull requests: 11
  • Average time to close issues: 6 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 18
  • Total pull request authors: 5
  • Average comments per issue: 1.13
  • Average comments per pull request: 1.27
  • Merged pull requests: 5
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • thomasp85 (8)
  • hadley (8)
  • jmw86069 (3)
  • dylanbeaudette (3)
  • EmilHvitfeldt (2)
  • QuLogic (2)
  • ericmelse (2)
  • Sunnyy651 (1)
  • royfrancis (1)
  • francisbarton (1)
  • SamGG (1)
  • caodudu (1)
  • krlmlr (1)
  • pmur002 (1)
  • MohoWu (1)
Pull Request Authors
  • zeehio (6)
  • mdsumner (2)
  • EmilHvitfeldt (2)
  • krlmlr (1)
  • romainfrancois (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 3
  • Total downloads:
    • cran 747,312 last-month
  • Total docker downloads: 158,577,836
  • Total dependent packages: 25
    (may contain duplicates)
  • Total dependent repositories: 114
    (may contain duplicates)
  • Total versions: 24
  • Total maintainers: 1
cran.r-project.org: farver

High Performance Colour Space Manipulation

  • Versions: 9
  • Dependent Packages: 20
  • Dependent Repositories: 63
  • Downloads: 747,312 Last month
  • Docker Downloads: 158,577,836
Rankings
Downloads: 0.3%
Dependent repos count: 3.0%
Dependent packages count: 3.5%
Stargazers count: 3.7%
Forks count: 5.3%
Average: 5.5%
Docker downloads count: 17.3%
Maintainers (1)
Last synced: 11 months ago
proxy.golang.org: github.com/thomasp85/farver
  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 11 months ago
conda-forge.org: r-farver
  • Versions: 8
  • Dependent Packages: 5
  • Dependent Repositories: 51
Rankings
Dependent repos count: 5.0%
Dependent packages count: 10.4%
Average: 23.9%
Stargazers count: 34.0%
Forks count: 46.2%
Last synced: 10 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action 4.1.4 composite
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pr-commands.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/pr-fetch v2 composite
  • r-lib/actions/pr-push v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • covr * suggests
  • testthat >= 3.0.0 suggests