filters

kis_ycbcr_u16_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_U16_COLORSPACE_H
00021 #define KIS_YCBCR_U16_COLORSPACE_H
00022 
00023 #include <kis_u16_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 KisYCbCrU16ColorSpace : public KisU16BaseColorSpace
00032 {
00033     public:
00034         KisYCbCrU16ColorSpace(KisColorSpaceFactoryRegistry* parent, KisProfile* p);
00035         ~KisYCbCrU16ColorSpace();
00036         virtual bool willDegrade(ColorSpaceIndependence )
00037         {
00038             return false;
00039         };
00040     public:
00041         void setPixel(Q_UINT8 *pixel, Q_UINT16 Y, Q_UINT16 Cb, Q_UINT16 Cr, Q_UINT16 alpha) const;
00042         void getPixel(const Q_UINT8 *pixel, Q_UINT16 *Y, Q_UINT16 *Cb, Q_UINT16 *Cr, Q_UINT16 *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 
00081     private:
00082 #define CLAMP_TO_16BITCHANNEL(a) CLAMP(a, 0, Q_UINT16_MAX)
00083         inline Q_UINT16 computeRed(Q_UINT16 Y, Q_UINT16 /*Cb*/, Q_UINT16 Cr)
00084         {
00085             return (Q_UINT16)( CLAMP_TO_16BITCHANNEL( (Cr - 32768)* (2-2*LUMA_RED) + Y )  );
00086         }
00087         inline Q_UINT16 computeGreen(Q_UINT16 Y, Q_UINT16 Cb, Q_UINT16 Cr)
00088         {
00089             return (Q_UINT16)( CLAMP_TO_16BITCHANNEL( (Y - LUMA_BLUE * computeBlue(Y,Cb,Cr) - LUMA_RED * computeRed(Y,Cb,Cr) ) / LUMA_GREEN ) );
00090         }
00091         inline Q_UINT16 computeBlue(Q_UINT16 Y, Q_UINT16 Cb, Q_UINT16 /*Cr*/)
00092         {
00093             return (Q_UINT16)( CLAMP_TO_16BITCHANNEL( (Cb - 32768)*(2 - 2 * LUMA_BLUE) + Y) );
00094         }
00095         inline Q_UINT16 computeY( Q_UINT16 r, Q_UINT16 b, Q_UINT16 g)
00096         {
00097             return (Q_UINT16)( CLAMP_TO_16BITCHANNEL( LUMA_RED*r + LUMA_GREEN*g + LUMA_BLUE*b ) );
00098         }
00099         inline Q_UINT16 computeCb( Q_UINT16 r, Q_UINT16 b, Q_UINT16 g)
00100         {
00101             return (Q_UINT16)( CLAMP_TO_16BITCHANNEL( (b - computeY(r,g,b))/(2-2*LUMA_BLUE) + 32768) );
00102         }
00103         inline Q_UINT16 computeCr( Q_UINT16 r, Q_UINT16 b, Q_UINT16 g)
00104         {
00105             return (Q_UINT8)( CLAMP_TO_16BITCHANNEL( (r - computeY(r,g,b))/(2-2*LUMA_RED) + 32768) );
00106         }
00107 #undef CLAMP_TO_16BITCHANNEL
00108         
00109         static const Q_UINT8 PIXEL_Y = 0;
00110         static const Q_UINT8 PIXEL_Cb = 1;
00111         static const Q_UINT8 PIXEL_Cr = 2;
00112         static const Q_UINT8 PIXEL_ALPHA = 3;
00113 
00114         struct Pixel {
00115             Q_UINT16 Y;
00116             Q_UINT16 Cb;
00117             Q_UINT16 Cr;
00118             Q_UINT16 alpha;
00119         };
00120 };
00121 
00122 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys