ultimatepp/bazaar/PixRaster/Lept-Scale.cpp
micio a74e1468c9 PixRaster : updated Leptonica library to version 1.65
git-svn-id: svn://ultimatepp.org/upp/trunk@2598 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2010-08-07 23:38:03 +00:00

34 lines
747 B
C++

#include "PixRaster.h"
NAMESPACE_UPP
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// toplevel scale function
Pix Pix::Scale(double scalex, double scaley)
{
if(IsEmpty())
return Pix();
PIX *dPix = pixScale(pix, (l_float32)scalex, (l_float32)scaley);
if(!dPix)
return Pix();
return Pix(&dPix);
}
Pix Pix::Fit(int width, int height, bool keepRatio)
{
// gets original sizes
int w = GetWidth();
int h = GetHeight();
// gets scale factor in both directions
double xScale = (double)width / (double)w;
double yScale = (double)height / (double)h;
if(keepRatio)
{
xScale = min(xScale, yScale);
yScale = xScale;
}
return Scale(xScale, yScale);
}
END_UPP_NAMESPACE