13#include <QCoreApplication>
20#ifndef __cpp_size_t_suffix
32 for (
unsigned int i = 255; i > 0; i--)
34 m_intense1[i] = cos(((
double)(255 - i) * std::numbers::pi) / 512.0);
59 int bufsize = (
m_size.height() + 2) * (
m_size.width() + 2);
61 m_rgbBuf =
new unsigned char[bufsize];
75#ifdef __cpp_size_t_suffix
91 uchar *iptr = ptr + bpl + 1;
96 uint sum = (iptr[-bpl] + iptr[-1] + iptr[1] + iptr[bpl]) >> 2;
107 uint red = color / 0x10000;
108 uint green = (color % 0x10000) / 0x100;
109 uint blue = color % 0x100;
111 for (
uint i = 255; i > 0; i--)
113 uint r = (
unsigned int)(((100 *
static_cast<double>(red) / 255)
115 r = std::min<uint>(r, 255);
116 uint g = (
unsigned int)(((100 *
static_cast<double>(green) / 255)
118 g = std::min<uint>(g, 255);
119 uint b = (
unsigned int)(((100 *
static_cast<double>(blue) / 255)
121 b = std::min<uint>(b, 255);
123 m_image->setColor(i, qRgba(r, g, b, 255));
138 double i = ((double)x / ((
double)
m_phongRad)) - 1;
139 double i2 = ((double)y / ((
double)
m_phongRad)) - 1;
142 i = 1 - pow(i*i2,.75) - (i*i) - (i2*i2);
153 i = std::min<double>(i, 255);
154 auto uci = (
unsigned char)i;
159 m_phongDat[(PHONGRES-1)-y][(PHONGRES-1)-x] = uci;
166 m_phongDat[(PHONGRES-1)-y][(PHONGRES-1)-x] = 0;
172static constexpr float M_PI_F { std::numbers::pi_v<float> };
179 int wd2 = (int)(WIDTH / 2);
180 int hd2 = (int)(HEIGHT / 2);
184 *angle = (int)(asinf((
float)(y-(HEIGHT/2.0F))/(float)*yo)/(
M_PI_F/180.0F));
185 *xo = (int)((x-(WIDTH/2.0F))/cosf(*angle*(
M_PI_F/180.0F)));
187 if (*xo >= -wd2 && *xo <= wd2) {
194 *angle = (int)(asinf((
float)(y-(HEIGHT/2.0F))/(float)*yo)/(
M_PI_F/180.0F));
195 *xo = (int)((x-(WIDTH/2.0F))/cosf(*angle*(
M_PI_F/180.0F)));
197 if (*xo >= -wd2 && *xo <= wd2) {
205 *angle = (int)(acosf((
float)(x-(WIDTH/2.0F))/(float)*xo)/(
M_PI_F/180.0F));
206 *yo = (int)((y-(HEIGHT/2.0F))/sinf(*angle*(
M_PI_F/180.0F)));
208 if (*yo >= -hd2 && *yo <= hd2) {
215 *angle = (int)(acosf((
float)(x-(WIDTH/2.0F))/(float)*xo)/(
M_PI_F/180.0F));
216 *yo = (int)((y-(HEIGHT/2.0F))/sinf(*angle*(
M_PI_F/180.0F)));
228 uchar *
p = buffer + ((y1 + 1) *
m_bpl) + x + 1;
229 for (
int y = y1; y <= y2; y++)
237 uchar *
p = buffer + ((y2 + 1) *
m_bpl) + x + 1;
238 for (
int y = y2; y <= y1; y++)
246 buffer[((y1 + 1) *
m_bpl) + x + 1] = 0xff;
256 int prev_y =
m_bpl + 1;
258 unsigned char *outputbuf =
m_image->bits();
260 for (dy = (-ly) + (PHONGRES / 2), j = 0; j <
m_height; j++, dy++,
265 for (dx = (-lx) + (PHONGRES / 2), i = 0; i <
m_width; i++, dx++,
271 if (yp < 0 || yp >= (
int)PHONGRES ||
272 xp < 0 || xp >= (int)PHONGRES)
274 outputbuf[out_y] = 0;
285 double r = (double)(color>>16) / 255.0;
286 double g = (double)((color>>8)&0xff) / 255.0;
287 double b = (double)(color&0xff) / 255.0;
290 max = std::max(g, max);
291 max = std::max(b, max);
294 min = std::min(g, min);
295 min = std::min(b, min);
299 if (max != 0.0) *s = (max - min) / max;
308 double delta = max - min;
310 if (r == max) *h = (g - b) / delta;
311 else if (g == max) *h = 2.0 + ((b - r) / delta);
312 else if (b == max) *h = 4.0 + ((r - g) / delta);
316 if (*h < 0.0) *h = *h + 360;
322 double r = __builtin_nan(
"");
323 double g = __builtin_nan(
"");
324 double b = __builtin_nan(
"");
335 if (h == 360.0) h = 0.0;
339 double w = v * (1.0 - s);
340 double q = v * (1.0 - (s * f));
341 double t = v * (1.0 - (s * (1.0 - f)));
345 case 0: r = v; g =
t; b = w;
break;
346 case 1: r = q; g = v; b = w;
break;
347 case 2: r = w; g = v; b =
t;
break;
348 case 3: r = w; g = q; b = v;
break;
349 case 4: r =
t; g = w; b = v;
break;
351 default: r = v; g = w; b = q;
break;
355 *color = ((
unsigned int)(r*255)<<16) | ((
unsigned int)(g*255)<<8) | ((
unsigned int)(b*255));
370 prev_y = std::max(prev_y, 0);
375 int y = (i * numSamps) / (
m_width - 1);
396 LOG(VB_GENERAL, LOG_ERR,
"BumpScope::draw: Bad image");
499 if (m_is <= 0 || m_is >= 0.5)
538 const QString &
name(
void)
const override
540 static QString s_name = QCoreApplication::translate(
"Visualizers",
552 [[maybe_unused]]
const QString &pluginName)
const override
static constexpr float M_PI_F
BumpScopeFactory BumpScopeFactory
uint plugins(QStringList *list) const override
const QString & name(void) const override
VisualBase * create(MainVisual *parent, const QString &pluginName) const override
void translate(int x, int y, int *xo, int *yo, int *xd, int *yd, int *angle) const
std::array< double, 256 > m_intense2
static void blur_8(unsigned char *ptr, int w, int h, ptrdiff_t bpl)
void generate_cmap(unsigned int color)
std::array< double, 256 > m_intense1
static void rgb_to_hsv(unsigned int color, double *h, double *s, double *v)
void resize(const QSize &size) override
bool process(VisualNode *node) override
void draw_vert_line(unsigned char *buffer, int x, int y1, int y2) const
void render_light(int lx, int ly)
std::vector< std::vector< unsigned char > > m_phongDat
static void hsv_to_rgb(double h, double s, double v, unsigned int *color)
void generate_phongdat(void)
bool draw(QPainter *p, const QColor &back) override
static std::vector< uint32_t > back
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Convenience inline random number generator functions.
uint32_t MythRandom()
generate 32 random bits
bool rand_bool(uint32_t chance=2)
return a random bool with P(true) = 1/chance