Skip to content
Snippets Groups Projects
Commit 2d915f2b authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Scaling optimizations

Use weight == 0 instead of int == double when deciding to copy pixel
When interpolating width, do it by column, not row
parent 5cc83981
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4168 passed
...@@ -818,18 +818,20 @@ interpolate_width(uint32_t* src, uint32_t* dst, int width, int height, int newwi ...@@ -818,18 +818,20 @@ interpolate_width(uint32_t* src, uint32_t* dst, int width, int height, int newwi
{ {
int x, y; int x, y;
const double mult = (double)width / newwidth; const double mult = (double)width / newwidth;
uint32_t *s = dst;
for (y = 0; y < height; y++) {
for (x = 0; x < newwidth; x++) { for (x = 0; x < newwidth; x++) {
// First, calculate which two pixels this is between. // First, calculate which two pixels this is between.
const double xpos = mult * x; const double xpos = mult * x;
const int xposi = xpos; const int xposi = xpos;
if (x == xpos) { const uint16_t weight = xpos * 65536;
dst = &s[x];
for (y = 0; y < height; y++) {
if (weight == 0) {
// Exact match! // Exact match!
*dst = src[width * y + x]; *dst = src[width * y + x];
} }
else { else {
const uint16_t weight = xpos * 65536;
// Now pick the two pixels // Now pick the two pixels
const uint32_t pix1 = src[y * width + xposi]; const uint32_t pix1 = src[y * width + xposi];
uint32_t pix2; uint32_t pix2;
...@@ -843,7 +845,7 @@ interpolate_width(uint32_t* src, uint32_t* dst, int width, int height, int newwi ...@@ -843,7 +845,7 @@ interpolate_width(uint32_t* src, uint32_t* dst, int width, int height, int newwi
*dst = blend(pix1, pix2, weight); *dst = blend(pix1, pix2, weight);
} }
} }
dst++; dst += newwidth;
} }
} }
} }
...@@ -886,6 +888,7 @@ interpolate_height(uint32_t* src, uint32_t* dst, int width, int height, int newh ...@@ -886,6 +888,7 @@ interpolate_height(uint32_t* src, uint32_t* dst, int width, int height, int newh
memcpy(nline, src + width, width * sizeof(*tline)); memcpy(nline, src + width, width * sizeof(*tline));
for (y = 0; y < newheight; y++) { for (y = 0; y < newheight; y++) {
const int yposi = ypos; const int yposi = ypos;
const uint16_t weight = ypos * 65536;
if (yposi != last_yposi) { if (yposi != last_yposi) {
ywn += width; ywn += width;
last_yposi = yposi; last_yposi = yposi;
...@@ -894,12 +897,11 @@ interpolate_height(uint32_t* src, uint32_t* dst, int width, int height, int newh ...@@ -894,12 +897,11 @@ interpolate_height(uint32_t* src, uint32_t* dst, int width, int height, int newh
nline = stmp; nline = stmp;
memcpy(nline, &src[ywn], nsz); memcpy(nline, &src[ywn], nsz);
} }
if (y == ypos || yposi >= height - 1) { if (weight == 0 || yposi >= height - 1) {
memcpy(dst, tline, tsz); memcpy(dst, tline, tsz);
dst += width; dst += width;
} }
else { else {
const uint16_t weight = ypos * 65536;
for (x = 0; x < width; x++) { for (x = 0; x < width; x++) {
// Now pick the two pixels // Now pick the two pixels
const uint32_t pix1 = tline[x]; const uint32_t pix1 = tline[x];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment