kis_f16half_base_colorspace.h
1/*
2 * Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#ifndef KIS_F16HALF_BASE_COLORSPACE_H_
19#define KIS_F16HALF_BASE_COLORSPACE_H_
20
21#include <tqcolor.h>
22
23#include <half.h>
24
25#include "kis_global.h"
26#include "kis_abstract_colorspace.h"
27#include "kis_integer_maths.h"
28
35inline half UINT8_TO_HALF(uint c)
36{
37 return static_cast<half>(c) / UINT8_MAX;
38}
39
40inline uint HALF_TO_UINT8(half c)
41{
42 return static_cast<uint>(CLAMP(static_cast<int>(c * static_cast<int>(UINT8_MAX) + 0.5),
43 static_cast<int>(UINT8_MIN), static_cast<int>(UINT8_MAX)));
44}
45
46
47inline uint HALF_TO_UINT16(half c)
48{
49 return static_cast<uint>(CLAMP(static_cast<int>(c * static_cast<int>(UINT16_MAX) + 0.5),
50 static_cast<int>(UINT16_MIN), static_cast<int>(UINT16_MAX)));
51}
52
53inline half HALF_BLEND(half a, half b, half alpha)
54{
55 return (a - b) * alpha + b;
56}
57
58#define F16HALF_OPACITY_OPAQUE ((half)1.0f)
59#define F16HALF_OPACITY_TRANSPARENT ((half)0.0f)
60
61class KisF16HalfBaseColorSpace : public KisAbstractColorSpace {
62
63public:
64
65 KisF16HalfBaseColorSpace(const KisID & id, DWORD cmType, icColorSpaceSignature colorSpaceSignature,
67 KisProfile *p)
68 : KisAbstractColorSpace(id, cmType, colorSpaceSignature, parent, p)
69 {
70 m_alphaSize = sizeof(half);
71 };
72
73 virtual TQ_UINT8 getAlpha(const TQ_UINT8 * pixel) const;
74 virtual void setAlpha(TQ_UINT8 * pixels, TQ_UINT8 alpha, TQ_INT32 nPixels) const;
75 virtual void multiplyAlpha(TQ_UINT8 * pixels, TQ_UINT8 alpha, TQ_INT32 nPixels);
76
77 virtual void applyAlphaU8Mask(TQ_UINT8 * pixels, TQ_UINT8 * alpha, TQ_INT32 nPixels);
78 virtual void applyInverseAlphaU8Mask(TQ_UINT8 * pixels, TQ_UINT8 * alpha, TQ_INT32 nPixels);
79
80 virtual TQString channelValueText(const TQ_UINT8 *pixel, TQ_UINT32 channelIndex) const;
81 virtual TQString normalisedChannelValueText(const TQ_UINT8 *pixel, TQ_UINT32 channelIndex) const;
82
83 virtual TQ_UINT8 scaleToU8(const TQ_UINT8 * srcPixel, TQ_INT32 channelPos);
84 virtual TQ_UINT16 scaleToU16(const TQ_UINT8 * srcPixel, TQ_INT32 channelPos);
85
86 virtual bool hasHighDynamicRange() const { return true; }
87
88protected:
89 // For Alpha Composite
90 struct F16HalfMult {
91 inline half operator()(const half& a, const half& b) const {
92 return a * b;
93 }
94 };
95 struct Uint8ToF16Half {
96 inline half operator()(const TQ_UINT8 src) const {
97 return UINT8_TO_HALF(src);
98 }
99 };
100 struct F16HalfOpacityTest {
101 inline bool operator()(const half& opacity) const {
102 return opacity > F16HALF_OPACITY_TRANSPARENT + HALF_EPSILON;
103 }
104 };
105};
106
107#endif // KIS_F16HALF_BASE_COLORSPACE_H_
A colorspace strategy is the definition of a certain color model in Chalk.
virtual TQString normalisedChannelValueText(const TQ_UINT8 *pixel, TQ_UINT32 channelIndex) const =0
Return a string with the channel's value with integer channels normalised to the floating point range...
virtual bool hasHighDynamicRange() const
Returns true if the colorspace supports channel values outside the (normalised) range 0 to 1.
virtual TQ_UINT16 scaleToU16(const TQ_UINT8 *srcPixel, TQ_INT32 channelPos)=0
Convert the value of the channel at the specified position into a 16-bit value.
virtual TQ_UINT8 scaleToU8(const TQ_UINT8 *srcPixel, TQ_INT32 channelPos)=0
Convert the value of the channel at the specified position into an 8-bit value.
virtual TQString channelValueText(const TQ_UINT8 *pixel, TQ_UINT32 channelIndex) const =0
Return a string with the channel's value suitable for display in the gui.
virtual KisID id() const
Chalk definition for use in .kra files and internally: unchanging name + i18n'able description.
virtual void applyAlphaU8Mask(TQ_UINT8 *pixels, TQ_UINT8 *alpha, TQ_INT32 nPixels)=0
Applies the specified 8-bit alpha mask to the pixels.
virtual TQ_UINT8 getAlpha(const TQ_UINT8 *pixel) const =0
Get the alpha value of the given pixel, downscaled to an 8-bit value.
virtual void applyInverseAlphaU8Mask(TQ_UINT8 *pixels, TQ_UINT8 *alpha, TQ_INT32 nPixels)=0
Applies the inverted 8-bit alpha mask to the pixels.
virtual void multiplyAlpha(TQ_UINT8 *pixels, TQ_UINT8 alpha, TQ_INT32 nPixels)=0
Multiply the alpha channel of the given run of pixels by the given value.
virtual void setAlpha(TQ_UINT8 *pixels, TQ_UINT8 alpha, TQ_INT32 nPixels) const =0
Set the alpha channel of the given run of pixels to the given value.
Chalk has a large number of extensible resources.
Definition kis_id.h:57