File indexing completed on 2025-03-09 04:08:37
0001 /* 0002 * SPDX-FileCopyrightText: 2006 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef RGBCOMPOSITEOPBUMPMAP_H 0008 #define RGBCOMPOSITEOPBUMPMAP_H 0009 0010 #include <KoCompositeOpAlphaBase.h> 0011 0012 template<class _CSTraits> 0013 class RgbCompositeOpBumpmap : public KoCompositeOpAlphaBase<_CSTraits, RgbCompositeOpBumpmap<_CSTraits>, true > 0014 { 0015 typedef typename _CSTraits::channels_type channels_type; 0016 typedef typename KoColorSpaceMathsTraits<typename _CSTraits::channels_type>::compositetype compositetype; 0017 0018 public: 0019 0020 RgbCompositeOpBumpmap(KoColorSpace *cs) 0021 : KoCompositeOpAlphaBase<_CSTraits, RgbCompositeOpBumpmap<_CSTraits>, true >(cs, COMPOSITE_BUMPMAP, KoCompositeOp::categoryMisc()) 0022 { 0023 } 0024 0025 inline static channels_type selectAlpha(channels_type srcAlpha, channels_type dstAlpha) 0026 { 0027 return qMin(srcAlpha, dstAlpha); 0028 } 0029 0030 inline static void composeColorChannels(channels_type srcBlend, 0031 const channels_type *src, 0032 channels_type *dst, 0033 bool allChannelFlags, 0034 const QBitArray &channelFlags) 0035 { 0036 qreal intensity; 0037 0038 // And I'm not sure whether this is correct, either. 0039 intensity = ((qreal)306.0 * src[_CSTraits::red_pos] + 0040 (qreal)601.0 * src[_CSTraits::green_pos] + 0041 (qreal)117.0 * src[_CSTraits::blue_pos]) / 1024.0; 0042 0043 for (uint i = 0; i < _CSTraits::channels_nb; i++) { 0044 if ((int)i != _CSTraits::alpha_pos && (allChannelFlags || channelFlags.testBit(i))) { 0045 channels_type srcChannel = (channels_type)(((qreal) 0046 intensity * dst[i]) / NATIVE_OPACITY_OPAQUE + 0.5); 0047 channels_type dstChannel = dst[i]; 0048 0049 dst[i] = KoColorSpaceMaths<channels_type>::blend(srcChannel, dstChannel, srcBlend); 0050 } 0051 } 0052 } 0053 0054 }; 0055 0056 #endif