/* Generate colors so that premultiplying will result in values in steps of 1/15th.
* Also make sure that an averaged gray value fits in that range. */ staticvoid
create_random_color (GdkRGBA *color)
{ int r, g, b; do
{
r = g_test_rand_int_range (0, 6);
g = g_test_rand_int_range (0, 6);
b = g_test_rand_int_range (0, 6);
} while ((r + g + b) % 3 != 0);
color->red = r / 5.f;
color->green = g / 5.f;
color->blue = b / 5.f;
color->alpha = g_test_rand_int_range (0, 4) / 3.f;
}
staticvoid
create_random_10bit_color (GdkRGBA *color)
{ int r, g, b;
r = g_test_rand_int_range (0, 4);
g = g_test_rand_int_range (0, 4);
b = g_test_rand_int_range (0, 4);
color->red = r / 3.f;
color->green = g / 3.f;
color->blue = b / 3.f;
color->alpha = 1.0;
}
/* If the format can't handle alpha, make things opaque
*/ if (gdk_memory_format_alpha (format) == GDK_MEMORY_ALPHA_OPAQUE)
color_make_opaque (color, color);
/* If the format has fewer color channels than the *target,makesurethecolorsgetadjusted.
*/ if (gdk_memory_format_n_colors (format) == 1)
color_make_gray (color, color); elseif (gdk_memory_format_n_colors (format) == 0)
color_make_white (color, color);
}
static GdkTexture *
create_solid_color_texture (GdkMemoryFormat format, int width, int height, const GdkRGBA *color)
{
TextureBuilder builder;
texture_builder_init (&builder, format, width, height);
texture_builder_fill (&builder, color);
return texture_builder_finish (&builder);
}
/* randomly creates 4 colors with values that are multiples *of8,sothataveragingthecolorsworkswithoutrounding *errors,andthencreatesastipplepatternlikethis: * *121212... *343434 *121212 *343434 *121212 *343434 *⋮
*/ static GdkTexture *
create_stipple_texture (GdkMemoryFormat format,
gsize width,
gsize height,
GdkRGBA colors[2][2],
GdkRGBA *average)
{
TextureBuilder builder;
GdkTexture *texture; int x, y; /* large enough */ float data[4 * 4 * 4];
GdkMemoryLayout layout; float adjust_color, adjust_alpha;
if (average->alpha != 0.0f)
{
average->red /= average->alpha;
average->green /= average->alpha;
average->blue /= average->alpha;
average->alpha /= 4.0f;
} else
{ /* Each component of the average has been multiplied by the alpha *already,soifthealphaiszero,allcomponentsshouldalso
* be zero */
g_assert_cmpfloat (average->red, ==, 0.0f);
g_assert_cmpfloat (average->green, ==, 0.0f);
g_assert_cmpfloat (average->blue, ==, 0.0f);
}
for (y = 0; y < 4; y++)
{ for (x = 0; x < 4; x++)
{
data[4 * (4 * y + x) + 0] = colors[x % 2][y % 2].red;
data[4 * (4 * y + x) + 1] = colors[x % 2][y % 2].green;
data[4 * (4 * y + x) + 2] = colors[x % 2][y % 2].blue;
data[4 * (4 * y + x) + 3] = colors[x % 2][y % 2].alpha;
}
}
gdk_memory_layout_init (&layout,
GDK_MEMORY_R32G32B32A32_FLOAT, 4, 4, 1);
layout.width = MIN (width, layout.width);
layout.height = MIN (height, layout.height);
texture_builder_init (&builder, format, width, height); for (y = 0; y < height; y += layout.height)
{ for (x = 0; x < width; x += layout.width)
{
texture_builder_draw_data (&builder,
x, y,
(guchar *) data,
&layout);
}
}
texture = texture_builder_finish (&builder);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.