[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd/cvd internal/convert_pixel_types.h inter...
From: |
Edward Rosten |
Subject: |
[libcvd-members] libcvd/cvd internal/convert_pixel_types.h inter... |
Date: |
Wed, 24 Jun 2009 09:46:13 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Changes by: Edward Rosten <edrosten> 09/06/24 09:46:13
Modified files:
cvd/internal : convert_pixel_types.h rgb_components.h
Added files:
cvd : argb.h
Log message:
ARGB datatype patch from Denis Chekhlov.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/argb.h?cvsroot=libcvd&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/convert_pixel_types.h?cvsroot=libcvd&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/rgb_components.h?cvsroot=libcvd&r1=1.9&r2=1.10
Patches:
Index: internal/convert_pixel_types.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/internal/convert_pixel_types.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- internal/convert_pixel_types.h 27 Jul 2006 11:15:42 -0000 1.11
+++ internal/convert_pixel_types.h 24 Jun 2009 09:46:13 -0000 1.12
@@ -208,6 +208,13 @@
}
};
+ template <class A,class T> struct RgbishToRgbish<A,Argb<T> > {
+ static inline void convert(const A& from, Argb<T>& to) {
+ RgbToRgb(from,to);
+ to.alpha = traits<T>::max_intensity;
+ }
+ };
+
template <class S,class T> struct RgbishToRgbish<Rgba<S>,Rgba<T> > {
static inline void convert(const Rgba<S>& from, Rgba<T>& to) {
RgbToRgb(from,to);
@@ -215,6 +222,15 @@
}
};
+ template <class S,class T> struct RgbishToRgbish<Argb<S>,Argb<T> > {
+ static inline void convert(const Argb<S>& from, Argb<T>& to) {
+ RgbToRgb(from,to);
+ to.alpha = scalar_convert<T,S>(from.alpha);
+ }
+ };
+
+
+
// Default conversions
template <class From, class To, int FN=Pixel::Component<From>::count, int
TN=Pixel::Component<To>::count> struct DefaultConversion {
@@ -244,9 +260,18 @@
template <class T, class S> struct DefaultConversion<Rgba<T>,Rgb<S>,4,3> {
typedef RgbishToRgbish<Rgba<T>, Rgb<S> > type; };
template <class T> struct DefaultConversion<Rgba<T>,Rgb8,4,3> { typedef
RgbishToRgbish<Rgba<T>, Rgb8> type; };
template <class T, class S> struct DefaultConversion<Rgba<T>,Rgba<S>,4,4> {
typedef RgbishToRgbish<Rgba<T>, Rgba<S> > type; };
+ template <class T, class S> struct DefaultConversion<Rgba<T>,Argb<S>,4,4> {
typedef RgbishToRgbish<Rgba<T>, Argb<S> > type; };
template <class T> struct DefaultConversion<Rgba<T>,Rgba<T>,4,4> { typedef
GenericConversion<Rgba<T>, Rgba<T> > type; };
+ // Argb<T> to X
+ template <class T, class S> struct DefaultConversion<Argb<T>,S,4,1> {
typedef CIE<Argb<T>,S> type; };
+ template <class T, class S> struct DefaultConversion<Argb<T>,Rgb<S>,4,3> {
typedef RgbishToRgbish<Argb<T>, Rgb<S> > type; };
+ template <class T> struct DefaultConversion<Argb<T>,Rgb8,4,3> { typedef
RgbishToRgbish<Argb<T>, Rgb8> type; };
+ template <class T, class S> struct DefaultConversion<Argb<T>,Rgba<S>,4,4> {
typedef RgbishToRgbish<Argb<T>, Rgba<S> > type; };
+ template <class T> struct DefaultConversion<Argb<T>,Argb<T>,4,4> { typedef
GenericConversion<Argb<T>, Argb<T> > type; };
+
+
template <class From, class To, class Conv=typename
DefaultConversion<From,To>::type,
bool both_pod=CVD::Internal::is_POD<From>::is_pod &&
CVD::Internal::is_POD<To>::is_pod> struct ConvertPixels {
static inline void convert(const From* from, To* to, size_t count) {
Index: internal/rgb_components.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/internal/rgb_components.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- internal/rgb_components.h 22 Oct 2008 15:50:41 -0000 1.9
+++ internal/rgb_components.h 24 Jun 2009 09:46:13 -0000 1.10
@@ -24,6 +24,7 @@
#include <cvd/rgb.h>
#include <cvd/rgba.h>
#include <cvd/rgb8.h>
+#include <cvd/qt_argb.h>
#include <cvd/la.h>
#include <cvd/internal/builtin_components.h>
#include <cvd/internal/pixel_traits.h>
@@ -105,10 +106,29 @@
}
};
+ template<class P> struct Component<Argb<P> >
+ {
+ typedef P type;
+ static const size_t count = 4;
+
+ static const P& get(const Argb<P>& pixel, size_t i)
+ {
+ //return *(reinterpret_cast<const
P*>(&pixel)+i);
+ return i == 0 ? pixel.red : (i==1 ? pixel.green
: (i==2 ?pixel.blue: pixel.alpha));
+ }
+
+ static P& get(Argb<P>& pixel, size_t i)
+ {
+ //return *(reinterpret_cast<P*>(&pixel)+i);
+ return i == 0 ? pixel.red : (i==1 ? pixel.green
: (i==2 ?pixel.blue: pixel.alpha));
+ }
+ };
+
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 }; };
template <class T> struct is_Rgb<Rgba<T> > { enum { value = 1
}; };
+ template <class T> struct is_Rgb<Argb<T> > { enum { value = 1
}; };
template<class T, int LIFT> struct traits<Rgb<T>, LIFT>
{
Index: argb.h
===================================================================
RCS file: argb.h
diff -N argb.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ argb.h 24 Jun 2009 09:46:13 -0000 1.1
@@ -0,0 +1,121 @@
+/*
+ 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_QT_ARGB_H
+#define CVD_QT_ARGB_H
+
+#include <iostream>
+#include <cvd/internal/is_pod.h>
+
+namespace CVD {
+
+
+//////////////////////////////
+// CVD::Argb
+// Template class to represent red, green, blue and alpha components
+//
+/// A colour consisting of red, green, blue and alpha components
+/// @param T The datatype of each component
+/// @ingroup gImage
+template <typename T>
+class Argb
+{
+public:
+ /// Default constructor. Does nothing.
+ Argb() {}
+ /// Constructs a colour as specified
+ /// @param r The red component
+ /// @param g The green component
+ /// @param b The blue component
+ /// @param a The alpha component
+ Argb(T a, T r, T g, T b) : red(r), green(g), blue(b), alpha(a) {}
+
+ T blue; ///< The blue component
+ T green; ///< The green component
+ T red; ///< The red component
+ T alpha; ///< The alpha component
+
+ /// Assignment operator
+ /// @param c The colour to copy from
+ Argb<T>& operator=(const Argb<T>& c)
+ {red = c.red; green = c.green; blue = c.blue; 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>
+ Argb<T>& operator=(const Argb<T2>& c){
+ red = static_cast<T>(c.red);
+ green = static_cast<T>(c.green);
+ blue = static_cast<T>(c.blue);
+ alpha = static_cast<T>(c.alpha);
+ return *this;
+ }
+
+ /// Logical equals operator. Returns true if each component is the same.
+ /// @param c Argb to compare with
+ bool operator==(const Argb<T>& c) const
+ {return red == c.red && green == c.green && blue == c.blue && alpha ==
c.alpha;}
+
+ /// Logical not-equals operator. Returns true unless each component is
the same.
+ /// @param c Argb to compare with
+ bool operator!=(const Argb<T>& c) const
+ {return red != c.red || green != c.green || blue != c.blue || alpha !=
c.alpha;}
+
+// T to_grey() const {return 0.3*red + 0.6*green + 0.1*blue;}
+};
+
+/// Write the colour to a stream in the format "(red,green,blue,alpha)"
+/// @param os The stream
+/// @param x The colour object
+/// @relates Argb
+template <typename T>
+std::ostream& operator <<(std::ostream& os, const Argb<T>& x)
+{
+ return os << "(" << x.alpha << "," << x.red << ","
+ << x.green << "," << x.blue << ")";
+}
+
+/// Write the colour to a stream in the format "(red,green,blue,alpha)"
+/// @param os The stream
+/// @param x The colour object
+/// @relates Argb
+inline std::ostream& operator <<(std::ostream& os, const Argb<unsigned char>&
x)
+{
+ return os << "(" << static_cast<unsigned int>(x.alpha) << ","
+ << static_cast<unsigned int>(x.red) << ","
+ << static_cast<unsigned int>(x.green) << ","
+ << static_cast<unsigned int>(x.blue) << ")";
+}
+
+#ifndef DOXYGEN_IGNORE_INTERNAL
+namespace Internal
+{
+ template<class C> struct is_POD<Argb<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/convert_pixel_types.h inter...,
Edward Rosten <=