00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "CaelumPrecompiled.h"
00022 #include "ImageHelper.h"
00023
00024 namespace caelum
00025 {
00026 Ogre::ColourValue getInterpolatedColour (
00027 float fx, float fy, Ogre::Image *img, bool wrapX)
00028 {
00029
00030 int imgWidth = static_cast<int>(img->getWidth ());
00031 int imgHeight = static_cast<int>(img->getHeight ());
00032
00033
00034 int py = Ogre::Math::IFloor(Ogre::Math::Abs (fy) * (imgHeight - 1));
00035
00036 py = std::max(0, std::min(py, imgHeight - 1));
00037
00038
00039
00040 float px = fx * (img->getWidth () - 1);
00041 int px1, px2;
00042 px1 = Ogre::Math::IFloor(px);
00043 px2 = Ogre::Math::ICeil(px);
00044
00045 if (wrapX) {
00046
00047
00048 px1 = (px1 % imgWidth + imgWidth) % imgWidth;
00049 px2 = (px2 % imgWidth + imgWidth) % imgWidth;
00050 } else {
00051 px1 = std::max(0, std::min(px1, imgWidth - 1));
00052 px2 = std::max(0, std::min(px2, imgWidth - 1));
00053 }
00054
00055
00056 Ogre::ColourValue c1, c2, cf;
00057 c1 = img->getColourAt (px1, py, 0);
00058 c2 = img->getColourAt (px2, py, 0);
00059
00060
00061
00062 float diff = px - px1;
00063 cf = c1 * (1 - diff) + c2 * diff;
00064
00065 return cf;
00066 }
00067 }