kis_f32_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_F32_BASE_COLORSPACE_H_
19#define KIS_F32_BASE_COLORSPACE_H_
20
21#include <tqcolor.h>
22
23#include "kis_global.h"
24#include "kis_abstract_colorspace.h"
25#include "kis_integer_maths.h"
26
31inline float UINT8_TO_FLOAT(uint c)
32{
33 return static_cast<float>(c) / UINT8_MAX;
34}
35
36inline uint FLOAT_TO_UINT8(float c)
37{
38 return static_cast<uint>(CLAMP(static_cast<int>(c * static_cast<int>(UINT8_MAX) + 0.5),
39 static_cast<int>(UINT8_MIN), static_cast<int>(UINT8_MAX)));
40}
41
42
43inline uint FLOAT_TO_UINT16(float c)
44{
45 return static_cast<uint>(CLAMP(static_cast<int>(c * static_cast<int>(UINT16_MAX) + 0.5),
46 static_cast<int>(UINT16_MIN), static_cast<int>(UINT16_MAX)));
47}
48
49inline float FLOAT_BLEND(float a, float b, float alpha)
50{
51 return (a - b) * alpha + b;
52}
53
54#define F32_OPACITY_OPAQUE 1.0f
55#define F32_OPACITY_TRANSPARENT 0.0f
56
57class KisF32BaseColorSpace : public KisAbstractColorSpace {
58
59public:
60
61 KisF32BaseColorSpace(const KisID & id, DWORD cmType, icColorSpaceSignature colorSpaceSignature, KisColorSpaceFactoryRegistry * parent, KisProfile *p)
62 : KisAbstractColorSpace(id, cmType, colorSpaceSignature, parent, p)
63 {
64 m_alphaSize = sizeof(float);
65 };
66
67 virtual TQ_UINT8 getAlpha(const TQ_UINT8 * pixel) const;
68 virtual void setAlpha(TQ_UINT8 * pixels, TQ_UINT8 alpha, TQ_INT32 nPixels) const;
69 virtual void multiplyAlpha(TQ_UINT8 * pixels, TQ_UINT8 alpha, TQ_INT32 nPixels);
70
71 virtual void applyAlphaU8Mask(TQ_UINT8 * pixels, TQ_UINT8 * alpha, TQ_INT32 nPixels);
72 virtual void applyInverseAlphaU8Mask(TQ_UINT8 * pixels, TQ_UINT8 * alpha, TQ_INT32 nPixels);
73
74 virtual TQString channelValueText(const TQ_UINT8 *pixel, TQ_UINT32 channelIndex) const;
75 virtual TQString normalisedChannelValueText(const TQ_UINT8 *pixel, TQ_UINT32 channelIndex) const;
76
77 virtual TQ_UINT8 scaleToU8(const TQ_UINT8 * srcPixel, TQ_INT32 channelPos);
78 virtual TQ_UINT16 scaleToU16(const TQ_UINT8 * srcPixel, TQ_INT32 channelPos);
79
80 virtual bool hasHighDynamicRange() const { return true; }
81};
82
83#endif // KIS_F32_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