krita

kis_colorspace.h

00001 /*
00002  *  Copyright (c) 2005 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_COLORSPACE_H_
00019 #define KIS_COLORSPACE_H_
00020 
00021 #include <config.h>
00022 #include LCMS_HEADER
00023 
00024 #include <qvaluevector.h>
00025 #include <qvaluelist.h>
00026 
00027 #include "kis_composite_op.h"
00028 #include "kis_channelinfo.h"
00029 
00030 class DCOPObject;
00031 
00032 class KisProfile;
00033 class KisColorSpaceFactoryRegistry;
00034 class KisMathToolbox;
00035 class KisFilter;
00036 
00037 class KisColorAdjustment
00038 {
00039 public:
00040 
00041     KisColorAdjustment() {};
00042     virtual ~KisColorAdjustment() {};
00043 };
00044 
00045 
00046 enum ColorSpaceIndependence {
00047     FULLY_INDEPENDENT,
00048     TO_LAB16,
00049     TO_RGBA8,
00050     TO_RGBA16
00051 };
00052 
00058 class KisColorSpace {
00059 
00060 
00061 public:
00062 
00063     KisColorSpace();
00064     virtual ~KisColorSpace();
00065 
00066     virtual DCOPObject * dcopObject();
00067 
00068     virtual bool operator==(const KisColorSpace& rhs) const {
00069         return id().id() == rhs.id().id();
00070     }
00071 
00072     
00073 public:
00074 
00075     //========== Channels =====================================================//
00076 
00078     virtual QValueVector<KisChannelInfo *> channels() const = 0;
00079 
00083     virtual Q_UINT32 nChannels() const = 0;
00084 
00089     virtual Q_UINT32 nColorChannels() const = 0;
00090 
00095     virtual Q_UINT32 nSubstanceChannels() const { return 0; };
00096 
00100     virtual Q_UINT32 pixelSize() const = 0;
00101 
00105     virtual QString channelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const = 0;
00106 
00111     virtual QString normalisedChannelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const = 0;
00112 
00118     virtual Q_UINT8 scaleToU8(const Q_UINT8 * srcPixel, Q_INT32 channelPos) = 0;
00119 
00125      virtual Q_UINT16 scaleToU16(const Q_UINT8 * srcPixel, Q_INT32 channelPos) = 0;
00126 
00132      virtual void getSingleChannelPixel(Q_UINT8 *dstPixel, const Q_UINT8 *srcPixel, Q_UINT32 channelIndex) = 0;
00133 
00134     //========== Identification ===============================================//
00135 
00140     virtual KisID id() const = 0;
00141 
00145     virtual Q_UINT32 colorSpaceType() = 0;
00146 
00147     virtual icColorSpaceSignature colorSpaceSignature() = 0;
00148 
00159     virtual bool willDegrade(ColorSpaceIndependence independence) = 0;
00160     
00161     //========== Capabilities =================================================//
00162 
00168     virtual KisCompositeOpList userVisiblecompositeOps() const = 0;
00169 
00174     virtual bool hasHighDynamicRange() const = 0;
00175 
00176 
00177     //========== Display profiles =============================================//
00178 
00182     virtual KisProfile * getProfile() = 0;
00183 
00184 //================= Conversion functions ==================================//
00185 
00186 
00196     virtual void fromQColor(const QColor& c, Q_UINT8 *dst, KisProfile * profile = 0) = 0;
00197 
00208     virtual void fromQColor(const QColor& c, Q_UINT8 opacity, Q_UINT8 *dst, KisProfile * profile = 0) = 0;
00209 
00210 
00220     virtual void toQColor(const Q_UINT8 *src, QColor *c, KisProfile * profile = 0) = 0;
00221 
00232     virtual void toQColor(const Q_UINT8 *src, QColor *c, Q_UINT8 *opacity, KisProfile * profile = 0) = 0;
00233 
00248     virtual QImage convertToQImage(const Q_UINT8 *data, Q_INT32 width, Q_INT32 height,
00249                                    KisProfile *  dstProfile, Q_INT32 renderingIntent = INTENT_PERCEPTUAL,
00250                                    float exposure = 0.0f) = 0;
00251 
00252 
00260     virtual void toLabA16(const Q_UINT8 * src, Q_UINT8 * dst, const Q_UINT32 nPixels) const = 0;
00261 
00270     virtual void fromLabA16(const Q_UINT8 * src, Q_UINT8 * dst, const Q_UINT32 nPixels) const = 0;
00271 
00278     virtual bool convertPixelsTo(const Q_UINT8 * src,
00279                                  Q_UINT8 * dst, KisColorSpace * dstColorSpace,
00280                                  Q_UINT32 numPixels,
00281                                  Q_INT32 renderingIntent = INTENT_PERCEPTUAL) = 0;
00282 
00283 //============================== Manipulation functions ==========================//
00284 
00285 
00286 //
00287 // The manipulation functions have default implementations that _convert_ the pixel
00288 // to a QColor and back. Reimplement these methods in your color strategy!
00289 //
00290 
00294     virtual Q_UINT8 getAlpha(const Q_UINT8 * pixel) const = 0;
00295 
00304     virtual void setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels) const = 0;
00305 
00314     virtual void multiplyAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels) = 0;
00315 
00321     virtual void applyAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels) = 0;
00322 
00328     virtual void applyInverseAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels) = 0;
00329 
00334     virtual KisColorAdjustment *createBrightnessContrastAdjustment(Q_UINT16 *transferValues) = 0;
00335 
00339     virtual KisColorAdjustment *createDesaturateAdjustment() = 0;
00340 
00345     virtual KisColorAdjustment *createPerChannelAdjustment(Q_UINT16 **transferValues) = 0;
00346 
00350     virtual void applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *, Q_INT32 nPixels) = 0;
00351 
00355     virtual void invertColor(Q_UINT8 * src, Q_INT32 nPixels) = 0;
00356 
00357     // XXX: What with alpha channels? YYY: Add an overloaded function that takes alpha into account?
00361     virtual Q_UINT8 difference(const Q_UINT8* src1, const Q_UINT8* src2) = 0;
00362 
00363 
00367     virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const = 0;
00368 
00373     virtual void convolveColors(Q_UINT8** colors, Q_INT32* kernelValues, KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 offset, Q_INT32 nPixels) const = 0;
00374 
00381     virtual void darken(const Q_UINT8 * src, Q_UINT8 * dst, Q_INT32 shade, bool compensate, double compensation, Q_INT32 nPixels) const = 0;
00382 
00386     virtual Q_UINT8 intensity8(const Q_UINT8 * src) const = 0;
00387     
00391     virtual KisID mathToolboxID() const =0;
00392     
00398     virtual void bitBlt(Q_UINT8 *dst,
00399                 Q_INT32 dststride,
00400                 KisColorSpace * srcSpace,
00401                 const Q_UINT8 *src,
00402                 Q_INT32 srcRowStride,
00403                 const Q_UINT8 *srcAlphaMask,
00404                 Q_INT32 maskRowStride,
00405                 Q_UINT8 opacity,
00406                 Q_INT32 rows,
00407                 Q_INT32 cols,
00408                 const KisCompositeOp& op) = 0;
00409 
00415     virtual QValueList<KisFilter*> createBackgroundFilters()
00416         { return QValueList<KisFilter*>(); };
00417 
00418 private:
00419 
00420     DCOPObject * m_dcop;
00421 
00422 };
00423 
00424 class KisColorSpaceFactory {
00425 public:
00430     virtual KisID id() const = 0;
00431 
00435     virtual Q_UINT32 colorSpaceType() = 0;
00436 
00437     virtual icColorSpaceSignature colorSpaceSignature() = 0;
00438 
00439     virtual KisColorSpace *createColorSpace(KisColorSpaceFactoryRegistry * parent, KisProfile *) = 0;
00440 
00446     virtual QString defaultProfile() = 0;
00447 
00448 };
00449 
00450 #endif // KIS_COLORSPACE_H_
KDE Home | KDE Accessibility Home | Description of Access Keys