kis_colorspace.h
1/*
2 * Copyright (c) 2005 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_COLORSPACE_H_
19#define KIS_COLORSPACE_H_
20
21#include <config.h>
22#include LCMS_HEADER
23
24#include <tqvaluevector.h>
25#include <tqvaluelist.h>
26
27#include "kis_composite_op.h"
28#include "kis_channelinfo.h"
29
30class DCOPObject;
31
32class KisProfile;
34class KisMathToolbox;
35class KisFilter;
36
37class KisColorAdjustment
38{
39public:
40
41 KisColorAdjustment() {};
42 virtual ~KisColorAdjustment() {};
43};
44
45
46enum ColorSpaceIndependence {
47 FULLY_INDEPENDENT,
48 TO_LAB16,
49 TO_RGBA8,
50 TO_RGBA16
51};
52
59
60
61public:
62
64 virtual ~KisColorSpace();
65
66 virtual DCOPObject * dcopObject();
67
68 virtual bool operator==(const KisColorSpace& rhs) const {
69 return id().id() == rhs.id().id();
70 }
71
72
73public:
74
75 //========== Channels =====================================================//
76
78 virtual TQValueVector<KisChannelInfo *> channels() const = 0;
79
83 virtual TQ_UINT32 nChannels() const = 0;
84
89 virtual TQ_UINT32 nColorChannels() const = 0;
90
95 virtual TQ_UINT32 nSubstanceChannels() const { return 0; };
96
100 virtual TQ_UINT32 pixelSize() const = 0;
101
105 virtual TQString channelValueText(const TQ_UINT8 *pixel, TQ_UINT32 channelIndex) const = 0;
106
111 virtual TQString normalisedChannelValueText(const TQ_UINT8 *pixel, TQ_UINT32 channelIndex) const = 0;
112
118 virtual TQ_UINT8 scaleToU8(const TQ_UINT8 * srcPixel, TQ_INT32 channelPos) = 0;
119
125 virtual TQ_UINT16 scaleToU16(const TQ_UINT8 * srcPixel, TQ_INT32 channelPos) = 0;
126
132 virtual void getSingleChannelPixel(TQ_UINT8 *dstPixel, const TQ_UINT8 *srcPixel, TQ_UINT32 channelIndex) = 0;
133
134 //========== Identification ===============================================//
135
140 virtual KisID id() const = 0;
141
145 virtual TQ_UINT32 colorSpaceType() = 0;
146
147 virtual icColorSpaceSignature colorSpaceSignature() = 0;
148
159 virtual bool willDegrade(ColorSpaceIndependence independence) = 0;
160
161 //========== Capabilities =================================================//
162
168 virtual KisCompositeOpList userVisiblecompositeOps() const = 0;
169
174 virtual bool hasHighDynamicRange() const = 0;
175
176
177 //========== Display profiles =============================================//
178
182 virtual KisProfile * getProfile() const = 0;
183
184//================= Conversion functions ==================================//
185
186
196 virtual void fromTQColor(const TQColor& c, TQ_UINT8 *dst, KisProfile * profile = 0) = 0;
197
208 virtual void fromTQColor(const TQColor& c, TQ_UINT8 opacity, TQ_UINT8 *dst, KisProfile * profile = 0) = 0;
209
210
220 virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, KisProfile * profile = 0) = 0;
221
232 virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, TQ_UINT8 *opacity, KisProfile * profile = 0) = 0;
233
248 virtual TQImage convertToTQImage(const TQ_UINT8 *data, TQ_INT32 width, TQ_INT32 height,
249 KisProfile * dstProfile, TQ_INT32 renderingIntent = INTENT_PERCEPTUAL,
250 float exposure = 0.0f) = 0;
251
252
260 virtual void toLabA16(const TQ_UINT8 * src, TQ_UINT8 * dst, const TQ_UINT32 nPixels) const = 0;
261
270 virtual void fromLabA16(const TQ_UINT8 * src, TQ_UINT8 * dst, const TQ_UINT32 nPixels) const = 0;
271
278 virtual bool convertPixelsTo(const TQ_UINT8 * src,
279 TQ_UINT8 * dst, KisColorSpace * dstColorSpace,
280 TQ_UINT32 numPixels,
281 TQ_INT32 renderingIntent = INTENT_PERCEPTUAL) = 0;
282
283//============================== Manipulation functions ==========================//
284
285
286//
287// The manipulation functions have default implementations that _convert_ the pixel
288// to a TQColor and back. Reimplement these methods in your color strategy!
289//
290
294 virtual TQ_UINT8 getAlpha(const TQ_UINT8 * pixel) const = 0;
295
304 virtual void setAlpha(TQ_UINT8 * pixels, TQ_UINT8 alpha, TQ_INT32 nPixels) const = 0;
305
314 virtual void multiplyAlpha(TQ_UINT8 * pixels, TQ_UINT8 alpha, TQ_INT32 nPixels) = 0;
315
321 virtual void applyAlphaU8Mask(TQ_UINT8 * pixels, TQ_UINT8 * alpha, TQ_INT32 nPixels) = 0;
322
328 virtual void applyInverseAlphaU8Mask(TQ_UINT8 * pixels, TQ_UINT8 * alpha, TQ_INT32 nPixels) = 0;
329
334 virtual KisColorAdjustment *createBrightnessContrastAdjustment(TQ_UINT16 *transferValues) = 0;
335
339 virtual KisColorAdjustment *createDesaturateAdjustment() = 0;
340
345 virtual KisColorAdjustment *createPerChannelAdjustment(TQ_UINT16 **transferValues) = 0;
346
350 virtual void applyAdjustment(const TQ_UINT8 *src, TQ_UINT8 *dst, KisColorAdjustment *, TQ_INT32 nPixels) = 0;
351
355 virtual void invertColor(TQ_UINT8 * src, TQ_INT32 nPixels) = 0;
356
357 // XXX: What with alpha channels? YYY: Add an overloaded function that takes alpha into account?
361 virtual TQ_UINT8 difference(const TQ_UINT8* src1, const TQ_UINT8* src2) = 0;
362
363
367 virtual void mixColors(const TQ_UINT8 **colors, const TQ_UINT8 *weights, TQ_UINT32 nColors, TQ_UINT8 *dst) const = 0;
368
373 virtual void convolveColors(TQ_UINT8** colors, TQ_INT32* kernelValues, KisChannelInfo::enumChannelFlags channelFlags, TQ_UINT8 *dst, TQ_INT32 factor, TQ_INT32 offset, TQ_INT32 nPixels) const = 0;
374
381 virtual void darken(const TQ_UINT8 * src, TQ_UINT8 * dst, TQ_INT32 shade, bool compensate, double compensation, TQ_INT32 nPixels) const = 0;
382
386 virtual TQ_UINT8 intensity8(const TQ_UINT8 * src) const = 0;
387
391 virtual KisID mathToolboxID() const =0;
392
398 virtual void bitBlt(TQ_UINT8 *dst,
399 TQ_INT32 dststride,
400 KisColorSpace * srcSpace,
401 const TQ_UINT8 *src,
402 TQ_INT32 srcRowStride,
403 const TQ_UINT8 *srcAlphaMask,
404 TQ_INT32 maskRowStride,
405 TQ_UINT8 opacity,
406 TQ_INT32 rows,
407 TQ_INT32 cols,
408 const KisCompositeOp& op) = 0;
409
415 virtual TQValueList<KisFilter*> createBackgroundFilters()
416 { return TQValueList<KisFilter*>(); };
417
418private:
419
420 DCOPObject * m_dcop;
421
422};
423
424class KisColorSpaceFactory {
425public:
430 virtual KisID id() const = 0;
431
435 virtual TQ_UINT32 colorSpaceType() = 0;
436
437 virtual icColorSpaceSignature colorSpaceSignature() = 0;
438
439 virtual KisColorSpace *createColorSpace(KisColorSpaceFactoryRegistry * parent, KisProfile *) = 0;
440
446 virtual TQString defaultProfile() = 0;
447
448};
449
450#endif // KIS_COLORSPACE_H_
A colorspace is the definition of a certain color model in Chalk.
virtual KisColorAdjustment * createDesaturateAdjustment()=0
Create an adjustment object for desaturating.
virtual void bitBlt(TQ_UINT8 *dst, TQ_INT32 dststride, KisColorSpace *srcSpace, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *srcAlphaMask, TQ_INT32 maskRowStride, TQ_UINT8 opacity, TQ_INT32 rows, TQ_INT32 cols, const KisCompositeOp &op)=0
Compose two arrays of pixels together.
virtual bool willDegrade(ColorSpaceIndependence independence)=0
If false, images in this colorspace will degrade considerably by functions, tools and filters that ha...
virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, KisProfile *profile=0)=0
The toTQColor methods take a byte array that is at least pixelSize() long and converts the contents t...
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 void applyAlphaU8Mask(TQ_UINT8 *pixels, TQ_UINT8 *alpha, TQ_INT32 nPixels)=0
Applies the specified 8-bit alpha mask to the pixels.
virtual TQ_UINT32 nColorChannels() const =0
The total number of color channels (excludes alpha and substance) for a single pixel in this color mo...
virtual void fromTQColor(const TQColor &c, TQ_UINT8 opacity, TQ_UINT8 *dst, KisProfile *profile=0)=0
The fromTQColor methods take a given color defined as an RGB TQColor and fills a byte array with the ...
virtual void mixColors(const TQ_UINT8 **colors, const TQ_UINT8 *weights, TQ_UINT32 nColors, TQ_UINT8 *dst) const =0
Mix the colors given their weights and return in dst The sum of weights is assumed 255.
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 void darken(const TQ_UINT8 *src, TQ_UINT8 *dst, TQ_INT32 shade, bool compensate, double compensation, TQ_INT32 nPixels) const =0
Darken all color channels with the given amount.
virtual KisCompositeOpList userVisiblecompositeOps() const =0
Returns the list of user-visible composite ops supported by this colourspace.
virtual TQ_UINT8 intensity8(const TQ_UINT8 *src) const =0
Calculate the intensity of the given pixel, scaled down to the range 0-255.
virtual void applyAdjustment(const TQ_UINT8 *src, TQ_UINT8 *dst, KisColorAdjustment *, TQ_INT32 nPixels)=0
Apply the adjustment created with onr of the other functions.
virtual void invertColor(TQ_UINT8 *src, TQ_INT32 nPixels)=0
Invert color channels of the given pixels.
virtual void fromTQColor(const TQColor &c, TQ_UINT8 *dst, KisProfile *profile=0)=0
The fromTQColor methods take a given color defined as an RGB TQColor and fills a byte array with the ...
virtual TQValueList< KisFilter * > createBackgroundFilters()
The backgroundfilters will be run periodically on the newly created paint device.
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 KisColorAdjustment * createBrightnessContrastAdjustment(TQ_UINT16 *transferValues)=0
Create an adjustment object for adjusting the brightness and contrast transferValues is a 256 bins ar...
virtual void convolveColors(TQ_UINT8 **colors, TQ_INT32 *kernelValues, KisChannelInfo::enumChannelFlags channelFlags, TQ_UINT8 *dst, TQ_INT32 factor, TQ_INT32 offset, TQ_INT32 nPixels) const =0
Convolve the given array of pointers to pixels and return the result in dst.
virtual bool convertPixelsTo(const TQ_UINT8 *src, TQ_UINT8 *dst, KisColorSpace *dstColorSpace, TQ_UINT32 numPixels, TQ_INT32 renderingIntent=INTENT_PERCEPTUAL)=0
Convert a byte array of srcLen pixels *src to the specified color space and put the converted bytes i...
virtual TQImage convertToTQImage(const TQ_UINT8 *data, TQ_INT32 width, TQ_INT32 height, KisProfile *dstProfile, TQ_INT32 renderingIntent=INTENT_PERCEPTUAL, float exposure=0.0f)=0
Convert the pixels in data to (8-bit BGRA) TQImage using the specified profiles.
virtual KisColorAdjustment * createPerChannelAdjustment(TQ_UINT16 **transferValues)=0
Create an adjustment object for adjusting individual channels transferValues is an array of nColorCha...
virtual TQValueVector< KisChannelInfo * > channels() const =0
Return a vector describing all the channels this color model has.
virtual TQ_UINT32 pixelSize() const =0
The size in bytes of a single pixel in this color model.
virtual void getSingleChannelPixel(TQ_UINT8 *dstPixel, const TQ_UINT8 *srcPixel, TQ_UINT32 channelIndex)=0
Set dstPixel to the pixel containing only the given channel of srcPixel.
virtual void applyInverseAlphaU8Mask(TQ_UINT8 *pixels, TQ_UINT8 *alpha, TQ_INT32 nPixels)=0
Applies the inverted 8-bit alpha mask to the pixels.
virtual TQ_UINT32 nChannels() const =0
The total number of channels for a single pixel in this color model.
virtual TQ_UINT32 nSubstanceChannels() const
The total number of substance channels for a single pixel in this color model.
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 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 toLabA16(const TQ_UINT8 *src, TQ_UINT8 *dst, const TQ_UINT32 nPixels) const =0
Convert the specified data to Lab.
virtual void fromLabA16(const TQ_UINT8 *src, TQ_UINT8 *dst, const TQ_UINT32 nPixels) const =0
Convert the specified data from Lab.
virtual bool hasHighDynamicRange() const =0
Returns true if the colorspace supports channel values outside the (normalised) range 0 to 1.
virtual KisID mathToolboxID() const =0
Create a mathematical toolbox compatible with this colorspace.
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 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.
virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, TQ_UINT8 *opacity, KisProfile *profile=0)=0
The toTQColor methods take a byte array that is at least pixelSize() long and converts the contents t...
virtual TQ_UINT32 colorSpaceType()=0
lcms colorspace type definition.
virtual TQ_UINT8 difference(const TQ_UINT8 *src1, const TQ_UINT8 *src2)=0
Get the difference between 2 colors, normalized in the range (0,255)
virtual KisID id() const =0
Chalk definition for use in .kra files and internally: unchanging name + i18n'able description.
virtual KisProfile * getProfile() const =0
Return the profile of this color space.
Basic interface of a Chalk filter.
Definition kis_filter.h:46
Chalk has a large number of extensible resources.
Definition kis_id.h:57