2007-06-13 10:31:40 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file 32bpp_base.hpp Base for all 32 bits blitters. */
|
2007-06-13 10:31:40 +00:00
|
|
|
|
2007-06-17 20:30:28 +00:00
|
|
|
#ifndef BLITTER_32BPP_BASE_HPP
|
|
|
|
#define BLITTER_32BPP_BASE_HPP
|
2007-06-13 10:31:40 +00:00
|
|
|
|
2007-06-17 20:30:28 +00:00
|
|
|
#include "base.hpp"
|
2007-12-21 19:21:21 +00:00
|
|
|
#include "../core/bitmath_func.hpp"
|
2007-06-13 10:31:40 +00:00
|
|
|
|
2007-06-17 20:30:28 +00:00
|
|
|
class Blitter_32bppBase : public Blitter {
|
2007-06-13 10:31:40 +00:00
|
|
|
public:
|
2007-06-17 20:30:28 +00:00
|
|
|
/* virtual */ uint8 GetScreenDepth() { return 32; }
|
|
|
|
// /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
|
|
|
// /* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
|
|
|
|
// /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
|
2007-06-13 10:31:40 +00:00
|
|
|
/* virtual */ void *MoveTo(const void *video, int x, int y);
|
|
|
|
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
|
|
|
|
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
|
2007-06-18 18:45:12 +00:00
|
|
|
/* virtual */ void DrawRect(void *video, int width, int height, uint8 color);
|
2007-06-18 19:38:23 +00:00
|
|
|
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color);
|
2007-06-21 12:36:46 +00:00
|
|
|
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height);
|
|
|
|
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height);
|
|
|
|
/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
|
2007-06-18 20:08:21 +00:00
|
|
|
/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
|
2007-06-13 10:31:40 +00:00
|
|
|
/* virtual */ int BufferSize(int width, int height);
|
2007-06-19 15:04:08 +00:00
|
|
|
/* virtual */ void PaletteAnimate(uint start, uint count);
|
|
|
|
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
|
2008-08-15 22:06:58 +00:00
|
|
|
/* virtual */ int GetBytesPerPixel() { return 4; }
|
2007-06-13 10:31:40 +00:00
|
|
|
|
2007-06-19 17:32:01 +00:00
|
|
|
/**
|
|
|
|
* Compose a colour based on RGB values.
|
|
|
|
*/
|
2008-06-26 15:46:19 +00:00
|
|
|
static inline uint32 ComposeColour(uint a, uint r, uint g, uint b)
|
2007-06-19 17:32:01 +00:00
|
|
|
{
|
|
|
|
return (((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up the colour in the current palette.
|
2008-06-18 21:19:04 +00:00
|
|
|
*/
|
|
|
|
static inline uint32 LookupColourInPalette(uint index)
|
2007-06-19 17:32:01 +00:00
|
|
|
{
|
2008-06-18 21:19:04 +00:00
|
|
|
return _cur_palette[index];
|
2007-06-19 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compose a colour based on RGBA values and the current pixel value.
|
|
|
|
*/
|
2008-06-26 15:46:19 +00:00
|
|
|
static inline uint32 ComposeColourRGBANoCheck(uint r, uint g, uint b, uint a, uint32 current)
|
|
|
|
{
|
|
|
|
uint cr = GB(current, 16, 8);
|
|
|
|
uint cg = GB(current, 8, 8);
|
|
|
|
uint cb = GB(current, 0, 8);
|
|
|
|
|
|
|
|
/* The 256 is wrong, it should be 255, but 256 is much faster... */
|
|
|
|
return ComposeColour(0xFF,
|
2008-07-17 23:43:47 +00:00
|
|
|
((int)(r - cr) * a) / 256 + cr,
|
|
|
|
((int)(g - cg) * a) / 256 + cg,
|
|
|
|
((int)(b - cb) * a) / 256 + cb);
|
2008-06-26 15:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compose a colour based on RGBA values and the current pixel value.
|
|
|
|
* Handles fully transparent and solid pixels in a special (faster) way.
|
|
|
|
*/
|
|
|
|
static inline uint32 ComposeColourRGBA(uint r, uint g, uint b, uint a, uint32 current)
|
2007-06-19 17:32:01 +00:00
|
|
|
{
|
2007-09-09 21:56:52 +00:00
|
|
|
if (a == 0) return current;
|
|
|
|
if (a >= 255) return ComposeColour(0xFF, r, g, b);
|
|
|
|
|
2008-06-26 15:46:19 +00:00
|
|
|
return ComposeColourRGBANoCheck(r, g, b, a, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compose a colour based on Pixel value, alpha value, and the current pixel value.
|
|
|
|
*/
|
|
|
|
static inline uint32 ComposeColourPANoCheck(uint32 colour, uint a, uint32 current)
|
|
|
|
{
|
|
|
|
uint r = GB(colour, 16, 8);
|
|
|
|
uint g = GB(colour, 8, 8);
|
|
|
|
uint b = GB(colour, 0, 8);
|
2007-06-19 17:32:01 +00:00
|
|
|
|
2008-07-17 23:43:47 +00:00
|
|
|
return ComposeColourRGBANoCheck(r, g, b, a, current);
|
2007-06-19 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-26 15:46:19 +00:00
|
|
|
* Compose a colour based on Pixel value, alpha value, and the current pixel value.
|
|
|
|
* Handles fully transparent and solid pixels in a special (faster) way.
|
|
|
|
*/
|
|
|
|
static inline uint32 ComposeColourPA(uint32 colour, uint a, uint32 current)
|
2007-06-19 17:32:01 +00:00
|
|
|
{
|
2007-09-09 21:56:52 +00:00
|
|
|
if (a == 0) return current;
|
|
|
|
if (a >= 255) return (colour | 0xFF000000);
|
|
|
|
|
2008-06-26 15:46:19 +00:00
|
|
|
return ComposeColourPANoCheck(colour, a, current);
|
2007-06-19 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a pixel looks like it is transparent.
|
|
|
|
* @param colour the colour already on the screen.
|
2008-06-26 16:47:29 +00:00
|
|
|
* @param nom the amount of transparency, nominator, makes colour lighter.
|
|
|
|
* @param denom denominator, makes colour darker.
|
2007-06-19 17:32:01 +00:00
|
|
|
* @return the new colour for the screen.
|
|
|
|
*/
|
2008-06-26 16:47:29 +00:00
|
|
|
static inline uint32 MakeTransparent(uint32 colour, uint nom, uint denom = 256)
|
2007-06-19 17:32:01 +00:00
|
|
|
{
|
2008-06-26 15:46:19 +00:00
|
|
|
uint r = GB(colour, 16, 8);
|
|
|
|
uint g = GB(colour, 8, 8);
|
|
|
|
uint b = GB(colour, 0, 8);
|
2007-06-19 17:32:01 +00:00
|
|
|
|
2008-06-26 16:47:29 +00:00
|
|
|
return ComposeColour(0xFF, r * nom / denom, g * nom / denom, b * nom / denom);
|
2007-06-19 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-18 04:37:06 +00:00
|
|
|
* Make a colour grey - based.
|
2007-06-19 17:32:01 +00:00
|
|
|
* @param colour the colour to make grey.
|
|
|
|
* @return the new colour, now grey.
|
|
|
|
*/
|
2008-06-26 15:46:19 +00:00
|
|
|
static inline uint32 MakeGrey(uint32 colour)
|
2007-06-19 17:32:01 +00:00
|
|
|
{
|
2008-06-26 15:46:19 +00:00
|
|
|
uint r = GB(colour, 16, 8);
|
|
|
|
uint g = GB(colour, 8, 8);
|
|
|
|
uint b = GB(colour, 0, 8);
|
2007-06-19 17:32:01 +00:00
|
|
|
|
|
|
|
/* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then
|
|
|
|
* divide by it to normalize the value to a byte again. See heightmap.cpp for
|
|
|
|
* information about the formula. */
|
|
|
|
colour = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
|
|
|
|
|
|
|
|
return ComposeColour(0xFF, colour, colour, colour);
|
2007-06-13 10:31:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-06-17 20:30:28 +00:00
|
|
|
#endif /* BLITTER_32BPP_BASE_HPP */
|