Sha256: a5368a062b8aaff91a13b3e410540af0e2edf2739eaf924b54772f50bba8370c

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

#include "psd_native_ext.h"

VALUE psd_native_combine_cmyk_channel(VALUE self) {
  psd_logger("debug", "Beginning CMYK processing");
  
  uint32_t num_pixels = FIX2UINT(rb_iv_get(self, "@num_pixels"));
  uint32_t pixel_step = FIX2UINT(rb_funcall(self, rb_intern("pixel_step"), 0));

  VALUE* channel_data = RARRAY_PTR(rb_iv_get(self, "@channel_data"));
  uint32_t channel_length = FIX2UINT(rb_iv_get(self, "@channel_length"));
  uint32_t channel_count = FIX2UINT(rb_funcall(self, rb_intern("channels"), 0));

  int i;
  uint32_t r, g, b;
  VALUE a, c, m, y, k, rgb;

  // Loop through every pixel in the image
  for (i = 0; i < num_pixels; i += pixel_step) {
    c = channel_data[i];
    m = channel_data[i + channel_length];
    y = channel_data[i + channel_length * 2];
    k = channel_data[i + channel_length * 3];
    a = (channel_count == 5 ? channel_data[i + channel_length * 4] : 255);

    rgb = psd_native_cmyk_to_rgb(
      self, 
      INT2FIX(255 - FIX2INT(c)), 
      INT2FIX(255 - FIX2INT(m)), 
      INT2FIX(255 - FIX2INT(y)),
      INT2FIX(255 - FIX2INT(k))
    );


    r = FIX2UINT(rb_hash_aref(rgb, ID2SYM(rb_intern("r"))));
    g = FIX2UINT(rb_hash_aref(rgb, ID2SYM(rb_intern("g"))));
    b = FIX2UINT(rb_hash_aref(rgb, ID2SYM(rb_intern("b"))));

    rb_ary_push(rb_iv_get(self, "@pixel_data"), INT2FIX(BUILD_PIXEL(r, g, b, a)));
  }

  return Qnil;
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
psd_native-0.6.0 ext/psd_native/image_mode_cmyk.c
psd_native-0.5.0 ext/psd_native/image_mode_cmyk.c
psd_native-0.4.0 ext/psd_native/image_mode_cmyk.c
psd_native-0.3.1 ext/psd_native/image_mode_cmyk.c