Commit b0504686 authored by Marek Dvoroznak's avatar Marek Dvoroznak Committed by Mikael Magnusson

libs: npd: add alpha blending

parent 3de5bc94
......@@ -183,6 +183,33 @@ npd_bilinear_color_interpolation (NPDColor *I0,
out->a = npd_bilinear_interpolation (I0->a, I1->a, I2->a, I3->a, dx, dy);
}
gint
npd_blend_band (gint src,
gint dst,
gfloat src_alpha,
gfloat dst_alpha,
gfloat out_alpha_recip)
{
return floor ((src * src_alpha +
dst * dst_alpha * (1 - src_alpha)) * out_alpha_recip);
}
void
npd_blend_colors (NPDColor *src,
NPDColor *dst,
NPDColor *out_color)
{
gfloat src_A = src->a / 255.0,
dst_A = dst->a / 255.0;
gfloat out_alpha = src_A + dst_A * (1 - src_A);
gfloat out_alpha_recip = 1 / out_alpha;
out_color->r = npd_blend_band (src->r, dst->r, src_A, dst_A, out_alpha_recip);
out_color->g = npd_blend_band (src->g, dst->g, src_A, dst_A, out_alpha_recip);
out_color->b = npd_blend_band (src->b, dst->b, src_A, dst_A, out_alpha_recip);
out_color->a = out_alpha * 255;
}
void
npd_texture_fill_triangle (gint x1,
gint y1,
......@@ -333,7 +360,7 @@ npd_draw_texture_line (gint x1,
for (x = x1; x <= x2; x++)
{
NPDPoint p, q;
NPDColor I0, I1, I2, I3, interpolated;
NPDColor I0, I1, I2, I3, interpolated, dest;
q.x = x; q.y = y;
npd_apply_transformation(A, &q, &p);
......@@ -350,6 +377,10 @@ npd_draw_texture_line (gint x1,
npd_get_pixel_color(input_image, fx+1, fy+1, &I3);
npd_bilinear_color_interpolation(&I0, &I1, &I2, &I3, dx, dy, &interpolated);
/* alpha blending */
npd_get_pixel_color (output_image, x, y, &dest);
npd_blend_colors (&interpolated, &dest, &interpolated);
npd_set_pixel_color (output_image, x, y, &interpolated);
}
}
......@@ -29,64 +29,72 @@ struct _NPDColor {
unsigned char a;
};
void npd_create_model_from_image (NPDModel *model,
NPDImage *image,
gint square_size);
void npd_create_mesh_from_image (NPDModel *model,
gint width,
gint height,
gint position_x,
gint position_y);
void npd_draw_model (NPDModel *model,
void npd_create_model_from_image (NPDModel *model,
NPDImage *image,
gint square_size);
void npd_create_mesh_from_image (NPDModel *model,
gint width,
gint height,
gint position_x,
gint position_y);
void npd_draw_model (NPDModel *model,
NPDDisplay *display);
gboolean npd_load_image (NPDImage *image,
gboolean npd_load_image (NPDImage *image,
const char *path);
void npd_destroy_image (NPDImage *image);
void npd_draw_image (NPDImage *image);
void npd_texture_fill_triangle (gint x1,
gint y1,
gint x2,
gint y2,
gint x3,
gint y3,
NPDMatrix *A,
NPDImage *input_image,
NPDImage *output_image);
void npd_texture_quadrilateral (NPDBone *reference_bone,
NPDBone *current_bone,
NPDImage *input_image,
NPDImage *output_image);
void npd_draw_texture_line (gint x1,
gint x2,
gint y,
NPDMatrix *A,
void npd_destroy_image (NPDImage *image);
//void npd_draw_image (NPDImage *image);
void npd_texture_fill_triangle (gint x1,
gint y1,
gint x2,
gint y2,
gint x3,
gint y3,
NPDMatrix *A,
NPDImage *input_image,
NPDImage *output_image);
gint npd_bilinear_interpolation (gint I0,
gint I1,
gint I2,
gint I3,
gfloat dx,
gfloat dy);
void npd_bilinear_color_interpolation (NPDColor *I0,
NPDColor *I1,
NPDColor *I2,
NPDColor *I3,
gfloat dx,
gfloat dy,
NPDColor *out);
void (*npd_get_pixel_color) (NPDImage *image,
gint x,
gint y,
NPDColor *color);
void (*npd_set_pixel_color) (NPDImage *image,
gint x,
gint y,
NPDColor *color);
gboolean npd_compare_colors (NPDColor *c1,
NPDColor *c2);
gboolean npd_is_color_transparent (NPDColor *color);
void npd_texture_quadrilateral (NPDBone *reference_bone,
NPDBone *current_bone,
NPDImage *input_image,
NPDImage *output_image);
void npd_draw_texture_line (gint x1,
gint x2,
gint y,
NPDMatrix *A,
NPDImage *input_image,
NPDImage *output_image);
gint npd_bilinear_interpolation (gint I0,
gint I1,
gint I2,
gint I3,
gfloat dx,
gfloat dy);
void npd_bilinear_color_interpolation (NPDColor *I0,
NPDColor *I1,
NPDColor *I2,
NPDColor *I3,
gfloat dx,
gfloat dy,
NPDColor *out);
gint npd_blend_band (gint src,
gint dst,
gfloat src_alpha,
gfloat dest_alpha,
gfloat out_alpha);
void npd_blend_colors (NPDColor *src,
NPDColor *dst,
NPDColor *out_color);
void (*npd_get_pixel_color) (NPDImage *image,
gint x,
gint y,
NPDColor *color);
void (*npd_set_pixel_color) (NPDImage *image,
gint x,
gint y,
NPDColor *color);
gboolean npd_compare_colors (NPDColor *c1,
NPDColor *c2);
gboolean npd_is_color_transparent (NPDColor *color);
gboolean npd_init_display (NPDDisplay *display);
void npd_destroy_display (NPDDisplay *display);
......
......@@ -127,7 +127,7 @@ npd_get_pixel_color_impl (NPDImage *image,
}
void
npd_draw_model (NPDModel *model,
npd_draw_model (NPDModel *model,
NPDDisplay *display)
{
NPDHiddenModel *hidden_model = model->hidden_model;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment