Sha256: 10fe325fbf11d6978a638fe13f96b6351488fdcbb6939ca199c94d9b342a46a7

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

#include "psd_native_ext.h"

VALUE psd_native_cmyk_to_rgb(VALUE self, VALUE c, VALUE m, VALUE y, VALUE k) {
  int r, g, b;

  r = psd_clamp_int((65535 - (FIX2INT(c) * (255 - FIX2INT(k)) + (FIX2INT(k) << 8))) >> 8, 0, 255);
  g = psd_clamp_int((65535 - (FIX2INT(m) * (255 - FIX2INT(k)) + (FIX2INT(k) << 8))) >> 8, 0, 255);
  b = psd_clamp_int((65535 - (FIX2INT(y) * (255 - FIX2INT(k)) + (FIX2INT(k) << 8))) >> 8, 0, 255);

  VALUE result = rb_hash_new();
  rb_hash_aset(result, ID2SYM(rb_intern("r")), INT2FIX(r));
  rb_hash_aset(result, ID2SYM(rb_intern("g")), INT2FIX(g));
  rb_hash_aset(result, ID2SYM(rb_intern("b")), INT2FIX(b));

  return result;
}

int psd_clamp_int(int n, int low, int high) {
  return n < low ? low : (n > high ? high : n);
}

int opaque(uint32_t color) {
  return a(color) == 0x000000ff;
}

int transparent(uint32_t color) {
  return a(color) == 0x00000000;
}

uint32_t r(uint32_t color) {
  return (color & 0xff000000) >> 24;
}

uint32_t g(uint32_t color) {
  return (color & 0x00ff0000) >> 16;
}

uint32_t b(uint32_t color) {
  return (color & 0x0000ff00) >> 8;
}

uint32_t a(uint32_t color) {
  return color & 0x000000ff;
}

uint32_t rgba(uint32_t r, uint32_t g, uint32_t b, uint32_t a) {
  return r << 24 | g << 16 | b << 8 | a;
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
psd_native-0.4.0 ext/psd_native/color.c