Fix white crest contrast on Silver surfaces (by Codex)
This commit is contained in:
1 parent
d615f03e15
commit
4b6c18f654
7 files changed
+176
-2
No files matched your search
@@ -6,6 +6,7 @@
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include "modern/ui/gui_assets.hpp"
|
||||
#include "modern/ui/model.hpp"
|
||||
#include "modern/ui/crest_contrast.hpp"
|
||||
#include "modern/ui/demo_environment.hpp"
|
||||
#include "modern/ui/demo_advertising.hpp"
|
||||
#include "modern/ui/demo_toto.hpp"
|
||||
@@ -13,6 +14,7 @@
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
#include "modern/ui/demo_stadium.hpp"
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
@@ -23,6 +25,61 @@ void require(bool value, const char *message) {
|
||||
if (!value)
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
void check_crest_contrast() {
|
||||
using bmh::editor::images::Raster;
|
||||
Raster source{16, 16, std::vector<uint8_t>(16 * 16 * 4)};
|
||||
const auto pixel = [](Raster &r, int x, int y, std::array<uint8_t,4> rgba) {
|
||||
std::copy(rgba.begin(), rgba.end(), r.pixels.begin() + (y * r.width + x) * 4);
|
||||
};
|
||||
for (int y = 3; y < 13; ++y)
|
||||
for (int x = 4; x < 12; ++x) pixel(source,x,y,{255,255,255,255});
|
||||
pixel(source,4,3,{224,224,224,96}); // antialiased edge
|
||||
pixel(source,5,3,{100,100,100,64}); // embossed shadow
|
||||
pixel(source,0,0,{213,29,91,0}); // invisible RGB is irrelevant
|
||||
const auto original = source;
|
||||
const auto variant = crest_for_light_surface(source);
|
||||
require(variant && variant->width == source.width && variant->height == source.height,
|
||||
"Light crest variant changed bounds or lost a shaded white crest");
|
||||
require(source.pixels == original.pixels, "Crest display variant mutated source bytes");
|
||||
for (size_t i = 0; i < source.pixels.size(); i += 4) {
|
||||
require(variant->pixels[i+3] == source.pixels[i+3], "Crest variant changed alpha coverage");
|
||||
if (!source.pixels[i+3])
|
||||
for (int c = 0; c < 3; ++c)
|
||||
require(variant->pixels[i+c] == source.pixels[i+c], "Invisible source RGB changed");
|
||||
}
|
||||
const auto luma = [](const Raster &r, size_t i) {
|
||||
double out = 0; const std::array<double,3> weights{.2126,.7152,.0722};
|
||||
for (size_t c = 0; c < 3; ++c) { const double v = r.pixels[i+c]/255.; out += weights[c]*(v<=.04045?v/12.92:std::pow((v+.055)/1.055,2.4)); }
|
||||
return out;
|
||||
};
|
||||
const size_t center = (8*16+8)*4;
|
||||
require((.8+.05)/(luma(*variant,center)+.05) > 7,
|
||||
"White crest is still illegible on a light menu surface");
|
||||
require(luma(*variant,(3*16+5)*4) < luma(*variant,center), "Crest shading was flattened");
|
||||
|
||||
auto coloured=source;pixel(coloured,8,8,{255,30,20,255});
|
||||
require(!crest_for_light_surface(coloured), "Coloured crest details were recoloured");
|
||||
auto black_white=source;
|
||||
for (int x=4;x<12;++x) pixel(black_white,x,8,{0,0,0,255});
|
||||
require(!crest_for_light_surface(black_white), "Black/white club crest was recoloured");
|
||||
Raster tiny_black_detail{32,32,std::vector<uint8_t>(32*32*4)};
|
||||
for(int y=4;y<28;++y)for(int x=4;x<28;++x)pixel(tiny_black_detail,x,y,{255,255,255,255});
|
||||
pixel(tiny_black_detail,16,16,{0,0,0,255});
|
||||
require(!crest_for_light_surface(tiny_black_detail), "Small black brand detail was recoloured");
|
||||
auto blue=source;
|
||||
for(size_t i=0;i<blue.pixels.size();i+=4)if(blue.pixels[i+3]) {blue.pixels[i]=220;blue.pixels[i+1]=240;blue.pixels[i+2]=255;}
|
||||
require(!crest_for_light_surface(blue), "Pale coloured crest was recoloured");
|
||||
Raster opaque{16,16,std::vector<uint8_t>(16*16*4,255)};
|
||||
require(!crest_for_light_surface(opaque), "White rectangular artwork was recoloured");
|
||||
pixel(opaque,0,0,{0,0,0,0});
|
||||
require(!crest_for_light_surface(opaque), "Tiny transparent corner made a white backdrop qualify");
|
||||
Raster empty{16,16,std::vector<uint8_t>(16*16*4,0)};
|
||||
require(!crest_for_light_surface(empty) && !crest_for_light_surface(*variant),
|
||||
"Empty/dark crest was recoloured");
|
||||
require(!crest_for_light_surface(Raster{0,16,{}}) &&
|
||||
!crest_for_light_surface(Raster{16,16,{255,255,255,255}}),
|
||||
"Malformed raster bounds were accepted");
|
||||
}
|
||||
void write(const fs::path &root, const std::string &file, const Json &value) {
|
||||
fs::create_directories((root / file).parent_path());
|
||||
bmh::editor::write_atomic(root / file, value.dump());
|
||||
@@ -327,6 +384,7 @@ void check_finance_source(const fs::path &root,
|
||||
}
|
||||
} // namespace
|
||||
int main(int argc, char **argv) try {
|
||||
check_crest_contrast();
|
||||
if (argc == 2) {
|
||||
auto catalog = Catalog::open(bmh::editor::path(argv[1]));
|
||||
const auto before = catalog->summary();
|
||||
|
||||
Reference in new issue
Block a user