C API

library(colorfast)

{colorfast} exports three C functions for use in other packages.

To use these functions:

void col_to_rgb(const char *col, uint8_t ptr[4]);
uint32_t col_to_int(const char *col); 
void int_to_col(uint32_t icol, char buf[10]);

String color to vector of RGBA values

void col_to_rgb(const char *col, uint8_t ptr[4])

The R call col_to_rgb('red'), can be called via the C api as:

#include <stdint.h>
#include <colorfast.h>

void convert_col_to_rgb(const char *col) {
  uint8_t values[4];
  col_to_rgb(col, values);
  
  for (int i = 0; i < 4; ++i) {
    printf("%i ", values[i]);
  }
}

String color to packed integer color

void col_to_int(const char *col)

#include <stdint.h>
#include <colorfast.h>

void convert_col_to_int(const char *col) {
  uint32_t value = col_to_int(col);
  
  printf("%i ", value);
}

Packed integer color to hexadecimal color

void int_to_col(uint32_t icol, char buf[10])

#include <stdint.h>
#include <colorfast.h>

void convert_int_to_col(uint32_t icol) {
  char buf[10];
  int_to_col(icol, buf);
  
  printf("%s\n", buf);
}