kis_f16half_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_f16half_base_colorspace.h"
22
23TQ_UINT8 KisF16HalfBaseColorSpace::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 half *pixel = reinterpret_cast<const half *>(U8_pixel);
30 return HALF_TO_UINT8(*pixel);
31}
32
33void KisF16HalfBaseColorSpace::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 half *pixel = reinterpret_cast<half *>(U8_pixel + m_alphaPos);
41 *pixel = UINT8_TO_HALF(alpha);
42
43 --nPixels;
44 U8_pixel += psize;
45 }
46}
47
48void KisF16HalfBaseColorSpace::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 half alpha = UINT8_TO_HALF(U8_alpha);
53
54 while (nPixels > 0) {
55
56 half *pixelAlpha = reinterpret_cast<half *>(U8_pixel + m_alphaPos);
57 *pixelAlpha *= alpha;
58
59 --nPixels;
60 U8_pixel += psize;
61 }
62}
63
64void KisF16HalfBaseColorSpace::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 half *pixelAlpha = reinterpret_cast<half *>(U8_pixel + m_alphaPos);
73 *pixelAlpha *= UINT8_TO_HALF(*alpha8);
74
75 ++alpha8;
76 U8_pixel += psize;
77 }
78}
79
80void KisF16HalfBaseColorSpace::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 half *pixelAlpha = reinterpret_cast<half *>(U8_pixels + m_alphaPos);
89 *pixelAlpha *= UINT8_TO_HALF(MAX_SELECTED - *alpha8);
90
91 U8_pixels += psize;
92 ++alpha8;
93 }
94}
95
96TQString KisF16HalfBaseColorSpace::channelValueText(const TQ_UINT8 *U8_pixel, TQ_UINT32 channelIndex) const
97{
98 Q_ASSERT(channelIndex < (TQ_UINT32)nChannels());
99 const half *pixel = reinterpret_cast<const half *>(U8_pixel);
100 TQ_UINT32 channelPosition = channels()[channelIndex] -> pos() / sizeof(half);
101
102 return TQString().setNum(pixel[channelPosition]);
103}
104
105TQString KisF16HalfBaseColorSpace::normalisedChannelValueText(const TQ_UINT8 *U8_pixel, TQ_UINT32 channelIndex) const
106{
107 Q_ASSERT(channelIndex < (TQ_UINT32)nChannels());
108 const half *pixel = reinterpret_cast<const half *>(U8_pixel);
109 TQ_UINT32 channelPosition = channels()[channelIndex] -> pos() / sizeof(half);
110
111 return TQString().setNum(100.0 * pixel[channelPosition]);
112}
113
114TQ_UINT8 KisF16HalfBaseColorSpace::scaleToU8(const TQ_UINT8 * U8_pixel, TQ_INT32 channelPos)
115{
116 const half *pixelChannel = reinterpret_cast<const half *>(U8_pixel + channelPos);
117 return HALF_TO_UINT8(*pixelChannel);
118}
119
120TQ_UINT16 KisF16HalfBaseColorSpace::scaleToU16(const TQ_UINT8 * U8_pixel, TQ_INT32 channelPos)
121{
122 const half *pixelChannel = reinterpret_cast<const half *>(U8_pixel + channelPos);
123 return HALF_TO_UINT16(*pixelChannel);
124}
125