AlbumShaper  1.0a3
Classes | Functions
tilt_internal.h File Reference
This graph shows which files directly or indirectly include this file:

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

§ blendColors()

QRgb blendColors ( QRgb  color1,
QRgb  color2,
double  alpha 
)

Definition at line 362 of file tilt.cpp.

References MAX, and MIN.

Referenced by interpolatedPixelValue().

363 {
364  double alpha2 = 1.0-alpha;
365  return qRgb( (int) MAX( MIN( 255, alpha2*qRed (Qt::color1) + alpha*qRed(color2) ), 0 ),
366  (int) MAX( MIN( 255, alpha2*qGreen(Qt::color1) + alpha*qGreen(color2) ), 0 ),
367  (int) MAX( MIN( 255, alpha2*qBlue (Qt::color1) + alpha*qBlue(color2) ), 0 ) );
368 }
#define MIN(x, y)
Definition: tilt.cpp:17
#define MAX(x, y)
Definition: tilt.cpp:18

§ findTwoLineIntersection()

DPoint findTwoLineIntersection ( DPoint  p1,
DPoint  p2,
DPoint  p3,
DPoint  p4 
)

Definition at line 370 of file tilt.cpp.

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

Referenced by correctImageTilt().

372 {
373  //----------------------------------------------
374  //=== Case 1: neither line has a change in X ===
375  //----------------------------------------------
376  //If there is no change in x for both lines,
377  //either lines will NEVER or ALWAYS intersect.
378  if(p1.x() == p2.x() &&
379  p4.x() == p3.x())
380  {
381  //Ok, if their x values are equal, return
382  //intersection point as line A's point A.
383  //Yes, this is a little arbitratry. But
384  //theoreticaly this section of code will almost
385  //never be executed.
386  if( p1.x() == p3.x() )
387  { return DPoint( p1.x(), p1.y() ); }
388  //Else lines will never intersect,
389  //return pair (-32000,-32000)
390  else
391  { return DPoint( -32000, -32000 ); }
392  }
393  //----------------------------------------------
394  //Else, we know at least one of the lines
395  //does NOT have a slope of infinity!!!
396  //----------------------------------------------
397 
398  //----------------------------------------------
399  //=== Case 2: line A has no change in X ===
400  //----------------------------------------------
401  //If line A has an infinite slope (no change in x)
402  //we know line B does not have an infinite slope...
403  else if( p1.x() == p2.x() )
404  {
405  double slopeB = ((double) (p4.y() - p3.y()) ) / (p4.x() - p3.x());
406 
407  double yInterceptB = p3.y() - slopeB*p3.x();
408 
409  //y = mx+b
410  return DPoint( p2.x(), slopeB*p2.x() + yInterceptB );
411  }
412  //----------------------------------------------
413  //=== Case 3: line B has no change in X ===
414  //----------------------------------------------
415  //If line B has an infinite slope (no change in x)
416  //we know line A does not have an infinite slope...
417  else if( p4.x() == p3.x() )
418  {
419  double slopeA = ((double) (p2.y() - p1.y()) ) / (p2.x() - p1.x());
420 
421  double yInterceptA = p1.y() - slopeA*p1.x();
422 
423  //y = mx+b
424  return DPoint( p4.x(), slopeA*p4.x() + yInterceptA );
425  }
426  //----------------------------------------------
427  //=== Case 4: both lines have non infinite slopes ===
428  //----------------------------------------------
429  else
430  {
431  double slopeA = ((double) (p2.y() - p1.y()) ) / (p2.x() - p1.x());
432  double slopeB = ((double) (p4.y() - p3.y()) ) / (p4.x() - p3.x());
433  double yInterceptA = p1.y() - slopeA*p1.x();
434  double yInterceptB = p3.y() - slopeB*p3.x();
435 
436  //y1 = mx1+b
437  //y2 = nx2+c
438  //at intersection y1=y2 and x1 = x2 so...
439  //mx +b = nx + c
440  //x(m-n) = c-b
441  //x = (c-b)/(m-n)
442  //where m and n are slope and
443  //b and c are y-intercepts.
444  //x = (c-b)/(m-n)
445  double x = (yInterceptB - yInterceptA) / (slopeA - slopeB);
446  return DPoint( x, (slopeA * x) + yInterceptA );
447  }
448 }
double x() const
Definition: tilt.cpp:459
double y() const
Definition: tilt.cpp:460

§ interpolatedPixelValue()

QRgb interpolatedPixelValue ( double  xp,
double  yp,
QImage *  image 
)

Definition at line 315 of file tilt.cpp.

References blendColors(), height, and width.

Referenced by correctImageTilt().

317 {
318  //do boundary checking to
319  //ensure we don't read beyond image boundaries
320  if(xp < 0 || xp >= image->width() ||
321  yp < 0 || yp >= image->height() )
322  return qRgb( 0, 0, 0 );
323 
324  //get four pixel colors,
325  int x = (int)xp;
326  int y = (int)yp;
327 
328  uchar* scanLine1 = image->scanLine( y );
329 
330  uchar* scanLine2;
331  if( y < image->height() - 1 )
332  scanLine2 = image->scanLine( y+1 );
333  else
334  scanLine2 = scanLine1;
335 
336  QRgb p1,p2,p3,p4;
337 
338  p1 = *((QRgb*)scanLine1+x);
339  p3 = *((QRgb*)scanLine2+x);
340 
341  if( x < image->width() - 1)
342  {
343  p2 = *((QRgb*)scanLine1+x+1);
344  p4 = *((QRgb*)scanLine2+x+1);
345  }
346  else
347  {
348  p2 = p1;
349  p4 = p3;
350  }
351 
352  //blend four colors
353  double alphaY = yp - y;
354  double alphaX = xp - x;
355 
356  p1 = blendColors( p1, p2, alphaX );
357  p3 = blendColors( p3, p4, alphaX );
358  p1 = blendColors( p1, p3, alphaY );
359  return p1;
360 }
int width
Definition: blur.cpp:79
QRgb blendColors(QRgb color1, QRgb color2, double alpha)
Definition: tilt.cpp:362
int height
Definition: blur.cpp:79