krita

kis_abstract_colorspace.h

00001 /*
00002  *  Copyright (c) 2002 Patrick Julien  <freak@codepimps.org>
00003  *  Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  */
00019 #ifndef KIS_ABSTRACT_COLORSPACE_H_
00020 #define KIS_ABSTRACT_COLORSPACE_H_
00021 
00022 #include <qmap.h>
00023 #include <qcolor.h>
00024 #include <qstringlist.h>
00025 #include <qpair.h>
00026 
00027 #include "kis_global.h"
00028 #include "kis_channelinfo.h"
00029 #include "kis_profile.h"
00030 #include "kis_id.h"
00031 #include "kis_composite_op.h"
00032 #include "kis_colorspace.h"
00033 
00034 class QPainter;
00035 class KisPixelRO;
00036 class KisColorSpaceFactoryRegistry;
00037 
00038 
00043 class KisAbstractColorSpace : public KisColorSpace {
00044 
00045 
00046 public:
00047 
00055     KisAbstractColorSpace(const KisID & id,
00056                           DWORD cmType,
00057                           icColorSpaceSignature colorSpaceSignature,
00058                           KisColorSpaceFactoryRegistry * parent,
00059                           KisProfile *profile);
00060 
00061     void init();
00062 
00063     virtual ~KisAbstractColorSpace();
00064 
00065     virtual bool operator==(const KisAbstractColorSpace& rhs) const {
00066         return (m_id == rhs.m_id && m_profile == rhs.m_profile);
00067     }
00068 
00069 
00070 //================== Information about this color strategy ========================//
00071 
00072 public:
00073 
00074 
00075     //========== Channels =====================================================//
00076 
00077     // Return a vector describing all the channels this color model has.
00078     virtual QValueVector<KisChannelInfo *> channels() const = 0;
00079 
00080     virtual Q_UINT32 nChannels() const = 0;
00081 
00082     virtual Q_UINT32 nColorChannels() const = 0;
00083 
00084     virtual Q_UINT32 nSubstanceChannels() const { return 0; };
00085 
00086     virtual Q_UINT32 pixelSize() const = 0;
00087 
00088     virtual QString channelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const = 0;
00089 
00090     virtual QString normalisedChannelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const = 0;
00091 
00092     virtual Q_UINT8 scaleToU8(const Q_UINT8 * srcPixel, Q_INT32 channelPos) = 0;
00093 
00094     virtual Q_UINT16 scaleToU16(const Q_UINT8 * srcPixel, Q_INT32 channelPos) = 0;
00095 
00096     virtual void getSingleChannelPixel(Q_UINT8 *dstPixel, const Q_UINT8 *srcPixel, Q_UINT32 channelIndex);
00097 
00098     //========== Identification ===============================================//
00099 
00100     virtual KisID id() const { return m_id; }
00101 
00102     void setColorSpaceType(Q_UINT32 type) { m_cmType = type; }
00103     Q_UINT32 colorSpaceType() { return m_cmType; }
00104 
00105     virtual icColorSpaceSignature colorSpaceSignature() { return m_colorSpaceSignature; }
00106 
00107     //========== Capabilities =================================================//
00108 
00109     virtual KisCompositeOpList userVisiblecompositeOps() const = 0;
00110 
00115     virtual bool hasHighDynamicRange() const { return false; }
00116 
00117     //========== Display profiles =============================================//
00118 
00119     virtual KisProfile * getProfile() { return m_profile; };
00120 
00121 
00122 //================= Conversion functions ==================================//
00123 
00124 
00125     virtual void fromQColor(const QColor& c, Q_UINT8 *dst, KisProfile * profile = 0);
00126     virtual void fromQColor(const QColor& c, Q_UINT8 opacity, Q_UINT8 *dst, KisProfile * profile = 0);
00127 
00128     virtual void toQColor(const Q_UINT8 *src, QColor *c, KisProfile * profile = 0);
00129     virtual void toQColor(const Q_UINT8 *src, QColor *c, Q_UINT8 *opacity, KisProfile * profile = 0);
00130 
00131     virtual QImage convertToQImage(const Q_UINT8 *data, Q_INT32 width, Q_INT32 height,
00132                                    KisProfile *  dstProfile,
00133                                    Q_INT32 renderingIntent = INTENT_PERCEPTUAL,
00134                                    float exposure = 0.0f);
00135 
00136     virtual bool convertPixelsTo(const Q_UINT8 * src,
00137                                  Q_UINT8 * dst, KisColorSpace * dstColorSpace,
00138                                  Q_UINT32 numPixels,
00139                                  Q_INT32 renderingIntent = INTENT_PERCEPTUAL);
00140 
00141 //============================== Manipulation fucntions ==========================//
00142 
00143 
00144 //
00145 // The manipulation functions have default implementations that _convert_ the pixel
00146 // to a QColor and back. Reimplement these methods in your color strategy!
00147 //
00148     virtual KisColorAdjustment *createBrightnessContrastAdjustment(Q_UINT16 *transferValues);
00149 
00150     virtual KisColorAdjustment *createDesaturateAdjustment();
00151 
00152     virtual KisColorAdjustment *createPerChannelAdjustment(Q_UINT16 **transferValues);
00153 
00154     virtual void applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *, Q_INT32 nPixels);
00155 
00156     virtual void invertColor(Q_UINT8 * src, Q_INT32 nPixels);
00157     
00158     virtual Q_UINT8 difference(const Q_UINT8* src1, const Q_UINT8* src2);
00159 
00160     virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;
00161 
00162     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;
00163 
00164     virtual void darken(const Q_UINT8 * src, Q_UINT8 * dst, Q_INT32 shade, bool compensate, double compensation, Q_INT32 nPixels) const;
00165 
00166     virtual Q_UINT8 intensity8(const Q_UINT8 * src) const;
00167     
00168     virtual KisID mathToolboxID() const;
00169 
00170     virtual void bitBlt(Q_UINT8 *dst,
00171                 Q_INT32 dststride,
00172                 KisColorSpace * srcSpace,
00173                 const Q_UINT8 *src,
00174                 Q_INT32 srcRowStride,
00175                 const Q_UINT8 *srcAlphaMask,
00176                 Q_INT32 maskRowStride,
00177                 Q_UINT8 opacity,
00178                 Q_INT32 rows,
00179                 Q_INT32 cols,
00180                 const KisCompositeOp& op);
00181 
00182 //========================== END of Public API ========================================//
00183 
00184 protected:
00185 
00186 
00191     virtual void bitBlt(Q_UINT8 *dst,
00192                 Q_INT32 dstRowSize,
00193                 const Q_UINT8 *src,
00194                 Q_INT32 srcRowStride,
00195                 const Q_UINT8 *srcAlphaMask,
00196                 Q_INT32 maskRowStride,
00197                 Q_UINT8 opacity,
00198                 Q_INT32 rows,
00199                 Q_INT32 cols,
00200                 const KisCompositeOp& op) = 0;
00201 
00202     virtual cmsHTRANSFORM createTransform(KisColorSpace * dstColorSpace,
00203                           KisProfile *  srcProfile,
00204                           KisProfile *  dstProfile,
00205                           Q_INT32 renderingIntent);
00206 
00207     virtual void compositeCopy(Q_UINT8 *dstRowStart, Q_INT32 dstRowStride, const Q_UINT8 *srcRowStart, Q_INT32 srcRowStride, const Q_UINT8 *maskRowStart, Q_INT32 maskRowStride, Q_INT32 rows, Q_INT32 numColumns, Q_UINT8 opacity);
00208 
00209 protected:
00210 
00211     QStringList m_profileFilenames;
00212     Q_UINT8 * m_qcolordata; // A small buffer for conversion from and to qcolor.
00213     Q_INT32 m_alphaPos; // The position in _bytes_ of the alpha channel
00214     Q_INT32 m_alphaSize; // The width in _bytes_ of the alpha channel
00215 
00216     QValueVector<KisChannelInfo *> m_channels;
00217 
00218     KisColorSpaceFactoryRegistry * m_parent;
00219 
00220 private:
00221 
00222     cmsHTRANSFORM m_defaultToRGB;    // Default transform to 8 bit sRGB
00223     cmsHTRANSFORM m_defaultFromRGB;  // Default transform from 8 bit sRGB
00224 
00225     cmsHPROFILE   m_lastRGBProfile;  // Last used profile to transform to/from RGB
00226     cmsHTRANSFORM m_lastToRGB;       // Last used transform to transform to RGB
00227     cmsHTRANSFORM m_lastFromRGB;     // Last used transform to transform from RGB
00228 
00229     cmsHTRANSFORM m_defaultToLab;
00230     cmsHTRANSFORM m_defaultFromLab;
00231 
00232     KisProfile *  m_profile;
00233     KisColorSpace *m_lastUsedDstColorSpace;
00234     cmsHTRANSFORM m_lastUsedTransform;
00235 
00236     KisID m_id;
00237     DWORD m_cmType;                           // The colorspace type as defined by littlecms
00238     icColorSpaceSignature m_colorSpaceSignature; // The colorspace signature as defined in icm/icc files
00239 
00240     // cmsHTRANSFORM is a void *, so this should work.
00241     typedef QMap<KisColorSpace *, cmsHTRANSFORM>  TransformMap;
00242     TransformMap m_transforms; // Cache for existing transforms
00243 
00244     KisAbstractColorSpace(const KisAbstractColorSpace&);
00245     KisAbstractColorSpace& operator=(const KisAbstractColorSpace&);
00246 
00247     QMemArray<Q_UINT8> m_conversionCache; // XXX: This will be a bad problem when we have threading.
00248 };
00249 
00250 #endif // KIS_STRATEGY_COLORSPACE_H_
KDE Home | KDE Accessibility Home | Description of Access Keys