Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

plfilterlightness.cpp

Go to the documentation of this file.
00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: plfilterlightness.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 "plfilterlightness.h"
00013 #include "plbitmap.h"
00014 
00015 PLFilterLightness::PLFilterLightness(int lightness)
00016 : PLFilter(),
00017   m_lightness(lightness)
00018 {
00019 }
00020 
00021 PLFilterLightness::~PLFilterLightness()
00022 {
00023 
00024 }
00025 
00026 void PLFilterLightness::Apply(PLBmp * pBmpSource, PLBmp * pBmpDest) const
00027 {
00028   double lightness = 2.55 * (double) (m_lightness);
00029 
00030   PLASSERT (pBmpSource->GetBitsPerPixel() == 32);
00031 
00032   pBmpDest->Create (pBmpSource->GetWidth(),
00033                     pBmpSource->GetHeight(),
00034                     pBmpSource->GetBitsPerPixel(),
00035                     pBmpSource->HasAlpha(),
00036                     pBmpSource->GetResolution());
00037 
00038   PLBYTE ** pSrcLines = pBmpSource->GetLineArray();
00039   PLBYTE ** pDstLines = pBmpDest->GetLineArray();
00040 
00041   int destWidth = pBmpDest->GetWidth();
00042 
00043   double red, green, blue;
00044 
00045   for (int y = 0; y < pBmpDest->GetHeight(); ++y)
00046   { // For each line
00047     PLBYTE * pSrcPixel = pSrcLines[y];
00048     PLBYTE * pDstPixel = pDstLines[y];
00049 
00050     for (int x = 0; x < destWidth; ++x)
00051     {
00052        red   = (double) pSrcPixel[PL_RGBA_RED] + lightness;
00053        green = (double) pSrcPixel[PL_RGBA_GREEN] + lightness;
00054        blue  = (double) pSrcPixel[PL_RGBA_BLUE] + lightness;
00055 
00056        if(red >= 255.0)
00057         pDstPixel[PL_RGBA_RED] = (PLBYTE) 255;
00058        else if (red < 0.0)
00059         pDstPixel[PL_RGBA_RED] = (PLBYTE) 0;
00060        else
00061         pDstPixel[PL_RGBA_RED] = (PLBYTE) red;
00062 
00063        if(green >= 255.0)
00064         pDstPixel[PL_RGBA_GREEN] = (PLBYTE) 255;
00065        else if (green < 0.0)
00066         pDstPixel[PL_RGBA_GREEN] = (PLBYTE) 0;
00067        else
00068         pDstPixel[PL_RGBA_GREEN] = (PLBYTE) green;
00069 
00070        if(blue >= 255.0)
00071         pDstPixel[PL_RGBA_BLUE] = (PLBYTE) 255;
00072        else if (blue < 0.0)
00073         pDstPixel[PL_RGBA_BLUE] = (PLBYTE) 0;
00074        else
00075         pDstPixel[PL_RGBA_BLUE] = (PLBYTE) blue;
00076 
00077        pSrcPixel += 4;
00078        pDstPixel += 4;
00079     }
00080   }
00081 }

Generated on Wed Dec 15 21:20:30 2004 for vuVolume by  doxygen 1.3.9.1