[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd/cvd/internal scalar_convert.h
From: |
Edward Rosten |
Subject: |
[libcvd-members] libcvd/cvd/internal scalar_convert.h |
Date: |
Sun, 05 Jul 2009 17:00:55 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Changes by: Edward Rosten <edrosten> 09/07/05 17:00:55
Modified files:
cvd/internal : scalar_convert.h
Log message:
Added correct scalar conversion to bool (ie != 0). This means that
loading
images in to Image<bool> generally does the correct thing, with nonzero
elements set to 1.
Also, marked some FIXMEs in the scalar convert code. I think that the
byte
to float conversion is not fully correct.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/scalar_convert.h?cvsroot=libcvd&r1=1.13&r2=1.14
Patches:
Index: scalar_convert.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/internal/scalar_convert.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- scalar_convert.h 12 Jun 2008 13:04:14 -0000 1.13
+++ scalar_convert.h 5 Jul 2009 17:00:54 -0000 1.14
@@ -114,6 +114,9 @@
inline float byte_to_float(int b) { return
float_for_byte[b+255]; }
inline double byte_to_double(int b) { return
double_for_byte[b+255]; }
+ //Convert a "D" to "To" scaled as if we are converting "From"
type to a "To" type.
+ //Special code is invoked if both D and To are integral.
+ //FIXME: why is the test on "From", not "D"??
template <class From, class To, class D=From, bool int1 =
traits<To>::integral && traits<From>::integral, bool int2 =traits<D>::integral>
struct ScalarConvert {
static inline To from(const D& from) {
static const double factor =
double(traits<To>::max_intensity)/traits<From>::max_intensity;
@@ -121,18 +124,41 @@
}
};
+
+ //If the input and output are integral, then use integer only
scaling code.
template <class From, class To, class D> struct
ScalarConvert<From,To,D,true, true> {
static inline To from(const D& f) {
return shift_convert<To, From,
int_info<To,From>::shift_dir>::from(f);
}
};
+ //If the destination is bool, then use != 0.
+ //Note two classes are needed here so that they are both more
specialized than
+ //the integral conversion code (above) in order to avoid
ambiguities.
+ template<class From, class D> struct ScalarConvert<From, bool,
D, true, true>
+ {
+ static inline bool from(const D& from)
+ {
+ return from != 0;
+ }
+ };
+ template<class From, class D> struct ScalarConvert<From, bool,
D, true, false>
+ {
+ static inline bool from(const D& from)
+ {
+ return from != 0;
+ }
+ };
+
+ //Lookup table conversion from byte to float.
+ //FIXME surely this can only work properly if D is also byte?
template <class D> struct
ScalarConvert<byte,float,D,false,true> {
static inline float from(const D& from) {
return byte_to_float(from);
}
};
+ //FIXME this is surely redundant
template <class D> struct
ScalarConvert<byte,float,D,false,false> {
static inline float from(const D& from) {
return static_cast<float>(from * (1.0/255.0));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] libcvd/cvd/internal scalar_convert.h,
Edward Rosten <=