You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

588 lines
14 KiB
C

//:Header:183, "llgfx_color", 3b940166
//
// File: llgfx_color.h
//
// G A M E.O.N.E - LOW LEVEL LIB V1.0
// Copyright (C) 2001 LEVEL ONE ENTERTAINMENT,
// Licensed under the terms of LGPL.
//:---------------------------------------------------------------------------
//:Description
//
// Color RGB - Hilfsfunktionen und Defines
//
// llgfx_GetDeviceColor(r,g,b)
// Liefert für den aktuellen Bilschirm den Farbwert in
// der richtigen Pixeltiefe.
//
// llgfx_GetRGBColor(pixel)
// Wandelt den Devicecolorwert eines Pixels in einen 24Bit Wert RGB Wert um.
//
// llgfx_GetColorByName(const char *namestring)
// Vergleicht den String clstring mit einem Farbcode und gibt den entsprechenden
// Farbcode laut der Define Liste zurück. Die Farbcode-Strings sind UPPERCASE und
// müssen exakt mit den Defines übereinstimmen, ansonsten wird 0=BLACK zurück
// geliefert.
//
//:-----------------------------------------------------------------------------
#if !defined(LLGFX_COLOR_INCLUDED)
#define LLGFX_COLOR_INCLUDED
//:Include
#include "lib_base.h"
extern int llgfx_pixsize;
extern int llgfx_bitspixel;
#define ALICEBLUE (TxU32)(0x00F0F8FF)
#define ANTIQUEWHITE (TxU32)(0x00FAEBD7)
#define AQUA (TxU32)(0x0000FFFF)
#define AQUAMARINE (TxU32)(0x007FFFD4)
#define AZURE (TxU32)(0x00F0FFFF)
#define BEIGE (TxU32)(0x00F5F5DC)
#define BISQUE (TxU32)(0x00FFE4C4)
#define BLACK (TxU32)(0x00000000)
#define BLANCHEDALMOND (TxU32)(0x00FFEBCD)
#define BLUE (TxU32)(0x000000FF)
#define BLUEVIOLET (TxU32)(0x008A2BE2)
#define BROWN (TxU32)(0x00A52A2A)
#define BURLYWOOD (TxU32)(0x00DEB887)
#define CADETBLUE (TxU32)(0x005F9EA0)
#define CHARTREUSE (TxU32)(0x007FFF00)
#define CHOCOLATE (TxU32)(0x00D2691E)
#define CORAL (TxU32)(0x00FF7F50)
#define CORNFLOWER (TxU32)(0x006495ED)
#define CORNSILK (TxU32)(0x00FFF8DC)
#define CRIMSON (TxU32)(0x00DC143C)
#define CYAN (TxU32)(0x0000FFFF)
#define DARKBLUE (TxU32)(0x0000008B)
#define DARKCYAN (TxU32)(0x00008B8B)
#define DARKGOLDENROD (TxU32)(0x00B8860B)
#define DARKGRAY (TxU32)(0x00A9A9A9)
#define DARKGREEN (TxU32)(0x00006400)
#define DARKKHAKI (TxU32)(0x00BDB76B)
#define DARKMAGENTA (TxU32)(0x008B008B)
#define DARKOLIVEGREEN (TxU32)(0x00556B2F)
#define DARKORANGE (TxU32)(0x00FF8C00)
#define DARKORCHID (TxU32)(0x009932CC)
#define DARKRED (TxU32)(0x008B0000)
#define DARKSALMON (TxU32)(0x00E9967A)
#define DARKSEAGREEN (TxU32)(0x008FBC8B)
#define DARKSLATEBLUE (TxU32)(0x00483D8B)
#define DARKSLATEGRAY (TxU32)(0x002F4F4F)
#define DARKTURQUOISE (TxU32)(0x0000CED1)
#define DARKVIOLET (TxU32)(0x009400D3)
#define DEEPPINK (TxU32)(0x00FF1493)
#define DEEPSKYBLUE (TxU32)(0x0000BFFF)
#define DIMGRAY (TxU32)(0x00696969)
#define DODGERBLUE (TxU32)(0x001E90FF)
#define FIREBRICK (TxU32)(0x00B22222)
#define FLORALWHITE (TxU32)(0x00FFFAF0)
#define FORESTGREEN (TxU32)(0x00228B22)
#define FUCHSIA (TxU32)(0x00FF00FF)
#define GAINSBORO (TxU32)(0x00DCDCDC)
#define GHOSTWHITE (TxU32)(0x00F8F8FF)
#define GOLD (TxU32)(0x00FFD700)
#define GOLDENROD (TxU32)(0x00DAA520)
#define GRAY (TxU32)(0x00808080)
#define GREEN (TxU32)(0x00008000)
#define GREENYELLOW (TxU32)(0x00ADFF2F)
#define HONEYDEW (TxU32)(0x00F0FFF0)
#define HOTPINK (TxU32)(0x00FF69B4)
#define INDIANRED (TxU32)(0x00CD5C5C)
#define INDIGO (TxU32)(0x004B0082)
#define IVORY (TxU32)(0x00FFFFF0)
#define KHAKI (TxU32)(0x00F0E68C)
#define LAVENDER (TxU32)(0x00E6E6FA)
#define LAVENDERBLUSH (TxU32)(0x00FFF0F5)
#define LAWNGREEN (TxU32)(0x007CFC00)
#define LEMONCHIFFON (TxU32)(0x00FFFACD)
#define LIGHTBLUE (TxU32)(0x00ADD8E6)
#define LIGHTCORAL (TxU32)(0x00F08080)
#define LIGHTCYAN (TxU32)(0x00E0FFFF)
#define LIGHTGOLDENRODYELLOW (TxU32)(0x00FAFAD2)
#define LIGHTGREEN (TxU32)(0x0090EE90)
#define LIGHTGREY (TxU32)(0x00D3D3D3)
#define LIGHTMAGENTA (TxU32)(0x00FF90FF)
#define LIGHTPINK (TxU32)(0x00FFB6C1)
#define LIGHTRED (TxU32)(0x00EE9090)
#define LIGHTSALMON (TxU32)(0x00FFA07A)
#define LIGHTSEAGREEN (TxU32)(0x0020B2AA)
#define LIGHTSKYBLUE (TxU32)(0x0087CEFA)
#define LIGHTSLATEGRAY (TxU32)(0x00778899)
#define LIGHTSLATESILVER (TxU32)(0x00AABBCC)
#define LIGHTSTEELBLUE (TxU32)(0x00B0C4DE)
#define LIGHTYELLOW (TxU32)(0x00FFFFE0)
#define LIME (TxU32)(0x0000FF00)
#define LIMEGREEN (TxU32)(0x0032CD32)
#define LINEN (TxU32)(0x00FAF0E6)
#define MAGENTA (TxU32)(0x00FF00FF)
#define MAROON (TxU32)(0x00800000)
#define MEDIUMAQUAMARINE (TxU32)(0x0066CDAA)
#define MEDIUMBLUE (TxU32)(0x000000CD)
#define MEDIUMORCHID (TxU32)(0x00BA55D3)
#define MEDIUMPURPLE (TxU32)(0x009370DB)
#define MEDIUMSEAGREEN (TxU32)(0x003CB371)
#define MEDIUMSLATEBLUE (TxU32)(0x007B68EE)
#define MEDIUMSPRINGGREEN (TxU32)(0x0000FA9A)
#define MEDIUMTURQUOISE (TxU32)(0x0048D1CC)
#define MEDIUMVIOLETRED (TxU32)(0x00C71585)
#define MIDNIGHTBLUE (TxU32)(0x00191970)
#define MINTCREAM (TxU32)(0x00F5FFFA)
#define MISTYROSE (TxU32)(0x00FFE4E1)
#define MOCCASIN (TxU32)(0x00FFE4B5)
#define NAVAJOWHITE (TxU32)(0x00FFDEAD)
#define NAVY (TxU32)(0x00000080)
#define OLDLACE (TxU32)(0x00FDF5E6)
#define OLIVE (TxU32)(0x00808000)
#define OLIVEDRAB (TxU32)(0x006B8E23)
#define ORANGE (TxU32)(0x00FFA500)
#define ORANGERED (TxU32)(0x00FF4500)
#define ORCHID (TxU32)(0x00DA70D6)
#define PALEGOLDENROD (TxU32)(0x00EEE8AA)
#define PALEGREEN (TxU32)(0x0098FB98)
#define PALETURQUOISE (TxU32)(0x00AFEEEE)
#define PALEVIOLETRED (TxU32)(0x00DB7093)
#define PAPAYAWHIP (TxU32)(0x00FFEFD5)
#define PEACHPUFF (TxU32)(0x00FFDAB9)
#define PERU (TxU32)(0x00CD853F)
#define PINK (TxU32)(0x00FFC0CB)
#define PLUM (TxU32)(0x00DDA0DD)
#define POWDERBLUE (TxU32)(0x00B0E0E6)
#define PURPLE (TxU32)(0x00800080)
#define RED (TxU32)(0x00FF0000)
#define ROSYBROWN (TxU32)(0x00BC8F8F)
#define ROYALBLUE (TxU32)(0x004169E1)
#define SADDLEBROWN (TxU32)(0x008B4513)
#define SALMON (TxU32)(0x00FA8072)
#define SANDYBROWN (TxU32)(0x00F4A460)
#define SEAGREEN (TxU32)(0x002E8B57)
#define SEASHELL (TxU32)(0x00FFF5EE)
#define SIENNA (TxU32)(0x00A0522D)
#define SILVER (TxU32)(0x00C0C0C0)
#define SKYBLUE (TxU32)(0x0087CEEB)
#define SLATEBLUE (TxU32)(0x006A5ACD)
#define SLATEGRAY (TxU32)(0x00708090)
#define SNOW (TxU32)(0x00FFFAFA)
#define SPRINGGREEN (TxU32)(0x0000FF7F)
#define STEELBLUE (TxU32)(0x004682B4)
#define TAN (TxU32)(0x00D2B48C)
#define TEAL (TxU32)(0x00008080)
#define THISTLE (TxU32)(0x00D8BFD8)
#define TOMATO (TxU32)(0x00FF6347)
#define TURQUOISE (TxU32)(0x0040E0D0)
#define VIOLET (TxU32)(0x00EE82EE)
#define WHEAT (TxU32)(0x00F5DEB3)
#define WHITE (TxU32)(0x00FFFFFF)
#define WHITESMOKE (TxU32)(0x00F5F5F5)
#define YELLOW (TxU32)(0x00FFFF00)
#define YELLOWGREEN (TxU32)(0x009ACD32)
//:End Custom
//:> +------------------------------------+
//:>-------------------| Global Function Declarations |-------------------
//:> +------------------------------------+
//::2
// +-------------------------+
// | llgfx_Get16BitColor() |
// +-------------------------+
//:Description
//
// Liefert den DeviceColor Wert für ein 16Bit Display,
// für die Parameter R,G,B
//
inline TxU16 llgfx_Get16BitColor(
const TxU32 argb);
//::3
// +------------------------+
// | llgfx_Get8BitColor() |
// +------------------------+
//:Description
//
// Liefert den DeviceColor Wert für ein 8Bit-Display,
// für die Parameter R,G,B
//
inline TxU8 llgfx_Get8BitColor(
const TxU32 argb);
//::1
// +--------------------------+
// | llgfx_GetColorByName() |
// +--------------------------+
//:Description
//
// Vergleicht den String clstring mit einem Farbcode und gibt den entsprechenden
// Farbcode laut der Define Liste zurück. Die Farbcode-Strings sind UPPERCASE und
// müssen exakt mit den Defines übereinstimmen, ansonsten wird 0=BLACK zurück
// geliefert.
//
TxU32 llgfx_GetColorByName(
const char* clstring);
//::4
// +--------------------------+
// | llgfx_GetDeviceColor() |
// +--------------------------+
//:Description
//
// Liefert den DeviceColor Wert für die Parameter R,G,B
//
inline TxU32 llgfx_GetDeviceColor(
TxU8 r,
TxU8 g,
TxU8 b);
//::5
// +--------------------------+
// | llgfx_GetDeviceColor() |
// +--------------------------+
//:Description
//
// Liefert den DeviceColor Wert für den RGB Wert des Parameters argb
//
inline TxU32 llgfx_GetDeviceColor(
const TxU32 argb);
//::6
// +-----------------------+
// | llgfx_GetRGBColor() |
// +-----------------------+
//:Description
//
// Wandelt den Wert des Parameters DeviceColor in ein RGB 24Bit Format.
//
inline TxU32 llgfx_GetRGBColor(
const TxU32 DeviceColor);
//::7
// +------------------------+
// | llgfx_GetRGBValues() |
// +------------------------+
inline void llgfx_GetRGBValues(
TxU32 argb,
float *R, // Zeiger auf float das den Rot Wert erhält
float *G, // Zeiger auf float das den Grün Wert erhält
float *B, // Zeiger auf float das den Blau Wert erhält
float *A); // Zeiger auf float das den Alpha Wert erhält
//::8
// +------------------------+
// | llgfx_GetRGBValues() |
// +------------------------+
inline void llgfx_GetRGBValues(
TxU32 argb,
TxU8 *R,
TxU8 *G,
TxU8 *B,
TxU8 *A);
//:> +-----------------------------------+
//:>-------------------| Global Function Definitions |--------------------
//:> +-----------------------------------+
//::2
// +-------------------------+
// | llgfx_Get16BitColor() |
// +-------------------------+
inline TxU16 llgfx_Get16BitColor(
const TxU32 argb)
{
return (TxU16)
( (argb>>8)&0xf800 )|
( (argb>>5)&0x07e0 )|
( (argb>>3)&0x001f )
;
}
//::2
// +-------------------------+
// | llgfx_Get15BitColor() |
// +-------------------------+
inline TxU16 llgfx_Get15BitColor(
const TxU32 argb)
{
return (TxU16)(
( (argb>>9)&0x7c00 ) |
( (argb>>6)&0x03e0 ) |
( (argb>>3)&0x001f )
);
}
//::3
// +------------------------+
// | llgfx_Get8BitColor() |
// +------------------------+
inline TxU8 llgfx_Get8BitColor(
const TxU32 argb)
{
return TxU8(
((argb>>16)&0xE0)|
((argb>>11)&0x1C)|
((argb>>6)&0x03)
);
}
//::4
// +--------------------------+
// | llgfx_GetDeviceColor() |
// +--------------------------+
inline TxU32 llgfx_GetDeviceColor(
TxU8 r,
TxU8 g,
TxU8 b)
{
switch( llgfx_bitspixel )
{
case 16:
return (TxU32)(
((r<<8)&0xf800) |
((g<<3)&0x07e0) |
((b>>3)&0x001f)
);
break;
case 15:
return (TxU32)(
((r<<7)&0x7C00) |
((g<<2)&0x03e0) |
((b>>3)&0x001f)
);
break;
case 8:
return (TxU32)(
(r&0xE0)|
((g>>3)&0x1C)|
((b>>6)&0x03)
);
break;
default:
//3,4
return (TxU32)(
(r<<16)|
(g<<8)|
(b)
);
break;
}
}
//::5
// +--------------------------+
// | llgfx_GetDeviceColor() |
// +--------------------------+
inline TxU32 llgfx_GetDeviceColor(
const TxU32 argb)
{
switch( llgfx_bitspixel )
{
case 16:
return (TxU16)(
((argb>>8)&0xf800 ) |
((argb>>5)&0x07e0 ) |
((argb>>3)&0x001f )
);
break;
case 15:
return (TxU16)(
((argb>>9)&0xEC00 ) |
((argb>>6)&0x03e0 ) |
((argb>>3)&0x001f )
);
break;
case 8:
return (TxU8)(
((argb>>16)&0xE0) |
((argb>>11)&0x1C) |
((argb>>6)&0x03)
);
break;
default: //3,4
return argb&0xFFFFFF;
break;
}
}
//::6
// +-----------------------+
// | llgfx_GetRGBColor() |
// +-----------------------+
inline TxU32 llgfx_GetRGBColor(
const TxU32 DeviceColor)
{
int rc;
switch( llgfx_bitspixel )
{
case 8:
rc = (
((DeviceColor&0xE0)<<16) |
((DeviceColor&0x1C)<<11) |
((DeviceColor&0x03)<<6)
);
if( DeviceColor & 0x20 ) rc |= 0x1F0000;
if( DeviceColor & 0x04 ) rc |= 0x001f00;
if( DeviceColor & 0x01 ) rc |= 0x00003f;
break;
case 16:
rc = (
((DeviceColor&0xf800)<<8) |
((DeviceColor&0x07e0)<<5) |
((DeviceColor&0x001f)<<3)
);
if( DeviceColor & 0x0800 ) rc |= 0x070000;
if( DeviceColor & 0x0020 ) rc |= 0x000300;
if( DeviceColor & 0x0001 ) rc |= 0x000007;
break;
case 15:
rc = (
((DeviceColor&0x7C00)<<9) |
((DeviceColor&0x03e0)<<6) |
((DeviceColor&0x001f)<<3)
);
if( DeviceColor& 0x0400 ) rc |= 0x070000;
if( DeviceColor& 0x0020 ) rc |= 0x000700;
if( DeviceColor& 0x0001 ) rc |= 0x000007;
break;
default: //3,4
rc = DeviceColor&0xFFFFFF;
break;
}
return rc;
}
//::7
// +------------------------+
// | llgfx_GetRGBValues() |
// +------------------------+
inline void llgfx_GetRGBValues(
TxU32 argb,
float *R, // Zeiger auf float das den Rot Wert erhält
float *G, // Zeiger auf float das den Grün Wert erhält
float *B, // Zeiger auf float das den Blau Wert erhält
float *A) // Zeiger auf float das den Alpha Wert erhält
{
if(A) *A = float((argb>>24)&0xFF);
if(R) *R = float((argb>>16)&0xFF);
if(G) *G = float((argb>>8)&0xFF);
if(B) *B = float((argb)&0xFF);
}
//::8
// +------------------------+
// | llgfx_GetRGBValues() |
// +------------------------+
inline void llgfx_GetRGBValues(
TxU32 argb,
TxU8 *R,
TxU8 *G,
TxU8 *B,
TxU8 *A)
{
if(A) *A = (TxU8)(argb>>24);
if(R) *R = (TxU8)(argb>>16);
if(G) *G = (TxU8)(argb>>8);
if(B) *B = (TxU8)(argb);
}
inline TxU16 llgfx_Get16BitColor(
TxU8 r,
TxU8 g,
TxU8 b)
{
return (TxU16)(
((r<<8)&0xf800) |
((g>>5)&0x07e0) |
((b>>3)&0x001f)
);
}
inline TxU16 llgfx_Get565BitColor(
TxU8 r,
TxU8 g,
TxU8 b)
{
return (TxU16)(
((r<<8)&0xf800) |
((g<<3)&0x07e0) |
((b>>3)&0x001f)
);
}
inline TxU16 llgfx_Get555BitColor(
TxU8 r,
TxU8 g,
TxU8 b)
{
return (TxU16)(
((r<<7)&0x7c00)|
((g<<2)&0x03e0)|
((b>>3)&0x001f)
);
}
inline TxU32 llgfx_Get8BitColor(
TxU8 r,
TxU8 g,
TxU8 b)
{
return (TxU8)(
(r&0xE0) |
((g>>3)&0x1C) |
((b>>6)&0x03)
);
}
inline TxU32 llgfx_Get24BitColor(
TxU8 r,
TxU8 g,
TxU8 b)
{
return (TxU32)(
(r<<16)|
(g<<8)|
(b)
);
}
inline TxU32 llgfx_Get32BitColor(
TxU8 r,
TxU8 g,
TxU8 b)
{
return (TxU32)(
(r<<16)|
(g<<8)|
(b)
);
}
#endif // LLGFX_COLOR_INCLUDED