Skip to content

Commit 7806270

Browse files
committed
archive: fix color parsing
(cherry picked from commit 59249e2)
1 parent f251a9b commit 7806270

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

source/archive/archive_ascii.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ namespace phoenix {
104104
glm::u8vec4 archive_reader_ascii::read_color() {
105105
std::stringstream in {read_entry("color")};
106106

107-
// in ASCII archives colors are saved as BGRA unlike everywhere else.
108107
std::uint16_t r, g, b, a;
109-
in >> b >> g >> r >> a;
108+
in >> r >> g >> b >> a;
110109
return glm::u8vec4 {(std::uint8_t) r, (std::uint8_t) g, (std::uint8_t) b, (std::uint8_t) a};
111110
}
112111

source/archive/archive_binary.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ namespace phoenix {
7171
}
7272

7373
glm::u8vec4 archive_reader_binary::read_color() {
74-
return glm::u8vec4 {input.get(), input.get(), input.get(), input.get()};
74+
auto b = input.get();
75+
auto g = input.get();
76+
auto r = input.get();
77+
auto a = input.get();
78+
79+
return {r, g, b, a};
7580
}
7681

7782
glm::vec3 archive_reader_binary::read_vec3() {

source/archive/archive_binsafe.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ namespace phoenix {
138138

139139
glm::u8vec4 archive_reader_binsafe::read_color() {
140140
ensure_entry_meta(bs_color);
141-
glm::u8vec4 c {
142-
input.get(),
143-
input.get(),
144-
input.get(),
145-
input.get(),
146-
};
147-
return c;
141+
142+
auto b = input.get();
143+
auto g = input.get();
144+
auto r = input.get();
145+
auto a = input.get();
146+
147+
return {r, g, b, a};
148148
}
149149

150150
glm::vec3 archive_reader_binsafe::read_vec3() {

tests/samples/ascii.zen

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ END
2323
someField4=int:32621
2424
someField5=enum:6
2525
someField6=bool:1
26-
someField7=color:255 1 2 3
26+
someField7=color:1 2 3 255
2727
someField8=vec3:50 100.123 -150
2828
someField9=rawFloat:111.11 -12.99
2929
someField10=rawFloat:12 34 56 78 89 0

tests/test_archive.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ TEST_SUITE("archive") {
3535
CHECK(reader->read_bool());
3636

3737
auto color = reader->read_color();
38-
CHECK(color.r == 2);
39-
CHECK(color.b == 255);
40-
CHECK(color.g == 1);
41-
CHECK(color.a == 3);
38+
CHECK(color.r == 1);
39+
CHECK(color.g == 2);
40+
CHECK(color.b == 3);
41+
CHECK(color.a == 255);
4242

4343
auto vec3 = reader->read_vec3();
4444
CHECK(vec3.x == 50);
@@ -104,9 +104,9 @@ TEST_SUITE("archive") {
104104
CHECK(reader->read_byte() == 0);
105105

106106
auto color = reader->read_color();
107-
CHECK(color.r == 0x19);
107+
CHECK(color.r == 0x2A);
108108
CHECK(color.g == 0x23);
109-
CHECK(color.b == 0x2A);
109+
CHECK(color.b == 0x19);
110110
CHECK(color.a == 0xFF);
111111

112112
CHECK(reader->read_float() == 60.0f);

tests/test_material.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ TEST_SUITE("material") {
1717

1818
CHECK(m1.name == "DT_BOOKSHELF_V1_1");
1919
CHECK(m1.group == material_group::undefined);
20-
CHECK(m1.color == glm::u8vec4 {0x19, 0x23, 0x2A, 0xFF});
20+
CHECK(m1.color == glm::u8vec4 {0x2A, 0x23, 0x19, 0xFF});
2121
CHECK(m1.smooth_angle == 60.0f);
2222
CHECK(m1.texture == "MODIBOOKS01.TGA");
2323
CHECK(m1.texture_scale == glm::vec2 {256.0f, 256.0f});
@@ -34,7 +34,7 @@ TEST_SUITE("material") {
3434
auto m2 = material::parse(*archive);
3535
CHECK(m2.name == "DT_BOOKSHELF_V1_2");
3636
CHECK(m2.group == material_group::undefined);
37-
CHECK(m2.color == glm::u8vec4 {0x19, 0x2A, 0x39, 0xFF});
37+
CHECK(m2.color == glm::u8vec4 {0x39, 0x2A, 0x19, 0xFF});
3838
CHECK(m2.smooth_angle == 60.0f);
3939
CHECK(m2.texture == "MOWOPLANKS05.TGA");
4040
CHECK(m2.texture_scale == glm::vec2 {128.0f, 128.0f});
@@ -56,7 +56,7 @@ TEST_SUITE("material") {
5656

5757
CHECK(m1.name == "MATERIAL #356");
5858
CHECK(m1.group == material_group::undefined);
59-
CHECK(m1.color == glm::u8vec4 {0x3B, 0x46, 0x75, 0xFF});
59+
CHECK(m1.color == glm::u8vec4 {0x75, 0x46, 0x3B, 0xFF});
6060
CHECK(m1.smooth_angle == 60.0f);
6161
CHECK(m1.texture == "HUM_EBRM2_ARMOR_V0.TGA");
6262
CHECK(m1.texture_scale == glm::vec2 {512.0f, 512.0f});
@@ -73,7 +73,7 @@ TEST_SUITE("material") {
7373
auto m2 = material::parse(*archive);
7474
CHECK(m2.name == "ERZZB1_TL");
7575
CHECK(m2.group == material_group::undefined);
76-
CHECK(m2.color == glm::u8vec4 {0x17, 0x1A, 0x21, 0xFF});
76+
CHECK(m2.color == glm::u8vec4 {0x21, 0x1A, 0x17, 0xFF});
7777
CHECK(m2.smooth_angle == 60.0f);
7878
CHECK(m2.texture == "HUM_EBRM1_ARMOR_V0.TGA");
7979
CHECK(m2.texture_scale == glm::vec2 {256.0f, 512.0f});

0 commit comments

Comments
 (0)