krita

kis_f32_base_colorspace.cc

00001 /*
00002  *  Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
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 #include "kdebug.h"
00019 
00020 #include "kis_global.h"
00021 #include "kis_f32_base_colorspace.h"
00022 
00023 Q_UINT8 KisF32BaseColorSpace::getAlpha(const Q_UINT8 * U8_pixel) const
00024 {
00025     if (m_alphaPos < 0) return OPACITY_OPAQUE;
00026 
00027     U8_pixel += m_alphaPos;
00028 
00029     const float *pixel = reinterpret_cast<const float *>(U8_pixel);
00030     return FLOAT_TO_UINT8(*pixel);
00031 }
00032 
00033 void KisF32BaseColorSpace::setAlpha(Q_UINT8 *U8_pixel, Q_UINT8 alpha, Q_INT32 nPixels) const
00034 {
00035     if (m_alphaPos < 0) return;
00036     Q_INT32 psize = pixelSize();
00037 
00038     while (nPixels > 0) {
00039 
00040         float *pixel = reinterpret_cast<float *>(U8_pixel + m_alphaPos);
00041         *pixel = UINT8_TO_FLOAT(alpha);
00042 
00043         --nPixels;
00044         U8_pixel += psize;
00045     }
00046 }
00047 
00048 void KisF32BaseColorSpace::multiplyAlpha(Q_UINT8 *U8_pixel, Q_UINT8 U8_alpha, Q_INT32 nPixels)
00049 {
00050     if (m_alphaPos < 0) return;
00051     Q_INT32 psize = pixelSize();
00052     float alpha = UINT8_TO_FLOAT(U8_alpha);
00053 
00054     while (nPixels > 0) {
00055 
00056         float *pixelAlpha = reinterpret_cast<float *>(U8_pixel + m_alphaPos);
00057         *pixelAlpha *= alpha;
00058 
00059         --nPixels;
00060         U8_pixel += psize;
00061     }
00062 }
00063 
00064 void KisF32BaseColorSpace::applyAlphaU8Mask(Q_UINT8 * U8_pixel, Q_UINT8 * alpha8, Q_INT32 nPixels)
00065 {
00066     if (m_alphaPos < 0) return;
00067 
00068     Q_INT32 psize = pixelSize();
00069 
00070     while (nPixels--) {
00071 
00072         float *pixelAlpha = reinterpret_cast<float *>(U8_pixel + m_alphaPos);
00073         *pixelAlpha *= UINT8_TO_FLOAT(*alpha8);
00074 
00075         ++alpha8;
00076         U8_pixel += psize;
00077     }
00078 }
00079 
00080 void KisF32BaseColorSpace::applyInverseAlphaU8Mask(Q_UINT8 * U8_pixels, Q_UINT8 * alpha8, Q_INT32 nPixels)
00081 {
00082     if (m_alphaPos < 0) return;
00083 
00084     Q_INT32 psize = pixelSize();
00085 
00086     while (nPixels--) {
00087 
00088             float *pixelAlpha = reinterpret_cast<float *>(U8_pixels + m_alphaPos);
00089             *pixelAlpha *= UINT8_TO_FLOAT(MAX_SELECTED - *alpha8);
00090 
00091             U8_pixels += psize;
00092             ++alpha8;
00093     }
00094 }
00095 
00096 QString KisF32BaseColorSpace::channelValueText(const Q_UINT8 *U8_pixel, Q_UINT32 channelIndex) const
00097 {
00098     Q_ASSERT(channelIndex < (Q_UINT32)nChannels());
00099     const float *pixel = reinterpret_cast<const float *>(U8_pixel);
00100     Q_UINT32 channelPosition = channels()[channelIndex]->pos() / sizeof(float);
00101 
00102     return QString().setNum(pixel[channelPosition]);
00103 }
00104 
00105 QString KisF32BaseColorSpace::normalisedChannelValueText(const Q_UINT8 *U8_pixel, Q_UINT32 channelIndex) const
00106 {
00107     Q_ASSERT(channelIndex < (Q_UINT32)nChannels());
00108     const float *pixel = reinterpret_cast<const float *>(U8_pixel);
00109     Q_UINT32 channelPosition = channels()[channelIndex]->pos() / sizeof(float);
00110 
00111     return QString().setNum(100.0 * pixel[channelPosition]);
00112 }
00113 
00114 Q_UINT8 KisF32BaseColorSpace::scaleToU8(const Q_UINT8 * U8_pixel, Q_INT32 channelPos)
00115 {
00116     const float *pixelChannel = reinterpret_cast<const float *>(U8_pixel + channelPos);
00117     return FLOAT_TO_UINT8(*pixelChannel);
00118 }
00119 
00120 Q_UINT16 KisF32BaseColorSpace::scaleToU16(const Q_UINT8 * U8_pixel, Q_INT32 channelPos)
00121 {
00122     const float *pixelChannel = reinterpret_cast<const float *>(U8_pixel + channelPos);
00123     return FLOAT_TO_UINT16(*pixelChannel);
00124 }
00125 
KDE Home | KDE Accessibility Home | Description of Access Keys