Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello I just need help simplifying this C code and making it run faster, please note where u make these changes, thank you.#include typedef struct
Hello I just need help simplifying this C code and making it run faster, please note where u make these changes, thank you.#include
typedef struct
uintt pixels;
unsigned int w;
unsigned int h;
imaget;
#define getBytevalue nvalue n & xFF
uintt getpixelimaget image unsigned int x unsigned int y
return imagepixelsyimagewx;
float maxfloat a float b return a b a : b; ;
float lerpfloat s float e float treturn sest;
float blerpfloat c float c float c float c float tx float ty
return lerplerpc c tx lerpc c tx ty;
void putpixelimaget image unsigned int x unsigned int y uintt color
imagepixelsyimagew x color;
void scaleimaget src imaget dst float scalex, float scaley
int newWidth intsrcwscalex;
int newHeightintsrchscaley;
int x y;
forx y; y newHeight; x
ifx newWidth
x ; y;
float gx x floatnewWidthsrcw ;
float gy y floatnewHeightsrch ;
Image should be clamped at the edges and not scaled.
float gx maxx floatnewWidthsrcwf srcw ;
float gy maxy floatnewHeightsrch srch ;
int gxi intgx;
int gyi intgy;
uintt result;
uintt c getpixelsrc gxi, gyi;
uintt c getpixelsrc gxi gyi;
uintt c getpixelsrc gxi, gyi;
uintt c getpixelsrc gxi gyi;
uintt i;
fori ; i ; i
uintt&resulti blerpuintt&ciuintt&ciuintt&ciuintt&ci gxi gx gyi gy; this is shady
result uinttblerpgetBytec i getBytec i getBytec i getBytec i gx gxi, gy gyii;
putpixeldstx y result;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started