Skip to content

Commit 377e8f0

Browse files
committed
Add missing files
1 parent 926dcf5 commit 377e8f0

File tree

2 files changed

+181
-0
lines changed

2 files changed

+181
-0
lines changed

ConvertBGRforInput.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef CONVERT_BGR_FOR_INPUT_FORMAT_V_C_MOHAN
2+
#define CONVERT_BGR_FOR_INPUT_FORMAT_V_C_MOHAN
3+
// input 8 bit bgr array. color array must be 12 bytes
4+
void convertBGRforInputFormat(uint8_t* color, const uint8_t* bgr, const VSFormat* fi);
5+
6+
void convertBGRforInputFormat(uint8_t* color, const uint8_t* bgr, const VSFormat* fi)
7+
{
8+
9+
uint8_t yuv[3];
10+
11+
BGRtoYUV( bgr, yuv);
12+
13+
int nbytes = fi->bytesPerSample;
14+
int nbits = fi->bitsPerSample;
15+
16+
for (int k = 0; k < 3; k++)
17+
{
18+
if (nbytes == 1)
19+
{
20+
if (fi->colorFamily == cmRGB)
21+
color[k] = bgr[k];
22+
else
23+
color[k] = yuv[k];
24+
}
25+
else if (nbytes == 2)
26+
{
27+
if (fi->colorFamily == cmRGB)
28+
*((uint16_t*)color + k) = (uint16_t)(bgr[k] << (nbits - 8));
29+
else
30+
*((uint16_t*)color + k) = (uint16_t)(yuv[k] << (nbits - 8));
31+
}
32+
else // float
33+
{
34+
if (fi->colorFamily == cmRGB)
35+
*((float*)color + k) = (float)(bgr[k] / 255.0f);
36+
else
37+
{
38+
if (k == 0)
39+
*((float*)color + k) = (float)((yuv[k] - 16) / 220.0f);
40+
else
41+
*((float*)color + k) = (float)((yuv[k] - 128) / 220.0f);
42+
}
43+
}
44+
45+
}
46+
}
47+
48+
49+
#endif

spotlightDim.h

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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

Comments
 (0)