third_party/pixman/pixman/pixman-utils.c
void
pixman_expand_to_float (argb_t               *dst,
			const uint32_t       *src,
			pixman_format_code_t  format,
			int                   width)
{
    static const float multipliers[16] = {
	0.0f,
	1.0f / ((1 <<  1) - 1),
	1.0f / ((1 <<  2) - 1),
	1.0f / ((1 <<  3) - 1),
	1.0f / ((1 <<  4) - 1),
	1.0f / ((1 <<  5) - 1),
	1.0f / ((1 <<  6) - 1),
	1.0f / ((1 <<  7) - 1),
	1.0f / ((1 <<  8) - 1),
	1.0f / ((1 <<  9) - 1),
	1.0f / ((1 << 10) - 1),
	1.0f / ((1 << 11) - 1),
	1.0f / ((1 << 12) - 1),
	1.0f / ((1 << 13) - 1),
	1.0f / ((1 << 14) - 1),
	1.0f / ((1 << 15) - 1),
    };
    int a_size, r_size, g_size, b_size;
    int a_shift, r_shift, g_shift, b_shift;
    float a_mul, r_mul, g_mul, b_mul;
    uint32_t a_mask, r_mask, g_mask, b_mask;
    int i;

    if (!PIXMAN_FORMAT_VIS (format))
	format = PIXMAN_a8r8g8b8;

    /*
     * Determine the sizes of each component and the masks and shifts
     * required to extract them from the source pixel.
     */
    a_size = PIXMAN_FORMAT_A (format);
    r_size = PIXMAN_FORMAT_R (format);
    g_size = PIXMAN_FORMAT_G (format);
    b_size = PIXMAN_FORMAT_B (format);

    a_shift = 32 - a_size;
    r_shift = 24 - r_size;
    g_shift = 16 - g_size;
    b_shift =  8 - b_size;

    a_mask = ((1 << a_size) - 1);
    r_mask = ((1 << r_size) - 1);
    g_mask = ((1 << g_size) - 1);
    b_mask = ((1 << b_size) - 1);

    a_mul = multipliers[a_size];
    r_mul = multipliers[r_size];
    g_mul = multipliers[g_size];
    b_mul = multipliers[b_size];

    /* Start at the end so that we can do the expansion in place
     * when src == dst
     */
    for (i = width - 1; i >= 0; i--)
    {
	const uint32_t pixel = src[i];

	dst[i].a = a_mask? ((pixel >> a_shift) & a_mask) * a_mul : 1.0f;
	dst[i].r = ((pixel >> r_shift) & r_mask) * r_mul;
	dst[i].g = ((pixel >> g_shift) & g_mask) * g_mul;
	dst[i].b = ((pixel >> b_shift) & b_mask) * b_mul;
    }
}
/*
 * This function expands images from a8r8g8b8 to argb_t.  To preserve
 * precision, it needs to know from which source format the a8r8g8b8 pixels
 * originally came.
 *
 * For example, if the source was PIXMAN_x1r5g5b5 and the red component
 * contained bits 12345, then the 8-bit value is 12345123.  To correctly
 * expand this to floating point, it should be 12345 / 31.0 and not
 * 12345123 / 255.0.
 */
This function expands images from a8r8g8b8 to argb_t.  To preserve
precision, it needs to know from which source format the a8r8g8b8 pixels
originally came.

For example, if the source was PIXMAN_x1r5g5b5 and the red component
contained bits 12345, then the 8-bit value is 12345123.  To correctly
expand this to floating point, it should be 12345 / 31.0 and not
12345123 / 255.0.
This function expands images from a8r8g8b8 to argb_t . To preserve precision it needs to know from which source format the a8r8g8b8 pixels originally came . For example if the source was PIXMAN_x1r5g5b5 and the red component contained bits 12345 then the 8 - bit value is 12345123 . To correctly expand this to floating point it should be 12345 / 31 . 0 and not 12345123 / 255 . 0 .
void
pixman_expand_to_float (argb_t               *dst,
			const uint32_t       *src,
			pixman_format_code_t  format,
			int                   width)
{
    static const float multipliers[16] = {
	0.0f,
	1.0f / ((1 <<  1) - 1),
	1.0f / ((1 <<  2) - 1),
	1.0f / ((1 <<  3) - 1),
	1.0f / ((1 <<  4) - 1),
	1.0f / ((1 <<  5) - 1),
	1.0f / ((1 <<  6) - 1),
	1.0f / ((1 <<  7) - 1),
	1.0f / ((1 <<  8) - 1),
	1.0f / ((1 <<  9) - 1),
	1.0f / ((1 << 10) - 1),
	1.0f / ((1 << 11) - 1),
	1.0f / ((1 << 12) - 1),
	1.0f / ((1 << 13) - 1),
	1.0f / ((1 << 14) - 1),
	1.0f / ((1 << 15) - 1),
    };
    int a_size, r_size, g_size, b_size;
    int a_shift, r_shift, g_shift, b_shift;
    float a_mul, r_mul, g_mul, b_mul;
    uint32_t a_mask, r_mask, g_mask, b_mask;
    int i;
    if (!PIXMAN_FORMAT_VIS (format))
	format = PIXMAN_a8r8g8b8;
    a_size = PIXMAN_FORMAT_A (format);
    r_size = PIXMAN_FORMAT_R (format);
    g_size = PIXMAN_FORMAT_G (format);
    b_size = PIXMAN_FORMAT_B (format);
    a_shift = 32 - a_size;
    r_shift = 24 - r_size;
    g_shift = 16 - g_size;
    b_shift =  8 - b_size;
    a_mask = ((1 << a_size) - 1);
    r_mask = ((1 << r_size) - 1);
    g_mask = ((1 << g_size) - 1);
    b_mask = ((1 << b_size) - 1);
    a_mul = multipliers[a_size];
    r_mul = multipliers[r_size];
    g_mul = multipliers[g_size];
    b_mul = multipliers[b_size];
    for (i = width - 1; i >= 0; i--)
    {
	const uint32_t pixel = src[i];
	dst[i].a = a_mask? ((pixel >> a_shift) & a_mask) * a_mul : 1.0f;
	dst[i].r = ((pixel >> r_shift) & r_mask) * r_mul;
	dst[i].g = ((pixel >> g_shift) & g_mask) * g_mul;
	dst[i].b = ((pixel >> b_shift) & b_mask) * b_mul;
    }
}
void pixman_expand_to_float ( argb_t * dst , const uint32_t * src , pixman_format_code_t format , int width ) { static const float multipliers [ 16 ] = { 0.0f , 1.0f / ( ( 1 << 1 ) - 1 ) , 1.0f / ( ( 1 << 2 ) - 1 ) , 1.0f / ( ( 1 << 3 ) - 1 ) , 1.0f / ( ( 1 << 4 ) - 1 ) , 1.0f / ( ( 1 << 5 ) - 1 ) , 1.0f / ( ( 1 << 6 ) - 1 ) , 1.0f / ( ( 1 << 7 ) - 1 ) , 1.0f / ( ( 1 << 8 ) - 1 ) , 1.0f / ( ( 1 << 9 ) - 1 ) , 1.0f / ( ( 1 << 10 ) - 1 ) , 1.0f / ( ( 1 << 11 ) - 1 ) , 1.0f / ( ( 1 << 12 ) - 1 ) , 1.0f / ( ( 1 << 13 ) - 1 ) , 1.0f / ( ( 1 << 14 ) - 1 ) , 1.0f / ( ( 1 << 15 ) - 1 ) , } ; int a_size , r_size , g_size , b_size ; int a_shift , r_shift , g_shift , b_shift ; float a_mul , r_mul , g_mul , b_mul ; uint32_t a_mask , r_mask , g_mask , b_mask ; int i ; if ( ! PIXMAN_FORMAT_VIS ( format ) ) format = PIXMAN_a8r8g8b8 ; a_size = PIXMAN_FORMAT_A ( format ) ; r_size = PIXMAN_FORMAT_R ( format ) ; g_size = PIXMAN_FORMAT_G ( format ) ; b_size = PIXMAN_FORMAT_B ( format ) ; a_shift = 32 - a_size ; r_shift = 24 - r_size ; g_shift = 16 - g_size ; b_shift = 8 - b_size ; a_mask = ( ( 1 << a_size ) - 1 ) ; r_mask = ( ( 1 << r_size ) - 1 ) ; g_mask = ( ( 1 << g_size ) - 1 ) ; b_mask = ( ( 1 << b_size ) - 1 ) ; a_mul = multipliers [ a_size ] ; r_mul = multipliers [ r_size ] ; g_mul = multipliers [ g_size ] ; b_mul = multipliers [ b_size ] ; for ( i = width - 1 ; i >= 0 ; i -- ) { const uint32_t pixel = src [ i ] ; dst [ i ] . a = a_mask ? ( ( pixel >> a_shift ) & a_mask ) * a_mul : 1.0f ; dst [ i ] . r = ( ( pixel >> r_shift ) & r_mask ) * r_mul ; dst [ i ] . g = ( ( pixel >> g_shift ) & g_mask ) * g_mul ; dst [ i ] . b = ( ( pixel >> b_shift ) & b_mask ) * b_mul ; } }
This function expands images from a8r8g8b8 to argb_t.
This function expands images from a8r8g8b8 to argb_t .
/*
     * Determine the sizes of each component and the masks and shifts
     * required to extract them from the source pixel.
     */ /* Start at the end so that we can do the expansion in place
     * when src == dst
     */