Files @ r17613:a9b2554a5d79
Branch filter:

Location: cpp/openttd-patchpack/source/src/blitter/32bpp_base.hpp - annotation

rubidium
(svn r22387) -Fix-ish [FS#4601]: Windows' recv seems to return "graceful closed" before having passed the remaining buffer which causes OpenTTD to think all connections are "incorrectly" terminated, i.e. without the "I'm leaving" packet from the client. So let the client wait a tiny bit after sending the "I'm leaving" packet and before gracefully closing the connection
r6937:bea726150bf3
r6937:bea726150bf3
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
r14248:a9050881acd7
r6937:bea726150bf3
r6937:bea726150bf3
r6937:bea726150bf3
r6937:bea726150bf3
r6937:bea726150bf3
r14310:91a5cd71c4e6
r17035:6216511eba9e
r6937:bea726150bf3
r11085:c87a330fb4c2
r11085:c87a330fb4c2
r6985:c27a9a2405aa
r6985:c27a9a2405aa
r6985:c27a9a2405aa
r6951:4f69e3e27c06
r6937:bea726150bf3
r6960:e903748e34e4
r6960:e903748e34e4
r9925:d94f8fd81eb5
r6937:bea726150bf3
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r9597:95581b9351bb
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r9551:5cfb47d30fe1
r9551:5cfb47d30fe1
r6969:c3926a150708
r12204:a49bd04a557a
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9654:b39d61f22aad
r9654:b39d61f22aad
r9654:b39d61f22aad
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r6969:c3926a150708
r7552:47c4bace5157
r7552:47c4bace5157
r7552:47c4bace5157
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r6969:c3926a150708
r9654:b39d61f22aad
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r6969:c3926a150708
r7552:47c4bace5157
r7552:47c4bace5157
r7552:47c4bace5157
r9597:95581b9351bb
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r11356:ae9277304002
r11356:ae9277304002
r11356:ae9277304002
r11356:ae9277304002
r11356:ae9277304002
r11356:ae9277304002
r9598:e6a0e60714ce
r6969:c3926a150708
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r6969:c3926a150708
r9598:e6a0e60714ce
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r11356:ae9277304002
r11356:ae9277304002
r11356:ae9277304002
r11356:ae9277304002
r9597:95581b9351bb
r6969:c3926a150708
r9597:95581b9351bb
r9597:95581b9351bb
r9597:95581b9351bb
r6969:c3926a150708
r6969:c3926a150708
r11356:ae9277304002
r11356:ae9277304002
r6969:c3926a150708
r6969:c3926a150708
r6969:c3926a150708
r6937:bea726150bf3
r6937:bea726150bf3
r6937:bea726150bf3
r6937:bea726150bf3
/* $Id$ */

/*
 * 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 "../gfx_func.h"

class Blitter_32bppBase : public Blitter {
public:
	/* virtual */ uint8 GetScreenDepth() { return 32; }
//	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
//	/* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal);
//	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
	/* virtual */ void *MoveTo(const void *video, int x, int y);
	/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour);
	/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);
	/* 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);
	/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
	/* virtual */ int BufferSize(int width, int height);
	/* virtual */ void PaletteAnimate(uint start, uint count);
	/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
	/* virtual */ int GetBytesPerPixel() { return 4; }

	/**
	 * Compose a colour based on RGB values.
	 */
	static inline uint32 ComposeColour(uint a, uint r, uint g, uint b)
	{
		return (((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF);
	}

	/**
	 * Look up the colour in the current palette.
	 */
	static inline uint32 LookupColourInPalette(uint index)
	{
		return _cur_palette[index].data;
	}

	/**
	 * Compose a colour based on RGBA values and the current pixel value.
	 */
	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,
							((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 uint32 ComposeColourRGBA(uint r, uint g, uint b, uint a, uint32 current)
	{
		if (a == 0) return current;
		if (a >= 255) return ComposeColour(0xFF, 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 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);

		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 uint32 ComposeColourPA(uint32 colour, uint a, uint32 current)
	{
		if (a == 0) return current;
		if (a >= 255) return (colour | 0xFF000000);

		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 uint32 MakeTransparent(uint32 colour, uint nom, uint denom = 256)
	{
		uint r = GB(colour, 16, 8);
		uint g = GB(colour, 8,  8);
		uint b = GB(colour, 0,  8);

		return ComposeColour(0xFF, r * nom / denom, g * nom / denom, b * nom / denom);
	}

	/**
	 * Make a colour grey - based.
	 * @param colour the colour to make grey.
	 * @return the new colour, now grey.
	 */
	static inline uint32 MakeGrey(uint32 colour)
	{
		uint r = GB(colour, 16, 8);
		uint g = GB(colour, 8,  8);
		uint b = GB(colour, 0,  8);

		/* 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);
	}
};

#endif /* BLITTER_32BPP_BASE_HPP */