Files
@ r28035:f86971abe639
Branch filter:
Location: cpp/openttd-patchpack/source/src/blitter/32bpp_base.hpp - annotation
r28035:f86971abe639
5.9 KiB
text/x-c++hdr
Update: Translations from eints
english (au): 3 changes by krysclarke
russian: 3 changes by Ln-Wolf
finnish: 3 changes by hpiirai
turkish: 4 changes by BeratSJ
french: 3 changes by ottdfevr
portuguese: 3 changes by azulcosta
portuguese (brazilian): 3 changes by pasantoro
english (au): 3 changes by krysclarke
russian: 3 changes by Ln-Wolf
finnish: 3 changes by hpiirai
turkish: 4 changes by BeratSJ
french: 3 changes by ottdfevr
portuguese: 3 changes by azulcosta
portuguese (brazilian): 3 changes by pasantoro
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r8113:7815c26d7612 r18811:79fa62ea3e00 r14248:a9050881acd7 r6937:bea726150bf3 r17617:7646682fc2c9 r6937:bea726150bf3 r6937:bea726150bf3 r27737:728d55b97775 r23497:a0ab44ebd2fa r27737:728d55b97775 r27737:728d55b97775 r27737:728d55b97775 r23497:a0ab44ebd2fa r23497:a0ab44ebd2fa r23497:a0ab44ebd2fa r23497:a0ab44ebd2fa r26711:a4f8e9c41dea r23497:a0ab44ebd2fa r23497:a0ab44ebd2fa r23497:a0ab44ebd2fa r6937:bea726150bf3 r6969:c3926a150708 r6969:c3926a150708 r9551:5cfb47d30fe1 r19212:c8e0af51e6c1 r6969:c3926a150708 r19212:c8e0af51e6c1 r6969:c3926a150708 r6969:c3926a150708 r6969:c3926a150708 r6969:c3926a150708 r6969:c3926a150708 r19212:c8e0af51e6c1 r9597:95581b9351bb r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r9597:95581b9351bb r9597:95581b9351bb r19212:c8e0af51e6c1 r9654:b39d61f22aad r9654:b39d61f22aad r9654:b39d61f22aad r9597:95581b9351bb r9597:95581b9351bb r9597:95581b9351bb r9597:95581b9351bb r9597:95581b9351bb r9597:95581b9351bb r19212:c8e0af51e6c1 r6969:c3926a150708 r7552:47c4bace5157 r19212:c8e0af51e6c1 r7552:47c4bace5157 r9597:95581b9351bb r9597:95581b9351bb r9597:95581b9351bb r9597:95581b9351bb r9597:95581b9351bb r9597:95581b9351bb r19212:c8e0af51e6c1 r9597:95581b9351bb r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r6969:c3926a150708 r9654:b39d61f22aad r6969:c3926a150708 r6969:c3926a150708 r6969:c3926a150708 r9597:95581b9351bb r9597:95581b9351bb r9597:95581b9351bb r19212:c8e0af51e6c1 r6969:c3926a150708 r7552:47c4bace5157 r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r7552:47c4bace5157 r9597:95581b9351bb r6969:c3926a150708 r6969:c3926a150708 r6969:c3926a150708 r11356:ae9277304002 r11356:ae9277304002 r11356:ae9277304002 r11356:ae9277304002 r11356:ae9277304002 r11356:ae9277304002 r19212:c8e0af51e6c1 r6969:c3926a150708 r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r6969:c3926a150708 r19212:c8e0af51e6c1 r6969:c3926a150708 r6969:c3926a150708 r6969:c3926a150708 r21364:fc9d03d2e2b8 r21364:fc9d03d2e2b8 r21364:fc9d03d2e2b8 r21364:fc9d03d2e2b8 r21364:fc9d03d2e2b8 r21364:fc9d03d2e2b8 r27737:728d55b97775 r21364:fc9d03d2e2b8 r21364:fc9d03d2e2b8 r21364:fc9d03d2e2b8 r21364:fc9d03d2e2b8 r21364:fc9d03d2e2b8 r21364:fc9d03d2e2b8 r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r27737:728d55b97775 r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r11356:ae9277304002 r11356:ae9277304002 r11356:ae9277304002 r11356:ae9277304002 r19212:c8e0af51e6c1 r6969:c3926a150708 r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r19212:c8e0af51e6c1 r6969:c3926a150708 r6969:c3926a150708 r11356:ae9277304002 r11356:ae9277304002 r19212:c8e0af51e6c1 r6969:c3926a150708 r19212:c8e0af51e6c1 r6937:bea726150bf3 r18811:79fa62ea3e00 r19670:84be3bfd92b8 r18811:79fa62ea3e00 r27737:728d55b97775 r22870:f3bd5fe2429d r27737:728d55b97775 r18811:79fa62ea3e00 r18811:79fa62ea3e00 r18811:79fa62ea3e00 r18811:79fa62ea3e00 r22870:f3bd5fe2429d r18811:79fa62ea3e00 r24910:137e83ad9c3d r27737:728d55b97775 r24910:137e83ad9c3d r27737:728d55b97775 r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r24910:137e83ad9c3d r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 | /*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file 32bpp_base.hpp Base for all 32 bits blitters. */
#ifndef BLITTER_32BPP_BASE_HPP
#define BLITTER_32BPP_BASE_HPP
#include "base.hpp"
#include "../core/bitmath_func.hpp"
#include "../core/math_func.hpp"
#include "../gfx_func.h"
/** Base for all 32bpp blitters. */
class Blitter_32bppBase : public Blitter {
public:
uint8_t GetScreenDepth() override { return 32; }
void *MoveTo(void *video, int x, int y) override;
void SetPixel(void *video, int x, int y, uint8_t colour) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override;
void DrawRect(void *video, int width, int height, uint8_t colour) override;
void CopyFromBuffer(void *video, const void *src, int width, int height) override;
void CopyToBuffer(const void *video, void *dst, int width, int height) override;
void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override;
void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
size_t BufferSize(uint width, uint height) override;
void PaletteAnimate(const Palette &palette) override;
Blitter::PaletteAnimation UsePaletteAnimation() override;
int GetBytesPerPixel() override { return 4; }
/**
* Look up the colour in the current palette.
*/
static inline Colour LookupColourInPalette(uint index)
{
return _cur_palette.palette[index];
}
/**
* Compose a colour based on RGBA values and the current pixel value.
*/
static inline Colour ComposeColourRGBANoCheck(uint r, uint g, uint b, uint a, Colour current)
{
uint cr = current.r;
uint cg = current.g;
uint cb = current.b;
/* The 256 is wrong, it should be 255, but 256 is much faster... */
return Colour(
((int)(r - cr) * a) / 256 + cr,
((int)(g - cg) * a) / 256 + cg,
((int)(b - cb) * a) / 256 + cb);
}
/**
* 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 Colour ComposeColourRGBA(uint r, uint g, uint b, uint a, Colour current)
{
if (a == 0) return current;
if (a >= 255) return Colour(r, g, b);
return ComposeColourRGBANoCheck(r, g, b, a, current);
}
/**
* Compose a colour based on Pixel value, alpha value, and the current pixel value.
*/
static inline Colour ComposeColourPANoCheck(Colour colour, uint a, Colour current)
{
uint r = colour.r;
uint g = colour.g;
uint b = colour.b;
return ComposeColourRGBANoCheck(r, g, b, a, current);
}
/**
* 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 Colour ComposeColourPA(Colour colour, uint a, Colour current)
{
if (a == 0) return current;
if (a >= 255) {
colour.a = 255;
return colour;
}
return ComposeColourPANoCheck(colour, a, current);
}
/**
* Make a pixel looks like it is transparent.
* @param colour the colour already on the screen.
* @param nom the amount of transparency, nominator, makes colour lighter.
* @param denom denominator, makes colour darker.
* @return the new colour for the screen.
*/
static inline Colour MakeTransparent(Colour colour, uint nom, uint denom = 256)
{
uint r = colour.r;
uint g = colour.g;
uint b = colour.b;
return Colour(r * nom / denom, g * nom / denom, b * nom / denom);
}
/**
* Make a colour dark grey, for specialized 32bpp remapping.
* @param r red component
* @param g green component
* @param b blue component
* @return the brightness value of the new colour, now dark grey.
*/
static inline uint8_t MakeDark(uint8_t r, uint8_t g, uint8_t b)
{
/* Magic-numbers are ~66% of those used in MakeGrey() */
return ((r * 13063) + (g * 25647) + (b * 4981)) / 65536;
}
/**
* Make a colour dark grey, for specialized 32bpp remapping.
* @param colour the colour to make dark.
* @return the new colour, now darker.
*/
static inline Colour MakeDark(Colour colour)
{
uint8_t d = MakeDark(colour.r, colour.g, colour.b);
return Colour(d, d, d);
}
/**
* Make a colour grey - based.
* @param colour the colour to make grey.
* @return the new colour, now grey.
*/
static inline Colour MakeGrey(Colour colour)
{
uint r = colour.r;
uint g = colour.g;
uint b = colour.b;
/* 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. */
uint grey = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
return Colour(grey, grey, grey);
}
static const int DEFAULT_BRIGHTNESS = 128;
static Colour ReallyAdjustBrightness(Colour colour, uint8_t brightness);
static inline Colour AdjustBrightness(Colour colour, uint8_t brightness)
{
/* Shortcut for normal brightness */
if (brightness == DEFAULT_BRIGHTNESS) return colour;
return ReallyAdjustBrightness(colour, brightness);
}
static inline uint8_t GetColourBrightness(Colour colour)
{
uint8_t rgb_max = std::max(colour.r, std::max(colour.g, colour.b));
/* Black pixel (8bpp or old 32bpp image), so use default value */
if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
return rgb_max;
}
};
#endif /* BLITTER_32BPP_BASE_HPP */
|