filters

kis_ycbcr_u8_colorspace.h

00001 /*
00002  *  Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
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,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #ifndef KIS_YCBCR_U8_COLORSPACE_H
00021 #define KIS_YCBCR_U8_COLORSPACE_H
00022 
00023 #include <kis_u8_base_colorspace.h>
00024 
00025 #define LUMA_RED 0.2989
00026 #define LUMA_GREEN 0.587
00027 #define LUMA_BLUE 0.114
00028 
00029 //TODO: for 1.6/2.0 move it to a krita/colorspaces/YCbCr_u8 and //i18nise it
00030 
00031 class KisYCbCrU8ColorSpace : public KisU8BaseColorSpace
00032 {
00033     public:
00034         KisYCbCrU8ColorSpace(KisColorSpaceFactoryRegistry* parent, KisProfile* p);
00035         ~KisYCbCrU8ColorSpace();
00036         virtual bool willDegrade(ColorSpaceIndependence )
00037         {
00038             return false;
00039         };
00040     public:
00041         void setPixel(Q_UINT8 *pixel, Q_UINT8 Y, Q_UINT8 Cb, Q_UINT8 Cr, Q_UINT8 alpha) const;
00042         void getPixel(const Q_UINT8 *pixel, Q_UINT8 *Y, Q_UINT8 *Cb, Q_UINT8 *Cr, Q_UINT8 *alpha) const;
00043 
00044         virtual void fromQColor(const QColor& c, Q_UINT8 *dst, KisProfile * profile = 0);
00045         virtual void fromQColor(const QColor& c, Q_UINT8 opacity, Q_UINT8 *dst, KisProfile * profile = 0);
00046 
00047         virtual void toQColor(const Q_UINT8 *src, QColor *c, KisProfile * profile = 0);
00048         virtual void toQColor(const Q_UINT8 *src, QColor *c, Q_UINT8 *opacity, KisProfile * profile = 0);
00049 
00050         virtual Q_UINT8 difference(const Q_UINT8 *src1, const Q_UINT8 *src2);
00051         virtual void mixColors(const Q_UINT8 **colors, const Q_UINT8 *weights, Q_UINT32 nColors, Q_UINT8 *dst) const;
00052 
00053         virtual QValueVector<KisChannelInfo *> channels() const;
00054         virtual Q_UINT32 nChannels() const;
00055         virtual Q_UINT32 nColorChannels() const;
00056         virtual Q_UINT32 pixelSize() const;
00057 
00058         virtual QImage convertToQImage(const Q_UINT8 *data, Q_INT32 width, Q_INT32 height,
00059                                        KisProfile *  dstProfile,
00060                                        Q_INT32 renderingIntent,
00061                                        float exposure = 0.0f);
00062 
00063         virtual KisCompositeOpList userVisiblecompositeOps() const;
00064 
00065     protected:
00066 
00067         virtual void bitBlt(Q_UINT8 *dst,
00068                             Q_INT32 dstRowStride,
00069                             const Q_UINT8 *src,
00070                             Q_INT32 srcRowStride,
00071                             const Q_UINT8 *srcAlphaMask,
00072                             Q_INT32 maskRowStride,
00073                             Q_UINT8 opacity,
00074                             Q_INT32 rows,
00075                             Q_INT32 cols,
00076                             const KisCompositeOp& op);
00077 
00078         void compositeOver(Q_UINT8 *dst, Q_INT32 dstRowStride, const Q_UINT8 *src, Q_INT32 srcRowStride, const Q_UINT8 *mask, Q_INT32 maskRowStride, Q_INT32 rows, Q_INT32 columns, Q_UINT8 opacity);
00079         void compositeErase(Q_UINT8 *dst, Q_INT32 dstRowStride, const Q_UINT8 *src, Q_INT32 srcRowStride, const Q_UINT8 *mask, Q_INT32 maskRowStride, Q_INT32 rows, Q_INT32 columns, Q_UINT8 opacity);
00080         void compositeCopy(Q_UINT8 *dst, Q_INT32 dstRowStride, const Q_UINT8 *src, Q_INT32 srcRowStride, const Q_UINT8 *mask, Q_INT32 maskRowStride, Q_INT32 rows, Q_INT32 columns, Q_UINT8 opacity);
00081 
00082     private:
00083 #define CLAMP_TO_8BITCHANNEL(a) CLAMP(a, 0, Q_UINT8_MAX)
00084         inline Q_UINT8 computeRed(Q_UINT8 Y, Q_UINT8 /*Cb*/, Q_UINT8 Cr)
00085         {
00086             return (Q_UINT8)( CLAMP_TO_8BITCHANNEL( (Cr - 128)* (2-2*LUMA_RED) + Y )  );
00087         }
00088         inline Q_UINT8 computeGreen(Q_UINT8 Y, Q_UINT8 Cb, Q_UINT8 Cr)
00089         {
00090             return (Q_UINT8)( CLAMP_TO_8BITCHANNEL( (Y - LUMA_BLUE * computeBlue(Y,Cb,Cr) - LUMA_RED * computeRed(Y,Cb,Cr) ) / LUMA_GREEN ) );
00091         }
00092         inline Q_UINT8 computeBlue(Q_UINT8 Y, Q_UINT8 Cb, Q_UINT8 /*Cr*/)
00093         {
00094             return (Q_UINT8)( CLAMP_TO_8BITCHANNEL( (Cb - 128)*(2 - 2 * LUMA_BLUE) + Y) );
00095         }
00096         inline Q_UINT8 computeY( Q_UINT8 r, Q_UINT8 b, Q_UINT8 g)
00097         {
00098             return (Q_UINT8)( CLAMP_TO_8BITCHANNEL( LUMA_RED*r + LUMA_GREEN*g + LUMA_BLUE*b ) );
00099         }
00100         inline Q_UINT8 computeCb( Q_UINT8 r, Q_UINT8 b, Q_UINT8 g)
00101         {
00102             return (Q_UINT8)( CLAMP_TO_8BITCHANNEL( (b - computeY(r,g,b))/(2-2*LUMA_BLUE) + 128) );
00103         }
00104         inline Q_UINT8 computeCr( Q_UINT8 r, Q_UINT8 b, Q_UINT8 g)
00105         {
00106             return (Q_UINT8)( CLAMP_TO_8BITCHANNEL( (r - computeY(r,g,b))/(2-2*LUMA_RED) + 128) );
00107         }
00108 #undef CLAMP_TO_8BITCHANNEL
00109 
00110         static const Q_UINT8 PIXEL_Y = 0;
00111         static const Q_UINT8 PIXEL_Cb = 1;
00112         static const Q_UINT8 PIXEL_Cr = 2;
00113         static const Q_UINT8 PIXEL_ALPHA = 3;
00114 
00115         struct Pixel {
00116             Q_UINT8 Y;
00117             Q_UINT8 Cb;
00118             Q_UINT8 Cr;
00119             Q_UINT8 alpha;
00120         };
00121 };
00122 
00123 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys