~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/vision/improc/im_sample.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 #include <math.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 #include <tina/vision.h>
  9 
 10 Imrect *imf_sample(double k, Imrect * im)
 11 {
 12     Imrect *im2;
 13     int     width, height;
 14     Imregion *region;
 15     int     lx, ux, ly, uy;
 16     int     x, y;
 17 
 18     if (im == NULL)
 19         return (NULL);
 20 
 21     region = roi_copy(im->region);
 22     lx = region->lx = (int)(region->lx*k);
 23     ly = region->ly = (int)(region->ly*k);
 24     ux = region->ux = (int)(region->ux*k);
 25     uy = region->uy = (int)(region->uy*k);
 26     width = (int)(k * im->width);
 27     height = (int)(k * im->height);
 28 
 29     im2 = im_alloc(height, width, region, float_v);
 30 
 31     for (x = lx; x < ux; x++)
 32         for (y = ly; y < uy; y++)
 33         {
 34             float   pixval;
 35 
 36             pixval = (float) im_sub_pixqf(im, (y + 0.5) / k, (x + 0.5) / k);
 37             im_put_pixf(pixval, im2, y, x);
 38         }
 39 
 40     return (im2);
 41 }
 42 
 43 Imrect *imf_halve(Imrect * im)
 44 {
 45     Imrect *im2;
 46     int     width, height;
 47     Imregion *roi;
 48     int     x, y;
 49     double  g1, g2, g3, g4, g;
 50 
 51     if (im == NULL)
 52         return (NULL);
 53 
 54     roi = roi_copy(im->region);
 55     roi->lx = (int)ceil(roi->lx / 2.0);
 56     roi->ly = (int)ceil(roi->ly / 2.0);
 57     roi->ux = (int)floor(roi->ux / 2.0);
 58     roi->uy = (int)floor(roi->uy / 2.0);
 59     width = (int)floor(im->width / 2.0);
 60     height = (int)floor(im->height / 2.0);
 61 
 62     im2 = im_alloc(height, width, roi, float_v);
 63 
 64     for (x = roi->lx; x < roi->ux; x++)
 65         for (y = roi->ly; y < roi->uy; y++)
 66         {
 67             int     x2 = 2 * x, y2 = 2 * y;
 68 
 69             IM_PIX_GET(im, y2, x2, g1);
 70             IM_PIX_GET(im, y2 + 1, x2, g2);
 71             IM_PIX_GET(im, y2, x2 + 1, g3);
 72             IM_PIX_GET(im, y2 + 1, x2 + 1, g4);
 73             g = 0.25 * (g1 + g2 + g3 + g4);
 74             IM_PIX_SET(im2, y, x, g);
 75         }
 76 
 77     return (im2);
 78 }
 79 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.