📄 argb.h
字号:
#ifndef __ARGB_H__#define __ARGB_H__#include "aconf.h"#include <qglobal.h>#include <limits>/** Define type with quadruple width */template<typename T> struct quadruple { /** The defined type. For base it is void (unknown) */ typedef void type; };/** 4x unsigned char is unsigned int */template<> struct quadruple<unsigned char> { /** The defined type (32bit unsigned int) */ typedef unsigned int type; };/** 4x unsigned short is unsigned int64 */template<> struct quadruple<unsigned short> { /** The defined type (64bit unsigned int) */ typedef quint64 type; };/** Information class that will return value corresponding to "maximal pixel intensity". It is maximal representable number for integer types and 1.0 for floating point types*/template<typename T> struct pixel_limits { /** Return value corresponding to full pixel intensity */ static T full() throw() { return std::numeric_limits<T>::max(); }};/** Specialization for double */template<> struct pixel_limits<double> { /** \copydoc pixel_limits::full() */ static double full() throw() { return 1.0; }};/** Specialization for float */template<> struct pixel_limits<float> { /** \copydoc pixel_limits::full() */ static float full() throw() { return 1.0; }};/** Specialization for long double */template<> struct pixel_limits<long double> { /** \copydoc pixel_limits::full() */ static long double full() throw() { return 1.0; }};/** 32bit ARGB pixel type*/template<class Pixel> class ARGB {public: union { /** ARGB value */ typename quadruple<Pixel>::type argb; struct {#ifdef WORDS_BIGENDIAN /** Alpha component */ Pixel a; /** Red component */ Pixel r; /** Green component */ Pixel g; /** Blue component */ Pixel b;#else /** Blue component */ Pixel b; /** Green component */ Pixel g; /** Red component */ Pixel r; /** Alpha component */ Pixel a;#endif }; }; /** Default constructor */ inline ARGB(){} /** Copy constructor @param t source object */ inline ARGB(const ARGB &t) { argb=t.argb; } /** multiplication by something @param n value used to multiply the pixel */ template<typename T> inline ARGB& operator*=(const T &n) { r*=n; g*=n; b*=n; a*=n; return this; } /** Addition of another pixel to this @param n pixel to add */ inline ARGB& operator+=(const ARGB &n) { r+=n.r; g+=n.g; b+=n.b; a+=n.a; return *this; } /** Subtraction of another pixel to this @param n pixel to subtract */ inline ARGB& operator-=(const ARGB &n) { r-=n.r; g-=n.g; b-=n.b; a-=n.a; return *this; } /** Addition of another pixel to this @param n pixel to add */ inline ARGB operator+(const ARGB &n) const { ARGB result; result.r=r+n.r; result.g=g+n.g; result.b=b+n.b; result.a=a+n.a; return result; } /** Subtraction of another pixel to this @param n pixel to subtract */ inline ARGB operator-(const ARGB &n) const { ARGB result; result.r=r-n.r; result.g=g-n.g; result.b=b-n.b; result.a=a-n.a; return result; } /** division by something @param n value used to divide the pixel */ template<typename T> inline ARGB& operator/=(const T &n) { r/=n; g/=n; b/=n; a/=n; return this; }};bool endianTest();#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -