[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60317] branches/soc-2013-vse/source/ blender/blenlib: Added nearest interpolation for size of 4for math lib
Alexander Kuznetsov
kuzsasha at gmail.com
Mon Sep 23 01:14:55 CEST 2013
Revision: 60317
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60317
Author: alexk
Date: 2013-09-22 23:14:55 +0000 (Sun, 22 Sep 2013)
Log Message:
-----------
Added nearest interpolation for size of 4for math lib
Modified Paths:
--------------
branches/soc-2013-vse/source/blender/blenlib/BLI_math_interp.h
branches/soc-2013-vse/source/blender/blenlib/intern/math_interp.c
Modified: branches/soc-2013-vse/source/blender/blenlib/BLI_math_interp.h
===================================================================
--- branches/soc-2013-vse/source/blender/blenlib/BLI_math_interp.h 2013-09-22 16:09:31 UTC (rev 60316)
+++ branches/soc-2013-vse/source/blender/blenlib/BLI_math_interp.h 2013-09-22 23:14:55 UTC (rev 60317)
@@ -41,4 +41,10 @@
void BLI_bilinear_interpolation_char(const unsigned char *buffer, unsigned char *output, int width, int height,
int components, float u, float v);
+void BLI_nearest_interpolation_fl(const float *buffer, float *output, int width, int height,
+ int components, float u, float v);
+
+void BLI_nearest_interpolation_char(const unsigned char *buffer, unsigned char *output, int width, int height,
+ int components, float u, float v);
+
#endif
Modified: branches/soc-2013-vse/source/blender/blenlib/intern/math_interp.c
===================================================================
--- branches/soc-2013-vse/source/blender/blenlib/intern/math_interp.c 2013-09-22 16:09:31 UTC (rev 60316)
+++ branches/soc-2013-vse/source/blender/blenlib/intern/math_interp.c 2013-09-22 23:14:55 UTC (rev 60317)
@@ -100,9 +100,6 @@
float a, b, w, wx, wy[4], out[4];
/* sample area entirely outside image? */
- if (ceil(u) < 0 || floor(u) > width - 1 || ceil(v) < 0 || floor(v) > height - 1) {
- return;
- }
i = (int)floor(u);
j = (int)floor(v);
@@ -260,25 +257,28 @@
y2 = (int)ceil(v);
/* sample area entirely outside image? */
- if (x2 < 0 || x1 > width - 1 || y2 < 0 || y1 > height - 1) {
- return;
+ if (x2 < -1 || x1 > width || y2 < -1 || y1 > height) {
+ //return;
}
+ if (x2 < 0 || x1 > width -1 || y2 < 0 || y1 > height-1) {
+ //return;
+ }
if (float_output) {
const float *row1, *row2, *row3, *row4;
float empty[4] = {0.0f, 0.0f, 0.0f, 0.0f};
/* sample including outside of edges of image */
- if (x1 < 0 || y1 < 0) row1 = empty;
+ if (x1 < 0 || x1 > width - 1 || y1 < 0 || y1 > height - 1) row1 = empty;
else row1 = float_buffer + width * y1 * components + components * x1;
- if (x1 < 0 || y2 > height - 1) row2 = empty;
+ if (x1 < 0 || x1 > width - 1 || y2 > height - 1 || y2 < 0) row2 = empty;
else row2 = float_buffer + width * y2 * components + components * x1;
- if (x2 > width - 1 || y1 < 0) row3 = empty;
+ if (x2 < 0 || x2 > width - 1 || y1 < 0 || y1 > height - 1) row3 = empty;
else row3 = float_buffer + width * y1 * components + components * x2;
- if (x2 > width - 1 || y2 > height - 1) row4 = empty;
+ if (x2 < 0 || x2 > width - 1 || y2 > height - 1 || y2 < 0) row4 = empty;
else row4 = float_buffer + width * y2 * components + components * x2;
a = u - floorf(u);
@@ -294,6 +294,7 @@
float_output[2] = ma_mb * row1[2] + a_mb * row3[2] + ma_b * row2[2] + a_b * row4[2];
}
else {
+ size_t ti;
float_output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
float_output[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];
float_output[2] = ma_mb * row1[2] + a_mb * row3[2] + ma_b * row2[2] + a_b * row4[2];
@@ -304,17 +305,19 @@
const unsigned char *row1, *row2, *row3, *row4;
unsigned char empty[4] = {0, 0, 0, 0};
+
+
/* sample including outside of edges of image */
- if (x1 < 0 || y1 < 0) row1 = empty;
+ if (x1 < 0 || x1 > width - 1 || y1 < 0 || y1 > height - 1) row1 = empty;
else row1 = byte_buffer + width * y1 * components + components * x1;
- if (x1 < 0 || y2 > height - 1) row2 = empty;
+ if (x1 < 0 || x1 > width - 1 || y2 > height - 1 || y2 < 0) row2 = empty;
else row2 = byte_buffer + width * y2 * components + components * x1;
- if (x2 > width - 1 || y1 < 0) row3 = empty;
+ if (x2 < 0 || x2 > width - 1 || y1 < 0 || y1 > height - 1) row3 = empty;
else row3 = byte_buffer + width * y1 * components + components * x2;
- if (x2 > width - 1 || y2 > height - 1) row4 = empty;
+ if (x2 < 0 || x2 > width - 1 || y2 > height - 1 || y2 < 0) row4 = empty;
else row4 = byte_buffer + width * y2 * components + components * x2;
a = u - floorf(u);
@@ -349,3 +352,71 @@
{
bilinear_interpolation(buffer, NULL, output, NULL, width, height, components, u, v);
}
+
+
+
+
+BLI_INLINE void nearest_interpolation(const unsigned char *inI, const float *inF, unsigned char outI[4], float outF[4], int width, int height, float u, float v)
+{
+ float *dataF;
+ unsigned char *dataI;
+ int y1, x1;
+
+ /* ImBuf in must have a valid rect or rect_float, assume this is already checked */
+
+ x1 = (int)(u);
+ y1 = (int)(v);
+
+ /* sample area entirely outside image? */
+ if (x1 < 0 || x1 > width - 1 || y1 < 0 || y1 > height - 1) {
+ return;
+ }
+
+ /* sample including outside of edges of image */
+ if (x1 < 0 || y1 < 0) {
+ if (outI) {
+ outI[0] = 0;
+ outI[1] = 0;
+ outI[2] = 0;
+ outI[3] = 0;
+ }
+ if (outF) {
+ outF[0] = 0.0f;
+ outF[1] = 0.0f;
+ outF[2] = 0.0f;
+ outF[3] = 0.0f;
+ }
+ }
+ else {
+ dataI = (unsigned char *)inI + width * y1 * 4 + 4 * x1;
+ if (outI) {
+ outI[0] = dataI[0];
+ outI[1] = dataI[1];
+ outI[2] = dataI[2];
+ outI[3] = dataI[3];
+ }
+ dataF = inF + width * y1 * 4 + 4 * x1;
+ if (outF) {
+ outF[0] = dataF[0];
+ outF[1] = dataF[1];
+ outF[2] = dataF[2];
+ outF[3] = dataF[3];
+ }
+ }
+}
+
+
+
+
+
+void BLI_nearest_interpolation_fl(const float *buffer, float *output, int width, int height,
+ int components, float u, float v)
+{
+ nearest_interpolation(NULL, buffer, NULL, output, width, height, u, v);
+}
+
+void BLI_nearest_interpolation_char(const unsigned char *buffer, unsigned char *output, int width, int height,
+ int components, float u, float v)
+{
+ nearest_interpolation(buffer, NULL, output, NULL, width, height, u, v);
+}
More information about the Bf-blender-cvs
mailing list