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

key_matte_threshold_Filter.cpp

Go to the documentation of this file.
00001 
00002 #include <key_matte_threshold_Filter.h>
00003 #include <math.h>
00004 
00005 /* ---------------------------------------------------------------------- */
00006 key_matte_threshold_Filter::key_matte_threshold_Filter(int value) :
00007     phFilter("key_matte_threshold_Filter")
00008 
00009 {
00010     this->m_format = (phImageGREY8);
00011 
00012     this->set(value);
00013 }
00014 
00015 /* ---------------------------------------------------------------------- */
00016 key_matte_threshold_Filter::~key_matte_threshold_Filter()
00017 {
00018 }
00019 
00020 /* ------------------------------------------------------------------------ */
00021 phFilter *key_matte_threshold_Filter::cloneFilter()
00022 {
00023     return (phFilter *)new key_matte_threshold_Filter(     this->m_value
00024                 );
00025 }
00026 
00027 /* ---------------------------------------------------------------------- */
00028 int key_matte_threshold_Filter::set(int value)
00029 {
00030     this->m_value = value;
00031     
00032     return phSUCCESS;
00033 }
00034 
00035 /* ---------------------------------------------------------------------- */
00036 int key_matte_threshold_Filter::filter()
00037 {
00038     phFUNCTION("key_matte_threshold_Filter::filter")
00039     
00040     unsigned int    row = 0;
00041     unsigned int    pixel = 0;
00042     unsigned int    index = 0; /* r:0 g:1 b:2 */
00043     const uint32_t  ai = 3;
00044     uint32_t        pv = 0;
00045     static float    scale_log_range_factor  = 255 / log(255);
00046     
00047     unsigned int x, y, d = 0;
00048    
00049     /* Begin filter */
00050     rc = this->m_workspaceImage->convert(phImageRGBA32);
00051     phPRINT_RC(rc,NULL,"Image->convert(outputFormat) failed.");
00052 
00053     /* rc == 0 means conversion happened */
00054     /* rc == 1 means no conversion */
00055     if (rc == phSUCCESS)
00056     {
00057         rc = this->setFilterVars();
00058         phPRINT_RC(rc,NULL,"setFilterVars");
00059     }
00060 
00061     for ( y = 0; y < height; y++ )
00062     {
00063         row = y * width;
00064         for ( x = 0; x < width; x++ ) 
00065         {
00066             pixel = (x+row)*depth;
00067             pv = (Image)[pixel+index];
00068             for (d = 0; d < depth; d++)
00069             {
00070                 if (d != index) (Image)[pixel+d] = 0;
00071             }
00072 
00073             if (pv < this->m_value)
00074             {
00075                 (Image)[pixel+ai/* alpha channel = 3 */] = 0;
00076             }
00077             else
00078             {
00079                 pv -= this->m_value;
00080                 //pv *= pv;
00081                 pv = log(pv) * scale_log_range_factor;
00082                 //pv += 100;
00083                 //if (pv > 0) pv /= 255;
00084                 if (pv > 255) pv = 255;
00085                 (Image)[pixel+ai/* alpha channel = 3 */] = pv; /* 185 */
00086             }
00087         }
00088     }
00089     
00090     return phSUCCESS;
00091 }
00092 
00093 




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:05 2007 for phission by  doxygen 1.4.4