00001 /* 00002 /-------------------------------------------------------------------- 00003 | 00004 | $Id: plfiltergrayscale.cpp,v 1.1 2004/05/21 21:02:53 maxx Exp $ 00005 | 00006 | Copyright (c) 1996-1998 Ulrich von Zadow 00007 | 00008 \-------------------------------------------------------------------- 00009 */ 00010 00011 #include "plstdpch.h" 00012 #include "plfiltergrayscale.h" 00013 #include "plbitmap.h" 00014 00015 00017 // Construction/Destruction 00019 00020 PLFilterGrayscale::PLFilterGrayscale() : PLFilter() 00021 { 00022 } 00023 00024 PLFilterGrayscale::~PLFilterGrayscale() 00025 { 00026 00027 } 00028 00029 void PLFilterGrayscale::Apply(PLBmp * pBmpSource, PLBmp * pBmpDest) const 00030 { 00031 // Only works for 32 bpp bitmaps at the moment. 00032 PLASSERT (pBmpSource->GetBitsPerPixel() == 32); 00033 00034 pBmpDest->Create (pBmpSource->GetWidth(), pBmpSource->GetHeight(), 8, 00035 false, pBmpSource->GetResolution()); 00036 PLBYTE ** pSrcLines = pBmpSource->GetLineArray(); 00037 PLBYTE ** pDstLines = pBmpDest->GetLineArray(); 00038 00039 for (int y = 0; y<pBmpDest->GetHeight(); ++y) 00040 { // For each line 00041 PLBYTE * pSrcPixel = pSrcLines[y]; 00042 PLBYTE * pDstPixel = pDstLines[y]; 00043 00044 for (int x = 0; x < pBmpDest->GetWidth(); ++x) 00045 { // For each pixel 00046 // For the coefficients used, see http://www.inforamp.net/~poynton/ 00047 // We could approximate this for more speed by using 00048 // Y = (54 * R + 183 * G + 19 * B)/256 like libpng does. 00049 *pDstPixel = PLBYTE (pSrcPixel[PL_RGBA_RED]*0.212671+ 00050 pSrcPixel[PL_RGBA_GREEN]*0.715160+ 00051 pSrcPixel[PL_RGBA_BLUE]*0.072169); 00052 pSrcPixel += sizeof(PLPixel32); 00053 ++pDstPixel; 00054 } 00055 } 00056 } 00057 00058 /* 00059 /-------------------------------------------------------------------- 00060 | 00061 | $Log: plfiltergrayscale.cpp,v $ 00062 | Revision 1.1 2004/05/21 21:02:53 maxx 00063 | Initial Version of vuVolume, moderatly changed to make it compile on my windows and linux machine. 00064 | 00065 | Revision 1.1 2002/11/13 01:59:48 mspindle 00066 | *** empty log message *** 00067 | 00068 | Revision 1.3 2001/10/16 17:12:26 uzadow 00069 | Added support for resolution information (Luca Piergentili) 00070 | 00071 | Revision 1.2 2001/10/06 22:37:08 uzadow 00072 | Linux compatibility. 00073 | 00074 | Revision 1.1 2001/09/16 19:03:23 uzadow 00075 | Added global name prefix PL, changed most filenames. 00076 | 00077 | Revision 1.7 2001/02/04 14:31:52 uzadow 00078 | Member initialization list cleanup (Erik Hoffmann). 00079 | 00080 | Revision 1.6 2001/01/15 15:05:31 uzadow 00081 | Added PLBmp::ApplyFilter() and PLBmp::CreateFilteredCopy() 00082 | 00083 | Revision 1.5 2000/12/18 22:42:53 uzadow 00084 | Replaced RGBAPIXEL with PLPixel32. 00085 | 00086 | Revision 1.4 2000/09/26 10:47:41 Administrator 00087 | Added comment 00088 | 00089 | Revision 1.3 2000/01/16 20:43:15 anonymous 00090 | Removed MFC dependencies 00091 | 00092 | Revision 1.2 1999/12/08 16:31:40 Ulrich von Zadow 00093 | Unix compatibility 00094 | 00095 | Revision 1.1 1999/10/21 16:05:17 Ulrich von Zadow 00096 | Moved filters to separate directory. Added Crop, Grayscale and 00097 | GetAlpha filters. 00098 | 00099 | Revision 1.1 1999/10/19 21:29:44 Ulrich von Zadow 00100 | Added filters. 00101 | 00102 | 00103 \-------------------------------------------------------------------- 00104 */