Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #pragma once
00024
00025 #include "cinder/Cinder.h"
00026
00027 namespace cinder {
00028
00029 template<typename T>
00030 struct CHANTRAIT
00031 {
00032 };
00033
00034 template<>
00035 struct CHANTRAIT<uint8_t>
00036 {
00037 typedef uint32_t Sum;
00038 typedef uint32_t Accum;
00039 typedef int32_t SignedSum;
00040 static uint8_t max() { return 255; }
00041 static uint8_t convert( uint8_t v ) { return v; }
00042 static uint8_t convert( uint16_t v ) { return v / 257; }
00043 static uint8_t convert( float v ) { return static_cast<uint8_t>( v * 255 ); }
00044 static uint8_t grayscale( uint8_t r, uint8_t g, uint8_t b ) { return ( r * 54 + g * 183 + b * 19 ) >> 8; }
00045 static uint8_t premultiply( uint8_t c, uint8_t a ) { return a * c / 255; }
00046
00047 static uint8_t inverse( uint8_t c ) { return ~c; }
00048 };
00049
00050 template<>
00051 struct CHANTRAIT<uint16_t>
00052 {
00053 typedef uint32_t Sum;
00054 typedef uint32_t Accum;
00055 typedef int32_t SignedSum;
00056 static uint16_t max() { return 65535; }
00057 static uint16_t convert( uint8_t v ) { return ( v << 8 ) | v; }
00058 static uint16_t convert( uint16_t v ) { return v; }
00059 static uint16_t convert( float v ) { return static_cast<uint16_t>( v * 65535 ); }
00060 static uint16_t grayscale( uint16_t r, uint16_t g, uint16_t b ) { return ( r * 6966 + g * 23436 + b * 2366 ) >> 15; }
00061 };
00062
00063 template<>
00064 struct CHANTRAIT<float>
00065 {
00066 typedef float Sum;
00067 typedef float Accum;
00068 typedef float SignedSum;
00069 static float max() { return 1.0f; }
00070 static float convert( uint8_t v ) { return v / 255.0f; }
00071 static float convert( uint16_t v ) { return v / 65535.0f; }
00072 static float convert( float v ) { return v; }
00073 static float grayscale( float r, float g, float b ) { return r * 0.2126f + g * 0.7152f + b * 0.0722f; }
00075 static float premultiply( float c, float a ) { return c * a; }
00076 static float inverse( float c ) { return 1.0f - c; }
00077 };
00078
00079 #define CHANNEL_TYPES (uint8_t)(float)
00080
00081 }