src/blitter/32bpp_base.hpp
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 23:20:33 +0300
changeset 11184 88c967f1422b
parent 11163 7034daa18792
permissions -rw-r--r--
add an empty bin/cache dir
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
     1
/* $Id$ */
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10229
diff changeset
     3
/** @file 32bpp_base.hpp Base for all 32 bits blitters. */
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
     4
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
     5
#ifndef BLITTER_32BPP_BASE_HPP
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
     6
#define BLITTER_32BPP_BASE_HPP
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
     7
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
     8
#include "base.hpp"
8609
8c0c3e9dd6a0 (svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents: 8048
diff changeset
     9
#include "../core/bitmath_func.hpp"
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    10
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    11
class Blitter_32bppBase : public Blitter {
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    12
public:
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    13
	/* virtual */ uint8 GetScreenDepth() { return 32; }
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    14
//	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    15
//	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    16
//	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    17
	/* virtual */ void *MoveTo(const void *video, int x, int y);
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    18
	/* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    19
	/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
7443
b8c8a0d029fd (svn r10201) -Codechange: Replace Blitter::SetHorizontalLine with Blitter::DrawRect, as the former was only used by the rectangle drawing code anyway. This lets us draw rectangles in one go.
peter1138
parents: 7436
diff changeset
    20
	/* virtual */ void DrawRect(void *video, int width, int height, uint8 color);
7444
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
    21
	/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color);
7481
699607d457a0 (svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight
parents: 7465
diff changeset
    22
	/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height);
699607d457a0 (svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight
parents: 7465
diff changeset
    23
	/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height);
699607d457a0 (svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight
parents: 7465
diff changeset
    24
	/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
7447
2537a074be26 (svn r10206) -Codechange: more moving things to blitter-layer: ScrollBuffer
truelight
parents: 7444
diff changeset
    25
	/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    26
	/* virtual */ int BufferSize(int width, int height);
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
    27
	/* virtual */ void PaletteAnimate(uint start, uint count);
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
    28
	/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
    29
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    30
	/**
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    31
	 * Compose a colour based on RGB values.
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    32
	 */
11082
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    33
	static inline uint32 ComposeColour(uint a, uint r, uint g, uint b)
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    34
	{
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    35
		return (((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF);
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    36
	}
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    37
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    38
	/**
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    39
	 * Look up the colour in the current palette.
11015
cf4b53f23fde (svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz
parents: 10429
diff changeset
    40
	 */
cf4b53f23fde (svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz
parents: 10429
diff changeset
    41
	static inline uint32 LookupColourInPalette(uint index)
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    42
	{
11015
cf4b53f23fde (svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz
parents: 10429
diff changeset
    43
		return _cur_palette[index];
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    44
	}
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    45
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    46
	/**
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    47
	 * Compose a colour based on RGBA values and the current pixel value.
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    48
	 */
11082
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    49
	static inline uint32 ComposeColourRGBANoCheck(uint r, uint g, uint b, uint a, uint32 current)
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    50
	{
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    51
		uint cr = GB(current, 16, 8);
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    52
		uint cg = GB(current, 8,  8);
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    53
		uint cb = GB(current, 0,  8);
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    54
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    55
		/* The 256 is wrong, it should be 255, but 256 is much faster... */
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    56
		return ComposeColour(0xFF,
11163
7034daa18792 (svn r13721) -Codechange: one less multiplication for colour mixing in 32bpp blitters (GeekToo)
smatz
parents: 11083
diff changeset
    57
							((int)(r - cr) * a) / 256 + cr,
7034daa18792 (svn r13721) -Codechange: one less multiplication for colour mixing in 32bpp blitters (GeekToo)
smatz
parents: 11083
diff changeset
    58
							((int)(g - cg) * a) / 256 + cg,
7034daa18792 (svn r13721) -Codechange: one less multiplication for colour mixing in 32bpp blitters (GeekToo)
smatz
parents: 11083
diff changeset
    59
							((int)(b - cb) * a) / 256 + cb);
11082
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    60
	}
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    61
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    62
	/**
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    63
	 * Compose a colour based on RGBA values and the current pixel value.
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    64
	 * Handles fully transparent and solid pixels in a special (faster) way.
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    65
	 */
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    66
	static inline uint32 ComposeColourRGBA(uint r, uint g, uint b, uint a, uint32 current)
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    67
	{
8048
7547093f21e6 (svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
truelight
parents: 7481
diff changeset
    68
		if (a == 0) return current;
7547093f21e6 (svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
truelight
parents: 7481
diff changeset
    69
		if (a >= 255) return ComposeColour(0xFF, r, g, b);
7547093f21e6 (svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
truelight
parents: 7481
diff changeset
    70
11082
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    71
		return ComposeColourRGBANoCheck(r, g, b, a, current);
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    72
	}
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    73
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    74
	/**
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    75
	 * Compose a colour based on Pixel value, alpha value, and the current pixel value.
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    76
	 */
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    77
	static inline uint32 ComposeColourPANoCheck(uint32 colour, uint a, uint32 current)
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    78
	{
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    79
		uint r  = GB(colour,  16, 8);
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    80
		uint g  = GB(colour,  8,  8);
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    81
		uint b  = GB(colour,  0,  8);
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    82
11163
7034daa18792 (svn r13721) -Codechange: one less multiplication for colour mixing in 32bpp blitters (GeekToo)
smatz
parents: 11083
diff changeset
    83
		return ComposeColourRGBANoCheck(r, g, b, a, current);
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    84
	}
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    85
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    86
	/**
11082
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    87
	 * Compose a colour based on Pixel value, alpha value, and the current pixel value.
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    88
	 * Handles fully transparent and solid pixels in a special (faster) way.
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    89
	 */
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    90
	static inline uint32 ComposeColourPA(uint32 colour, uint a, uint32 current)
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    91
	{
8048
7547093f21e6 (svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
truelight
parents: 7481
diff changeset
    92
		if (a == 0) return current;
7547093f21e6 (svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
truelight
parents: 7481
diff changeset
    93
		if (a >= 255) return (colour | 0xFF000000);
7547093f21e6 (svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
truelight
parents: 7481
diff changeset
    94
11082
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
    95
		return ComposeColourPANoCheck(colour, a, current);
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    96
	}
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    97
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    98
	/**
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
    99
	* Make a pixel looks like it is transparent.
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   100
	* @param colour the colour already on the screen.
11083
19aff1f3244e (svn r13640) -Codechange: make colours behind not fully solid objects less darker for BM_TRANSPARENT (for 32bpp blitters)
smatz
parents: 11082
diff changeset
   101
	* @param nom the amount of transparency, nominator, makes colour lighter.
19aff1f3244e (svn r13640) -Codechange: make colours behind not fully solid objects less darker for BM_TRANSPARENT (for 32bpp blitters)
smatz
parents: 11082
diff changeset
   102
	* @param denom denominator, makes colour darker.
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   103
	* @return the new colour for the screen.
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   104
	*/
11083
19aff1f3244e (svn r13640) -Codechange: make colours behind not fully solid objects less darker for BM_TRANSPARENT (for 32bpp blitters)
smatz
parents: 11082
diff changeset
   105
	static inline uint32 MakeTransparent(uint32 colour, uint nom, uint denom = 256)
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   106
	{
11082
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
   107
		uint r = GB(colour, 16, 8);
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
   108
		uint g = GB(colour, 8,  8);
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
   109
		uint b = GB(colour, 0,  8);
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   110
11083
19aff1f3244e (svn r13640) -Codechange: make colours behind not fully solid objects less darker for BM_TRANSPARENT (for 32bpp blitters)
smatz
parents: 11082
diff changeset
   111
		return ComposeColour(0xFF, r * nom / denom, g * nom / denom, b * nom / denom);
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   112
	}
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   113
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   114
	/**
10229
fba3f9fa44d7 (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents: 8609
diff changeset
   115
	* Make a colour grey - based.
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   116
	* @param colour the colour to make grey.
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   117
	* @return the new colour, now grey.
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   118
	*/
11082
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
   119
	static inline uint32 MakeGrey(uint32 colour)
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   120
	{
11082
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
   121
		uint r = GB(colour, 16, 8);
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
   122
		uint g = GB(colour, 8,  8);
45ab75d184a0 (svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
smatz
parents: 11015
diff changeset
   123
		uint b = GB(colour, 0,  8);
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   124
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   125
		/* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   126
		*  divide by it to normalize the value to a byte again. See heightmap.cpp for
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   127
		*  information about the formula. */
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   128
		colour = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   129
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7456
diff changeset
   130
		return ComposeColour(0xFF, colour, colour, colour);
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
   131
	}
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
   132
};
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
   133
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
diff changeset
   134
#endif /* BLITTER_32BPP_BASE_HPP */