Flesh out usage of block classes more
parent
e5521796aa
commit
6018ab0cfb
@ -1,6 +1,10 @@
|
|||||||
---
|
---
|
||||||
BasedOnStyle: LLVM
|
BasedOnStyle: google
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
ColumnLimit: 160
|
ColumnLimit: 160
|
||||||
|
AllowShortBlocksOnASingleLine: Always
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AlwaysBreakTemplateDeclarations: MultiLine
|
||||||
|
#AlignConsecutiveDeclarations: true
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -1,21 +1,18 @@
|
|||||||
---
|
FormatStyle: google
|
||||||
FormatStyle: LLVM
|
|
||||||
Checks: 'clang-diagnostic-*,clang-analyzer-*,readability-*'
|
|
||||||
|
|
||||||
|
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,readability-identifier-naming,cppcoreguidelines-narrowing-conversions'
|
||||||
CheckOptions:
|
CheckOptions:
|
||||||
- key: readability-identifier-naming.AbstractClassCase
|
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
|
||||||
value: 'CamelCase'
|
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
|
||||||
- key: readability-identifier-naming.ClassCase
|
- { key: readability-identifier-naming.StructCase, value: CamelCase }
|
||||||
value: 'CamelCase'
|
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
|
||||||
- key: readability-identifier-naming.EnumCase
|
- { key: readability-identifier-naming.FunctionCase, value: aNy_CasE }
|
||||||
value: 'CamelCase'
|
- { key: readability-identifier-naming.VariableCase, value: lower_case }
|
||||||
- key: readability-identifier-naming.StructCase
|
- { key: readability-identifier-naming.MemberCase, value: lower_case }
|
||||||
value: 'CamelCase'
|
- { key: readability-identifier-naming.PrivateMemberPrefix, value: _ }
|
||||||
- key: readability-identifier-naming.TypedefCase
|
- { key: readability-identifier-naming.ProtectedMemberPrefix, value: _ }
|
||||||
value: 'CamelCase'
|
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
|
||||||
- key: readability-identifier-naming.MemberCase
|
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
|
||||||
value: 'CamelCase'
|
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
|
||||||
- key: readability-identifier-naming.FunctionCase
|
- { key: readability-identifier-naming.MemberConstantCase, value: CamelCase }
|
||||||
value: 'camelBack'
|
- { key: readability-identifier-naming.StaticConstantCase, value: CamelCase }
|
||||||
- key: readability-identifier-naming.ClassMethodCase
|
|
||||||
value: 'camelBack'
|
|
@ -0,0 +1,76 @@
|
|||||||
|
/* 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 Affero 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 Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
// region Color32 implementation
|
||||||
|
Color32::Color32() { set(0, 0, 0, 0xFF); }
|
||||||
|
|
||||||
|
Color32::Color32(uint8_t R, uint8_t G, uint8_t B, uint8_t A) { set(R, G, B, A); }
|
||||||
|
|
||||||
|
uint16_t Color32::pack565Unscaled(uint16_t R, uint16_t G, uint16_t B) { return B | (G << 5) | (R << 11); }
|
||||||
|
|
||||||
|
uint16_t Color32::pack565(uint16_t R, uint16_t G, uint16_t B) { return pack565Unscaled(scale8To5(R), scale8To6(G), scale8To5(B)); }
|
||||||
|
|
||||||
|
Color32 Color32::unpack565(uint16_t Packed) {
|
||||||
|
uint8_t R = scale5To8((Packed >> 11) & 0x1F);
|
||||||
|
uint8_t G = scale6To8((Packed >> 5) & 0x3F);
|
||||||
|
uint8_t B = scale5To8(Packed & 0x1F);
|
||||||
|
|
||||||
|
return Color32(R, G, B);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Color32::operator[](uint32_t Index) const {
|
||||||
|
assert(Index < 4);
|
||||||
|
return C[Index];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t &Color32::operator[](uint32_t Index) {
|
||||||
|
assert(Index < 4);
|
||||||
|
return C[Index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Color32::set(uint8_t R, uint8_t G, uint8_t B, uint8_t A) {
|
||||||
|
this->R = R;
|
||||||
|
this->G = G;
|
||||||
|
this->B = B;
|
||||||
|
this->A = A;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Color32::set(const Color32 &Other) {
|
||||||
|
this->R = Other.R;
|
||||||
|
this->G = Other.G;
|
||||||
|
this->B = Other.B;
|
||||||
|
this->A = Other.A;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color32 Color32::min(const Color32 &a, const Color32 &b) {
|
||||||
|
return Color32(std::min(a[0], b[0]), std::min(a[1], b[1]), std::min(a[2], b[2]), std::min(a[3], b[3]));
|
||||||
|
}
|
||||||
|
|
||||||
|
Color32 Color32::max(const Color32 &a, const Color32 &b) {
|
||||||
|
return Color32(std::max(a[0], b[0]), std::max(a[1], b[1]), std::max(a[2], b[2]), std::max(a[3], b[3]));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t Color32::pack565() { return pack565(R, G, B); }
|
||||||
|
|
||||||
|
uint16_t Color32::pack565Unscaled() { return pack565Unscaled(R, G, B); }
|
||||||
|
// endregion
|
@ -0,0 +1,64 @@
|
|||||||
|
/* 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 Affero 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 Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "util.h"
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
class Color32 {
|
||||||
|
public:
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
uint8_t R;
|
||||||
|
uint8_t G;
|
||||||
|
uint8_t B;
|
||||||
|
uint8_t A;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t C[4];
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
static Color32 unpack565(uint16_t Packed);
|
||||||
|
|
||||||
|
bool operator==(const Color32 &Rhs) const { return R == Rhs.R && G == Rhs.G && B == Rhs.B && A == Rhs.A; }
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
void set(const Color32 &Other);
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
Loading…
Reference in New Issue