krita

kis_u8_base_colorspace.cc

00001 /*
00002  *  Copyright (c) 2005 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 
00019 #include <qcolor.h>
00020 
00021 #include <kdebug.h>
00022 
00023 #include "kis_abstract_colorspace.h"
00024 #include "kis_u8_base_colorspace.h"
00025 #include "kis_integer_maths.h"
00026 
00027 Q_UINT8 KisU8BaseColorSpace::getAlpha(const Q_UINT8 * pixel) const
00028 {
00029     return pixel[m_alphaPos];
00030 }
00031 
00032 
00033 
00034 void KisU8BaseColorSpace::setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels) const
00035 {
00036     if (m_alphaPos < 0) return;
00037     Q_INT32 psize = pixelSize();
00038 
00039     pixels += m_alphaPos;
00040     while (nPixels > 0) {
00041         *pixels = alpha;
00042         --nPixels;
00043         pixels += psize;
00044     }
00045 
00046 }
00047 
00048 void KisU8BaseColorSpace::multiplyAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels)
00049 {
00050     if (m_alphaPos < 0) return;
00051     Q_INT32 psize = pixelSize();
00052 
00053     while (nPixels > 0) {
00054         pixels[m_alphaPos] = UINT8_MULT(pixels[m_alphaPos], alpha);
00055         --nPixels;
00056         pixels += psize;
00057     }
00058 }
00059 
00060 void KisU8BaseColorSpace::applyAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels)
00061 {
00062     Q_INT32 psize = pixelSize();
00063 
00064     while (nPixels--) {
00065 
00066         pixels[m_alphaPos] = UINT8_MULT(*(pixels + m_alphaPos) , *alpha);
00067 
00068         alpha++;
00069         pixels += psize;
00070 
00071     }
00072 }
00073 
00074 void KisU8BaseColorSpace::applyInverseAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels)
00075 {
00076     Q_INT32 psize = pixelSize();
00077 
00078     while(nPixels--) {
00079 
00080             Q_UINT16 p_alpha, s_alpha;
00081 
00082             p_alpha = getAlpha(pixels);
00083             s_alpha = MAX_SELECTED - *alpha;
00084 
00085             setAlpha(pixels, UINT8_MULT(p_alpha, s_alpha), 1);
00086 
00087             pixels += psize;
00088             ++alpha;
00089     }
00090 }
00091 
00092 QString KisU8BaseColorSpace::channelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const
00093 {
00094     Q_ASSERT(channelIndex < (Q_UINT32)nChannels());
00095     Q_UINT32 channelPosition = m_channels[channelIndex]->pos();
00096 
00097     return QString().setNum(pixel[channelPosition]);
00098 }
00099 
00100 QString KisU8BaseColorSpace::normalisedChannelValueText(const Q_UINT8 *pixel, Q_UINT32 channelIndex) const
00101 {
00102     Q_ASSERT(channelIndex < (Q_UINT32)nChannels());
00103     Q_UINT32 channelPosition = m_channels[channelIndex]->pos();
00104 
00105     return QString().setNum(100.0 * static_cast<float>(pixel[channelPosition]) / UINT8_MAX);
00106 }
00107 
00108 
00109 Q_UINT8 KisU8BaseColorSpace::scaleToU8(const Q_UINT8 * pixel, Q_INT32 channelPos)
00110 {
00111     return pixel[channelPos];
00112 }
00113 
00114 Q_UINT16 KisU8BaseColorSpace::scaleToU16(const Q_UINT8 * pixel, Q_INT32 channelPos)
00115 {
00116     return UINT8_TO_UINT16(pixel[channelPos]);
00117 }
00118 
KDE Home | KDE Accessibility Home | Description of Access Keys