krita

kis_f16half_base_colorspace.h

00001 /*
00002  *  Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 #ifndef KIS_F16HALF_BASE_COLORSPACE_H_
00019 #define KIS_F16HALF_BASE_COLORSPACE_H_
00020 
00021 #include <qcolor.h>
00022 
00023 #include <half.h>
00024 
00025 #include "kis_global.h"
00026 #include "kis_abstract_colorspace.h"
00027 #include "kis_integer_maths.h"
00028 
00035 inline half UINT8_TO_HALF(uint c)
00036 {
00037     return static_cast<half>(c) / UINT8_MAX;
00038 }
00039 
00040 inline uint HALF_TO_UINT8(half c)
00041 {
00042     return static_cast<uint>(CLAMP(static_cast<int>(c * static_cast<int>(UINT8_MAX) + 0.5),
00043                                    static_cast<int>(UINT8_MIN), static_cast<int>(UINT8_MAX)));
00044 }
00045 
00046 
00047 inline uint HALF_TO_UINT16(half c)
00048 {
00049     return static_cast<uint>(CLAMP(static_cast<int>(c * static_cast<int>(UINT16_MAX) + 0.5),
00050                                    static_cast<int>(UINT16_MIN), static_cast<int>(UINT16_MAX)));
00051 }
00052 
00053 inline half HALF_BLEND(half a, half b, half alpha)
00054 {
00055     return (a - b) * alpha + b;
00056 }
00057 
00058 #define F16HALF_OPACITY_OPAQUE ((half)1.0f)
00059 #define F16HALF_OPACITY_TRANSPARENT ((half)0.0f)
00060 
00061 class KisF16HalfBaseColorSpace : public KisAbstractColorSpace {
00062 
00063 public:
00064 
00065     KisF16HalfBaseColorSpace(const KisID & id, DWORD cmType, icColorSpaceSignature colorSpaceSignature,
00066                              KisColorSpaceFactoryRegistry * parent,
00067                              KisProfile *p)
00068     : KisAbstractColorSpace(id, cmType, colorSpaceSignature, parent, p)
00069     {
00070         m_alphaSize = sizeof(half);
00071     };
00072 
00073     virtual Q_UINT8 getAlpha(const Q_UINT8 * pixel) const;
00074     virtual void setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels) const;
00075     virtual void multiplyAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels);
00076 
00077     virtual void applyAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels);
00078     virtual void applyInverseAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels);
00079 
00080     virtual QString channelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const;
00081     virtual QString normalisedChannelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const;
00082 
00083     virtual Q_UINT8 scaleToU8(const Q_UINT8 * srcPixel, Q_INT32 channelPos);
00084     virtual Q_UINT16 scaleToU16(const Q_UINT8 * srcPixel, Q_INT32 channelPos);
00085 
00086     virtual bool hasHighDynamicRange() const { return true; }
00087 
00088 protected:
00089     // For Alpha Composite
00090     struct F16HalfMult {
00091         inline half operator()(const half& a, const half& b) const {
00092             return a * b;
00093         }
00094     };
00095     struct Uint8ToF16Half {
00096         inline half operator()(const Q_UINT8 src) const {
00097             return UINT8_TO_HALF(src);
00098         }
00099     };
00100     struct F16HalfOpacityTest {
00101         inline bool operator()(const half& opacity) const {
00102             return opacity > F16HALF_OPACITY_TRANSPARENT + HALF_EPSILON;
00103         }
00104     };
00105 };
00106 
00107 #endif // KIS_F16HALF_BASE_COLORSPACE_H_
KDE Home | KDE Accessibility Home | Description of Access Keys