Cleanup: remove redundant imbuf return values
Some functions always returned the input argument which was never used. This made code read as if there might be a leak. Now return a boolean (true the imbuf is modified).
This commit is contained in:
@@ -380,13 +380,13 @@ struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1);
|
||||
*
|
||||
* \attention Defined in scaling.c
|
||||
*/
|
||||
struct ImBuf *IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy);
|
||||
bool IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy);
|
||||
|
||||
/**
|
||||
*
|
||||
* \attention Defined in scaling.c
|
||||
*/
|
||||
struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy);
|
||||
bool IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy);
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -399,7 +399,7 @@ void IMB_scaleImBuf_threaded(struct ImBuf *ibuf, unsigned int newx, unsigned int
|
||||
* \attention Defined in writeimage.c
|
||||
*/
|
||||
short IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags);
|
||||
struct ImBuf *IMB_prepare_write_ImBuf(const bool isfloat, struct ImBuf *ibuf);
|
||||
bool IMB_prepare_write_ImBuf(const bool isfloat, struct ImBuf *ibuf);
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -1550,12 +1550,17 @@ static void scalefast_Z_ImBuf(ImBuf *ibuf, int newx, int newy)
|
||||
}
|
||||
}
|
||||
|
||||
struct ImBuf *IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
|
||||
/**
|
||||
* Return true if \a ibuf is modified.
|
||||
*/
|
||||
bool IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
|
||||
{
|
||||
if (ibuf == NULL) return (NULL);
|
||||
if (ibuf->rect == NULL && ibuf->rect_float == NULL) return (ibuf);
|
||||
if (ibuf == NULL) return false;
|
||||
if (ibuf->rect == NULL && ibuf->rect_float == NULL) return false;
|
||||
|
||||
if (newx == ibuf->x && newy == ibuf->y) { return ibuf; }
|
||||
if (newx == ibuf->x && newy == ibuf->y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* scaleup / scaledown functions below change ibuf->x and ibuf->y
|
||||
* so we first scale the Z-buffer (if any) */
|
||||
@@ -1564,7 +1569,7 @@ struct ImBuf *IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int
|
||||
/* try to scale common cases in a fast way */
|
||||
/* disabled, quality loss is unacceptable, see report #18609 (ton) */
|
||||
if (0 && q_scale_linear_interpolation(ibuf, newx, newy)) {
|
||||
return ibuf;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (newx && (newx < ibuf->x)) scaledownx(ibuf, newx);
|
||||
@@ -1572,14 +1577,17 @@ struct ImBuf *IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int
|
||||
if (newx && (newx > ibuf->x)) scaleupx(ibuf, newx);
|
||||
if (newy && (newy > ibuf->y)) scaleupy(ibuf, newy);
|
||||
|
||||
return(ibuf);
|
||||
return true;
|
||||
}
|
||||
|
||||
struct imbufRGBA {
|
||||
float r, g, b, a;
|
||||
};
|
||||
|
||||
struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
|
||||
/**
|
||||
* Return true if \a ibuf is modified.
|
||||
*/
|
||||
bool IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
|
||||
{
|
||||
unsigned int *rect, *_newrect, *newrect;
|
||||
struct imbufRGBA *rectf, *_newrectf, *newrectf;
|
||||
@@ -1590,16 +1598,16 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned
|
||||
rect = NULL; _newrect = NULL; newrect = NULL;
|
||||
rectf = NULL; _newrectf = NULL; newrectf = NULL;
|
||||
|
||||
if (ibuf == NULL) return(NULL);
|
||||
if (ibuf == NULL) return false;
|
||||
if (ibuf->rect) do_rect = true;
|
||||
if (ibuf->rect_float) do_float = true;
|
||||
if (do_rect == false && do_float == false) return(ibuf);
|
||||
if (do_rect == false && do_float == false) return false;
|
||||
|
||||
if (newx == ibuf->x && newy == ibuf->y) return(ibuf);
|
||||
if (newx == ibuf->x && newy == ibuf->y) return false;
|
||||
|
||||
if (do_rect) {
|
||||
_newrect = MEM_mallocN(newx * newy * sizeof(int), "scalefastimbuf");
|
||||
if (_newrect == NULL) return(ibuf);
|
||||
if (_newrect == NULL) return false;
|
||||
newrect = _newrect;
|
||||
}
|
||||
|
||||
@@ -1607,7 +1615,7 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned
|
||||
_newrectf = MEM_mallocN(newx * newy * sizeof(float) * 4, "scalefastimbuf f");
|
||||
if (_newrectf == NULL) {
|
||||
if (_newrect) MEM_freeN(_newrect);
|
||||
return(ibuf);
|
||||
return false;
|
||||
}
|
||||
newrectf = _newrectf;
|
||||
}
|
||||
@@ -1643,18 +1651,18 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned
|
||||
ibuf->mall |= IB_rect;
|
||||
ibuf->rect = _newrect;
|
||||
}
|
||||
|
||||
|
||||
if (do_float) {
|
||||
imb_freerectfloatImBuf(ibuf);
|
||||
ibuf->mall |= IB_rectfloat;
|
||||
ibuf->rect_float = (float *)_newrectf;
|
||||
}
|
||||
|
||||
|
||||
scalefast_Z_ImBuf(ibuf, newx, newy);
|
||||
|
||||
|
||||
ibuf->x = newx;
|
||||
ibuf->y = newy;
|
||||
return(ibuf);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ******** threaded scaling ******** */
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include "IMB_colormanagement.h"
|
||||
#include "IMB_colormanagement_intern.h"
|
||||
|
||||
static ImBuf *prepare_write_imbuf(const ImFileType *type, ImBuf *ibuf)
|
||||
static bool prepare_write_imbuf(const ImFileType *type, ImBuf *ibuf)
|
||||
{
|
||||
return IMB_prepare_write_ImBuf((type->flag & IM_FTYPE_FLOAT), ibuf);
|
||||
}
|
||||
@@ -64,15 +64,11 @@ short IMB_saveiff(struct ImBuf *ibuf, const char *name, int flags)
|
||||
|
||||
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
|
||||
if (type->save && type->ftype(type, ibuf)) {
|
||||
ImBuf *write_ibuf;
|
||||
short result = false;
|
||||
|
||||
write_ibuf = prepare_write_imbuf(type, ibuf);
|
||||
prepare_write_imbuf(type, ibuf);
|
||||
|
||||
result = type->save(write_ibuf, name, flags);
|
||||
|
||||
if (write_ibuf != ibuf)
|
||||
IMB_freeImBuf(write_ibuf);
|
||||
result = type->save(ibuf, name, flags);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -83,9 +79,9 @@ short IMB_saveiff(struct ImBuf *ibuf, const char *name, int flags)
|
||||
return false;
|
||||
}
|
||||
|
||||
ImBuf *IMB_prepare_write_ImBuf(const bool isfloat, ImBuf *ibuf)
|
||||
bool IMB_prepare_write_ImBuf(const bool isfloat, ImBuf *ibuf)
|
||||
{
|
||||
ImBuf *write_ibuf = ibuf;
|
||||
bool changed = false;
|
||||
|
||||
if (isfloat) {
|
||||
/* pass */
|
||||
@@ -94,8 +90,11 @@ ImBuf *IMB_prepare_write_ImBuf(const bool isfloat, ImBuf *ibuf)
|
||||
if (ibuf->rect == NULL && ibuf->rect_float) {
|
||||
ibuf->rect_colorspace = colormanage_colorspace_get_roled(COLOR_ROLE_DEFAULT_BYTE);
|
||||
IMB_rect_from_float(ibuf);
|
||||
if (ibuf->rect != NULL) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return write_ibuf;
|
||||
return changed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user