PicScalerRGB24Impl.cpp

Go to the documentation of this file.
00001 
00038 #ifdef _WINDOWS
00039 #define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
00040 #include <windows.h>
00041 #else
00042 #include <stdio.h>
00043 #endif
00044 
00045 #include <string.h>
00046 #include <stdlib.h>
00047 #include <math.h>
00048 
00049 #include "PicScalerRGB24Impl.h"
00050 
00051 /*
00052 ===========================================================================
00053         Interface Methods.
00054 ===========================================================================
00055 */
00063 int PicScalerRGB24Impl::Scale(void* pOutImg, void* pInImg)
00064 {
00065         if( (pOutImg == NULL) || (pInImg == NULL) )
00066                 return(0);
00067 
00068         unsigned char*  pSrc            = (unsigned char*)pInImg;
00069         unsigned char*  pDst            = (unsigned char*)pOutImg;
00070         
00071         double scalex = ((double)_widthIn)/((double)_widthOut);
00072         double scaley = ((double)_heightIn)/((double)_heightOut);
00073 
00074         int x,y,posx,posy,i,j;
00075 
00076         for(y = 0; y < _heightOut; y++)
00077         {
00078                 posy = (int)((scaley * (double)y) + 0.5);
00079                 if(posy < 0)    posy = 0;
00080                 else if(posy >= _heightIn) posy = _heightIn-1;
00081 
00082                 for(x = 0; x < _widthOut; x++)
00083                 {
00084                         posx = (int)((scalex * (double)x) + 0.5);
00085                         if(posx < 0) posx = 0;
00086                         else if(posx >= _widthIn) posx = _widthIn-1;
00087 
00089                         int ai = (posy*_widthIn*3) + (posx*3);
00090                         int b = 7 * (int)(*(pSrc + ai));
00091                         int g = 7 * (int)(*(pSrc + (ai+1)));
00092                         int r = 7 * (int)(*(pSrc + (ai+2)));
00093                         for(i = -1; i <= 1; i++)
00094                         {
00095                                 int row = posy + i;
00096                                 if(row < 0)     row = 0;
00097                                 else if(row >= _heightIn) row = _heightIn-1;
00098                                 for(j = -1; j <= 1; j++)
00099                                 {
00100                                         int col = posx + j;
00101                                         if(col < 0) col = 0;
00102                                         else if(col >= _widthIn) col = _widthIn-1;
00103 
00104                                         int aii = (row*_widthIn*3) + (col*3);
00105                                         b += (int)(*(pSrc + aii));
00106                                         g += (int)(*(pSrc + (aii+1)));
00107                                         r += (int)(*(pSrc + (aii+2)));
00108 
00109                                 }//end for j...
00110                         }//end for i...
00111 
00113                         int ao = (y*_widthOut*3) + (x*3);
00114                         *(pDst + ao)                    = (unsigned char)((b + 8) >> 4);
00115                         *(pDst + (ao+1))        = (unsigned char)((g + 8) >> 4);
00116                         *(pDst + (ao+2))        = (unsigned char)((r + 8) >> 4);
00117 
00118                 }//end for x...
00119                 
00120         }//end for y...
00121 
00122         return(1);
00123 }//end Scale.
00124 

Generated on Fri Mar 13 14:12:38 2009 for RTVC by  doxygen 1.5.3