kis_f32_base_colorspace.cpp
1/*
2 * Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#include "kdebug.h"
19
20#include "kis_global.h"
21#include "kis_f32_base_colorspace.h"
22
23TQ_UINT8 KisF32BaseColorSpace::getAlpha(const TQ_UINT8 * U8_pixel) const
24{
25 if (m_alphaPos < 0) return OPACITY_OPAQUE;
26
27 U8_pixel += m_alphaPos;
28
29 const float *pixel = reinterpret_cast<const float *>(U8_pixel);
30 return FLOAT_TO_UINT8(*pixel);
31}
32
33void KisF32BaseColorSpace::setAlpha(TQ_UINT8 *U8_pixel, TQ_UINT8 alpha, TQ_INT32 nPixels) const
34{
35 if (m_alphaPos < 0) return;
36 TQ_INT32 psize = pixelSize();
37
38 while (nPixels > 0) {
39
40 float *pixel = reinterpret_cast<float *>(U8_pixel + m_alphaPos);
41 *pixel = UINT8_TO_FLOAT(alpha);
42
43 --nPixels;
44 U8_pixel += psize;
45 }
46}
47
48void KisF32BaseColorSpace::multiplyAlpha(TQ_UINT8 *U8_pixel, TQ_UINT8 U8_alpha, TQ_INT32 nPixels)
49{
50 if (m_alphaPos < 0) return;
51 TQ_INT32 psize = pixelSize();
52 float alpha = UINT8_TO_FLOAT(U8_alpha);
53
54 while (nPixels > 0) {
55
56 float *pixelAlpha = reinterpret_cast<float *>(U8_pixel + m_alphaPos);
57 *pixelAlpha *= alpha;
58
59 --nPixels;
60 U8_pixel += psize;
61 }
62}
63
64void KisF32BaseColorSpace::applyAlphaU8Mask(TQ_UINT8 * U8_pixel, TQ_UINT8 * alpha8, TQ_INT32 nPixels)
65{
66 if (m_alphaPos < 0) return;
67
68 TQ_INT32 psize = pixelSize();
69
70 while (nPixels--) {
71
72 float *pixelAlpha = reinterpret_cast<float *>(U8_pixel + m_alphaPos);
73 *pixelAlpha *= UINT8_TO_FLOAT(*alpha8);
74
75 ++alpha8;
76 U8_pixel += psize;
77 }
78}
79
80void KisF32BaseColorSpace::applyInverseAlphaU8Mask(TQ_UINT8 * U8_pixels, TQ_UINT8 * alpha8, TQ_INT32 nPixels)
81{
82 if (m_alphaPos < 0) return;
83
84 TQ_INT32 psize = pixelSize();
85
86 while (nPixels--) {
87
88 float *pixelAlpha = reinterpret_cast<float *>(U8_pixels + m_alphaPos);
89 *pixelAlpha *= UINT8_TO_FLOAT(MAX_SELECTED - *alpha8);
90
91 U8_pixels += psize;
92 ++alpha8;
93 }
94}
95
96TQString KisF32BaseColorSpace::channelValueText(const TQ_UINT8 *U8_pixel, TQ_UINT32 channelIndex) const
97{
98 Q_ASSERT(channelIndex < (TQ_UINT32)nChannels());
99 const float *pixel = reinterpret_cast<const float *>(U8_pixel);
100 TQ_UINT32 channelPosition = channels()[channelIndex]->pos() / sizeof(float);
101
102 return TQString().setNum(pixel[channelPosition]);
103}
104
105TQString KisF32BaseColorSpace::normalisedChannelValueText(const TQ_UINT8 *U8_pixel, TQ_UINT32 channelIndex) const
106{
107 Q_ASSERT(channelIndex < (TQ_UINT32)nChannels());
108 const float *pixel = reinterpret_cast<const float *>(U8_pixel);
109 TQ_UINT32 channelPosition = channels()[channelIndex]->pos() / sizeof(float);
110
111 return TQString().setNum(100.0 * pixel[channelPosition]);
112}
113
114TQ_UINT8 KisF32BaseColorSpace::scaleToU8(const TQ_UINT8 * U8_pixel, TQ_INT32 channelPos)
115{
116 const float *pixelChannel = reinterpret_cast<const float *>(U8_pixel + channelPos);
117 return FLOAT_TO_UINT8(*pixelChannel);
118}
119
120TQ_UINT16 KisF32BaseColorSpace::scaleToU16(const TQ_UINT8 * U8_pixel, TQ_INT32 channelPos)
121{
122 const float *pixelChannel = reinterpret_cast<const float *>(U8_pixel + channelPos);
123 return FLOAT_TO_UINT16(*pixelChannel);
124}
125