in TNLExample/TNLXImageSupport.m [419:456]
CGSize TNLXSizeScale(CGSize sourceSize, CGSize desiredSize, UIViewContentMode contentMode)
{
switch (contentMode) {
case UIViewContentModeScaleToFill:
return desiredSize;
case UIViewContentModeScaleAspectFit:
case UIViewContentModeScaleAspectFill:
{
CGFloat widthRatio = sourceSize.width / desiredSize.width;
CGFloat heightRatio = sourceSize.height / desiredSize.height;
if (UIViewContentModeScaleAspectFit == contentMode) {
if (heightRatio > widthRatio) {
widthRatio = heightRatio;
}
} else {
if (heightRatio < widthRatio) {
widthRatio = heightRatio;
}
}
desiredSize.width = (CGFloat)floor(sourceSize.width * 2.0f / widthRatio) / 2.0f;
desiredSize.height = (CGFloat)floor(sourceSize.height * 2.0f / widthRatio) / 2.0f;
return desiredSize;
}
case UIViewContentModeRedraw:
case UIViewContentModeCenter:
case UIViewContentModeTop:
case UIViewContentModeBottom:
case UIViewContentModeLeft:
case UIViewContentModeRight:
case UIViewContentModeTopLeft:
case UIViewContentModeTopRight:
case UIViewContentModeBottomLeft:
case UIViewContentModeBottomRight:
return sourceSize;
}
}