Changeset 2308


Ignore:
Timestamp:
Feb 1, 2013, 1:35:56 AM (7 years ago)
Author:
sam
Message:

math: implement clamp() for base C++ types and add more safeguards
to the RGB to HSV conversion.

Location:
trunk/src/lol
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/image/color.h

    r2307 r2308  
    124124        float luma = src.r + min(src.g, src.b);
    125125        float h = min(abs(K + (src.g - src.b) / (6.f * chroma)), 1.f);
    126         float s = clamp(chroma / (min(luma, 2.f - luma)), 0.f, 1.f);
     126        float s = min(abs(chroma / (min(luma, 2.f - luma))), 1.f);
    127127        return vec3(h, s, 0.5f * luma);
    128128    }
  • trunk/src/lol/math/math.h

    r2216 r2308  
    155155static inline ldouble fract(ldouble x) { return x - std::floor(x); }
    156156
    157 static inline uint8_t min(uint8_t x, uint8_t y) { return std::min(x, y); }
    158 static inline int8_t min(int8_t x, int8_t y) { return std::min(x, y); }
    159 static inline uint16_t min(uint16_t x, uint16_t y) { return std::min(x, y); }
    160 static inline int16_t min(int16_t x, int16_t y) { return std::min(x, y); }
    161 static inline uint32_t min(uint32_t x, uint32_t y) { return std::min(x, y); }
    162 static inline int32_t min(int32_t x, int32_t y) { return std::min(x, y); }
    163 static inline uint64_t min(uint64_t x, uint64_t y) { return std::min(x, y); }
    164 static inline int64_t min(int64_t x, int64_t y) { return std::min(x, y); }
    165 static inline float min(float x, float y) { return std::min(x, y); }
    166 static inline double min(double x, double y) { return std::min(x, y); }
    167 static inline ldouble min(ldouble x, ldouble y) { return std::min(x, y); }
    168 
    169 static inline uint8_t max(uint8_t x, uint8_t y) { return std::max(x, y); }
    170 static inline int8_t max(int8_t x, int8_t y) { return std::max(x, y); }
    171 static inline uint16_t max(uint16_t x, uint16_t y) { return std::max(x, y); }
    172 static inline int16_t max(int16_t x, int16_t y) { return std::max(x, y); }
    173 static inline uint32_t max(uint32_t x, uint32_t y) { return std::max(x, y); }
    174 static inline int32_t max(int32_t x, int32_t y) { return std::max(x, y); }
    175 static inline uint64_t max(uint64_t x, uint64_t y) { return std::max(x, y); }
    176 static inline int64_t max(int64_t x, int64_t y) { return std::max(x, y); }
    177 static inline float max(float x, float y) { return std::max(x, y); }
    178 static inline double max(double x, double y) { return std::max(x, y); }
    179 static inline ldouble max(ldouble x, ldouble y) { return std::max(x, y); }
     157#define LOL_MIN_MAX_CLAMP(T) \
     158    static inline T min(T x, T y) { return std::min(x, y); } \
     159    static inline T max(T x, T y) { return std::max(x, y); } \
     160    static inline T clamp(T x, T y, T z) { return min(max(x, y), z); }
     161LOL_MIN_MAX_CLAMP(uint8_t)
     162LOL_MIN_MAX_CLAMP(int8_t)
     163LOL_MIN_MAX_CLAMP(uint16_t)
     164LOL_MIN_MAX_CLAMP(int16_t)
     165LOL_MIN_MAX_CLAMP(uint32_t)
     166LOL_MIN_MAX_CLAMP(int32_t)
     167LOL_MIN_MAX_CLAMP(uint64_t)
     168LOL_MIN_MAX_CLAMP(int64_t)
     169LOL_MIN_MAX_CLAMP(float)
     170LOL_MIN_MAX_CLAMP(double)
     171LOL_MIN_MAX_CLAMP(ldouble)
     172#undef LOL_CLAMP
    180173
    181174} /* namespace lol */
Note: See TracChangeset for help on using the changeset viewer.