Beispiel #1
0
t_rgb		put_transparence(t_inter inter, t_scene *scene, t_vector pos_3d)
{
  t_cam		save;
  t_vector	t;
  t_inter      	color;
  float		scal;
  float		n;

  save.pos = scene->eye->pos;
  save.angle = scene->eye->pos;
  init_vec(&scene->eye->pos, inter.p.x, inter.p.y, inter.p.z);
  init_vec(&scene->eye->angle, 0, 0, 0);
  init_rgb(&color.rgb, 0, 0, 0);
  normalize_vec(&inter.n);
  normalize_vec(&pos_3d);
  n = 0.9;
  scal = get_scalaire(inter.n, pos_3d);
  scal = n * scal - sqrtf(1 + pow(n, 2) * (pow(scal, 2) - 1));
  t.x = n * pos_3d.x + scal * inter.n.x;
  t.y = n * pos_3d.y + scal * inter.n.y;
  t.z = n * pos_3d.z + scal * inter.n.z;
  color = get_pixel_color(t, scene);
  scene->eye->pos = save.pos;
  scene->eye->pos = save.angle;
  return (color.rgb);
}
Beispiel #2
0
void
glow_fill_do_action(int x, int y, texture_info * tex, VALUE hash_arg,
                    texplay_sync sync_mode, bool primary, action_struct * payload)
{
    action_struct cur;
    rgba seed_color;
    texture_info fill_image;
    texture_info * fill_image_ptr = NULL;
    
    if(!bound_by_rect(x, y, 0, 0, tex->width, tex->height)) return;

    draw_prologue(&cur, tex, 0, 0, 1024, 1024, &hash_arg, sync_mode, primary, &payload);

    /* fill hates alpha_blend so let's turn it off */
    payload->pen.alpha_blend = false;

    if(is_a_hash(hash_arg)) {
        VALUE try_image = get_from_hash(hash_arg, "texture");
        if(is_gosu_image(try_image)) {
            get_texture_info(try_image, &fill_image);
            fill_image_ptr = &fill_image;
        }
    }

    seed_color = get_pixel_color(tex, x, y);

    /* last argument is pointer to texture fill data (if it exists) or NULL (if it doesn't) */
    glow_floodFill( x, y, &seed_color, &cur, tex, fill_image_ptr );

    draw_epilogue(&cur, tex, primary);
}
Beispiel #3
0
/***********************************************************************
 *           dibdrv_SetTextColor
 */
static COLORREF dibdrv_SetTextColor( PHYSDEV dev, COLORREF color )
{
    PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetTextColor );
    dibdrv_physdev *pdev = get_dibdrv_pdev(dev);

    pdev->text_color = get_pixel_color( pdev, color, TRUE );
    update_aa_ranges( pdev );

    return next->funcs->pSetTextColor( next, color );
}
Beispiel #4
0
int		calc(int x, int y, t_win *mlxwin)
{
  int		n;
  t_pos		xyz;

  xyz.x = 100;
  xyz.y = 500 - x;
  xyz.z = 500 - y;
  rotate_x(&xyz, mlxwin->r_oeil.x);
  rotate_y(&xyz, mlxwin->r_oeil.y);
  rotate_z(&xyz, mlxwin->r_oeil.z);
  return (get_pixel_color(xyz, mlxwin));
}
Beispiel #5
0
int main(int argc, char *argv[]) {
	Display *d = XOpenDisplay(NULL);
	if (!d) {
		printf("Unable to open display\n");
		return;
	}
#ifdef USB_PIXEL
	usb_dev_handle *handle = NULL;

	int usb_present = open_usb(&handle);
	if (!handle) {
		printf("Unable to open usb device, proceeding anyway...\n");
	}
#endif
	int radius = RADIUS;

	init_shm(d, radius);
	init_xinput(d);

	int x = -1;
	int y = -1;
	int old_x = -1;
	int old_y = -1;
	struct rgb_color color;
	color.alpha = 255;
	uint8_t buf[3];
	while(1) {
		wait_for_movement(d, &x, &y);
		if (x != old_x || y != old_y) {
			refresh_image(d, x, y, radius);
			get_pixel_color(d, x, y, &color, radius);
			printf("%d/%d\t(%d/%d/%d)\n", x, y, color.red, color.green, color.blue);
#ifdef USB_PIXEL
			if (usb_present) {
				buf[0] = color.red;
				buf[1] = color.green;
				buf[2] = color.blue;
				int8_t sent = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_RGB, 0, 0, buf, 3, 100);
				if (sent < 0) {
					printf("Lost contact to USB device\n");
					usb_present = 0;
					handle = NULL;
				}
			}
#endif
			old_x = x;
			old_y = y;
		}
	}
	XCloseDisplay(d);
}
Beispiel #6
0
// RGBA array [255, 255, 255, 255]
VALUE Ashton_PixelCache_get_rgba_array(VALUE self, VALUE x, VALUE y)
{
    PIXEL_CACHE();

    Color_i rgba = get_pixel_color(pixel_cache, x, y);

    VALUE array = rb_ary_new();
    rb_ary_push(array, UINT2NUM(rgba.red));
    rb_ary_push(array, UINT2NUM(rgba.green));
    rb_ary_push(array, UINT2NUM(rgba.blue));
    rb_ary_push(array, UINT2NUM(rgba.alpha));

    return array;
}
Beispiel #7
0
// Gosu:Color object.
VALUE Ashton_PixelCache_get_pixel(VALUE self, VALUE x, VALUE y)
{
    PIXEL_CACHE();

    Color_i rgba = get_pixel_color(pixel_cache, x, y);

    VALUE color = rb_funcall(rb_cColor, rb_intern("new"), 1,
                             UINT2NUM((rgba.alpha << 24) +
                                      (rgba.red   << 16) +
                                      (rgba.green <<  8) +
                                       rgba.blue));

    return color;
}
Beispiel #8
0
static rgba
exec_color_control_proc(action_struct * cur, texture_info * tex, int x, int y, rgba blended_pixel)
{
    int arity = cur->pen.color_control_arity;
    VALUE proc = cur->pen.color_control_proc;
    rgba old_color = get_pixel_color(tex, x, y);
    rgba current_color = blended_pixel;
    rgba new_color;

    if(!cur->pen.has_color_control_proc)
        rb_raise(rb_eRuntimeError, "needs a proc");

    switch(arity) {
    case -1:
    case 0:
        new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), 0));
        break;

    case 1:
        new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
                                                        convert_rgba_to_rb_color(&old_color)));
        break;

    case 2:
        new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
                                                        convert_rgba_to_rb_color(&old_color),
                                                        convert_rgba_to_rb_color(&current_color)));
        break;

    case 3:
        new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
                                                        convert_rgba_to_rb_color(&old_color),
                                                        INT2FIX(x), INT2FIX(y)));
        break;
    case 4:
        new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
                                                        convert_rgba_to_rb_color(&old_color),
                                                        convert_rgba_to_rb_color(&current_color),
                                                        INT2FIX(x), INT2FIX(y)));
        break;
    default:
        rb_raise(rb_eArgError, "permissible arities for color_control proc are 1, 2, 3  and 4. Got %d\n",
                 arity);
    }

    /* update the action color */
    return new_color;
}
Beispiel #9
0
static bool
skip_pixel(rgba source_color, action_struct * payload, texture_info * tex, int x, int y)
{

  if (!payload->pen.has_color_select) return false;

  rgba dest_color = get_pixel_color(tex, x, y);
  bool color_match = false;

  if (payload->pen.source_select.size > 0) {
    for (int i = 0; i < payload->pen.source_select.size; i++) {
        if (cmp_color_with_or_without_tolerance(source_color, payload->pen.source_select.colors[i], payload)) {
            color_match = true;
            break;
        }
        if (!color_match) return true;
    }
  }

  if (payload->pen.source_ignore.size > 0) {
    for (int i = 0; i < payload->pen.source_ignore.size; i++) {
      if (cmp_color_with_or_without_tolerance(source_color, payload->pen.source_ignore.colors[i], payload))
              return true;
    }
  }

  color_match = false;
  if (payload->pen.dest_select.size > 0) {
    for (int i = 0; i < payload->pen.dest_select.size; i++) {
      if (cmp_color_with_or_without_tolerance(dest_color, payload->pen.dest_select.colors[i], payload)) {
            color_match = true;
            break;
        }
    }
    if (!color_match) return true;
  }

  if (payload->pen.dest_ignore.size > 0) {
    for (int i = 0; i < payload->pen.dest_ignore.size; i++) {
      if (cmp_color_with_or_without_tolerance(dest_color, payload->pen.dest_ignore.colors[i], payload))
              return true;
    }
  }

  return false;
}
Beispiel #10
0
/** glow fill algorithm, from the gosu forums **/ 
static void
glow_floodFill( int x, int y, rgba * seed_color, action_struct * cur, texture_info * tex, texture_info * tex2 )
{
    /* used to flood in both horizontal directions from the given point to form a line. */
    int fillL, fillR;     
    int i;

    /* initialize the flood directions */
    fillL = fillR = x;

    /* flood left until a new color is hit - or the edge of the image */
    do {
        /* for texture filling */
        if(tex2)
            cur->color = get_pixel_color(tex2, fillL % tex2->width, y % tex2->height);
        
        /* TWO VERSIONS of below */

        /* SLOW BUT MODERN VERSION */
        /*        set_pixel_color_with_style(cur, tex, fillL, y); */

        /* FAST but old version */
        set_pixel_color(&cur->color, tex, fillL, y);

        fillL--;
    } while( (fillL >= 0 ) && (cmp_color(get_pixel_color(tex, fillL, y), *seed_color)) );

    /* flood right until a new color is hit - or the edge of the image */
    do {
        //        for texture filling
        if(tex2)
            cur->color = get_pixel_color(tex2, fillR % tex2->width, y % tex2->height);
        
        /*        set_pixel_color_with_style(cur, tex, fillR, y); */
         
        set_pixel_color(&cur->color, tex, fillR, y);

        fillR++;
    } while( (fillR < cur->xmax - 1) && (cmp_color(get_pixel_color(tex, fillR, y), *seed_color)) );

    /* recurse to the line above and the line below at each point */
    for( i = fillL + 1; i < fillR; i++ ) {
        /* Flood above */
        if( ( y > 0 ) && ( cmp_color(get_pixel_color(tex, i, y - 1), *seed_color)  ) ) {
            
            glow_floodFill( i, y-1, seed_color, cur, tex, tex2 );
        }
        /* flood below */
        if( (y < cur->ymax - 1) && (cmp_color(get_pixel_color(tex, i, y + 1), *seed_color) )) {
            glow_floodFill( i, y+1, seed_color, cur, tex, tex2 );
        }
    }
}
Beispiel #11
0
void
set_pixel_color_with_style(action_struct * payload, texture_info * tex, int x, int y)
{

    rgba blended_pixel;

    blended_pixel = payload->color;


    /* for linear interpolation */
    if(payload->pen.has_lerp) {
      blended_pixel = apply_lerp(payload, tex, x, y);
    }

    /* for color_control transform */
    if(payload->pen.has_color_control_transform)
        blended_pixel = apply_color_control_transform(payload, tex, x, y);

    /* for texture fill  */
    if(payload->pen.has_source_texture)
        blended_pixel = get_pixel_color(&payload->pen.source_tex,
                                         x % payload->pen.source_tex.width,
                                         y % payload->pen.source_tex.height);

    /* for color_control proc */
    if(payload->pen.has_color_control_proc)
        blended_pixel = exec_color_control_proc(payload, tex, x,  y, blended_pixel);

    /* should skip this pixel? color selection */
    if (skip_pixel(blended_pixel, payload, tex, x, y))
      return;

    /* drawing modes */
    if(payload->pen.has_drawing_mode) {
      blended_pixel = apply_drawing_mode(payload, tex, x, y, blended_pixel);
    }

    /*  TO DO: refactor into its own helper function
        & rewrite using sse2 */
    if(payload->pen.alpha_blend)
        blended_pixel = apply_alpha_blend(payload, tex, x,  y, blended_pixel);


    set_pixel_color(&blended_pixel, tex, x, y);
}
Beispiel #12
0
/***********************************************************************
 *           dibdrv_SetDIBColorTable
 */
static UINT dibdrv_SetDIBColorTable( PHYSDEV dev, UINT pos, UINT count, const RGBQUAD *colors )
{
    PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetDIBColorTable );
    dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
    TRACE("(%p, %d, %d, %p)\n", dev, pos, count, colors);

    if( pdev->dib.color_table && pos < pdev->dib.color_table_size )
    {
        if( pos + count > pdev->dib.color_table_size ) count = pdev->dib.color_table_size - pos;
        memcpy( pdev->dib.color_table + pos, colors, count * sizeof(RGBQUAD) );

        pdev->bkgnd_color = get_pixel_color( pdev, GetBkColor( dev->hdc ), FALSE );
        update_fg_colors( pdev );

        update_masks( pdev, GetROP2( dev->hdc ) );
    }
    return next->funcs->pSetDIBColorTable( next, pos, count, colors );
}
Beispiel #13
0
/***********************************************************************
 *           dibdrv_SetBkColor
 */
static COLORREF dibdrv_SetBkColor( PHYSDEV dev, COLORREF color )
{
    PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetBkColor );
    dibdrv_physdev *pdev = get_dibdrv_pdev(dev);

    pdev->bkgnd_color = get_pixel_color( pdev, color, FALSE );

    if( GetBkMode(dev->hdc) == OPAQUE )
        calc_and_xor_masks( GetROP2(dev->hdc), pdev->bkgnd_color, &pdev->bkgnd_and, &pdev->bkgnd_xor );
    else
    {
        pdev->bkgnd_and = ~0u;
        pdev->bkgnd_xor = 0;
    }

    update_fg_colors( pdev ); /* Only needed in the 1 bpp case */

    return next->funcs->pSetBkColor( next, color );
}
Beispiel #14
0
/* TODO: reimplement using SSE2 */
static rgba
apply_color_control_transform(action_struct * payload, texture_info * tex, int x, int y)

{
    rgba transformed_color;

    transformed_color = get_pixel_color(tex, x, y);

    transformed_color.red += payload->pen.color_add.red;
    transformed_color.green += payload->pen.color_add.green;
    transformed_color.blue += payload->pen.color_add.blue;
    transformed_color.alpha += payload->pen.color_add.alpha;

    transformed_color.red *= payload->pen.color_mult.red;
    transformed_color.green *= payload->pen.color_mult.green;
    transformed_color.blue *= payload->pen.color_mult.blue;
    transformed_color.alpha *= payload->pen.color_mult.alpha;

    return transformed_color;
}
Beispiel #15
0
static rgba
apply_lerp(action_struct * payload, texture_info * tex, int x, int y)
{
  rgba finished_pixel;
  rgba dest_pixel = get_pixel_color(tex, x, y);

  finished_pixel.red = payload->pen.lerp * payload->color.red +
    (1 - payload->pen.lerp) * dest_pixel.red;

  finished_pixel.green = payload->pen.lerp * payload->color.green +
    (1 - payload->pen.lerp) * dest_pixel.green;

  finished_pixel.blue = payload->pen.lerp * payload->color.blue +
    (1 - payload->pen.lerp) * dest_pixel.blue;

  finished_pixel.alpha = payload->pen.lerp * payload->color.alpha +
    (1 - payload->pen.lerp) * dest_pixel.alpha;

  return finished_pixel;
}
Beispiel #16
0
void
each_pixel_do_action(int x1, int y1, int x2, int y2, VALUE proc, texture_info * tex, VALUE hash_arg,
                     texplay_sync sync_mode, bool primary, action_struct * payload)
{
    action_struct cur;
    int arity;
    VALUE rb_pix = rb_ary_new2(4);
    
    draw_prologue(&cur, tex, x1, y1, x2, y2, &hash_arg, sync_mode, primary, &payload);

    arity = FIX2INT(rb_funcall(proc, rb_intern("arity"), 0));

    for(int y = y1; y < y2 + 1; y++)
        for(int x = x1; x < x2 + 1; x++) {
            rgba pix = get_pixel_color(tex, x, y);

            set_color_array(rb_pix, &pix);
            
            /* invoke the block */
            switch(arity) {
            case 1:
                rb_funcall(proc, rb_intern("call"), 1, rb_pix);
                break;
            case 3:
                rb_funcall(proc, rb_intern("call"), 3, rb_pix, INT2FIX(x), INT2FIX(y));
                break;
            default:
                rb_raise(rb_eArgError, "permissible arities for each are 1 & 3. Got %d\n",
                         arity);

            }

            pix = convert_rb_color_to_rgba(rb_pix);

            set_pixel_color(&pix, tex, x, y);
        }

    draw_epilogue(&cur, tex, primary);
}
Beispiel #17
0
void	draw_line(t_env *e, int x)
{
	int				height;
	int				i;

	i = 0;
	if (e->dist_ray <= 0)
	{
		e->dist_ray = 0.01;
		e->side = 0x0000ff;
	}
	fog(e);
	height = 277 / e->dist_ray;
	while (i < (double)WIN_Y / 2.0 - (double)height / 2.0)
		get_pixel_color(e, x, i++);
	while (i < (double)WIN_Y / 2.0 + (double)height / 2.0)
		pixel_put(e, x, i++, e->fog);
	while (i < WIN_Y - 1)
	{
		pixel_put(e, x, i, find_ground_color(e, i, x));
		i++;
	}
}
Beispiel #18
0
t_rgb		put_reflexion(t_inter inter, t_scene *scene, t_vector pos_3d)
{
  t_cam		save;
  t_vector	r;
  t_inter      	color;
  float		scal;

  save.pos = scene->eye->pos;
  save.angle = scene->eye->pos;
  init_vec(&scene->eye->pos, inter.p.x, inter.p.y, inter.p.z);
  init_vec(&scene->eye->angle, 0, 0, 0);
  init_rgb(&color.rgb, 0, 0, 0);
  normalize_vec(&inter.n);
  normalize_vec(&pos_3d);
  scal = get_scalaire(inter.n, pos_3d);
  r.x = ((-2.0 * inter.n.x) * scal) + pos_3d.x;
  r.y = ((-2.0 * inter.n.y) * scal) + pos_3d.y;
  r.z = ((-2.0 * inter.n.z) * scal) + pos_3d.z;
  color = get_pixel_color(r, scene);
  scene->eye->pos = save.pos;
  scene->eye->pos = save.angle;
  return (color.rgb);
}
Beispiel #19
0
static void update_fg_colors( dibdrv_physdev *pdev )
{
    pdev->pen_color   = get_pixel_color( pdev, pdev->pen_colorref,   TRUE );
    pdev->brush_color = get_pixel_color( pdev, pdev->brush_colorref, TRUE );
}
Beispiel #20
0
void
scan_fill_do_action(int x, int y, texture_info * tex, VALUE hash_arg,
                    texplay_sync sync_mode, bool primary, action_struct * payload)
{
    action_struct cur;
    rgba old_color;
    int y1;
    bool spanLeft, spanRight;

    if(!bound_by_rect(x, y, 0, 0, tex->width - 1, tex->height - 1)) return;

    /* NB: using XMAX_OOB etc since we dont know the drawing area yet; drawing area will be set by
       update_bounds() function in main loop */
    draw_prologue(&cur, tex, XMAX_OOB, YMAX_OOB, XMIN_OOB, YMIN_OOB, &hash_arg, sync_mode, primary, &payload);

    /* fill hates alpha_blend so let's turn it off */
    payload->pen.alpha_blend = false;
    
    old_color = get_pixel_color(tex, x, y);

    if(cmp_color(old_color, cur.color)) return;
    
    emptyStack();
    
    if(!push(x, y, tex->width - 1)) return;
    
    while(pop(&x, &y, tex->width - 1))
        {    
            y1 = y;
            while(y1 >= 0 && cmp_color(old_color, get_pixel_color(tex, x, y1))) y1--;
            y1++;
            spanLeft = spanRight = false;
            while(y1 < tex->height && cmp_color(old_color, get_pixel_color(tex, x, y1)) )
                {
                    set_pixel_color_with_style(payload, tex, x, y1);

                    /* update the drawing rectangle */
                    update_bounds(payload, x, y1, x, y1);

                    if(!spanLeft && x > 0 && cmp_color(old_color, get_pixel_color(tex, x - 1, y1))) 
                        {
                            if(!push(x - 1, y1, tex->width - 1)) return;
                            spanLeft = true;
                        }

                    else if(spanLeft && !cmp_color(old_color, get_pixel_color(tex, x - 1, y1)))
                        {
                            spanLeft = false;
                        }

                    if(!spanRight && x < tex->width - 1 && cmp_color(old_color,
                                                                     get_pixel_color(tex, x + 1, y1))) 
                        {
                            if(!push(x + 1, y1, tex->width - 1)) return;
                            spanRight = true;
                        }

                    else if(spanRight && x < tex->width - 1 && !cmp_color(old_color,get_pixel_color(tex, x + 1, y1)))
                        {
                            spanRight = false;
                        } 
                    y1++;
                }
        }
    draw_epilogue(&cur, tex, primary);
}
Beispiel #21
0
static rgba
apply_drawing_mode(action_struct * payload, texture_info * tex, int x, int y, rgba source_pixel)
{
  rgba finished_pixel;

  rgba dest_pixel = get_pixel_color(tex, x, y);

  rgba_char dest_pixel_char = color_float_to_int_format(dest_pixel);
  rgba_char source_pixel_char = color_float_to_int_format(source_pixel);

  switch(payload->pen.drawing_mode)
    {

    /* bitwise blending functions */
    case clear:
      finished_pixel = (rgba) { 0, 0, 0, 0 };
      break;
    case copy:
      finished_pixel = source_pixel;
      break;
    case noop:
      finished_pixel = dest_pixel;
      break;
    case set:
      finished_pixel = (rgba) { 1, 1, 1, 1 };
      break;
    case copy_inverted:
      finished_pixel = color_int_vals_to_float_format(~source_pixel_char.red,
                                               ~source_pixel_char.green,
                                               ~source_pixel_char.blue,
                                               source_pixel_char.alpha);
      break;
    case invert:
      finished_pixel = color_int_vals_to_float_format(~dest_pixel_char.red,
                                               ~dest_pixel_char.green,
                                               ~dest_pixel_char.blue,
                                               dest_pixel_char.alpha);

      break;
    case and_reverse:
      finished_pixel = color_int_vals_to_float_format(source_pixel_char.red | ~dest_pixel_char.red,
                                               source_pixel_char.green | ~dest_pixel_char.green,
                                               source_pixel_char.blue | ~dest_pixel_char.blue,
                                               source_pixel_char.alpha);
      break;
    case and:
      finished_pixel = color_int_vals_to_float_format(source_pixel_char.red & dest_pixel_char.red,
                                               source_pixel_char.green & dest_pixel_char.green,
                                               source_pixel_char.blue & dest_pixel_char.blue,
                                               source_pixel_char.alpha);
      break;
    case or:
      finished_pixel = color_int_vals_to_float_format(source_pixel_char.red | dest_pixel_char.red,
                                               source_pixel_char.green | dest_pixel_char.green,
                                               source_pixel_char.blue | dest_pixel_char.blue,
                                               source_pixel_char.alpha);

      break;
    case nand:
      finished_pixel = color_int_vals_to_float_format(~(source_pixel_char.red & dest_pixel_char.red),
                                               ~(source_pixel_char.green & dest_pixel_char.green),
                                               ~(source_pixel_char.blue & dest_pixel_char.blue),
                                               ~(source_pixel_char.alpha & dest_pixel_char.alpha));

      break;
    case nor:
      finished_pixel = color_int_vals_to_float_format(~(source_pixel_char.red | dest_pixel_char.red),
                                               ~(source_pixel_char.green | dest_pixel_char.green),
                                               ~(source_pixel_char.blue | dest_pixel_char.blue),
                                               source_pixel_char.alpha);

      break;
    case xor:
      finished_pixel = color_int_vals_to_float_format(source_pixel_char.red ^ dest_pixel_char.red,
                                               source_pixel_char.green ^ dest_pixel_char.green,
                                               source_pixel_char.blue ^ dest_pixel_char.blue,
                                               source_pixel_char.alpha);

      break;
    case equiv:
      finished_pixel = color_int_vals_to_float_format(~(source_pixel_char.red ^ dest_pixel_char.red),
                                               ~(source_pixel_char.green ^ dest_pixel_char.green),
                                               ~(source_pixel_char.blue ^ dest_pixel_char.blue),
                                               source_pixel_char.alpha);

      break;
    case and_inverted:
      finished_pixel = color_int_vals_to_float_format(~source_pixel_char.red & dest_pixel_char.red,
                                               ~source_pixel_char.green & dest_pixel_char.green,
                                               ~source_pixel_char.blue & dest_pixel_char.blue,
                                               source_pixel_char.alpha);
      break;
    case or_inverted:
      finished_pixel = color_int_vals_to_float_format(~source_pixel_char.red | dest_pixel_char.red,
                                               ~source_pixel_char.green | dest_pixel_char.green,
                                               ~source_pixel_char.blue | dest_pixel_char.blue,
                                               source_pixel_char.alpha);

      break;

    /* photoshop style blending functions */
    case additive:
      finished_pixel = (rgba) { MIN(source_pixel.red + dest_pixel.red, 1),
                                MIN(source_pixel.green + dest_pixel.green, 1),
                                MIN(source_pixel.blue + dest_pixel.blue, 1),
                                MIN(source_pixel.alpha + dest_pixel.alpha, 1) };
      break;
    case multiply:
      finished_pixel = mode_multiply(dest_pixel, source_pixel);

      break;
    case screen:
      finished_pixel = mode_screen(dest_pixel, source_pixel);

      break;
    case overlay:
      finished_pixel = mode_hardlight(source_pixel, dest_pixel);

      break;
    case darken:
      finished_pixel = (rgba) { MIN(source_pixel.red, dest_pixel.red),
                                MIN(source_pixel.green, dest_pixel.green),
                                MIN(source_pixel.blue, dest_pixel.blue),
                                MIN(source_pixel.alpha, dest_pixel.alpha) };
      break;
    case lighten:
      finished_pixel = (rgba) { MAX(source_pixel.red, dest_pixel.red),
                                MAX(source_pixel.green, dest_pixel.green),
                                MAX(source_pixel.blue, dest_pixel.blue),
                                MAX(source_pixel.alpha, dest_pixel.alpha) };
      break;
    case color_dodge:
      finished_pixel = (rgba) { mode_colordodge_channel(dest_pixel.red, source_pixel.red),
                                mode_colordodge_channel(dest_pixel.green, source_pixel.green),
                                mode_colordodge_channel(dest_pixel.blue, source_pixel.blue),
                                mode_colordodge_channel(dest_pixel.alpha, source_pixel.alpha) };

      break;
    case color_burn:
      finished_pixel = (rgba) { mode_colorburn_channel(dest_pixel.red, source_pixel.red),
                                mode_colorburn_channel(dest_pixel.green, source_pixel.green),
                                mode_colorburn_channel(dest_pixel.blue, source_pixel.blue),
                                mode_colorburn_channel(dest_pixel.alpha, source_pixel.alpha) };
      break;
    case hard_light:
      finished_pixel = mode_hardlight(dest_pixel, source_pixel);

      break;
    case soft_light:
      finished_pixel = mode_softlight(dest_pixel, source_pixel);

      break;
    case difference:
      finished_pixel = (rgba) { ABS(dest_pixel.red - source_pixel.red),
                                ABS(dest_pixel.green - source_pixel.green),
                                ABS(dest_pixel.blue - source_pixel.blue),
                                ABS(dest_pixel.alpha - source_pixel.alpha) };
      break;
    case exclusion:
      finished_pixel = (rgba) { dest_pixel.red + source_pixel.red - (2 * dest_pixel.red * source_pixel.red),
                                dest_pixel.green + source_pixel.green - (2 * dest_pixel.green * source_pixel.green),
                                dest_pixel.blue + source_pixel.blue - (2 * dest_pixel.blue * source_pixel.blue),
                                dest_pixel.alpha + source_pixel.alpha - (2 * dest_pixel.alpha * source_pixel.alpha) };
      break;
    }

  return finished_pixel;
}
Beispiel #22
0
/** splice algorithm **/
void
splice_do_action(int x0, int y0, int cx1, int cy1, int cx2, int cy2, texture_info * splice_tex,
                 texture_info * tex, VALUE hash_arg, texplay_sync sync_mode,
                 bool primary, action_struct * payload)
{
    action_struct cur;
    int xbound;
    int ybound;
    rgba chromakey;
    float * image_buf = NULL;
    bool inverse_chroma = false;
    bool same_image = false;
    bool has_chroma = false;

    constrain_boundaries(&cx1, &cy1, &cx2, &cy2, splice_tex->width, splice_tex->height);
    xbound = cx2 - cx1 + 1;
    ybound = cy2 - cy1 + 1;

    draw_prologue(&cur, tex, x0, y0,
                  x0 + xbound, y0 + ybound, &hash_arg, sync_mode, primary, &payload);


    if(has_optional_hash_arg(hash_arg, "chroma_key")) {
        VALUE c = get_from_hash(hash_arg, "chroma_key");
        chromakey = convert_rb_color_to_rgba(c);
        has_chroma = true;
    }
    else if(has_optional_hash_arg(hash_arg, "chroma_key_not")) {
        chromakey = convert_rb_color_to_rgba(get_from_hash(hash_arg, "chroma_key_not"));
        inverse_chroma = true;
        has_chroma = true;
    }

    if(splice_tex->image == tex->image)
        same_image = true;

    /* NB: we do not use this in the general case since it's almost 1.5 times as slow.
       It is necessary for splicing from/to the same region of pixels though.
    */
    if(same_image) 
        image_buf = get_image_chunk(splice_tex, cx1, cy1, cx2, cy2);
    
    for(int y = 0; y < ybound; y++)
        for(int x = 0; x < xbound; x++) {
            
            if(!same_image)
                payload->color = get_pixel_color(splice_tex, cx1 + x, cy1 + y);
            else 
                payload->color = get_pixel_color_from_chunk(image_buf, xbound, ybound, x, y);
                
            if(has_chroma) {
                bool chroma_match = cmp_color(payload->color, chromakey);
                
                /* look at released 0.2.0 code to see how USED to do this.
                   this is now a simplified boolean expression (XOR) */
                if(chroma_match == inverse_chroma)
                    set_pixel_color_with_style(payload, tex, x0 + x, y0 + y);
            }
            else
                set_pixel_color_with_style(payload, tex, x0 + x, y0 + y);
        }

    if(same_image)
        free(image_buf);

    draw_epilogue(&cur, tex, primary);
}
Beispiel #23
0
VALUE Ashton_PixelCache_get_alpha(VALUE self, VALUE x, VALUE y)
{
    PIXEL_CACHE();
    Color_i rgba = get_pixel_color(pixel_cache, x, y);
    return UINT2NUM(rgba.alpha);
}
Beispiel #24
0
static rgba
apply_alpha_blend(action_struct * payload, texture_info * tex, int x, int y, rgba blended_pixel)
{
  rgba dest_pixel = get_pixel_color(tex, x, y);
  rgba finished_pixel;

  if (not_a_color(blended_pixel))
    return blended_pixel;

  alpha_blend_mode_t blend_mode = payload->pen.alpha_blend_mode;

  switch(blend_mode)
    {
    case source:
    case source_with_fixed_alpha:
      /** TO DO: rewrite this using sse2 instructions **/
      finished_pixel.red = blended_pixel.alpha * blended_pixel.red + (1 - blended_pixel.alpha)
        * dest_pixel.red;

      finished_pixel.green = blended_pixel.alpha * blended_pixel.green + (1 - blended_pixel.alpha)
        * dest_pixel.green;

      finished_pixel.blue = blended_pixel.alpha * blended_pixel.blue + (1 - blended_pixel.alpha)
        * dest_pixel.blue;

      if(blend_mode == source) {
        finished_pixel.alpha = blended_pixel.alpha * blended_pixel.alpha + (1 - blended_pixel.alpha)
          * dest_pixel.alpha;
      }
      else {

        // fixed alpha
        finished_pixel.alpha = dest_pixel.alpha;
      }

      break;
    case dest:
    case dest_with_fixed_alpha:
      finished_pixel.red = dest_pixel.alpha * blended_pixel.red + (1 - dest_pixel.alpha)
        * dest_pixel.red;

      finished_pixel.green = dest_pixel.alpha * blended_pixel.green + (1 - dest_pixel.alpha)
        * dest_pixel.green;

      finished_pixel.blue = dest_pixel.alpha * blended_pixel.blue + (1 - dest_pixel.alpha)
        * dest_pixel.blue;

      if(blend_mode == dest) {
        finished_pixel.alpha = dest_pixel.alpha * blended_pixel.alpha + (1 - dest_pixel.alpha)
          * dest_pixel.alpha;
      }
      else {

        // fixed alpha
        finished_pixel.alpha = dest_pixel.alpha;
      }

      break;
    default:
      rb_raise(rb_eRuntimeError,
               "apply_alpha_blend() impossible error. got %d\n", blend_mode);

    }

  return finished_pixel;
}
Beispiel #25
0
VALUE Ashton_PixelCache_is_transparent(VALUE self, VALUE x, VALUE y)
{
    PIXEL_CACHE();
    Color_i rgba = get_pixel_color(pixel_cache, x, y);
    return (rgba.alpha == 0) ? Qtrue : Qfalse;
}
Beispiel #26
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *roi)
{
    GeglRectangle src_rect;
    GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
    GeglOperationAreaFilter *op_area;
    gfloat* in_buf;
    gfloat* out_buf;
    gfloat* out_pixel;
    gint x,y;

    gdouble theta = o->angle * G_PI / 180.0;
    gdouble offset_x = o->length * cos(theta);
    gdouble offset_y = o->length * sin(theta);
    gint num_steps = (gint)ceil(o->length) + 1;
    gfloat inv_num_steps = 1.0f / num_steps;

    op_area = GEGL_OPERATION_AREA_FILTER (operation);

    src_rect = *roi;
    src_rect.x -= op_area->left;
    src_rect.y -= op_area->top;
    src_rect.width += op_area->left + op_area->right;
    src_rect.height += op_area->top + op_area->bottom;

    if (gegl_cl_is_opencl_available())
    {
        motion_blur_cl(input, &src_rect, output, roi, num_steps, offset_x, offset_y);
        return TRUE;
    }

    in_buf = g_new (gfloat, src_rect.width * src_rect.height * 4);
    out_buf = g_new0 (gfloat, roi->width * roi->height * 4);
    out_pixel = out_buf;

    gegl_buffer_get (input, 1.0, &src_rect, babl_format ("RaGaBaA float"), in_buf, GEGL_AUTO_ROWSTRIDE);

    for (y=0; y<roi->height; ++y)
    {
        for (x=0; x<roi->width; ++x)
        {
            gint step;
            gint c;
            gint px = x+roi->x;
            gint py = y+roi->y;
            gfloat sum[4] = {0,0,0,0};
            for (step=0; step<num_steps; ++step)
            {
                gdouble t = num_steps == 1 ? 0.0 : step / (gdouble)(num_steps-1) - 0.5;

                /* get the interpolated pixel position for this step */
                gdouble xx = px + t*offset_x;
                gdouble yy = py + t*offset_y;
                gint ix = (gint)floor(xx);
                gint iy = (gint)floor(yy);
                gdouble dx = xx - floor(xx);
                gdouble dy = yy - floor(yy);

                /* do bilinear interpolation to get a nice smooth result */
                gfloat *pix0, *pix1, *pix2, *pix3;
                gfloat mixy0[4];
                gfloat mixy1[4];

                pix0 = get_pixel_color(in_buf, &src_rect, ix, iy);
                pix1 = get_pixel_color(in_buf, &src_rect, ix+1, iy);
                pix2 = get_pixel_color(in_buf, &src_rect, ix, iy+1);
                pix3 = get_pixel_color(in_buf, &src_rect, ix+1, iy+1);
                for (c=0; c<4; ++c)
                {
                    mixy0[c] = dy*(pix2[c] - pix0[c]) + pix0[c];
                    mixy1[c] = dy*(pix3[c] - pix1[c]) + pix1[c];
                    sum[c] += dx*(mixy1[c] - mixy0[c]) + mixy0[c];
                }
            }

            for (c=0; c<4; ++c)
                *out_pixel++ = sum[c] * inv_num_steps;
        }
    }

    gegl_buffer_set (output, roi, babl_format ("RaGaBaA float"), out_buf, GEGL_AUTO_ROWSTRIDE);

    g_free (in_buf);
    g_free (out_buf);


    return  TRUE;
}
Beispiel #27
0
static void update_fg_colors( dibdrv_physdev *pdev )
{
    pdev->pen_color   = get_pixel_color( pdev, pdev->pen_colorref,   TRUE );
    pdev->brush_color = get_pixel_color( pdev, pdev->brush_colorref, TRUE );
    pdev->text_color  = get_pixel_color( pdev, GetTextColor( pdev->dev.hdc ), TRUE );
}
Beispiel #28
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *roi,
         gint                 level)
{
  GeglOperationAreaFilter *op_area = GEGL_OPERATION_AREA_FILTER (operation);
  GeglProperties          *o       = GEGL_PROPERTIES (operation);
  gfloat                  *in_buf, *out_buf, *out_pixel;
  gint                     x, y;
  GeglRectangle            src_rect;
  GeglRectangle           *whole_region;
  gdouble                  angle;
  gdouble                  center_x, center_y;

  whole_region = gegl_operation_source_get_bounding_box (operation, "input");

  center_x = gegl_coordinate_relative_to_pixel (
                    o->center_x, whole_region->width);
  center_y = gegl_coordinate_relative_to_pixel (
                    o->center_y, whole_region->height);


  src_rect = *roi;
  src_rect.x -= op_area->left;
  src_rect.y -= op_area->top;
  src_rect.width += op_area->left + op_area->right;
  src_rect.height += op_area->top + op_area->bottom;

  in_buf    = g_new  (gfloat, src_rect.width * src_rect.height * 4);
  out_buf   = g_new0 (gfloat, roi->width * roi->height * 4);
  out_pixel = out_buf;

  gegl_buffer_get (input, &src_rect, 1.0, babl_format ("RaGaBaA float"),
                   in_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);

  angle = o->angle * G_PI / 180.0;

  while (angle < 0.0)
    angle += 2 * G_PI;

  for (y = roi->y; y < roi->height + roi->y; ++y)
    {
      for (x = roi->x; x < roi->width + roi->x; ++x)
        {
          gint c, i;
          gdouble phi_base, phi_start, phi_step;
          gfloat sum[] = {0, 0, 0, 0};
          gint count = 0;

          gdouble xr = x - center_x;
          gdouble yr = y - center_y;
          gdouble radius  = sqrt (SQR (xr) + SQR (yr));

          /* This is not the "real" length, a bit shorter */
          gdouble arc_length = radius * angle * SQRT_2;

          /* ensure quality with small angles */
          gint n = MAX (ceil (arc_length), 3);

          /* performance concern */
          if (n > NOMINAL_NUM_IT)
            n = NOMINAL_NUM_IT + (gint) sqrt (n - NOMINAL_NUM_IT);

          phi_base = compute_phi (xr, yr);
          phi_start = phi_base + angle / 2.0;
          phi_step = angle / (gdouble) n;

          /* Iterate other the arc */
          for (i = 0; i < n; i++)
            {
              gfloat s_val = sin (phi_start - i * phi_step);
              gfloat c_val = cos (phi_start - i * phi_step);

              gfloat ix = center_x + radius * c_val;
              gfloat iy = center_y + radius * s_val;

              if (ix >= whole_region->x && ix < whole_region->x + whole_region->width &&
                  iy >= whole_region->y && iy < whole_region->y + whole_region->height)
                {
                  /* do bilinear interpolation to get a nice smooth result */
                  gfloat dx = ix - floor (ix);
                  gfloat dy = iy - floor (iy);

                  gfloat *pix0, *pix1, *pix2, *pix3;
                  gfloat mixy0[4];
                  gfloat mixy1[4];

                  pix0 = get_pixel_color (in_buf, &src_rect, ix, iy);
                  pix1 = get_pixel_color (in_buf, &src_rect, ix+1, iy);
                  pix2 = get_pixel_color (in_buf, &src_rect, ix, iy+1);
                  pix3 = get_pixel_color (in_buf, &src_rect, ix+1, iy+1);

                  for (c = 0; c < 4; ++c)
                    {
                      mixy0[c] = dy * (pix2[c] - pix0[c]) + pix0[c];
                      mixy1[c] = dy * (pix3[c] - pix1[c]) + pix1[c];

                      sum[c] +=  dx * (mixy1[c] - mixy0[c]) + mixy0[c];
                    }

                  count++;
                }
            }

          if (count == 0)
            {
              gfloat *pix = get_pixel_color (in_buf, &src_rect, x, y);
              for (c = 0; c < 4; ++c)
                *out_pixel++ = pix[c];
            }
          else
            {
              for (c = 0; c < 4; ++c)
                *out_pixel++ = sum[c] / (gfloat) count;
            }
        }
    }

  gegl_buffer_set (output, roi, 0, babl_format ("RaGaBaA float"),
                   out_buf, GEGL_AUTO_ROWSTRIDE);

  g_free (in_buf);
  g_free (out_buf);

  return  TRUE;
}
Beispiel #29
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *roi,
         gint                 level)
{
  GeglOperationAreaFilter *op_area = GEGL_OPERATION_AREA_FILTER (operation);
  GeglProperties          *o       = GEGL_PROPERTIES (operation);
  gfloat                  *in_buf, *out_buf, *out_pixel;
  gint                     x, y;
  GeglRectangle            src_rect;

  GeglRectangle           *whole_region;
  gdouble                  center_x, center_y;

  whole_region = gegl_operation_source_get_bounding_box (operation, "input");
  center_x = gegl_coordinate_relative_to_pixel (
                o->center_x, whole_region->width);
  center_y = gegl_coordinate_relative_to_pixel (
                o->center_y, whole_region->height);

  src_rect = *roi;
  src_rect.x -= op_area->left;
  src_rect.y -= op_area->top;
  src_rect.width += op_area->left + op_area->right;
  src_rect.height += op_area->top + op_area->bottom;

  in_buf  = g_new  (gfloat, src_rect.width * src_rect.height * 4);
  out_buf = g_new0 (gfloat, roi->width * roi->height * 4);
  out_pixel = out_buf;

  gegl_buffer_get (input, &src_rect, 1.0, babl_format ("RaGaBaA float"),
                   in_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);

  for (y = roi->y; y < roi->height + roi->y; ++y)
    {
      for (x = roi->x; x < roi->width + roi->x; ++x)
        {
          gint c, i;
          gfloat dxx, dyy, ix, iy, inv_xy_len;
          gfloat sum[] = {0, 0, 0, 0};

          gfloat x_start = x;
          gfloat y_start = y;
          gfloat x_end   = x + (center_x - (gfloat) x) * o->factor;
          gfloat y_end   = y + (center_y - (gfloat) y) * o->factor;

          gint dist = ceil (sqrt (SQR (x_end - x_start) + SQR (y_end - y_start)) +1);

          /* ensure quality when near the center or with small factor */
          gint xy_len = MAX (dist, 3);

          /* performance concern */
          if (xy_len > NOMINAL_NUM_IT)
            xy_len = MIN (NOMINAL_NUM_IT + (gint) sqrt (xy_len - NOMINAL_NUM_IT), MAX_NUM_IT);

          inv_xy_len = 1.0 / (gfloat) xy_len;

          dxx = (x_end - x_start) * inv_xy_len;
          dyy = (y_end - y_start) * inv_xy_len;

          ix  = x_start;
          iy  = y_start;

          for (i = 0; i < xy_len; i++)
            {
              gfloat dx = ix - floor (ix);
              gfloat dy = iy - floor (iy);

              /* do bilinear interpolation to get a nice smooth result */
              gfloat *pix0, *pix1, *pix2, *pix3;
              gfloat mixy0[4];
              gfloat mixy1[4];

              pix0 = get_pixel_color (in_buf, &src_rect, ix, iy);
              pix1 = get_pixel_color (in_buf, &src_rect, ix+1, iy);
              pix2 = get_pixel_color (in_buf, &src_rect, ix, iy+1);
              pix3 = get_pixel_color (in_buf, &src_rect, ix+1, iy+1);

              for (c = 0; c < 4; ++c)
                {
                  mixy0[c] = dy * (pix2[c] - pix0[c]) + pix0[c];
                  mixy1[c] = dy * (pix3[c] - pix1[c]) + pix1[c];

                  sum[c] +=  dx * (mixy1[c] - mixy0[c]) + mixy0[c];
                }

              ix += dxx;
              iy += dyy;
            }

          for (c = 0; c < 4; ++c)
            *out_pixel++ = sum[c] * inv_xy_len;
        }
    }

  gegl_buffer_set (output, roi, 0, babl_format ("RaGaBaA float"),
                   out_buf, GEGL_AUTO_ROWSTRIDE);

  g_free (in_buf);
  g_free (out_buf);

  return  TRUE;
}
Beispiel #30
0
void
flood_fill_do_action(int x, int y, texture_info * tex, VALUE hash_arg,
                     texplay_sync sync_mode, bool primary, action_struct * payload)
{
    int left, x1, x2, dy;
    rgba old_color;
    LINESEGMENT stack[MAXDEPTH], *sp = stack;

    action_struct cur;

    int nMinX, nMinY, nMaxX, nMaxY;
    
    /* NOTE: 1024 is just a place-holder to indicate maximum possible width/height.
       Values will be constrained to realistic dimensions by constrain_boundaries() function */
    draw_prologue(&cur, tex, 0, 0, 1024, 1024, &hash_arg, sync_mode, primary, &payload);

    /* fill hates alpha_blend so let's turn it off */
    payload->pen.alpha_blend = false;

    nMinX = cur.xmin; nMinY = cur.ymin;
    nMaxX = cur.xmax; nMaxY = cur.ymax;

    old_color = get_pixel_color(tex, x, y);
    if( cmp_color(old_color, cur.color) )
        return;

    if( x < nMinX || x > nMaxX || y < nMinX || y > nMaxY )
        return;

    PUSH(x, x, y, 1);        /* needed in some cases */
    PUSH(x, x, y + 1, -1);    /* seed segment (popped 1st) */

    while( sp > stack ) {
        POP(x1, x2, y, dy);

        for( x = x1; x >= nMinX && cmp_color(get_pixel_color(tex, x, y), old_color); --x ) {
            set_pixel_color_with_style(payload, tex, x, y);
        }

        if( x >= x1 )
            goto SKIP;

        left = x + 1;
        if( left < x1 )
            PUSH(y, left, x1 - 1, -dy);    /* leak on left? */

        x = x1 + 1;

        do {
            for( ; x <= nMaxX && cmp_color(get_pixel_color(tex, x, y), old_color); ++x ){
                set_pixel_color_with_style(payload, tex, x, y);
            }

            PUSH(left, x - 1, y, dy);

            if( x > x2 + 1 )
                PUSH(x2 + 1, x - 1, y, -dy);    /* leak on right? */

        SKIP:        for( ++x; x <= x2 && !cmp_color(get_pixel_color(tex, x, y), old_color); ++x ) {;}

            left = x;
        } while( x <= x2 );
    }

    draw_epilogue(&cur, tex, primary);
}