crop.cpp

Go to the documentation of this file.
00001 #include "runtime.h"
00002 #include "aux.h"
00003 #include "box.h"
00004 
00005 Value * Runtime::crop(Value * image, Value * box)
00006 {
00007   // input checks
00008   if (image==NULL)  return NULL;
00009   if (box==NULL) return NULL;
00010   if (typeid(*image)!=typeid(ImageValue)) return NULL;
00011   if (typeid(*box)!=typeid(BoxValue)) return NULL;
00012   // convertions
00013   ImageValue * I = (ImageValue*)image;
00014   BoxValue   * B = (BoxValue*)box;
00015   PointValue & otl = B->tl;
00016   PointValue & otr = B->tr;
00017   PointValue & obl = B->bl;
00018   PointValue & obr = B->br;
00019 
00020   DirectPoint dtl = I->ocsToDcs(otl);
00021   DirectPoint dtr = I->ocsToDcs(otr);
00022   DirectPoint dbl = I->ocsToDcs(obl);
00023   DirectPoint dbr = I->ocsToDcs(obr);
00024   
00025   // final output size is the largest size we need to represent every
00026   // pixel
00027   int as = 1+(int)max(dist(dtl,dtr),dist(dbl,dbr));
00028   int bs = 1+(int)max(dist(dtl,dbl),dist(dtr,dbr));
00029   int cs = I->channelcount();
00030   ImageValue * O = new ImageValue(as,bs,cs);
00031   // we run trhough all the target pixels and fill in the values
00032   for(int c = 0 ; c < cs ; c++)
00033     for(int a = 0 ; a < as ; a++)
00034       for(int b = 0 ; b < bs ; b++)
00035         {
00036           int ml_x = pos(dtl.x,dbl.x,b,bs);
00037           int ml_y = pos(dtl.y,dbl.y,b,bs);
00038           int mr_x = pos(dtr.x,dbr.x,b,bs);
00039           int mr_y = pos(dtr.y,dbr.y,b,bs);
00040           int x = pos(ml_x,mr_x,a,as);
00041           int y = pos(ml_y,mr_y,a,as);
00042           O->set_direct(a,b,c,I->get_direct(x,y,c));
00043         }
00044   return O;
00045 }
00046 
00047 Value * Runtime::crop(vector<Value*> v)
00048 {
00049   if (v.size()==2) return crop(v[0],v[1]);
00050   return NULL;
00051 }
00052 

Generated on Mon Jun 5 22:08:41 2006 for iis by  doxygen 1.4.6