Ejemplo n.º 1
0
PIXEL oily_png_color_interpolate_quick(PIXEL fg, PIXEL bg, int alpha) {
  BYTE a_com, new_r, new_g, new_b, new_a;

  if (alpha >= 255) return fg;
  if (alpha <= 0) return bg;

  a_com = 255 - alpha;
  new_r = INT8_MULTIPLY(alpha, R_BYTE(fg)) + INT8_MULTIPLY(a_com, R_BYTE(bg));
  new_g = INT8_MULTIPLY(alpha, G_BYTE(fg)) + INT8_MULTIPLY(a_com, G_BYTE(bg));
  new_b = INT8_MULTIPLY(alpha, B_BYTE(fg)) + INT8_MULTIPLY(a_com, B_BYTE(bg));
  new_a = INT8_MULTIPLY(alpha, A_BYTE(fg)) + INT8_MULTIPLY(a_com, A_BYTE(bg));

  return BUILD_PIXEL(new_r, new_g, new_b, new_a);
}
Ejemplo n.º 2
0
PIXEL oily_png_compose_color(PIXEL fg, PIXEL bg) {
  
  // Check for simple cases first
  if ((A_BYTE(fg) == 0xff) || (A_BYTE(bg) == 0x00)) return fg;
  if (A_BYTE(fg) == 0x00) return bg;

  // Calculate the new values using fast 8-bit multiplication
  BYTE a_com = INT8_MULTIPLY(0xff - A_BYTE(fg), A_BYTE(bg));
  BYTE new_r = INT8_MULTIPLY(A_BYTE(fg), R_BYTE(fg)) + INT8_MULTIPLY(a_com, R_BYTE(bg));
  BYTE new_g = INT8_MULTIPLY(A_BYTE(fg), G_BYTE(fg)) + INT8_MULTIPLY(a_com, G_BYTE(bg));
  BYTE new_b = INT8_MULTIPLY(A_BYTE(fg), B_BYTE(fg)) + INT8_MULTIPLY(a_com, B_BYTE(bg));
  BYTE new_a = A_BYTE(fg) + a_com;
  
  return BUILD_PIXEL(new_r, new_g, new_b, new_a);
}
Ejemplo n.º 3
0
// Assume R == G == B. ChunkyPNG uses the B byte fot performance reasons. 
// We'll uses the same to remain compatible with ChunkyPNG.
void oily_png_encode_scanline_grayscale_8bit(BYTE* bytes, VALUE pixels, long y, long width, VALUE encoding_palette) {
  UNUSED_PARAMETER(encoding_palette);
  long x; PIXEL pixel;
  for (x = 0; x < width; x++) {
    pixel = NUM2UINT(rb_ary_entry(pixels, y * width + x));
    bytes[x] = B_BYTE(pixel);
  }
}
Ejemplo n.º 4
0
void oily_png_encode_scanline_truecolor_alpha_8bit(BYTE* bytes, VALUE pixels, long y, long width, VALUE encoding_palette) {
  UNUSED_PARAMETER(encoding_palette);
  long x; PIXEL pixel;
  for (x = 0; x < width; x++) {
    pixel = NUM2UINT(rb_ary_entry(pixels, y * width + x));
    bytes[x * 4 + 0] = R_BYTE(pixel);
    bytes[x * 4 + 1] = G_BYTE(pixel);
    bytes[x * 4 + 2] = B_BYTE(pixel);
    bytes[x * 4 + 3] = A_BYTE(pixel);
  }
}
Ejemplo n.º 5
0
SDL_Color rubysdl2_Color_to_SDL_Color(VALUE rgba)
{
    SDL_Color color;
    if (rgba == Qnil) {
        color.r = color.g = color.b = 0; color.a = 255;
        return color;
    } else {
      PIXEL pixel = NUM2UINT(rgba);
      color.r = R_BYTE(pixel);
      color.g = G_BYTE(pixel);
      color.b = B_BYTE(pixel);
      color.a = A_BYTE(pixel);
      return color;
    }

}
Ejemplo n.º 6
0
VALUE Color_s_b(VALUE self, VALUE value) {
  return INT2FIX(B_BYTE(NUM2UINT(value)));
}
Ejemplo n.º 7
0
VALUE oily_png_color_b(VALUE self, VALUE value) {
  UNUSED_PARAMETER(self);
  return INT2FIX(B_BYTE(NUM2UINT(value)));
}