MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / GetAverageColor

Function GetAverageColor

Source/Graphics/textures.cpp:73–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71using namespace PhoenixTextures;
72
73vec4 GetAverageColor(const char* abs_path) {
74 TextureData texture_data;
75 texture_data.Load(abs_path);
76
77 unsigned total_pixels = texture_data.GetWidth() *
78 texture_data.GetHeight();
79 unsigned total_bytes = total_pixels * 32 / 8;
80
81 float total_color[4] = {0};
82
83 std::vector<unsigned char> img_data;
84 img_data.resize(total_bytes);
85 texture_data.GetUncompressedData(&img_data[0]);
86 for (unsigned j = 0; j < total_bytes; j += 4) {
87 total_color[0] += img_data[j + 0];
88 total_color[1] += img_data[j + 1];
89 total_color[2] += img_data[j + 2];
90 total_color[3] += img_data[j + 3];
91 }
92
93 vec4 average_color;
94 average_color[0] = total_color[0] / total_pixels;
95 average_color[1] = total_color[1] / total_pixels;
96 average_color[2] = total_color[2] / total_pixels;
97 average_color[3] = total_color[3] / total_pixels;
98
99 return average_color;
100}
101
102bool IsCompressedGLFormat(GLenum format) {
103 switch (format) {

Callers 1

LoadMethod · 0.85

Calls 5

GetUncompressedDataMethod · 0.80
LoadMethod · 0.45
GetWidthMethod · 0.45
GetHeightMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected