summaryrefslogtreecommitdiff
path: root/src/video_core/texture/etc1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/texture/etc1.cpp')
-rw-r--r--src/video_core/texture/etc1.cpp122
1 files changed, 0 insertions, 122 deletions
diff --git a/src/video_core/texture/etc1.cpp b/src/video_core/texture/etc1.cpp
deleted file mode 100644
index 43f7f56db..000000000
--- a/src/video_core/texture/etc1.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <array>
6#include "common/bit_field.h"
7#include "common/color.h"
8#include "common/common_types.h"
9#include "common/math_util.h"
10#include "common/vector_math.h"
11#include "video_core/texture/etc1.h"
12
13namespace Pica {
14namespace Texture {
15
16namespace {
17
18constexpr std::array<std::array<u8, 2>, 8> etc1_modifier_table = {{
19 {2, 8}, {5, 17}, {9, 29}, {13, 42}, {18, 60}, {24, 80}, {33, 106}, {47, 183},
20}};
21
22union ETC1Tile {
23 u64 raw;
24
25 // Each of these two is a collection of 16 bits (one per lookup value)
26 BitField<0, 16, u64> table_subindexes;
27 BitField<16, 16, u64> negation_flags;
28
29 unsigned GetTableSubIndex(unsigned index) const {
30 return (table_subindexes >> index) & 1;
31 }
32
33 bool GetNegationFlag(unsigned index) const {
34 return ((negation_flags >> index) & 1) == 1;
35 }
36
37 BitField<32, 1, u64> flip;
38 BitField<33, 1, u64> differential_mode;
39
40 BitField<34, 3, u64> table_index_2;
41 BitField<37, 3, u64> table_index_1;
42
43 union {
44 // delta value + base value
45 BitField<40, 3, s64> db;
46 BitField<43, 5, u64> b;
47
48 BitField<48, 3, s64> dg;
49 BitField<51, 5, u64> g;
50
51 BitField<56, 3, s64> dr;
52 BitField<59, 5, u64> r;
53 } differential;
54
55 union {
56 BitField<40, 4, u64> b2;
57 BitField<44, 4, u64> b1;
58
59 BitField<48, 4, u64> g2;
60 BitField<52, 4, u64> g1;
61
62 BitField<56, 4, u64> r2;
63 BitField<60, 4, u64> r1;
64 } separate;
65
66 const Math::Vec3<u8> GetRGB(unsigned int x, unsigned int y) const {
67 int texel = 4 * x + y;
68
69 if (flip)
70 std::swap(x, y);
71
72 // Lookup base value
73 Math::Vec3<int> ret;
74 if (differential_mode) {
75 ret.r() = static_cast<int>(differential.r);
76 ret.g() = static_cast<int>(differential.g);
77 ret.b() = static_cast<int>(differential.b);
78 if (x >= 2) {
79 ret.r() += static_cast<int>(differential.dr);
80 ret.g() += static_cast<int>(differential.dg);
81 ret.b() += static_cast<int>(differential.db);
82 }
83 ret.r() = Color::Convert5To8(ret.r());
84 ret.g() = Color::Convert5To8(ret.g());
85 ret.b() = Color::Convert5To8(ret.b());
86 } else {
87 if (x < 2) {
88 ret.r() = Color::Convert4To8(static_cast<u8>(separate.r1));
89 ret.g() = Color::Convert4To8(static_cast<u8>(separate.g1));
90 ret.b() = Color::Convert4To8(static_cast<u8>(separate.b1));
91 } else {
92 ret.r() = Color::Convert4To8(static_cast<u8>(separate.r2));
93 ret.g() = Color::Convert4To8(static_cast<u8>(separate.g2));
94 ret.b() = Color::Convert4To8(static_cast<u8>(separate.b2));
95 }
96 }
97
98 // Add modifier
99 unsigned table_index =
100 static_cast<int>((x < 2) ? table_index_1.Value() : table_index_2.Value());
101
102 int modifier = etc1_modifier_table[table_index][GetTableSubIndex(texel)];
103 if (GetNegationFlag(texel))
104 modifier *= -1;
105
106 ret.r() = MathUtil::Clamp(ret.r() + modifier, 0, 255);
107 ret.g() = MathUtil::Clamp(ret.g() + modifier, 0, 255);
108 ret.b() = MathUtil::Clamp(ret.b() + modifier, 0, 255);
109
110 return ret.Cast<u8>();
111 }
112};
113
114} // anonymous namespace
115
116Math::Vec3<u8> SampleETC1Subtile(u64 value, unsigned int x, unsigned int y) {
117 ETC1Tile tile{value};
118 return tile.GetRGB(x, y);
119}
120
121} // namespace Texture
122} // namespace Pica