krita

kis_f32_base_colorspace.h

00001 /*
00002  *  Copyright (c) 2004 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_F32_BASE_COLORSPACE_H_
00019 #define KIS_F32_BASE_COLORSPACE_H_
00020 
00021 #include <qcolor.h>
00022 
00023 #include "kis_global.h"
00024 #include "kis_abstract_colorspace.h"
00025 #include "kis_integer_maths.h"
00026 
00031 inline float UINT8_TO_FLOAT(uint c)
00032 {
00033     return static_cast<float>(c) / UINT8_MAX;
00034 }
00035 
00036 inline uint FLOAT_TO_UINT8(float c)
00037 {
00038     return static_cast<uint>(CLAMP(static_cast<int>(c * static_cast<int>(UINT8_MAX) + 0.5),
00039                                    static_cast<int>(UINT8_MIN), static_cast<int>(UINT8_MAX)));
00040 }
00041 
00042 
00043 inline uint FLOAT_TO_UINT16(float c)
00044 {
00045     return static_cast<uint>(CLAMP(static_cast<int>(c * static_cast<int>(UINT16_MAX) + 0.5),
00046                                    static_cast<int>(UINT16_MIN), static_cast<int>(UINT16_MAX)));
00047 }
00048 
00049 inline float FLOAT_BLEND(float a, float b, float alpha)
00050 {
00051     return (a - b) * alpha + b;
00052 }
00053 
00054 #define F32_OPACITY_OPAQUE 1.0f
00055 #define F32_OPACITY_TRANSPARENT 0.0f
00056 
00057 class KisF32BaseColorSpace : public KisAbstractColorSpace {
00058 
00059 public:
00060 
00061     KisF32BaseColorSpace(const KisID & id, DWORD cmType, icColorSpaceSignature colorSpaceSignature, KisColorSpaceFactoryRegistry * parent, KisProfile *p)
00062     : KisAbstractColorSpace(id, cmType, colorSpaceSignature, parent, p)
00063     {
00064     m_alphaSize = sizeof(float);
00065     };
00066 
00067     virtual Q_UINT8 getAlpha(const Q_UINT8 * pixel) const;
00068     virtual void setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels) const;
00069     virtual void multiplyAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels);
00070 
00071     virtual void applyAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels);
00072     virtual void applyInverseAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels);
00073 
00074     virtual QString channelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const;
00075     virtual QString normalisedChannelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const;
00076 
00077     virtual Q_UINT8 scaleToU8(const Q_UINT8 * srcPixel, Q_INT32 channelPos);
00078     virtual Q_UINT16 scaleToU16(const Q_UINT8 * srcPixel, Q_INT32 channelPos);
00079 
00080     virtual bool hasHighDynamicRange() const { return true; }
00081 };
00082 
00083 #endif // KIS_F32_BASE_COLORSPACE_H_
KDE Home | KDE Accessibility Home | Description of Access Keys