• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE Support
  • Sitemap
  • Contact Us
 

qimageblitz

interpolate.h

Go to the documentation of this file.
00001 #ifndef __PIXIE_INTERPOLATE_H
00002 #define __PIXIE_INTERPOLATE_H
00003 
00004 /*
00005  Copyright (C) 2005, 2007 Daniel M. Duley <daniel.duley@verizon.net>
00006 
00007 Redistribution and use in source and binary forms, with or without
00008 modification, are permitted provided that the following conditions
00009 are met:
00010 
00011 1. Redistributions of source code must retain the above copyright
00012    notice, this list of conditions and the following disclaimer.
00013 2. Redistributions in binary form must reproduce the above copyright
00014    notice, this list of conditions and the following disclaimer in the
00015    documentation and/or other materials provided with the distribution.
00016 
00017 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 
00028 */
00029 
00030 #include <QImage>
00031 #include <QVector>
00032 #include <cmath>
00033 
00041 class InlineInterpolate
00042 {
00043 public:
00054     InlineInterpolate(QImage *image, unsigned int background){
00055         img = image; ptr = img->bits();
00056         colorTable = img->colorTable();
00057         w=img->width(); h=img->height();
00058         bg=background; truecolor = img->depth() > 8;
00059     }
00064     inline unsigned int interpolate(float x_offset, float y_offset);
00069     inline unsigned int interpolateBackground(float x_offset, float y_offset);
00070 private:
00071     int w, h;
00072     unsigned int p, q, r, s, bg;
00073     unsigned char *ptr;
00074     QVector<QRgb> colorTable;
00075     bool truecolor;
00076     QImage *img;
00077 };
00078 
00079 inline unsigned int InlineInterpolate::interpolate(float x_offset,
00080                                                    float y_offset)
00081 {
00082     int x = qBound(0, (int)x_offset, w-2);
00083     int y = qBound(0, (int)y_offset, h-2);
00084 
00085     if(truecolor){
00086         p = *(((QRgb *)ptr)+(y*w)+x);
00087         q = *(((QRgb *)ptr)+(y*w)+x+1);
00088         r = *(((QRgb *)ptr)+((y+1)*w)+x);
00089         s = *(((QRgb *)ptr)+((y+1)*w)+x+1);
00090     }
00091     else{
00092         p = colorTable[*(ptr+(y*w)+x)];
00093         q = colorTable[*(ptr+(y*w)+x+1)];
00094         r = colorTable[*(ptr+((y+1)*w)+x)];
00095         s = colorTable[*(ptr+((y+1)*w)+x+1)];
00096     }
00097     x_offset -= std::floor(x_offset); y_offset -= std::floor(y_offset);
00098     unsigned int alpha = (unsigned int)(255*x_offset);
00099     unsigned int beta = (unsigned int)(255*y_offset);
00100 
00101     p = BlitzPrivate::interpolate255(p, 255-alpha, q, alpha);
00102     r = BlitzPrivate::interpolate255(r, 255-alpha, s, alpha);
00103     return(BlitzPrivate::interpolate255(p, 255-beta, r, beta));
00104 }
00105 
00106 inline unsigned int InlineInterpolate::interpolateBackground(float x_offset,
00107                                                              float y_offset)
00108 {
00109     int x = (int)x_offset;
00110     int y = (int)y_offset;
00111     p = q = r = s = bg;
00112 
00113     if(truecolor){
00114         if(y >= 0 && y < h && x >= 0 && x < w){
00115             p = *(((QRgb *)ptr)+(y*w)+x);
00116             if(y+1 < h) r = *(((QRgb *)ptr)+((y+1)*w)+x);
00117             if(x+1 < w){
00118                 q = *(((QRgb *)ptr)+(y*w)+x+1);
00119                 if(y+1 < h) q = *(((QRgb *)ptr)+((y+1)*w)+x+1);
00120             }
00121         }
00122     }
00123     else{
00124         if(y >= 0 && y < h && x >= 0 && x < w){
00125             p = colorTable[*(ptr+(y*w)+x)];
00126             if(y+1 < h) r = colorTable[*(ptr+((y+1)*w)+x)];
00127             if(x+1 < w){
00128                 q = colorTable[*(ptr+(y*w)+x+1)];
00129                 if(y+1 < h) s = colorTable[*(ptr+((y+1)*w)+x+1)];
00130             }
00131         }
00132     }
00133     x_offset -= std::floor(x_offset); y_offset -= std::floor(y_offset);
00134     unsigned int alpha = (unsigned int)(255*x_offset);
00135     unsigned int beta = (unsigned int)(255*y_offset);
00136 
00137     p = BlitzPrivate::interpolate255(p, 255-alpha, q, alpha);
00138     r = BlitzPrivate::interpolate255(r, 255-alpha, s, alpha);
00139     return(BlitzPrivate::interpolate255(p, 255-beta, r, beta));
00140 }
00141 
00142 #endif
00143 

qimageblitz

Skip menu "qimageblitz"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

KDE Support

Skip menu "KDE Support"
  • akonadi
  • Decibel
  • grantlee
  • kdewin
  • phonon
  •     Backend
  • polkit-qt
  • qca
  • qimageblitz
  • soprano
  • strigi
  •     searchclient
  •     streamanalyzer
  •     streams
Generated for KDE Support by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal