krita
kis_f16half_base_colorspace.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "kdebug.h"
00019
00020 #include "kis_global.h"
00021 #include "kis_f16half_base_colorspace.h"
00022
00023 Q_UINT8 KisF16HalfBaseColorSpace::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 half *pixel = reinterpret_cast<const half *>(U8_pixel);
00030 return HALF_TO_UINT8(*pixel);
00031 }
00032
00033 void KisF16HalfBaseColorSpace::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 half *pixel = reinterpret_cast<half *>(U8_pixel + m_alphaPos);
00041 *pixel = UINT8_TO_HALF(alpha);
00042
00043 --nPixels;
00044 U8_pixel += psize;
00045 }
00046 }
00047
00048 void KisF16HalfBaseColorSpace::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 half alpha = UINT8_TO_HALF(U8_alpha);
00053
00054 while (nPixels > 0) {
00055
00056 half *pixelAlpha = reinterpret_cast<half *>(U8_pixel + m_alphaPos);
00057 *pixelAlpha *= alpha;
00058
00059 --nPixels;
00060 U8_pixel += psize;
00061 }
00062 }
00063
00064 void KisF16HalfBaseColorSpace::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 half *pixelAlpha = reinterpret_cast<half *>(U8_pixel + m_alphaPos);
00073 *pixelAlpha *= UINT8_TO_HALF(*alpha8);
00074
00075 ++alpha8;
00076 U8_pixel += psize;
00077 }
00078 }
00079
00080 void KisF16HalfBaseColorSpace::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 half *pixelAlpha = reinterpret_cast<half *>(U8_pixels + m_alphaPos);
00089 *pixelAlpha *= UINT8_TO_HALF(MAX_SELECTED - *alpha8);
00090
00091 U8_pixels += psize;
00092 ++alpha8;
00093 }
00094 }
00095
00096 QString KisF16HalfBaseColorSpace::channelValueText(const Q_UINT8 *U8_pixel, Q_UINT32 channelIndex) const
00097 {
00098 Q_ASSERT(channelIndex < (Q_UINT32)nChannels());
00099 const half *pixel = reinterpret_cast<const half *>(U8_pixel);
00100 Q_UINT32 channelPosition = channels()[channelIndex] -> pos() / sizeof(half);
00101
00102 return QString().setNum(pixel[channelPosition]);
00103 }
00104
00105 QString KisF16HalfBaseColorSpace::normalisedChannelValueText(const Q_UINT8 *U8_pixel, Q_UINT32 channelIndex) const
00106 {
00107 Q_ASSERT(channelIndex < (Q_UINT32)nChannels());
00108 const half *pixel = reinterpret_cast<const half *>(U8_pixel);
00109 Q_UINT32 channelPosition = channels()[channelIndex] -> pos() / sizeof(half);
00110
00111 return QString().setNum(100.0 * pixel[channelPosition]);
00112 }
00113
00114 Q_UINT8 KisF16HalfBaseColorSpace::scaleToU8(const Q_UINT8 * U8_pixel, Q_INT32 channelPos)
00115 {
00116 const half *pixelChannel = reinterpret_cast<const half *>(U8_pixel + channelPos);
00117 return HALF_TO_UINT8(*pixelChannel);
00118 }
00119
00120 Q_UINT16 KisF16HalfBaseColorSpace::scaleToU16(const Q_UINT8 * U8_pixel, Q_INT32 channelPos)
00121 {
00122 const half *pixelChannel = reinterpret_cast<const half *>(U8_pixel + channelPos);
00123 return HALF_TO_UINT16(*pixelChannel);
00124 }
00125
|