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 };
00051 
00057 class KisColorSpace {
00058 
00059 
00060 public:
00061 
00062     KisColorSpace();
00063     virtual ~KisColorSpace();
00064 
00065     virtual DCOPObject * dcopObject();
00066 
00067     virtual bool operator==(const KisColorSpace& rhs) const {
00068         return id().id() == rhs.id().id();
00069     }
00070 
00071     
00072 public:
00073 
00074     //========== Channels =====================================================//
00075 
00077     virtual QValueVector<KisChannelInfo *> channels() const = 0;
00078 
00082     virtual Q_UINT32 nChannels() const = 0;
00083 
00088     virtual Q_UINT32 nColorChannels() const = 0;
00089 
00094     virtual Q_UINT32 nSubstanceChannels() const { return 0; };
00095 
00099     virtual Q_UINT32 pixelSize() const = 0;
00100 
00104     virtual QString channelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const = 0;
00105 
00110     virtual QString normalisedChannelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const = 0;
00111 
00117     virtual Q_UINT8 scaleToU8(const Q_UINT8 * srcPixel, Q_INT32 channelPos) = 0;
00118 
00124      virtual Q_UINT16 scaleToU16(const Q_UINT8 * srcPixel, Q_INT32 channelPos) = 0;
00125 
00131      virtual void getSingleChannelPixel(Q_UINT8 *dstPixel, const Q_UINT8 *srcPixel, Q_UINT32 channelIndex) = 0;
00132 
00133     //========== Identification ===============================================//
00134 
00139     virtual KisID id() const = 0;
00140 
00144     virtual Q_UINT32 colorSpaceType() = 0;
00145 
00146     virtual icColorSpaceSignature colorSpaceSignature() = 0;
00147 
00158     virtual bool willDegrade(ColorSpaceIndependence independence) = 0;
00159     
00160     //========== Capabilities =================================================//
00161 
00167     virtual KisCompositeOpList userVisiblecompositeOps() const = 0;
00168 
00173     virtual bool hasHighDynamicRange() const = 0;
00174 
00175 
00176     //========== Display profiles =============================================//
00177 
00181     virtual KisProfile * getProfile() = 0;
00182 
00183 //================= Conversion functions ==================================//
00184 
00185 
00195     virtual void fromQColor(const QColor& c, Q_UINT8 *dst, KisProfile * profile = 0) = 0;
00196 
00207     virtual void fromQColor(const QColor& c, Q_UINT8 opacity, Q_UINT8 *dst, KisProfile * profile = 0) = 0;
00208 
00218     virtual void toQColor(const Q_UINT8 *src, QColor *c, KisProfile * profile = 0) = 0;
00219 
00230     virtual void toQColor(const Q_UINT8 *src, QColor *c, Q_UINT8 *opacity, KisProfile * profile = 0) = 0;
00231 
00246     virtual QImage convertToQImage(const Q_UINT8 *data, Q_INT32 width, Q_INT32 height,
00247                                    KisProfile *  dstProfile, Q_INT32 renderingIntent = INTENT_PERCEPTUAL,
00248                                    float exposure = 0.0f) = 0;
00249 
00250 
00251 
00258     virtual bool convertPixelsTo(const Q_UINT8 * src,
00259                                  Q_UINT8 * dst, KisColorSpace * dstColorSpace,
00260                                  Q_UINT32 numPixels,
00261                                  Q_INT32 renderingIntent = INTENT_PERCEPTUAL) = 0;
00262 
00263 //============================== Manipulation functions ==========================//
00264 
00265 
00266 //
00267 // The manipulation functions have default implementations that _convert_ the pixel
00268 // to a QColor and back. Reimplement these methods in your color strategy!
00269 //
00270 
00274     virtual Q_UINT8 getAlpha(const Q_UINT8 * pixel) const = 0;
00275 
00284     virtual void setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels) const = 0;
00285 
00294     virtual void multiplyAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels) = 0;
00295 
00301     virtual void applyAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels) = 0;
00302 
00308     virtual void applyInverseAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels) = 0;
00309 
00314     virtual KisColorAdjustment *createBrightnessContrastAdjustment(Q_UINT16 *transferValues) = 0;
00315 
00319     virtual KisColorAdjustment *createDesaturateAdjustment() = 0;
00320 
00325     virtual KisColorAdjustment *createPerChannelAdjustment(Q_UINT16 **transferValues) = 0;
00326 
00330     virtual void applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *, Q_INT32 nPixels) = 0;
00331 
00335     virtual void invertColor(Q_UINT8 * src, Q_INT32 nPixels) = 0;
00336 
00337     // XXX: What with alpha channels? YYY: Add an overloaded function that takes alpha into account?
00341     virtual Q_UINT8 difference(const Q_UINT8* src1, const Q_UINT8* src2) = 0;
00342 
00343 
00347     virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const = 0;
00348 
00353     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;
00354 
00361     virtual void darken(const Q_UINT8 * src, Q_UINT8 * dst, Q_INT32 shade, bool compensate, double compensation, Q_INT32 nPixels) const = 0;
00362 
00366     virtual Q_UINT8 intensity8(const Q_UINT8 * src) const = 0;
00367     
00371     virtual KisID mathToolboxID() const =0;
00372     
00378     virtual void bitBlt(Q_UINT8 *dst,
00379                 Q_INT32 dststride,
00380                 KisColorSpace * srcSpace,
00381                 const Q_UINT8 *src,
00382                 Q_INT32 srcRowStride,
00383                 const Q_UINT8 *srcAlphaMask,
00384                 Q_INT32 maskRowStride,
00385                 Q_UINT8 opacity,
00386                 Q_INT32 rows,
00387                 Q_INT32 cols,
00388                 const KisCompositeOp& op) = 0;
00389 
00395     virtual QValueList<KisFilter*> createBackgroundFilters()
00396         { return QValueList<KisFilter*>(); };
00397 
00398 private:
00399 
00400     DCOPObject * m_dcop;
00401 
00402 };
00403 
00404 class KisColorSpaceFactory {
00405 public:
00410     virtual KisID id() const = 0;
00411 
00415     virtual Q_UINT32 colorSpaceType() = 0;
00416 
00417     virtual icColorSpaceSignature colorSpaceSignature() = 0;
00418 
00419     virtual KisColorSpace *createColorSpace(KisColorSpaceFactoryRegistry * parent, KisProfile *) = 0;
00420 
00426     virtual QString defaultProfile() = 0;
00427 
00428 };
00429 
00430 #endif // KIS_COLORSPACE_H_
KDE Home | KDE Accessibility Home | Description of Access Keys