quicktex/src/color.h

62 lines
1.9 KiB
C
Raw Normal View History

2021-02-06 03:44:19 +00:00
/* Python-rgbcx Texture Compression Library
Copyright (C) 2021 Andrew Cassidy <drewcassidy@me.com>
Partially derived from rgbcx.h written by Richard Geldreich <richgel99@gmail.com>
and licenced under the public domain
This program is free software: you can redistribute it and/or modify
2021-02-07 23:20:03 +00:00
it under the terms of the GNU Lesser General Public License as published by
2021-02-06 03:44:19 +00:00
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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
2021-02-07 23:20:03 +00:00
GNU Lesser General Public License for more details.
2021-02-06 03:44:19 +00:00
2021-02-07 23:20:03 +00:00
You should have received a copy of the GNU Lesser General Public License
2021-02-06 03:44:19 +00:00
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <array>
2021-02-06 03:44:19 +00:00
#include <cstdint>
#pragma pack(push, 1)
class Color32 {
2021-02-06 09:15:23 +00:00
public:
2021-02-06 03:44:19 +00:00
union {
struct {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
2021-02-06 03:44:19 +00:00
};
std::array<uint8_t, 4> c;
2021-02-06 03:44:19 +00:00
};
Color32();
Color32(uint8_t R, uint8_t G, uint8_t B, uint8_t A = 0xFF);
static uint16_t Pack565Unscaled(uint16_t R, uint16_t G, uint16_t B);
static uint16_t Pack565(uint16_t R, uint16_t G, uint16_t B);
2021-02-06 03:44:19 +00:00
static Color32 Unpack565(uint16_t Packed);
2021-02-06 03:44:19 +00:00
bool operator==(const Color32 &Rhs) const { return r == Rhs.r && g == Rhs.g && b == Rhs.b && a == Rhs.a; }
2021-02-06 03:44:19 +00:00
uint8_t operator[](uint32_t Index) const;
uint8_t &operator[](uint32_t Index);
uint16_t pack565();
uint16_t pack565Unscaled();
static Color32 min(const Color32 &A, const Color32 &B);
static Color32 max(const Color32 &A, const Color32 &B);
void Set(uint8_t R, uint8_t G, uint8_t B, uint8_t A);
2021-02-06 03:44:19 +00:00
void Set(const Color32 &Other);
2021-02-06 03:44:19 +00:00
};
#pragma pack(pop)