|
| 1 | +#pragma once |
| 2 | +#ifndef SPOTLIGHT_DIM_A_COLOR_PLANE_V_C_MOHAN |
| 3 | +#define SPOTLIGHT_DIM_A_COLOR_PLANE_V_C_MOHAN |
| 4 | + |
| 5 | +// dims a color plane |
| 6 | + |
| 7 | +template <typename finc> |
| 8 | +void dimplaneRGB(finc* dp, const finc* sp, int pitch, |
| 9 | + int wd, int ht, float dim); |
| 10 | + |
| 11 | +template <typename finc> |
| 12 | +void dimplaneYUV(finc* dp, const finc* sp, int pitch, |
| 13 | + int wd, int ht, float dim, finc limit); |
| 14 | + |
| 15 | +template <typename finc> |
| 16 | +void YUVspotLight(finc* dp, const finc* sp, int pitch, |
| 17 | + int x, int y, int r, int wd, int ht, int subW, int subH, |
| 18 | + finc gray, finc color); |
| 19 | + |
| 20 | +template <typename finc> |
| 21 | +void RGBspotLight(finc* dp, const finc* sp, int pitch, |
| 22 | + int x, int y, int r, int wd, int ht, finc color); |
| 23 | + |
| 24 | + |
| 25 | +//--------------------------------------------------------------- |
| 26 | +template <typename finc> |
| 27 | +void dimplaneRGB(finc* dp, const finc* sp, int pitch, |
| 28 | + int wd, int ht, float dim) |
| 29 | +{ |
| 30 | + for (int h = 0; h < ht; h++) |
| 31 | + { |
| 32 | + for (int w = 0; w < wd; w++) |
| 33 | + { |
| 34 | + dp[w] = (finc)(sp[w] * dim); |
| 35 | + } |
| 36 | + dp += pitch; |
| 37 | + sp += pitch; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +template <typename finc> |
| 42 | +void dimplaneYUV(finc* dp, const finc* sp, int pitch, |
| 43 | + int wd, int ht, float dim, finc limit) |
| 44 | +{ |
| 45 | + for (int h = 0; h < ht; h++) |
| 46 | + { |
| 47 | + for (int w = 0; w < wd; w++) |
| 48 | + { |
| 49 | + dp[w] = (finc)((sp[w] - limit) * dim) + limit; |
| 50 | + } |
| 51 | + dp += pitch; |
| 52 | + sp += pitch; |
| 53 | + } |
| 54 | +} |
| 55 | +//------------------------------------------------------------ |
| 56 | +template <typename finc> |
| 57 | +void RGBspotLight(finc* dp, const finc* sp, int pitch, |
| 58 | + int x, int y, int r, int wd, int ht, finc color) |
| 59 | +{ |
| 60 | + int sx = VSMIN(VSMAX(x - r, 0), wd - 1); |
| 61 | + int ex = VSMIN(VSMAX(x + r, 0), wd - 1); |
| 62 | + |
| 63 | + int sy = VSMIN(VSMAX(y - r, 0), ht - 1); |
| 64 | + int ey = VSMIN(VSMAX(y + r, 0), ht - 1); |
| 65 | + int rsq = r * r; |
| 66 | + |
| 67 | + for (int h = sy; h < ey; h++) |
| 68 | + { |
| 69 | + int hsq = (h - y) * (h - y); |
| 70 | + |
| 71 | + for (int w = sx; w < ex; w++) |
| 72 | + { |
| 73 | + if (hsq + (w - x) * (w - x) <= rsq) |
| 74 | + { |
| 75 | + finc col = *(sp + (h * pitch + w)); |
| 76 | + if ( color < col) |
| 77 | + { |
| 78 | + |
| 79 | + *(dp + h * pitch + w) = color; |
| 80 | + } |
| 81 | + else |
| 82 | + { |
| 83 | + *(dp + h * pitch + w) = col; |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | +} |
| 90 | +//-------------------------------------------------------------------------------------------------- |
| 91 | +template <typename finc> |
| 92 | +void YUVspotLight(finc* dp, const finc* sp, int pitch, |
| 93 | + int x, int y, int r, int wd, int ht, int subW, int subH, |
| 94 | + finc gray, finc color) |
| 95 | +{ |
| 96 | + // x, y, r , wd, ht are values for y plane. |
| 97 | + // gray will be 0 for y and some value for u, v |
| 98 | + int sx = (VSMIN(VSMAX(x - r, 0), wd - 1)) >> subW; |
| 99 | + int ex = (VSMIN(VSMAX(x + r, 0), wd - 1)) >> subW; |
| 100 | + |
| 101 | + int sy = (VSMIN(VSMAX(y - r, 0), ht - 1)) >> subH; |
| 102 | + int ey = (VSMIN(VSMAX(y + r, 0), ht - 1)) >> subH; |
| 103 | + // initialize pointers |
| 104 | + |
| 105 | + int rsq = r * r; |
| 106 | + int rsubW = r >> subW, rsubH = r >> subH; |
| 107 | + |
| 108 | + //finc yuv[] = { yuvCol[3 * colFlag], yuvCol[3 * colFlag + 1], yuvCol[3 * colFlag + 2] }; |
| 109 | + |
| 110 | + for (int h = sy; h < ey; h++) |
| 111 | + { |
| 112 | + int hsq = ( ((h << subH) - y) * ((h << subH) - y) ); |
| 113 | + |
| 114 | + for (int w = sx; w < ex; w++) |
| 115 | + { |
| 116 | + int wsq = ( ((w << subW) - x) * ((w << subW) - x) ); |
| 117 | + |
| 118 | + if (hsq + wsq <= rsq) |
| 119 | + { |
| 120 | + finc col = *(sp + h * pitch + w); |
| 121 | + *(dp + h * pitch + w) |
| 122 | + = col >= gray && color > gray || |
| 123 | + col <= gray && color < gray ? (col + color)/2 |
| 124 | + :(col); |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | +} |
| 130 | + |
| 131 | +#endif |
| 132 | + |
0 commit comments