@@ -84,7 +84,7 @@ void OL_DarkenImage::DoBlendImage(ImageOverlayInternal* base, ImageOverlayIntern
8484 }
8585}
8686
87-
87+ // float not supported yet
8888template <typename pixel_t , bool maskMode, bool of_darken>
8989void OL_DarkenImage::BlendImageMask (ImageOverlayInternal* base, ImageOverlayInternal* overlay, ImageOverlayInternal* mask) {
9090
@@ -110,17 +110,18 @@ void OL_DarkenImage::BlendImageMask(ImageOverlayInternal* base, ImageOverlayInte
110110 const int maskpitch = maskMode ? (mask->pitch ) / sizeof (pixel_t ) : 0 ;
111111
112112 // avoid "uint16*uint16 can't get into int32" overflows
113- typedef typename std::conditional < sizeof ( pixel_t ) == 1 , int , typename std::conditional < sizeof (pixel_t ) == 2 , int64_t , float >::type >::type result_t ;
113+ using result_t = typename std::conditional< sizeof (pixel_t ) == 1 , int , int64_t >::type;
114114
115115 int w = base->w ();
116116 int h = base->h ();
117117 if (opacity == 256 ) {
118- if (maskMode) {
118+ // full opacity - optimize
119+ if constexpr (maskMode) {
119120 // opacity == 256 && maskMode
120121 for (int y = 0 ; y < h; y++) {
121122 for (int x = 0 ; x < w; x++) {
122123 bool cmp;
123- if (of_darken)
124+ if constexpr (of_darken)
124125 cmp = ovY[x] < baseY[x];
125126 else
126127 cmp = ovY[x] > baseY[x];
@@ -147,7 +148,7 @@ void OL_DarkenImage::BlendImageMask(ImageOverlayInternal* base, ImageOverlayInte
147148 }
148149 } else {
149150 // opacity == 256 && !maskMode
150- if (of_darken) {
151+ if constexpr (of_darken) {
151152#ifdef INTEL_INTRINSICS
152153 if (sizeof (pixel_t )==1 && (env->GetCPUFlags () & CPUF_SSE4_1)) {
153154 overlay_darken_sse41 ((BYTE *)baseY, (BYTE *)baseU, (BYTE *)baseV, (BYTE *)ovY, (BYTE *)ovU, (BYTE *)ovV, basepitch, overlaypitch, w, h);
@@ -189,12 +190,12 @@ void OL_DarkenImage::BlendImageMask(ImageOverlayInternal* base, ImageOverlayInte
189190 for (int y = 0 ; y < h; y++) {
190191 for (int x = 0 ; x < w; x++) {
191192 bool cmp;
192- if (of_darken)
193+ if constexpr (of_darken)
193194 cmp = ovY[x] < baseY[x];
194195 else
195196 cmp = ovY[x] > baseY[x];
196197 if (cmp) {
197- if (maskMode) {
198+ if constexpr (maskMode) {
198199 result_t mY = (maskY[x] * opacity) >> OPACITY_SHIFT;
199200 result_t mU = (maskU[x] * opacity) >> OPACITY_SHIFT;
200201 result_t mV = (maskV[x] * opacity) >> OPACITY_SHIFT;
@@ -217,7 +218,7 @@ void OL_DarkenImage::BlendImageMask(ImageOverlayInternal* base, ImageOverlayInte
217218 ovU += overlaypitch;
218219 ovV += overlaypitch;
219220
220- if (maskMode) {
221+ if constexpr (maskMode) {
221222 maskY += maskpitch;
222223 maskU += maskpitch;
223224 maskV += maskpitch;
0 commit comments