Move color structs & functions to own header
To prepare for the map zoom level support
This commit is contained in:
parent
1fbcdc281e
commit
7dc3b48a7c
47
Color.h
Normal file
47
Color.h
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
#ifndef COLOR_H
|
||||
#define COLOR_H
|
||||
|
||||
struct Color {
|
||||
Color(): r(0xFF), g(0xFF), b(0xFF), a(0) {};
|
||||
Color(uint8_t r, uint8_t g, uint8_t b): r(r), g(g), b(b), a(0xFF) {};
|
||||
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a): r(r), g(g), b(b), a(a) {};
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t a;
|
||||
};
|
||||
|
||||
struct ColorEntry {
|
||||
ColorEntry(): r(0), g(0), b(0), a(0), t(0) {};
|
||||
ColorEntry(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t t): r(r), g(g), b(b), a(a), t(t) {};
|
||||
inline Color to_color() const { return Color(r, g, b, a); }
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t a;
|
||||
uint8_t t;
|
||||
};
|
||||
|
||||
inline int rgb2int(uint8_t r, uint8_t g, uint8_t b, uint8_t a=0xFF)
|
||||
{
|
||||
return (a << 24) + (r << 16) + (g << 8) + b;
|
||||
}
|
||||
|
||||
//libgd treats 255 as transparent, and 0 as opaque ...
|
||||
inline int rgb2libgd(uint8_t r, uint8_t g, uint8_t b, uint8_t a=0xFF)
|
||||
{
|
||||
return rgb2int(r, g, b, 0xff-a);
|
||||
}
|
||||
|
||||
inline int color2int(Color c)
|
||||
{
|
||||
return rgb2int(c.r, c.g, c.b, c.a);
|
||||
}
|
||||
|
||||
inline int color2libgd(Color c)
|
||||
{
|
||||
return rgb2libgd(c.r, c.g, c.b, c.a);
|
||||
}
|
||||
|
||||
#endif // COLOR_H
|
@ -54,27 +54,6 @@ static inline uint16_t readU16(const unsigned char *data)
|
||||
return data[0] << 8 | data[1];
|
||||
}
|
||||
|
||||
static inline int rgb2int(uint8_t r, uint8_t g, uint8_t b, uint8_t a=0xFF)
|
||||
{
|
||||
return (a << 24) + (r << 16) + (g << 8) + b;
|
||||
}
|
||||
|
||||
//libgd treats 255 as transparent, and 0 as opaque ...
|
||||
static inline int rgb2libgd(uint8_t r, uint8_t g, uint8_t b, uint8_t a=0xFF)
|
||||
{
|
||||
return rgb2int(r, g, b, 0xff-a);
|
||||
}
|
||||
|
||||
static inline int color2int(Color c)
|
||||
{
|
||||
return rgb2int(c.r, c.g, c.b, c.a);
|
||||
}
|
||||
|
||||
static inline int color2libgd(Color c)
|
||||
{
|
||||
return rgb2libgd(c.r, c.g, c.b, c.a);
|
||||
}
|
||||
|
||||
static inline int readBlockContent(const unsigned char *mapData, int version, int datapos)
|
||||
{
|
||||
if (version >= 24) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include "PixelAttributes.h"
|
||||
#include "Color.h"
|
||||
#include "db.h"
|
||||
|
||||
#define MINETEST_MAPBLOCK_MIN (-2048)
|
||||
@ -27,28 +28,6 @@
|
||||
#define TILECENTER_IS_WORLDCENTER INT_MAX
|
||||
#define TILECENTER_IS_MAPCENTER INT_MIN
|
||||
|
||||
struct Color {
|
||||
Color(): r(0xFF), g(0xFF), b(0xFF), a(0) {};
|
||||
Color(uint8_t r, uint8_t g, uint8_t b): r(r), g(g), b(b), a(0xFF) {};
|
||||
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a): r(r), g(g), b(b), a(a) {};
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t a;
|
||||
};
|
||||
|
||||
struct ColorEntry {
|
||||
ColorEntry(): r(0), g(0), b(0), a(0), t(0) {};
|
||||
ColorEntry(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t t): r(r), g(g), b(b), a(a), t(t) {};
|
||||
inline Color to_color() const { return Color(r, g, b, a); }
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t a;
|
||||
uint8_t t;
|
||||
};
|
||||
|
||||
|
||||
struct BlockPos {
|
||||
int x;
|
||||
int y;
|
||||
|
Loading…
x
Reference in New Issue
Block a user