Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

tilt_internal.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Classes

class  DPoint

Functions

QRgb interpolatedPixelValue (double xp, double yp, QImage *image)
QRgb blendColors (QRgb color1, QRgb color2, double alpha)
DPoint findTwoLineIntersection (DPoint p1, DPoint p2, DPoint p3, DPoint p4)


Function Documentation

QRgb blendColors QRgb  color1,
QRgb  color2,
double  alpha
 

Definition at line 359 of file tilt.cpp.

Referenced by interpolatedPixelValue().

00360 {
00361   double alpha2 = 1.0-alpha;
00362   return qRgb( (int) QMAX( QMIN( 255, alpha2*qRed  (color1) + alpha*qRed(color2)   ), 0 ),
00363                (int) QMAX( QMIN( 255, alpha2*qGreen(color1) + alpha*qGreen(color2) ), 0 ),
00364                (int) QMAX( QMIN( 255, alpha2*qBlue (color1) + alpha*qBlue(color2)  ), 0 ) );
00365 }

DPoint findTwoLineIntersection DPoint  p1,
DPoint  p2,
DPoint  p3,
DPoint  p4
 

Definition at line 367 of file tilt.cpp.

References DPoint::x(), and DPoint::y().

Referenced by correctImageTilt().

00369 {
00370   //----------------------------------------------
00371   //=== Case 1: neither line has a change in X ===
00372   //----------------------------------------------
00373   //If there is no change in x for both lines, 
00374   //either lines will NEVER or ALWAYS intersect.
00375   if(p1.x() == p2.x() &&
00376      p4.x() == p3.x())
00377   {
00378     //Ok, if their x values are equal, return 
00379     //intersection point as line A's point A.
00380     //Yes, this is a little arbitratry. But 
00381     //theoreticaly this section of code will almost
00382     //never be executed.
00383     if( p1.x() == p3.x() )
00384     { return DPoint( p1.x(), p1.y() ); }
00385     //Else lines will never intersect,
00386     //return pair (-32000,-32000)
00387     else
00388     { return DPoint( -32000, -32000 ); }
00389   } 
00390   //----------------------------------------------
00391   //Else, we know at least one of the lines 
00392   //does NOT have a slope of infinity!!!
00393   //----------------------------------------------
00394   
00395   //----------------------------------------------
00396   //=== Case 2: line A has no change in X      ===
00397   //----------------------------------------------
00398   //If line A has an infinite slope (no change in x)
00399   //we know line B does not have an infinite slope...
00400   else if( p1.x() == p2.x() )
00401   {
00402     double slopeB = ((double) (p4.y() - p3.y()) ) / (p4.x() - p3.x());
00403     
00404     double yInterceptB = p3.y() - slopeB*p3.x();
00405     
00406     //y = mx+b
00407     return DPoint( p2.x(), slopeB*p2.x() + yInterceptB );
00408   }
00409   //----------------------------------------------
00410   //=== Case 3: line B has no change in X      ===
00411   //----------------------------------------------
00412   //If line B has an infinite slope (no change in x)
00413   //we know line A does not have an infinite slope...
00414   else if( p4.x() == p3.x() )
00415   {
00416     double slopeA = ((double) (p2.y() - p1.y()) ) / (p2.x() - p1.x());
00417     
00418     double yInterceptA = p1.y() - slopeA*p1.x();
00419     
00420     //y = mx+b
00421     return DPoint( p4.x(), slopeA*p4.x() + yInterceptA );
00422   }
00423   //----------------------------------------------
00424   //=== Case 4: both lines have non infinite slopes ===
00425   //----------------------------------------------
00426   else
00427   {
00428     double slopeA = ((double) (p2.y() - p1.y()) ) / (p2.x() - p1.x());
00429     double slopeB = ((double) (p4.y() - p3.y()) ) / (p4.x() - p3.x());
00430     double yInterceptA = p1.y() - slopeA*p1.x();
00431     double yInterceptB = p3.y() - slopeB*p3.x();
00432     
00433     //y1 = mx1+b
00434     //y2 = nx2+c
00435     //at intersection y1=y2 and x1 = x2 so...
00436     //mx +b = nx + c
00437     //x(m-n) = c-b
00438     //x = (c-b)/(m-n)
00439     //where m and n are slope and
00440     //b and c are y-intercepts.
00441     //x = (c-b)/(m-n)
00442     double x = (yInterceptB - yInterceptA) / (slopeA - slopeB);
00443     return DPoint( x, (slopeA * x) + yInterceptA );
00444   }
00445 }

QRgb interpolatedPixelValue double  xp,
double  yp,
QImage *  image
 

Definition at line 312 of file tilt.cpp.

References blendColors().

Referenced by correctImageTilt().

00314 {
00315   //do boundary checking to 
00316   //ensure we don't read beyond image boundaries
00317   if(xp < 0 || xp >= image->width() ||
00318      yp < 0 || yp >= image->height() )
00319     return qRgb( 0, 0, 0 );
00320 
00321   //get four pixel colors, 
00322   int x = (int)xp;
00323   int y = (int)yp;
00324   
00325   uchar* scanLine1 = image->scanLine( y );
00326 
00327   uchar* scanLine2;
00328   if( y < image->height() - 1 )
00329     scanLine2 = image->scanLine( y+1 );
00330   else
00331     scanLine2 = scanLine1;
00332   
00333   QRgb p1,p2,p3,p4;
00334   
00335   p1 = *((QRgb*)scanLine1+x);
00336   p3 = *((QRgb*)scanLine2+x);
00337         
00338   if( x < image->width() - 1)
00339   {
00340     p2 = *((QRgb*)scanLine1+x+1);
00341     p4 = *((QRgb*)scanLine2+x+1);     
00342   }
00343   else
00344   {
00345     p2 = p1;
00346     p4 = p3;
00347   }
00348   
00349   //blend four colors
00350   double alphaY = yp - y;
00351   double alphaX = xp - x;
00352   
00353   p1 = blendColors( p1, p2, alphaX );
00354   p3 = blendColors( p3, p4, alphaX );
00355   p1 = blendColors( p1, p3, alphaY );
00356   return p1;
00357 }


Generated on Wed May 4 11:10:52 2005 for AlbumShaper by  doxygen 1.3.9.1