Module: PSDNative::Compose

Defined in:
ext/psd_native/psd_native_ext.c

Class Method Summary collapse

Class Method Details

.normal(r_fg, r_bg, opts) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'ext/psd_native/compose.c', line 5

VALUE psd_native_compose_normal(VALUE self, VALUE r_fg, VALUE r_bg, VALUE opts) {
  uint32_t fg = FIX2UINT(r_fg);
  uint32_t bg = FIX2UINT(r_bg);
  uint32_t new_r, new_g, new_b;

  if (opaque(fg) || transparent(bg)) return INT2FIX(fg);
  if (transparent(fg)) return INT2FIX(bg);

  calculate_alphas(fg, bg, &opts);

  new_r = blend_channel(r(bg), r(fg), alpha.mix);
  new_g = blend_channel(g(bg), g(fg), alpha.mix);
  new_b = blend_channel(b(bg), b(fg), alpha.mix);

  return INT2FIX(rgba(new_r, new_g, new_b, alpha.dst));
}