From c843871ac19f03f262ec9a66339306956e739d88 Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Thu, 25 Mar 2021 02:07:17 -0700 Subject: [PATCH] make Color have a constexpr constructor and add Block class --- quicktex/Block.h | 42 ++++++++++++++++++++++++++++++++++++++++++ quicktex/Color.cpp | 4 ++-- quicktex/Color.h | 4 ++-- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 quicktex/Block.h diff --git a/quicktex/Block.h b/quicktex/Block.h new file mode 100644 index 0000000..8b9cc2c --- /dev/null +++ b/quicktex/Block.h @@ -0,0 +1,42 @@ +/* Python-rgbcx Texture Compression Library + Copyright (C) 2021 Andrew Cassidy + Partially derived from rgbcx.h written by Richard Geldreich + 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 . + */ + +#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 class Block { + static_assert(N > 0); + static_assert(M > 0); + + public: + static constexpr int Width = N; + static constexpr int Height = M; +}; + +} // namespace quicktex \ No newline at end of file diff --git a/quicktex/Color.cpp b/quicktex/Color.cpp index a51ee37..917e3da 100644 --- a/quicktex/Color.cpp +++ b/quicktex/Color.cpp @@ -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]); } diff --git a/quicktex/Color.h b/quicktex/Color.h index f0c9f62..44dcda0 100644 --- a/quicktex/Color.h +++ b/quicktex/Color.h @@ -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);