tahoma2d/toonz/sources/include/tpixelgr.h

148 lines
4.4 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef _PIXEL_GR_H
#define _PIXEL_GR_H
#include "tcommon.h"
#include <math.h>
#undef DVAPI
#undef DVVAR
#ifdef TCOLOR_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//! r,g,b,m; 4 byte/pixel
class TPixelRGBM32;
//! r,g,b,m; 8 byte/pixel
class TPixelRGBM64;
//! Double r,g,b,m ; 16 byte/pixel
class TPixelD;
//! Gray Scale 1 byte/pixel
class TPixelGR8;
//! Gray Scale 2 byte/pixel
class TPixelGR16;
class TPixelF;
2016-03-19 06:57:51 +13:00
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
/*! grey tones, 8 bits
2016-03-19 06:57:51 +13:00
A set of predefined colors are included as well.
*/
2016-06-15 18:43:10 +12:00
class DVAPI TPixelGR8 {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
static const int maxChannelValue;
typedef UCHAR Channel;
UCHAR value;
TPixelGR8(int v = 0) : value(v){};
TPixelGR8(const TPixelGR8 &pix) : value(pix.value){};
inline bool operator==(const TPixelGR8 &p) const { return value == p.value; };
inline bool operator!=(const TPixelGR8 &p) const { return value != p.value; };
inline bool operator<(const TPixelGR8 &p) const { return value < p.value; };
inline bool operator<=(const TPixelGR8 &p) const { return value <= p.value; };
inline bool operator>(const TPixelGR8 &p) const { return value > p.value; };
inline bool operator>=(const TPixelGR8 &p) const { return value >= p.value; };
inline void setValue(int _value) { value = (UCHAR)_value; }
//! In this conversion instead of truncating values from 16 to 8 a randomic
2016-06-15 18:43:10 +12:00
//! dithering is performed.
// randomNumber is an unsigned int random value
static inline TPixelGR8 from(const TPixelGR16 &pix,
TUINT32 randomNumber); // per il dithering
//! In this conversion instead of truncating values from 64 to 8 a randomic
2016-06-15 18:43:10 +12:00
//! dithering is performed.
// randomNumber is an unsigned int random value
static TPixelGR8 from(const TPixelRGBM64 &pix,
TUINT32 randomNumber); // per il dithering
//! Converts TPixelRGBM32 into TPixelGR8
static TPixelGR8 from(const TPixelRGBM32 &pix);
//! Converts TPixelGR16 into TPixelGR8
static inline TPixelGR8 from(const TPixelGR16 &pix);
//! Converts TPixelD into TPixelGR8
static TPixelGR8 from(const TPixelD &pix);
static const TPixelGR8 White;
static const TPixelGR8 Black;
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
/*!grey tones, 16 bits */
2016-06-15 18:43:10 +12:00
class DVAPI TPixelGR16 {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
static const int maxChannelValue;
typedef USHORT Channel;
USHORT value;
TPixelGR16(int v = 0) : value(v){};
TPixelGR16(const TPixelGR16 &pix) : value(pix.value){};
inline bool operator==(const TPixelGR16 &p) const {
return value == p.value;
};
inline bool operator!=(const TPixelGR16 &p) const {
return value != p.value;
};
inline bool operator<(const TPixelGR16 &p) const { return value < p.value; };
inline bool operator<=(const TPixelGR16 &p) const {
return value <= p.value;
};
inline bool operator>(const TPixelGR16 &p) const { return value > p.value; };
inline bool operator>=(const TPixelGR16 &p) const {
return value >= p.value;
};
inline void setValue(int _value) { value = (USHORT)_value; }
static TPixelGR16 from(const TPixelRGBM64 &pix);
static TPixelGR16 from(const TPixelD &pix);
static const TPixelGR16 White;
static const TPixelGR16 Black;
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
class DVAPI TPixelGRF {
public:
typedef float Channel;
float value;
TPixelGRF(float v = 0.f) : value(v){};
TPixelGRF(const TPixelGRF &pix) : value(pix.value){};
inline bool operator==(const TPixelGRF &p) const { return value == p.value; };
inline bool operator<(const TPixelGRF &p) const { return value < p.value; };
inline void setValue(float _value) { value = (float)_value; }
static TPixelGRF from(const TPixelF &pix);
};
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TPixelGRD {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef double Channel;
double value;
TPixelGRD(double v = 0.0) : value(v){};
TPixelGRD(const TPixelGRD &pix) : value(pix.value){};
inline bool operator==(const TPixelGRD &p) const { return value == p.value; };
inline bool operator<(const TPixelGRD &p) const { return value < p.value; };
inline void setValue(double _value) { value = (double)_value; }
static TPixelGRD from(const TPixelGR8 &pix) {
return TPixelGRD((double)(pix.value));
}
2016-03-19 06:57:51 +13:00
};
#endif