diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-04-28 14:18:54 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-04-28 16:29:33 -0700 |
commit | fd9a7050e9afba9da061b5a9ca83c95a36eba44a (patch) | |
tree | 94323f64220c4f95717fd20b5630a962c77661db /src/modules | |
parent | 40897672efd931e0094c42db9c5f931da795f84f (diff) |
libs/din: minor optimization
compute scaled x/y coordinates less often by reusing them
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/swab/swab.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/modules/swab/swab.c b/src/modules/swab/swab.c index 7d7c440..6a0d81d 100644 --- a/src/modules/swab/swab.c +++ b/src/modules/swab/swab.c @@ -122,16 +122,19 @@ static void swab_render_fragment(void *context, unsigned ticks, unsigned cpu, ti float yscale = 1.f / (float)fragment->frame_height; for (int y = fragment->y; y < fragment->y + fragment->height; y++) { + float yscaled = (float)y * yscale; + for (int x = fragment->x; x < fragment->x + fragment->width; x++) { + float xscaled = (float)x * xscale; color_t color; uint32_t pixel; float t; - t = din(ctxt->din, &(v3f_t){ .x = (float)x * xscale * .5f, .y = (float)y * yscale * .5f, .z = -z2 }) * 33.f; + t = din(ctxt->din, &(v3f_t){ .x = xscaled * .5f, .y = yscaled * .5f, .z = -z2 }) * 33.f; - color.r = din(ctxt->din, &(v3f_t){ .x = (float)x * xscale * .7f, .y = (float)y * yscale * .7f, .z = z1 }) * t; - color.g = din(ctxt->din, &(v3f_t){ .x = (float)x * xscale * .93f, .y = (float)y * yscale * .93f, .z = -z1 }) * t; - color.b = din(ctxt->din, &(v3f_t){ .x = (float)x * xscale * .81f, .y = (float)y * yscale * .81f, .z = z2 }) * t; + color.r = din(ctxt->din, &(v3f_t){ .x = xscaled * .7f, .y = yscaled * .7f, .z = z1 }) * t; + color.g = din(ctxt->din, &(v3f_t){ .x = xscaled * .93f, .y = yscaled * .93f, .z = -z1 }) * t; + color.b = din(ctxt->din, &(v3f_t){ .x = xscaled * .81f, .y = yscaled * .81f, .z = z2 }) * t; pixel = color_to_uint32(color); til_fb_fragment_put_pixel_unchecked(fragment, x, y, pixel); |