Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/intern/bmp.c6
-rw-r--r--source/blender/imbuf/intern/filter.c4
-rw-r--r--source/blender/imbuf/intern/imageprocess.c9
-rw-r--r--source/blender/imbuf/intern/scaling.c26
4 files changed, 26 insertions, 19 deletions
diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c
index 31f8b651eff..f517a3c15e8 100644
--- a/source/blender/imbuf/intern/bmp.c
+++ b/source/blender/imbuf/intern/bmp.c
@@ -21,6 +21,8 @@
* \ingroup imbuf
*/
+#include <math.h>
+
#include "BLI_fileops.h"
#include "BLI_utildefines.h"
@@ -327,8 +329,8 @@ int imb_savebmp(ImBuf *ibuf, const char *name, int UNUSED(flags))
putShortLSB(is_grayscale ? 8 : 24, ofile);
putIntLSB(0, ofile);
putIntLSB(bytesize, ofile);
- putIntLSB((int)(ibuf->ppm[0] + 0.5), ofile);
- putIntLSB((int)(ibuf->ppm[1] + 0.5), ofile);
+ putIntLSB(round(ibuf->ppm[0] + 0.5), ofile);
+ putIntLSB(round(ibuf->ppm[1] + 0.5), ofile);
putIntLSB(0, ofile);
putIntLSB(0, ofile);
diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c
index 12f90f27309..cce264624ce 100644
--- a/source/blender/imbuf/intern/filter.c
+++ b/source/blender/imbuf/intern/filter.c
@@ -22,6 +22,8 @@
* \ingroup imbuf
*/
+#include <math.h>
+
#include "MEM_guardedalloc.h"
#include "BLI_math_base.h"
@@ -527,7 +529,7 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter)
else {
for (c = 0; c < depth; c++) {
((unsigned char *)dstbuf)[depth * index + c] =
- acc[c] > 255 ? 255 : (acc[c] < 0 ? 0 : ((unsigned char)(acc[c] + 0.5f)));
+ acc[c] > 255 ? 255 : (acc[c] < 0 ? 0 : (unsigned char)roundf(acc[c]));
}
}
diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c
index bf58f047773..8525991aa40 100644
--- a/source/blender/imbuf/intern/imageprocess.c
+++ b/source/blender/imbuf/intern/imageprocess.c
@@ -27,6 +27,7 @@
* but we'll keep it here for the time being. (nzc)
*/
+#include <math.h>
#include <stdlib.h>
#include "MEM_guardedalloc.h"
@@ -202,10 +203,10 @@ void bilinear_interpolation_color_wrap(
/* need to add 0.5 to avoid rounding down (causes darken with the smear brush)
* tested with white images and this should not wrap back to zero */
- outI[0] = (ma_mb * row1I[0] + a_mb * row3I[0] + ma_b * row2I[0] + a_b * row4I[0]) + 0.5f;
- outI[1] = (ma_mb * row1I[1] + a_mb * row3I[1] + ma_b * row2I[1] + a_b * row4I[1]) + 0.5f;
- outI[2] = (ma_mb * row1I[2] + a_mb * row3I[2] + ma_b * row2I[2] + a_b * row4I[2]) + 0.5f;
- outI[3] = (ma_mb * row1I[3] + a_mb * row3I[3] + ma_b * row2I[3] + a_b * row4I[3]) + 0.5f;
+ outI[0] = roundf(ma_mb * row1I[0] + a_mb * row3I[0] + ma_b * row2I[0] + a_b * row4I[0]);
+ outI[1] = roundf(ma_mb * row1I[1] + a_mb * row3I[1] + ma_b * row2I[1] + a_b * row4I[1]);
+ outI[2] = roundf(ma_mb * row1I[2] + a_mb * row3I[2] + ma_b * row2I[2] + a_b * row4I[2]);
+ outI[3] = roundf(ma_mb * row1I[3] + a_mb * row3I[3] + ma_b * row2I[3] + a_b * row4I[3]);
}
}
diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c
index 1fd9bba68f3..fbd50374711 100644
--- a/source/blender/imbuf/intern/scaling.c
+++ b/source/blender/imbuf/intern/scaling.c
@@ -22,6 +22,8 @@
* \ingroup imbuf
*/
+#include <math.h>
+
#include "BLI_math_color.h"
#include "BLI_math_interp.h"
#include "BLI_utildefines.h"
@@ -1000,10 +1002,10 @@ static ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
val[3] = rect[3];
rect += 4;
- newrect[0] = ((nval[0] + sample * val[0]) / add + 0.5f);
- newrect[1] = ((nval[1] + sample * val[1]) / add + 0.5f);
- newrect[2] = ((nval[2] + sample * val[2]) / add + 0.5f);
- newrect[3] = ((nval[3] + sample * val[3]) / add + 0.5f);
+ newrect[0] = roundf((nval[0] + sample * val[0]) / add);
+ newrect[1] = roundf((nval[1] + sample * val[1]) / add);
+ newrect[2] = roundf((nval[2] + sample * val[2]) / add);
+ newrect[3] = roundf((nval[3] + sample * val[3]) / add);
newrect += 4;
}
@@ -1142,10 +1144,10 @@ static ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
val[3] = rect[3];
rect += skipx;
- newrect[0] = ((nval[0] + sample * val[0]) / add + 0.5f);
- newrect[1] = ((nval[1] + sample * val[1]) / add + 0.5f);
- newrect[2] = ((nval[2] + sample * val[2]) / add + 0.5f);
- newrect[3] = ((nval[3] + sample * val[3]) / add + 0.5f);
+ newrect[0] = roundf((nval[0] + sample * val[0]) / add);
+ newrect[1] = roundf((nval[1] + sample * val[1]) / add);
+ newrect[2] = roundf((nval[2] + sample * val[2]) / add);
+ newrect[3] = roundf((nval[3] + sample * val[3]) / add);
newrect += skipx;
}
@@ -1573,8 +1575,8 @@ static void scalefast_Z_ImBuf(ImBuf *ibuf, int newx, int newy)
return;
}
- stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5;
- stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5;
+ stepx = round(65536.0 * (ibuf->x - 1.0) / (newx - 1.0));
+ stepy = round(65536.0 * (ibuf->y - 1.0) / (newy - 1.0));
ofsy = 32768;
newzbuf = _newzbuf;
@@ -1713,8 +1715,8 @@ bool IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy
newrectf = _newrectf;
}
- stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5;
- stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5;
+ stepx = round(65536.0 * (ibuf->x - 1.0) / (newx - 1.0));
+ stepy = round(65536.0 * (ibuf->y - 1.0) / (newy - 1.0));
ofsy = 32768;
for (y = newy; y > 0; y--, ofsy += stepy) {