Revision: 56670
http://sourceforge.net/p/brlcad/code/56670
Author: mohitdaga
Date: 2013-08-07 16:37:23 +0000 (Wed, 07 Aug 2013)
Log Message:
-----------
Add wraper function for icv_resize(..). Also do data validation in private
functions for resize.
Modified Paths:
--------------
brlcad/trunk/include/icv.h
brlcad/trunk/src/libicv/decimate.c
Modified: brlcad/trunk/include/icv.h
===================================================================
--- brlcad/trunk/include/icv.h 2013-08-07 16:33:27 UTC (rev 56669)
+++ brlcad/trunk/include/icv.h 2013-08-07 16:37:23 UTC (rev 56670)
@@ -573,7 +573,23 @@
*/
ICV_EXPORT double *icv_max(icv_image_t* img);
+/** @file decimate.c
+ *
+ * This file contains routines to scale down an image to a lower
+ * resolution or scale up an image to an higher Resolution.
+ *
+ */
+typedef enum {
+ ICV_RESIZE_UPSAMPLE,
+ ICV_RESIZE_SHRINK,
+ ICV_RESIZE_NINTERP,
+ ICV_RESIZE_BINTERP
+} ICV_RESIZE_METHOD;
+
+ICV_EXPORT int icv_resize(icv_image_t *bif, ICV_RESIZE_METHOD method, int
out_width, int out_height, unsigned int factor);
+
+
/** @} */
/* end image utilities */
Modified: brlcad/trunk/src/libicv/decimate.c
===================================================================
--- brlcad/trunk/src/libicv/decimate.c 2013-08-07 16:33:27 UTC (rev 56669)
+++ brlcad/trunk/src/libicv/decimate.c 2013-08-07 16:37:23 UTC (rev 56670)
@@ -28,13 +28,19 @@
#include "icv.h"
#include "vmath.h"
-HIDDEN void shrink_image(icv_image_t* bif, int factor)
+HIDDEN int shrink_image(icv_image_t* bif, unsigned int factor)
{
double *data_p, *res_p; /**< input and output pointers */
double *p;
- int facsq, x, y, py, px, c;
+ unsigned int facsq, py, px;
+ int x, y, c;
size_t widthstep = bif->width*bif->channels;
+ if (UNLIKELY(factor == 0)) {
+ bu_log("shrink_image : Cannot shrink image to 0 factor, factor should
be non zero Unisgned Integer");
+ return -1;
+ }
+
facsq = factor*factor;
res_p = bif->data;
p = bu_malloc(bif->channels*sizeof(double), "shrink_image : Pixel Values
Temp Buffer");
@@ -63,15 +69,20 @@
bif->height = (int) bif->height/factor;
bif->data = bu_realloc(bif->data, (size_t)
(bif->width*bif->height*bif->channels)*sizeof(double), "shrink_image :
Reallocation");
- return;
+ return 0;
}
-HIDDEN void under_sample(icv_image_t* bif, int factor)
+HIDDEN int under_sample(icv_image_t* bif, unsigned int factor)
{
double *data_p, *res_p;
int x, y, widthstep;
+ if (UNLIKELY(factor == 0)) {
+ bu_log("under_sample : Cannot shrink image to 0 factor, factor should
be non zero Unisgned Integer");
+ return -1;
+ }
+
widthstep = bif->width*bif->channels;
res_p = data_p = bif->data;
@@ -85,13 +96,13 @@
bif->height = (int) bif->height/factor;
bif->data = bu_realloc(bif->data, (size_t)
(bif->width*bif->height*bif->channels), "under_sample : Reallocation");
- return;
+ return 0;
}
-HIDDEN void nintrep(icv_image_t* bif, int out_width, int out_height)
+HIDDEN int ninterp(icv_image_t* bif, unsigned int out_width, unsigned int
out_height)
{
double xstep, ystep;
- int i, j;
+ unsigned int i, j;
int x, y;
int widthstep;
double *in_r, *in_c; /*<< Pointer to row and col of input buffers*/
@@ -99,6 +110,11 @@
xstep = (double) (bif->width-1) / (double) (out_width) - 1.0e-06;
ystep = (double) (bif->height-1) / (double) (out_height) - 1.0e-06;
+ if ((xstep < 1.0 && ystep > 1.0) || (xstep > 1.0 && ystep < 1.0)) {
+ bu_log("nitrep: Can't stretch one way and compress another\n");
+ return -1;
+ }
+
out_p = out_data =
bu_malloc(out_width*out_height*bif->channels*sizeof(double), "intrep :
out_data");
widthstep= bif->width*bif->channels;
@@ -124,12 +140,13 @@
bif->width = out_width;
bif->height = out_height;
- return;
+ return 0;
}
-HIDDEN void binterp(icv_image_t *bif, int out_width, int out_height)
+HIDDEN int binterp(icv_image_t *bif, unsigned int out_width, unsigned int
out_height)
{
- int i, j, c;
+ unsigned int i, j;
+ int c;
double x, y, dx, dy, mid1, mid2;
double xstep, ystep;
double *out_data, *out_p;
@@ -140,6 +157,11 @@
xstep = (double) (bif->width - 1) / (double)out_width - 1.0e-6;
ystep = (double) (bif->height -1) / (double)out_height - 1.0e-6;
+ if ((xstep < 1.0 && ystep > 1.0) || (xstep > 1.0 && ystep < 1.0)) {
+ bu_log("bintrep: Can't stretch one way and compress another\n");
+ return -1;
+ }
+
out_p = out_data =
bu_malloc(out_width*out_height*bif->channels*sizeof(double), "binterp : out
data");
widthstep = bif->width*bif->channels;
@@ -173,8 +195,28 @@
bif->data = out_data;
bif->width = out_width;
bif->height = out_height;
+ return 0;
+
}
+int icv_resize(icv_image_t *bif, ICV_RESIZE_METHOD method, int out_width, int
out_height, unsigned int factor)
+{
+ switch(method) {
+ case ICV_RESIZE_UPSAMPLE :
+ return shrink_image(bif, factor);
+ case ICV_RESIZE_SHRINK :
+ return under_sample(bif, factor);
+ case ICV_RESIZE_NINTERP :
+ return ninterp(bif, out_width,out_height);
+ case ICV_RESIZE_BINTERP :
+ return binterp(bif, out_width, out_height);
+ default :
+ bu_log("icv_resize : Invalid Option to resize");
+ return -1;
+ }
+
+}
+
/*
* Local Variables:
* tab-width: 8
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits