make Color have a constexpr constructor and add Block class

This commit is contained in:
Andrew Cassidy 2021-03-25 02:07:17 -07:00
parent e5f60ec030
commit c843871ac1
3 changed files with 46 additions and 4 deletions

42
quicktex/Block.h Normal file
View File

@ -0,0 +1,42 @@
/* 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
it under the terms of the GNU Lesser General Public License as published by
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
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
namespace quicktex {
/**
* Base class for all compressed blocks
*
* IMPORTANT: this class cannot contain any virtual methods or the vtable would add to the derived class size,
* it is only to act as a base class for type checking reasons. As such, it has limited utility on its own.
*
* @tparam N Block width in pixels
* @tparam M Block height in pixels
*/
template <int N, int M> class Block {
static_assert(N > 0);
static_assert(M > 0);
public:
static constexpr int Width = N;
static constexpr int Height = M;
};
} // namespace quicktex

View File

@ -26,9 +26,9 @@
namespace quicktex {
Color::Color() { SetRGBA(0, 0, 0, 0xFF); }
constexpr Color::Color() { SetRGBA(0, 0, 0, 0xFF); }
Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { SetRGBA(r, g, b, a); }
constexpr Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { SetRGBA(r, g, b, a); }
Color::Color(Vector4Int v) { SetRGBA((uint8_t)v[0], (uint8_t)v[1], (uint8_t)v[2], (uint8_t)v[3]); }

View File

@ -34,9 +34,9 @@ class Color {
uint8_t b;
uint8_t a;
Color();
constexpr Color();
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF);
constexpr Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF);
Color(Vector4Int v);