[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd/cvd internal/gl_types.h internal/rgb_com...
From: |
Georg Klein |
Subject: |
[libcvd-members] libcvd/cvd internal/gl_types.h internal/rgb_com... |
Date: |
Wed, 22 Oct 2008 15:43:37 +0000 |
CVSROOT: /sources/libcvd
Module name: libcvd
Changes by: Georg Klein <georgklein> 08/10/22 15:43:37
Modified files:
cvd/internal : gl_types.h rgb_components.h
Added files:
cvd : la.h
Log message:
Added luminance-alpha pixel type La<T> (similar to Rgba<T>)
Added arithmetic ops for Rgba<T> and La<T> much like they exist for
Rgb<T>
(These only make sense if using pre-multiplied alpha)
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/la.h?cvsroot=libcvd&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/gl_types.h?cvsroot=libcvd&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/rgb_components.h?cvsroot=libcvd&r1=1.7&r2=1.8
Patches:
Index: internal/gl_types.h
===================================================================
RCS file: /sources/libcvd/libcvd/cvd/internal/gl_types.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- internal/gl_types.h 16 Jul 2008 02:38:24 -0000 1.4
+++ internal/gl_types.h 22 Oct 2008 15:43:36 -0000 1.5
@@ -29,6 +29,7 @@
#include <cvd/byte.h>
#include <cvd/rgb8.h>
#include <cvd/rgba.h>
+#include <cvd/la.h>
namespace CVD
{
@@ -189,6 +190,57 @@
static const int format=GL_RGBA;
static const int type =GL_DOUBLE;
};
+
+
+ //La<*> types
+ template<> struct data<La<unsigned char> >
+ {
+ static const int format=GL_LUMINANCE_ALPHA;
+ static const int type =GL_UNSIGNED_BYTE;
+ };
+
+ template<> struct data<La<signed char> >
+ {
+ static const int format=GL_LUMINANCE_ALPHA;
+ static const int type =GL_BYTE;
+ };
+
+ template<> struct data<La<unsigned short> >
+ {
+ static const int format=GL_LUMINANCE_ALPHA;
+ static const int type =GL_UNSIGNED_SHORT;
+ };
+
+ template<> struct data<La<short> >
+ {
+ static const int format=GL_LUMINANCE_ALPHA;
+ static const int type =GL_SHORT;
+ };
+
+ template<> struct data<La<unsigned int> >
+ {
+ static const int format=GL_LUMINANCE_ALPHA;
+ static const int type =GL_UNSIGNED_INT;
+ };
+
+ template<> struct data<La<int> >
+ {
+ static const int format=GL_LUMINANCE_ALPHA;
+ static const int type =GL_INT;
+ };
+
+ template<> struct data<La<float> >
+ {
+ static const int format=GL_LUMINANCE_ALPHA;
+ static const int type =GL_FLOAT;
+ };
+
+ template<> struct data<La<double> >
+ {
+ static const int format=GL_LUMINANCE_ALPHA;
+ static const int type =GL_DOUBLE;
+ };
+
//Rgb8 type
template<> struct data<Rgb8>
Index: internal/rgb_components.h
===================================================================
RCS file: /sources/libcvd/libcvd/cvd/internal/rgb_components.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- internal/rgb_components.h 12 Jun 2008 13:04:13 -0000 1.7
+++ internal/rgb_components.h 22 Oct 2008 15:43:36 -0000 1.8
@@ -24,6 +24,7 @@
#include <cvd/rgb.h>
#include <cvd/rgba.h>
#include <cvd/rgb8.h>
+#include <cvd/la.h>
#include <cvd/internal/builtin_components.h>
#include <cvd/internal/pixel_traits.h>
@@ -88,6 +89,22 @@
}
};
+ template<class P> struct Component<La<P> >
+ {
+ typedef P type;
+ static const size_t count = 2;
+
+ static const P& get(const La<P>& pixel, size_t i)
+ {
+ return *(reinterpret_cast<const P*>(&pixel)+i);
+ }
+
+ static P& get(La<P>& pixel, size_t i)
+ {
+ return *(reinterpret_cast<P*>(&pixel)+i);
+ }
+ };
+
template <class T> struct is_Rgb { enum { value = 0 }; };
template <class T> struct is_Rgb<Rgb<T> > { enum { value = 1 };
};
template <> struct is_Rgb<Rgb8> { enum { value = 1 }; };
@@ -99,6 +116,18 @@
typedef Rgb<typename Pixel::traits<T>::float_type> float_type;
};
+ template<class T, int LIFT> struct traits<Rgba<T>, LIFT>
+ {
+ typedef Rgba<typename Pixel::traits<T>::wider_type>
wider_type;
+ typedef Rgba<typename Pixel::traits<T>::float_type>
float_type;
+ };
+
+ template<class T, int LIFT> struct traits<La<T>, LIFT>
+ {
+ typedef La<typename Pixel::traits<T>::wider_type> wider_type;
+ typedef La<typename Pixel::traits<T>::float_type> float_type;
+ };
+
template<int LIFT> struct traits<Rgb8, LIFT>
{
typedef Rgb<int> wider_type;
@@ -130,6 +159,53 @@
template <class T, class S> inline Rgb<T>& operator/=(Rgb<T>&
a, const S& b) { Rgb_ops<Rgb<T> >::div(a,b); return a; }
+ template <class T> struct Rgba_ops {
+ template <class S> static inline T sum(const T& a, const S&
b) { return T(a.red+b.red, a.green+b.green, a.blue+b.blue, a.alpha+b.alpha); }
+ template <class S> static inline void add(T& a, const S& b) {
a.red+=b.red; a.green+=b.green; a.blue+=b.blue; a.alpha+=b.alpha;}
+ template <class S> static inline T diff(const T& a, const S&
b) { return T(a.red-b.red, a.green-b.green, a.blue-b.blue, a.alpha-b.alpha); }
+ template <class S> static inline void sub(T& a, const S& b) {
a.red-=b.red; a.green-=b.green; a.blue-=b.blue; a.alpha-=b.alpha; }
+ template <class S> static inline T prod(const T& a, const S&
b) { return T(a.red*b, a.green*b, a.blue*b, a.alpha*b); }
+ template <class S> static inline void mul(T& a, const S& b) {
a.red*=b; a.green*=b; a.blue*=b; a.alpha*=b; }
+ template <class S> static inline T quot(const T& a, const S&
b) { return T(a.red/b, a.green/b, a.blue/b, a.alpha/b); }
+ template <class S> static inline void div(T& a, const S& b) {
a.red/=b; a.green/=b; a.blue/=b; a.alpha/=b;}
+ template <class S> static inline void assign(T& a, const S&
b) { a.red=b.red; a.green=b.green; a.blue=b.blue; a.alpha=b.alpha; }
+ };
+
+ template <class T, class S> inline Rgba<T> operator+(const
Rgba<T>& a, const Rgba<S>& b) { return Rgba_ops<Rgba<T> >::sum(a,b); }
+ template <class T, class S> inline Rgba<T>& operator+=(Rgba<T>&
a, const Rgba<S>& b) { Rgba_ops<Rgba<T> >::add(a,b); return a; }
+ template <class T, class S> inline Rgba<T> operator-(const
Rgba<T>& a, const Rgba<S>& b) { return Rgba_ops<Rgba<T> >::diff(a,b); }
+ template <class T, class S> inline Rgba<T>& operator-=(Rgba<T>&
a, const Rgba<S>& b) { Rgba_ops<Rgba<T> >::sub(a,b); return a; }
+ template <class T, class S> inline Rgba<T> operator*(const
Rgba<T>& a, const S& b) { return Rgba_ops<Rgba<T> >::prod(a,b); }
+ template <class T, class S> inline Rgba<T> operator*(const S&
b, const Rgba<T>& a) { return Rgba_ops<Rgba<T> >::prod(a,b); }
+ template <class T, class S> inline Rgba<T>& operator*=(Rgba<T>&
a, const S& b) { Rgba_ops<Rgba<T> >::mul(a,b); return a; }
+ template <class T, class S> inline Rgba<T> operator/(const
Rgba<T>& a, const S& b) { return Rgba_ops<Rgba<T> >::quot(a,b); }
+ template <class T, class S> inline Rgba<T> operator/(const S&
b, const Rgba<T>& a) { return Rgba_ops<Rgba<T> >::quot(a,b); }
+ template <class T, class S> inline Rgba<T>& operator/=(Rgba<T>&
a, const S& b) { Rgba_ops<Rgba<T> >::div(a,b); return a; }
+
+ template <class T> struct La_ops {
+ template <class S> static inline T sum(const T& a, const S&
b) { return T(a.red+b.red, a.alpha+b.alpha); }
+ template <class S> static inline void add(T& a, const S& b) {
a.red+=b.red; a.alpha+=b.alpha;}
+ template <class S> static inline T diff(const T& a, const S&
b) { return T(a.red-b.red, a.alpha-b.alpha); }
+ template <class S> static inline void sub(T& a, const S& b) {
a.red-=b.red; a.alpha-=b.alpha; }
+ template <class S> static inline T prod(const T& a, const S&
b) { return T(a.red*b, a.alpha*b); }
+ template <class S> static inline void mul(T& a, const S& b) {
a.red*=b; a.alpha*=b; }
+ template <class S> static inline T quot(const T& a, const S&
b) { return T(a.red/b, a.alpha/b); }
+ template <class S> static inline void div(T& a, const S& b) {
a.red/=b; a.alpha/=b;}
+ template <class S> static inline void assign(T& a, const S&
b) { a.red=b.red; a.alpha=b.alpha; }
+ };
+
+ template <class T, class S> inline La<T> operator+(const La<T>&
a, const La<S>& b) { return La_ops<La<T> >::sum(a,b); }
+ template <class T, class S> inline La<T>& operator+=(La<T>& a,
const La<S>& b) { La_ops<La<T> >::add(a,b); return a; }
+ template <class T, class S> inline La<T> operator-(const La<T>&
a, const La<S>& b) { return La_ops<La<T> >::diff(a,b); }
+ template <class T, class S> inline La<T>& operator-=(La<T>& a,
const La<S>& b) { La_ops<La<T> >::sub(a,b); return a; }
+ template <class T, class S> inline La<T> operator*(const La<T>&
a, const S& b) { return La_ops<La<T> >::prod(a,b); }
+ template <class T, class S> inline La<T> operator*(const S& b,
const La<T>& a) { return La_ops<La<T> >::prod(a,b); }
+ template <class T, class S> inline La<T>& operator*=(La<T>& a,
const S& b) { La_ops<La<T> >::mul(a,b); return a; }
+ template <class T, class S> inline La<T> operator/(const La<T>&
a, const S& b) { return La_ops<La<T> >::quot(a,b); }
+ template <class T, class S> inline La<T> operator/(const S& b,
const La<T>& a) { return La_ops<La<T> >::quot(a,b); }
+ template <class T, class S> inline La<T>& operator/=(La<T>& a,
const S& b) { La_ops<La<T> >::div(a,b); return a; }
+
+
}
#endif
Index: la.h
===================================================================
RCS file: la.h
diff -N la.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ la.h 22 Oct 2008 15:43:36 -0000 1.1
@@ -0,0 +1,113 @@
+/*
+ This file is part of the CVD Library.
+
+ Copyright (C) 2005 The Authors
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+#ifndef CVD_LA_H
+#define CVD_LA_H
+
+#include <iostream>
+#include <cvd/internal/is_pod.h>
+
+namespace CVD {
+
+
+ //////////////////////////////
+ // CVD::La
+ // Template class to represent luminance and alpha components
+ //
+ /// A colour consisting of luminance and alpha components
+ /// @param T The datatype of each component
+ /// @ingroup gImage
+ template <typename T>
+ class La
+ {
+ public:
+ /// Default constructor. Does nothing.
+ La() {}
+ /// Constructs a colour as specified
+ /// @param l The luminance component
+ /// @param a The alpha component
+ La(T l, T a) : luminance(l), alpha(a) {}
+
+ T luminance; ///< The luminance component
+ T green; ///< The green component
+ T blue; ///< The blue component
+ T alpha; ///< The alpha component
+
+ /// Assignment operator
+ /// @param c The colour to copy from
+ La<T>& operator=(const La<T>& c)
+ {luminance = c.luminance; alpha = c.alpha; return *this;}
+
+ /// Assignment operator between two different storage types, using the
standard casts as necessary
+ /// @param c The colour to copy from
+ template <typename T2>
+ La<T>& operator=(const La<T2>& c){
+ luminance = static_cast<T>(c.luminance);
+ alpha = static_cast<T>(c.alpha);
+ return *this;
+ }
+
+ /// Logical equals operator. Returns true if each component is the same.
+ /// @param c La to compare with
+ bool operator==(const La<T>& c) const
+ {return luminance == c.luminance && alpha == c.alpha;}
+
+ /// Logical not-equals operator. Returns true unless each component is
the same.
+ /// @param c La to compare with
+ bool operator!=(const La<T>& c) const
+ {return luminance != c.luminance || alpha != c.alpha;}
+
+ };
+
+ /// Write the colour to a stream in the format "(luminance,alpha)"
+ /// @param os The stream
+ /// @param x The colour object
+ /// @relates La
+ template <typename T>
+ std::ostream& operator <<(std::ostream& os, const La<T>& x)
+ {
+ return os << "(" << x.luminance << "," << x.alpha << ")";
+ }
+
+ /// Write the colour to a stream in the format "(luminance,alpha)"
+ /// @param os The stream
+ /// @param x The colour object
+ /// @relates La
+ inline std::ostream& operator <<(std::ostream& os, const La<unsigned char>&
x)
+ {
+ return os << "(" << static_cast<unsigned int>(x.luminance) << ","
+ << static_cast<unsigned int>(x.alpha) << ")";
+ }
+
+#ifndef DOXYGEN_IGNORE_INTERNAL
+ namespace Internal
+ {
+ template<class C> struct is_POD<La<C> >
+ {
+ enum { is_pod = is_POD<C>::is_pod };
+ };
+ }
+#endif
+
+
+
+} // end namespace
+#endif
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] libcvd/cvd internal/gl_types.h internal/rgb_com...,
Georg Klein <=