CBitmapManip Class Reference

Performs bitmap manipulations. More...

#include <bmanip.h>

List of all members.

Public Member Functions

BOOL ApplyGaussianFilter (BYTE *bits, INT32 wid, INT32 hei, INT32 matrix[3][3], BOOL IgnoreBlankPixels=FALSE)
 Applies a 3x3 matrix to the bitmap's alpha channel.


Detailed Description

Performs bitmap manipulations.

Author:
David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
Date:
17-3-98
See also:
WebStyle program

Definition at line 124 of file bmanip.h.


Member Function Documentation

BOOL CBitmapManip::ApplyGaussianFilter BYTE *  bits,
INT32  wid,
INT32  hei,
INT32  matrix[3][3],
BOOL  bIgnoreBlankPixels = FALSE
 

Applies a 3x3 matrix to the bitmap's alpha channel.

Author:
David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
Date:
1-10-98
Parameters:
The source bitmap bits, its width and height and the matrix to apply [INPUTS]
Returns:
-
Notes: Remember DIB's are held upside-down in memory

Definition at line 124 of file bmanip.cpp.

00126 {
00127     // we need a temporary bitmap
00128     INT32 ksize = (wid) * (hei) * 4;
00129 
00130     BYTE * tmpBits = new BYTE[ksize];
00131 
00132     if (!tmpBits)
00133         return FALSE;
00134 
00135     memcpy(tmpBits, bits, ksize);
00136 
00137     INT32 size = wid * hei;
00138     size -= wid * 2;
00139     size -= 2;
00140 
00141     COLORREF *srcPtr = ((COLORREF *)bits);
00142     COLORREF *destPtr = ((COLORREF *)tmpBits) + wid + 1;
00143 
00144     UINT32 srcAlpha = 0;
00145     UINT32 destAlpha = 0;
00146 
00147     INT32 incBy1 = wid*4;
00148 
00149     INT32 sum = 0;
00150 
00151     INT32 posX = 0;
00152     INT32 posY = 1;
00153 
00154     COLORREF Area[3][3];
00155 
00156     INT32 i = 0;
00157     INT32 j = 0;
00158 
00159     BYTE R = 0;
00160     BYTE A = 0;
00161 
00162     INT32 SumR;
00163     INT32 SumA;
00164 
00165     while (posY < hei - 1)
00166     {
00167         // transfer colour
00168         for (i = 0 ; i < 3; i++)
00169         {
00170             for (j = 0 ; j < 3; j++)
00171             {
00172                 Area[i][j] = *(srcPtr + i * wid + j);
00173             }
00174         }
00175 
00176         // now, ignore transparent areas
00177         if (((Area[1][1] & 0xff000000) >> 24) != 0xff || !bIgnoreBlankPixels)
00178         {
00179             SumR = 0;
00180             SumA = 0;
00181             sum = 0;
00182 
00183             for (i = 0 ; i < 3; i++)
00184             {
00185                 for (j = 0 ; j < 3; j++)
00186                 {
00187                     A = (BYTE)(Area[i][j] & 0xff000000) >> 24;
00188                     R = (BYTE)(Area[i][j] & 0xff);
00189                     
00190                     if (A != 0xff || !bIgnoreBlankPixels)
00191                     {
00192                         SumR += ((INT32)R) * matrix[i][j];
00193                         SumA += ((INT32)A) * matrix[i][j];
00194                         sum += matrix[i][j];
00195                     }
00196                 }
00197             }
00198 
00199             SumR /= sum;
00200             SumA /= sum;
00201             
00202             *destPtr = SumR + (SumR << 8) + (SumR << 16) + (SumA << 24);
00203         }
00204 
00205         // increment of pointers
00206         posX ++;
00207         
00208         destPtr ++;
00209         srcPtr ++;
00210 
00211         if (posX >= wid - 3)
00212         {
00213             destPtr += 3;
00214             srcPtr += 3;
00215             posX = 0;
00216             posY ++;
00217         }   
00218     }
00219 
00220     memcpy(bits, tmpBits, wid * hei * 4);
00221 
00222     delete [] tmpBits;
00223 
00224     return TRUE;
00225 }


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:51:57 2007 for Camelot by  doxygen 1.4.4