Skip to content

Commit

Permalink
Refactor oslScaleImageCreate function for improved readability and ef…
Browse files Browse the repository at this point in the history
…ficiency

- Implement early returns to reduce nesting and enhance code clarity.
- Remove redundant NULL checks after oslCreateImage.
- Simplify the flow of operations, ensuring consistent error handling.
  • Loading branch information
dogo committed Sep 2, 2024
1 parent 82bfc18 commit 37acd6d
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/image/oslScaleImage.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
**
*/


#define RGBA_GETR(pixel) ((pixel)&0xff)
#define RGBA_GETG(pixel) (((pixel)>>8)&0xff)
#define RGBA_GETB(pixel) (((pixel)>>16)&0xff)
Expand Down Expand Up @@ -125,11 +124,6 @@ static void horizontalScale(const float rs[], const float gs[], const float bs[]
}
}

// if (newcol < newcols-1 || newcol > newcols)
// pm_error("Internal error: last column filled is %d, but %d "
// "is the rightmost output column.",
// newcol, newcols-1);

if (newcol < newcols ) {
/* We were still working on the last output column when we
ran out of input columns. This would be because of rounding
Expand Down Expand Up @@ -245,15 +239,22 @@ void oslScaleImage(OSL_IMAGE *dstImg, OSL_IMAGE *srcImg, int newX, int newY, int

OSL_IMAGE *oslScaleImageCreate(OSL_IMAGE *img, short newLocation, int newWidth, int newHeight, short newPixelFormat)
{
OSL_IMAGE* newImg;
if(!img)
return NULL;
newImg = oslCreateImage(newWidth, newHeight, newLocation, newPixelFormat);
if (newImg) {
oslScaleImage(newImg, img, 0, 0, newWidth, newHeight);
if (newImg != NULL && oslImageLocationIsSwizzled(newLocation))
oslSwizzleImage(newImg);
oslUncacheImage(newImg);
}
return newImg;
if (!img) {
return NULL;
}

OSL_IMAGE *newImg = oslCreateImage(newWidth, newHeight, newLocation, newPixelFormat);
if (!newImg) {
return NULL;
}

oslScaleImage(newImg, img, 0, 0, newWidth, newHeight);

if (oslImageLocationIsSwizzled(newLocation)) {
oslSwizzleImage(newImg);
}

oslUncacheImage(newImg);

return newImg;
}

0 comments on commit 37acd6d

Please sign in to comment.