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

agg_gray8.h

00001 //----------------------------------------------------------------------------
00002 // Anti-Grain Geometry - Version 2.2
00003 // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
00004 //
00005 // Permission to copy, use, modify, sell and distribute this software 
00006 // is granted provided this copyright notice appears in all copies. 
00007 // This software is provided "as is" without express or implied
00008 // warranty, and with no claim as to its suitability for any purpose.
00009 //
00010 //----------------------------------------------------------------------------
00011 // Contact: mcseem@antigrain.com
00012 //          mcseemagg@yahoo.com
00013 //          http://www.antigrain.com
00014 //----------------------------------------------------------------------------
00015 //
00016 // color type gray8
00017 //
00018 //----------------------------------------------------------------------------
00019 
00020 #ifndef AGG_GRAY8_INCLUDED
00021 #define AGG_GRAY8_INCLUDED
00022 
00023 #include "agg_basics.h"
00024 #include "agg_color_rgba.h"
00025 #include "agg_color_rgba8.h"
00026 
00027 namespace agg
00028 {
00029 
00030     //===================================================================gray8
00031     struct gray8 
00032     {
00033         typedef int8u alpha_type;
00034         int8u v;
00035         int8u a;
00036 
00037         //--------------------------------------------------------------------
00038         gray8() {}
00039 
00040         //--------------------------------------------------------------------
00041         gray8(unsigned v_, unsigned a_=255) :
00042             v(int8u(v_)), a(int8u(a_)) {}
00043 
00044         //--------------------------------------------------------------------
00045         gray8(const rgba& c) :
00046             v(int8u((0.299*c.r + 0.587*c.g + 0.114*c.b) * 255.0 + 0.5)),
00047             a(int8u(c.a*255.0)) {}
00048 
00049         //--------------------------------------------------------------------
00050         gray8(const rgba8& c) :
00051             v((c.r*77 + c.g*150 + c.b*29) >> 8),
00052             a(c.a) {}
00053 
00054         //--------------------------------------------------------------------
00055         void clear()
00056         {
00057             v = a = 0;
00058         }
00059 
00060         //--------------------------------------------------------------------
00061         const gray8& transparent()
00062         {
00063             a = 0;
00064             return *this;
00065         }
00066 
00067         //--------------------------------------------------------------------
00068         void opacity(double a_)
00069         {
00070             if(a_ < 0.0) a_ = 0.0;
00071             if(a_ > 1.0) a_ = 1.0;
00072             a = int8u(a_ * 255.0);
00073         }
00074 
00075         //--------------------------------------------------------------------
00076         double opacity() const
00077         {
00078             return double(a) / 255.0;
00079         }
00080 
00081         //--------------------------------------------------------------------
00082         gray8 gradient(gray8 c, double k) const
00083         {
00084             gray8 ret;
00085             int ik = int(k * 256);
00086             ret.v = int8u(int(v) + (((int(c.v) - int(v)) * ik) >> 8));
00087             ret.a = int8u(int(a) + (((int(c.a) - int(a)) * ik) >> 8));
00088             return ret;
00089         }
00090 
00091         //--------------------------------------------------------------------
00092         gray8 pre() const
00093         {
00094             return gray8((v*a) >> 8, a);
00095 
00096         }
00097 
00098         //--------------------------------------------------------------------
00099         static gray8 no_color() { return gray8(0,0); }
00100     };
00101 
00102 
00103 }
00104 
00105 
00106 
00107 
00108 #endif

Generated on Wed Feb 9 11:31:34 2005 for OpenGUI by  doxygen 1.4.0