Conversation
65f1dd7 to
288418a
Compare
288418a to
f6602d4
Compare
There was a problem hiding this comment.
Code looks good to me.
This pattern (uint8_t(CLAMP() is reused in a few other locations in the codebase. Should some of these be changed too?
51 results - 9 files
core/io/image.cpp:
3264 case FORMAT_L8: {
3265: ptr[ofs] = uint8_t(CLAMP(p_color.get_v() * 255.0, 0, 255));
3266 } break;
3267 case FORMAT_LA8: {
3268: ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.get_v() * 255.0, 0, 255));
3269: ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.a * 255.0, 0, 255));
3270 } break;
3271 case FORMAT_R8: {
3272: ptr[ofs] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255));
3273 } break;
3274 case FORMAT_RG8: {
3275: ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255));
3276: ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.g * 255.0, 0, 255));
3277 } break;
3278 case FORMAT_RGB8: {
3279: ptr[ofs * 3 + 0] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255));
3280: ptr[ofs * 3 + 1] = uint8_t(CLAMP(p_color.g * 255.0, 0, 255));
3281: ptr[ofs * 3 + 2] = uint8_t(CLAMP(p_color.b * 255.0, 0, 255));
3282 } break;
3283 case FORMAT_RGBA8: {
3284: ptr[ofs * 4 + 0] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255));
3285: ptr[ofs * 4 + 1] = uint8_t(CLAMP(p_color.g * 255.0, 0, 255));
3286: ptr[ofs * 4 + 2] = uint8_t(CLAMP(p_color.b * 255.0, 0, 255));
3287: ptr[ofs * 4 + 3] = uint8_t(CLAMP(p_color.a * 255.0, 0, 255));
3288 } break;
drivers/gles3/rasterizer_canvas_gles3.cpp:
174 for (int i = 0; i < 4; i++) {
175: state.light_uniforms[index].shadow_color[i] = uint8_t(CLAMP(int32_t(l->shadow_color[i] * 255.0), 0, 255));
176 state.light_uniforms[index].color[i] = l->color[i];
245 for (int i = 0; i < 4; i++) {
246: state.light_uniforms[index].shadow_color[i] = uint8_t(CLAMP(int32_t(l->shadow_color[i] * 255.0), 0, 255));
247 state.light_uniforms[index].color[i] = l->color[i];
scene/3d/lightmap_gi.cpp:
986 for (uint32_t i = 0; i < len; i += 4) {
987: w_albedo[i + 0] = uint8_t(CLAMP(float(r_aa[i + 0]) * (1.0 - float(r_orm[i + 2] / 255.0)), 0, 255));
988: w_albedo[i + 1] = uint8_t(CLAMP(float(r_aa[i + 1]) * (1.0 - float(r_orm[i + 2] / 255.0)), 0, 255));
989: w_albedo[i + 2] = uint8_t(CLAMP(float(r_aa[i + 2]) * (1.0 - float(r_orm[i + 2] / 255.0)), 0, 255));
990 w_albedo[i + 3] = r_aa[i + 3];
scene/3d/sprite_3d.cpp:
217 uint8_t v_color[4] = {
218: uint8_t(CLAMP(color.r * 255.0, 0.0, 255.0)),
219: uint8_t(CLAMP(color.g * 255.0, 0.0, 255.0)),
220: uint8_t(CLAMP(color.b * 255.0, 0.0, 255.0)),
221: uint8_t(CLAMP(color.a * 255.0, 0.0, 255.0))
222 };
scene/resources/gradient_texture.cpp:
122
123: wd8[i * 4 + 0] = uint8_t(CLAMP(color.r * 255.0, 0, 255));
124: wd8[i * 4 + 1] = uint8_t(CLAMP(color.g * 255.0, 0, 255));
125: wd8[i * 4 + 2] = uint8_t(CLAMP(color.b * 255.0, 0, 255));
126: wd8[i * 4 + 3] = uint8_t(CLAMP(color.a * 255.0, 0, 255));
127 }
261
262: wd8[(x + (y * width)) * 4 + 0] = uint8_t(CLAMP(c.r * 255.0, 0, 255));
263: wd8[(x + (y * width)) * 4 + 1] = uint8_t(CLAMP(c.g * 255.0, 0, 255));
264: wd8[(x + (y * width)) * 4 + 2] = uint8_t(CLAMP(c.b * 255.0, 0, 255));
265: wd8[(x + (y * width)) * 4 + 3] = uint8_t(CLAMP(c.a * 255.0, 0, 255));
266 }
scene/resources/immediate_mesh.cpp:
256
257: color8[0] = uint8_t(CLAMP(colors[i].r * 255.0, 0.0, 255.0));
258: color8[1] = uint8_t(CLAMP(colors[i].g * 255.0, 0.0, 255.0));
259: color8[2] = uint8_t(CLAMP(colors[i].b * 255.0, 0.0, 255.0));
260: color8[3] = uint8_t(CLAMP(colors[i].a * 255.0, 0.0, 255.0));
261 }
scene/resources/mesh.cpp:
1220
1221: dst[0] = uint8_t(CLAMP(src[0] * 255.0, 0.0, 255.0));
1222: dst[1] = uint8_t(CLAMP(src[1] * 255.0, 0.0, 255.0));
1223: dst[2] = uint8_t(CLAMP(src[2] * 255.0, 0.0, 255.0));
1224: dst[3] = uint8_t(CLAMP(src[3] * 255.0, 0.0, 255.0));
1225 }
servers/rendering_server.cpp:
133
134: w[(y * TEST_TEXTURE_SIZE + x) * 3 + 0] = uint8_t(CLAMP(c.r, 0, 255));
135: w[(y * TEST_TEXTURE_SIZE + x) * 3 + 1] = uint8_t(CLAMP(c.g, 0, 255));
136: w[(y * TEST_TEXTURE_SIZE + x) * 3 + 2] = uint8_t(CLAMP(c.b, 0, 255));
137 }
712 uint8_t color8[4] = {
713: uint8_t(CLAMP(src[i].r * 255.0, 0.0, 255.0)),
714: uint8_t(CLAMP(src[i].g * 255.0, 0.0, 255.0)),
715: uint8_t(CLAMP(src[i].b * 255.0, 0.0, 255.0)),
716: uint8_t(CLAMP(src[i].a * 255.0, 0.0, 255.0))
717 };
servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp:
550 for (int i = 0; i < 4; i++) {
551: state.light_uniforms[index].shadow_color[i] = uint8_t(CLAMP(int32_t(l->shadow_color[i] * 255.0), 0, 255));
552 state.light_uniforms[index].color[i] = l->color[i];
620 for (int i = 0; i < 4; i++) {
621: state.light_uniforms[index].shadow_color[i] = uint8_t(CLAMP(int32_t(l->shadow_color[i] * 255.0), 0, 255));
622 state.light_uniforms[index].color[i] = l->color[i];
3286
3287: uint8_t a = uint8_t(CLAMP(info.specular_color.a * 255.0, 0.0, 255.0));
3288: uint8_t b = uint8_t(CLAMP(info.specular_color.b * 255.0, 0.0, 255.0));
3289: uint8_t g = uint8_t(CLAMP(info.specular_color.g * 255.0, 0.0, 255.0));
3290: uint8_t r = uint8_t(CLAMP(info.specular_color.r * 255.0, 0.0, 255.0));
3291 p_info->specular_shininess = uint32_t(a) << 24 | uint32_t(b) << 16 | uint32_t(g) << 8 | uint32_t(r);
Yes, the color should likely be rounded everywhere on that list: e.g. it doesn't make sense to pick |
|
Thanks! |
Fixes: #100780
In majority of the cases this doesn't change anything, but if the gradient colors happen to be close you now get the full range without duplicates e.g.:


Master:
This pr:
3px gradient from (11, 0, 11) to (13, 100, 13). The center pixel is now (12, 50, 12) instead of (11, 50, 11). (I know you can't see sh*t, but take a color picker and try yourself).
Rounding is necessary since color values are floats on disk and won't yield the same value when multiplied by 255.0 and floored:
E.g. 11 is represented as
0.04313725.