src/blitter/32bpp_base.hpp
changeset 8048 7547093f21e6
parent 7481 699607d457a0
child 8609 8c0c3e9dd6a0
equal deleted inserted replaced
8047:bcc7782ef238 8048:7547093f21e6
    46 	/**
    46 	/**
    47 	 * Compose a colour based on RGBA values and the current pixel value.
    47 	 * Compose a colour based on RGBA values and the current pixel value.
    48 	 */
    48 	 */
    49 	static inline uint ComposeColourRGBA(uint r, uint g, uint b, uint a, uint current)
    49 	static inline uint ComposeColourRGBA(uint r, uint g, uint b, uint a, uint current)
    50 	{
    50 	{
       
    51 		if (a == 0) return current;
       
    52 		if (a >= 255) return ComposeColour(0xFF, r, g, b);
       
    53 
    51 		uint cr, cg, cb;
    54 		uint cr, cg, cb;
    52 		cr = GB(current, 16, 8);
    55 		cr = GB(current, 16, 8);
    53 		cg = GB(current, 8,  8);
    56 		cg = GB(current, 8,  8);
    54 		cb = GB(current, 0,  8);
    57 		cb = GB(current, 0,  8);
    55 
    58 
       
    59 		/* The 256 is wrong, it should be 255, but 256 is much faster... */
    56 		return ComposeColour(0xFF,
    60 		return ComposeColour(0xFF,
    57 												(r * a + cr * (255 - a)) / 255,
    61 												(r * a + cr * (256 - a)) / 256,
    58 												(g * a + cg * (255 - a)) / 255,
    62 												(g * a + cg * (256 - a)) / 256,
    59 												(b * a + cb * (255 - a)) / 255);
    63 												(b * a + cb * (256 - a)) / 256);
    60 	}
    64 	}
    61 
    65 
    62 	/**
    66 	/**
    63 	* Compose a colour based on Pixel value, alpha value, and the current pixel value.
    67 	* Compose a colour based on Pixel value, alpha value, and the current pixel value.
    64 	*/
    68 	*/
    65 	static inline uint ComposeColourPA(uint colour, uint a, uint current)
    69 	static inline uint ComposeColourPA(uint colour, uint a, uint current)
    66 	{
    70 	{
       
    71 		if (a == 0) return current;
       
    72 		if (a >= 255) return (colour | 0xFF000000);
       
    73 
    67 		uint r, g, b, cr, cg, cb;
    74 		uint r, g, b, cr, cg, cb;
    68 		r  = GB(colour,   16, 8);
    75 		r  = GB(colour,  16, 8);
    69 		g  = GB(colour,   8,  8);
    76 		g  = GB(colour,  8,  8);
    70 		b  = GB(colour,   0,  8);
    77 		b  = GB(colour,  0,  8);
    71 		cr = GB(current, 16, 8);
    78 		cr = GB(current, 16, 8);
    72 		cg = GB(current, 8,  8);
    79 		cg = GB(current, 8,  8);
    73 		cb = GB(current, 0,  8);
    80 		cb = GB(current, 0,  8);
    74 
    81 
       
    82 		/* The 256 is wrong, it should be 255, but 256 is much faster... */
    75 		return ComposeColour(0xFF,
    83 		return ComposeColour(0xFF,
    76 												(r * a + cr * (255 - a)) / 255,
    84 												(r * a + cr * (256 - a)) / 256,
    77 												(g * a + cg * (255 - a)) / 255,
    85 												(g * a + cg * (256 - a)) / 256,
    78 												(b * a + cb * (255 - a)) / 255);
    86 												(b * a + cb * (256 - a)) / 256);
    79 	}
    87 	}
    80 
    88 
    81 	/**
    89 	/**
    82 	* Make a pixel looks like it is transparent.
    90 	* Make a pixel looks like it is transparent.
    83 	* @param colour the colour already on the screen.
    91 	* @param colour the colour already on the screen.
    84 	* @param amount the amount of transparency, times 100.
    92 	* @param amount the amount of transparency, times 256.
    85 	* @return the new colour for the screen.
    93 	* @return the new colour for the screen.
    86 	*/
    94 	*/
    87 	static inline uint MakeTransparent(uint colour, uint amount)
    95 	static inline uint MakeTransparent(uint colour, uint amount)
    88 	{
    96 	{
    89 		uint r, g, b;
    97 		uint r, g, b;
    90 		r = GB(colour, 16, 8);
    98 		r = GB(colour, 16, 8);
    91 		g = GB(colour, 8,  8);
    99 		g = GB(colour, 8,  8);
    92 		b = GB(colour, 0,  8);
   100 		b = GB(colour, 0,  8);
    93 
   101 
    94 		return ComposeColour(0xFF, r * amount / 100, g * amount / 100, b * amount / 100);
   102 		return ComposeColour(0xFF, r * amount / 256, g * amount / 256, b * amount / 256);
    95 	}
   103 	}
    96 
   104 
    97 	/**
   105 	/**
    98 	* Make a colour grey-based.
   106 	* Make a colour grey-based.
    99 	* @param colour the colour to make grey.
   107 	* @param colour the colour to make grey.