33 d->m_rectangle = region;
46 QImage image = pixmap.copy(d->m_rectangle).toImage();
48 const float sigma = 1.0 * value / 2.57;
49 const float deno = 1.0 / (sigma * sqrt(2.0 * M_PI));
50 const float nume = -1.0 / (2.0 * sigma * sigma);
52 float* gaussMatrix = (
float*)
malloc(
sizeof(
float)* (value + value + 1));
54 for(
int i = 0, x = -value; x <= value; ++x, ++i)
56 float g = deno * exp(1.0 * nume * x * x);
62 const int len = value + value + 1;
63 for(
int i = 0; i < len; ++i)
65 gaussMatrix[i] /= gaussSum;
68 const int width = image.width();
69 const int height = image.height();
70 int *pix = (
int*)image.bits();
71 int *rowData = (
int*)
malloc(width *
sizeof(
int));
72 int *listData = (
int*)
malloc(height *
sizeof(
int));
74 for(
int y = 0; y < height; ++y)
76 memcpy(rowData, pix + y * width,
sizeof(
int) *width);
78 for(
int x = 0; x < width; ++x)
80 float r = 0, g = 0, b = 0;
83 for(
int i = -value; i <= value; ++i)
87 if(0 <= k && k <= width)
89 int color = rowData[k];
90 int cr = (color & 0x00ff0000) >> 16;
91 int cg = (color & 0x0000ff00) >> 8;
92 int cb = (color & 0x000000ff);
94 r += cr * gaussMatrix[i + value];
95 g += cg * gaussMatrix[i + value];
96 b += cb * gaussMatrix[i + value];
98 gaussSum += gaussMatrix[i + value];
102 int cr = (
int)(r / gaussSum);
103 int cg = (
int)(g / gaussSum);
104 int cb = (
int)(b / gaussSum);
106 pix[y * width + x] = cr << 16 | cg << 8 | cb | 0xff000000;
110 for(
int x = 0; x < width; ++x)
112 for(
int y = 0; y < height; ++y)
114 listData[y] = pix[y * width + x];
117 for(
int y = 0; y < height; ++y)
119 float r = 0, g = 0, b = 0;
122 for(
int j = -value; j <= value; ++j)
126 if(0 <= k && k <= height)
128 int color = listData[k];
129 int cr = (color & 0x00ff0000) >> 16;
130 int cg = (color & 0x0000ff00) >> 8;
131 int cb = (color & 0x000000ff);
133 r += cr * gaussMatrix[j + value];
134 g += cg * gaussMatrix[j + value];
135 b += cb * gaussMatrix[j + value];
137 gaussSum += gaussMatrix[j + value];
141 int cr = (
int)(r / gaussSum);
142 int cg = (
int)(g / gaussSum);
143 int cb = (
int)(b / gaussSum);
145 pix[y * width + x] = cr << 16 | cg << 8 | cb | 0xff000000;
152 return QPixmap::fromImage(image);
168 bool isValid(
int index,
int value)
const;
186 m_row = ceil(height * 1.0 / 8);
191 return (index < 0 || index >
m_data.count()) ?
false : (
m_data[index] > value);
211 d->initialize(region.width(), region.height());
212 for(
int index = 0; index < d->count(); ++index)
221 QPixmap pix(d->m_rectangle.size());
223 pix.fill(Qt::transparent);
224 for(
int index = 0; index < d->count(); ++index)
226 QPainter painter(&pix);
228 const int row = index / 8;
229 const int column = index % 8;
231 QRect rect(QRect(row * d->m_column, column * d->m_row, d->m_column, d->m_row));
232 if(rect.y() + rect.height() > pixmap.height())
234 rect.setHeight(pixmap.height() - rect.y());
237 if(d->isValid(index, value))
239 painter.fillRect(rect, QColor(0xFF, 0xFF, 0xFF, 255 - 2.55 * value));
242 painter.setCompositionMode(QPainter::CompositionMode_SourceOut);
243 painter.drawPixmap(rect, pixmap.copy(rect));
262 void initialize(
const QImage &image,
int radius);
347 const int diameter = (m_sourceRadius << 1) + 1;
348 const int rate = m_sourceRadius / value;
349 const int size = diameter * diameter;
354 for(
int x = 0; x <= diameter; ++x)
356 for(
int y = 0; y <= diameter; ++y)
358 const int distanceSquare = (m_sourceRadius - x) * (m_sourceRadius - x) + (m_sourceRadius - y) * (m_sourceRadius - y);
359 if(distanceSquare <= value)
380 for(
int i = 0; i <
size; ++i)
389 for(
int i =
m_width; i < length; ++i)
404 for(
int y = 1; y <
m_height - 1; ++y)
406 for(
int x = 0; x <
m_width; ++x, ++w)
409 if(w + offset > 0 && w + offset < m_width * m_height)
426 d->initialize(image, radius);
434 d->setWaveSourcePosition(region.width() / 2, region.height() / 2);
442 QImage image = pixmap.toImage();
443 memcpy(image.bits(), (
const uchar*)d->data(),
QtImageBytes(image));
445 QPixmap pix(d->m_rectangle.size());
446 pix.fill(Qt::transparent);
448 QPainter painter(&pix);
449 painter.fillRect(d->m_rectangle, QColor(0xFF, 0xFF, 0xFF, qMin(2.55 * 2 * value, 255.0)));
450 painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
451 painter.drawPixmap(d->m_rectangle, QPixmap::fromImage(image));
#define TTKStaticCast(x, y)
#define QtImageBytes(p)
Image byte count.
The class of the water wave.
#define TTK_INIT_PRIVATE_OBJECT(PVT)
The class of the image render.
WaterWave(const QImage &image, int radius)
The class of the water wave private.
TTK_MODULE_EXPORT void initRandom()
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
virtual QPixmap render(const QPixmap &pixmap, int value) overridefinal
The namespace of the algorithm.
void setWaveSourcePower(int depth)
void initialize(const QImage &image, int radius)
TTK_MODULE_EXPORT int random(int value=RAND_MAX)
virtual void input(const QRect ®ion)
virtual QPixmap render(const QPixmap &pixmap, int value) overridefinal
#define TTK_CREATE_PRIVATE(Class)
virtual void input(const QRect ®ion) overridefinal
virtual QPixmap render(const QPixmap &pixmap, int value) overridefinal
The class of the cube wave.
void setWaveSourcePosition(int x, int y)
virtual void input(const QRect ®ion) overridefinal
The class of the ttk private base.
void initialize(int width, int height)
The class of the image render private.
bool isValid(int index, int value) const
The class of the cube wave private.