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

plfilterintensity.cpp

Go to the documentation of this file.
00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: plfilterintensity.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 "plfilterintensity.h"
00013 #include "plbitmap.h"
00014 #include "plpaintlibdefs.h"
00015 
00016 #include  <math.h>
00017 
00018 PLFilterIntensity::PLFilterIntensity(double intensity, PLBYTE offset, double exponent)
00019   : PLFilter(),
00020     m_intensity(intensity),
00021     m_offset(offset),
00022     m_exponent(exponent)
00023 {
00024 
00025 }
00026 
00027 PLFilterIntensity::~PLFilterIntensity()
00028 {
00029 
00030 }
00031 
00032 void PLFilterIntensity::Apply(PLBmp * pBmpSource, PLBmp * pBmpDest) const 
00033 {
00034   double h, s, v;
00035   double intensityFactor;
00036   register int inc=0;
00037   extern void fp_rgb_to_hsv(double* r, double* g, double *b);
00038   extern void fp_hsv_to_rgb(double* r, double* g, double *b);
00039 
00040   // double intensity = 4.0 * m_intensity - 200.0;
00041   double intensity = m_intensity-20;
00042   intensity /= 4.0;
00043   PLASSERT (pBmpSource->GetBitsPerPixel() >= 24);
00044 
00045   pBmpDest->Create (pBmpSource->GetWidth(), 
00046                     pBmpSource->GetHeight(),
00047                     pBmpSource->GetBitsPerPixel(),
00048                     pBmpSource->HasAlpha(),
00049                     pBmpSource->GetResolution());
00050 
00051   PLBYTE ** pSrcLines = pBmpSource->GetLineArray();
00052   PLBYTE ** pDstLines = pBmpDest->GetLineArray();
00053 
00054   register int destWidth = pBmpDest->GetWidth();
00055 
00056   if(pBmpSource->GetBitsPerPixel() == 24)
00057    inc = 3;
00058 
00059   if(pBmpSource->GetBitsPerPixel() == 32)
00060    inc = sizeof(PLPixel32);
00061 
00062   double csupp = intensity/pow(255.0, m_exponent);
00063 
00064   for (int y = 0; y < pBmpDest->GetHeight(); ++y)
00065   { // For each line
00066     PLBYTE * pSrcPixel = pSrcLines[y];
00067     PLBYTE * pDstPixel = pDstLines[y];
00068 
00069     for (register int x = 0; x < destWidth; ++x)
00070     {
00071        // Transform rgb->hsv
00072        h =(double) pSrcPixel[PL_RGBA_RED];
00073        s =(double) pSrcPixel[PL_RGBA_GREEN];
00074        v =(double) pSrcPixel[PL_RGBA_BLUE];
00075 
00076        fp_rgb_to_hsv(&h, &s, &v);
00077 
00078        // Modify the intensity
00079        if (v >= m_offset)
00080         intensityFactor = 1.0 + csupp * pow((v-m_offset), m_exponent);
00081        else
00082         intensityFactor = 1.0;
00083 
00084        v *= intensityFactor;
00085 
00086        // Transform back to rgb.
00087        fp_hsv_to_rgb(&h, &s, &v);
00088 
00089        pDstPixel[PL_RGBA_RED]   = (PLBYTE) h;
00090        pDstPixel[PL_RGBA_GREEN] = (PLBYTE) s;
00091        pDstPixel[PL_RGBA_BLUE]  = (PLBYTE) v;
00092 
00093        if(h >= 255.0)
00094          pDstPixel[PL_RGBA_RED]   = (PLBYTE) 255;
00095        if(s >= 255.0)
00096          pDstPixel[PL_RGBA_GREEN] = (PLBYTE) 255;
00097        if(v >= 255.0)
00098          pDstPixel[PL_RGBA_BLUE]  = (PLBYTE) 255;
00099        if(h <= 0.0)
00100          pDstPixel[PL_RGBA_RED]   = (PLBYTE) 0;
00101        if(s <= 0.0)
00102          pDstPixel[PL_RGBA_GREEN] = (PLBYTE) 0;
00103        if(v <= 0.0)
00104          pDstPixel[PL_RGBA_BLUE]  = (PLBYTE) 0;
00105 
00106        pSrcPixel += inc;
00107        pDstPixel += inc;
00108     }
00109   }
00110 }
00111 
00112 /*
00113 /--------------------------------------------------------------------
00114 |
00115 |      $Log: plfilterintensity.cpp,v $
00116 |      Revision 1.1  2004/05/21 21:02:53  maxx
00117 |      Initial Version of vuVolume, moderatly changed to make it compile on my windows and linux machine.
00118 |
00119 |      Revision 1.3  2003/01/25 02:54:42  mspindle
00120 |      *** empty log message ***
00121 |
00122 |      Revision 1.2  2003/01/07 16:14:59  sbergner
00123 |      *** empty log message ***
00124 |
00125 |      Revision 1.1  2002/11/13 01:59:48  mspindle
00126 |      *** empty log message ***
00127 |
00128 |      Revision 1.4  2001/10/16 17:12:26  uzadow
00129 |      Added support for resolution information (Luca Piergentili)
00130 |
00131 |      Revision 1.3  2001/10/06 22:03:26  uzadow
00132 |      Added PL prefix to basic data types.
00133 |
00134 |      Revision 1.2  2001/10/06 15:32:22  uzadow
00135 |      Removed types LPBYTE, DWORD, UCHAR, VOID and INT from the code.
00136 |
00137 |      Revision 1.1  2001/09/16 19:03:23  uzadow
00138 |      Added global name prefix PL, changed most filenames.
00139 |
00140 |      Revision 1.5  2001/09/15 21:02:44  uzadow
00141 |      Cleaned up stdpch.h and config.h to make them internal headers.
00142 |
00143 |      Revision 1.4  2001/02/04 14:31:52  uzadow
00144 |      Member initialization list cleanup (Erik Hoffmann).
00145 |
00146 |      Revision 1.3  2001/01/15 15:05:31  uzadow
00147 |      Added PLBmp::ApplyFilter() and PLBmp::CreateFilteredCopy()
00148 |
00149 |      Revision 1.2  2000/12/18 22:42:53  uzadow
00150 |      Replaced RGBAPIXEL with PLPixel32.
00151 |
00152 |      Revision 1.1  2000/11/06 23:20:22  uzadow
00153 |      Added Contrast, Intensity and Lightness filters by
00154 |      Thomas Hirschmann
00155 |
00156 |
00157 \--------------------------------------------------------------------
00158 */

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