Changeset View
Changeset View
Standalone View
Standalone View
imagelib/effects/blitz.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
61 | dealings in ImageMagick without prior written authorization from the | 61 | dealings in ImageMagick without prior written authorization from the | ||
62 | ImageMagick Studio. | 62 | ImageMagick Studio. | ||
63 | */ | 63 | */ | ||
64 | 64 | | |||
65 | #include "blitz.h" | 65 | #include "blitz.h" | ||
66 | 66 | | |||
67 | #include <QColor> | 67 | #include <QColor> | ||
68 | #include <cmath> | 68 | #include <cmath> | ||
69 | #include <omp.h> | | |||
70 | 69 | | |||
71 | #define M_SQ2PI 2.50662827463100024161235523934010416269302368164062 | 70 | #define M_SQ2PI 2.50662827463100024161235523934010416269302368164062 | ||
72 | #define M_EPSILON 1.0e-6 | 71 | #define M_EPSILON 1.0e-6 | ||
73 | 72 | | |||
74 | #define CONVOLVE_ACC(weight, pixel) \ | 73 | #define CONVOLVE_ACC(weight, pixel) \ | ||
75 | r+=((weight))*(qRed((pixel))); g+=((weight))*(qGreen((pixel))); \ | 74 | r+=((weight))*(qRed((pixel))); g+=((weight))*(qGreen((pixel))); \ | ||
76 | b+=((weight))*(qBlue((pixel))); | 75 | b+=((weight))*(qBlue((pixel))); | ||
77 | 76 | | |||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Line(s) | 270 | for (auto y = 0; y < height; ++y) { | |||
289 | memset(bs, 0, static_cast<unsigned int>(width) * sizeof(int)); | 288 | memset(bs, 0, static_cast<unsigned int>(width) * sizeof(int)); | ||
290 | 289 | | |||
291 | 290 | | |||
292 | switch (img_format) { | 291 | switch (img_format) { | ||
293 | case QImage::Format_ARGB32_Premultiplied: { | 292 | case QImage::Format_ARGB32_Premultiplied: { | ||
294 | QRgb pixel; | 293 | QRgb pixel; | ||
295 | for (auto i = 0; i < mh; i++) { | 294 | for (auto i = 0; i < mh; i++) { | ||
296 | p2 = (QRgb *)img.scanLine(i + my); | 295 | p2 = (QRgb *)img.scanLine(i + my); | ||
297 | #pragma omp for | | |||
298 | for (auto j = 0; j < width; ++j) { | 296 | for (auto j = 0; j < width; ++j) { | ||
299 | p2++; | 297 | p2++; | ||
300 | pixel = convertFromPremult(*p2); | 298 | pixel = convertFromPremult(*p2); | ||
301 | as[j] += qAlpha(pixel); | 299 | as[j] += qAlpha(pixel); | ||
302 | rs[j] += qRed(pixel) * qRed(pixel); | 300 | rs[j] += qRed(pixel) * qRed(pixel); | ||
303 | gs[j] += qGreen(pixel) * qGreen(pixel); | 301 | gs[j] += qGreen(pixel) * qGreen(pixel); | ||
304 | bs[j] += qBlue(pixel) * qBlue(pixel); | 302 | bs[j] += qBlue(pixel) * qBlue(pixel); | ||
305 | } | 303 | } | ||
306 | } | 304 | } | ||
307 | break; | 305 | break; | ||
308 | } | 306 | } | ||
309 | 307 | | |||
310 | case QImage::Format_Indexed8: { | 308 | case QImage::Format_Indexed8: { | ||
311 | QRgb pixel; | 309 | QRgb pixel; | ||
312 | unsigned char *ptr; | 310 | unsigned char *ptr; | ||
313 | for (auto i = 0; i < mh; ++i) { | 311 | for (auto i = 0; i < mh; ++i) { | ||
314 | ptr = img.scanLine(i + my); | 312 | ptr = img.scanLine(i + my); | ||
315 | #pragma omp for | | |||
316 | for (auto j = 0; j < width; ++j) { | 313 | for (auto j = 0; j < width; ++j) { | ||
317 | ptr++; | 314 | ptr++; | ||
318 | pixel = colorTable[*ptr]; | 315 | pixel = colorTable[*ptr]; | ||
319 | as[j] += qAlpha(pixel); | 316 | as[j] += qAlpha(pixel); | ||
320 | rs[j] += qRed(pixel) * qRed(pixel); | 317 | rs[j] += qRed(pixel) * qRed(pixel); | ||
321 | gs[j] += qGreen(pixel) * qGreen(pixel); | 318 | gs[j] += qGreen(pixel) * qGreen(pixel); | ||
322 | bs[j] += qBlue(pixel) * qBlue(pixel); | 319 | bs[j] += qBlue(pixel) * qBlue(pixel); | ||
323 | } | 320 | } | ||
324 | } | 321 | } | ||
325 | break; | 322 | break; | ||
326 | } | 323 | } | ||
327 | 324 | | |||
328 | default: { | 325 | default: { | ||
329 | for (auto i = 0; i < mh; ++i) { | 326 | for (auto i = 0; i < mh; ++i) { | ||
330 | p2 = (QRgb *)img.scanLine(i + my); | 327 | p2 = (QRgb *)img.scanLine(i + my); | ||
331 | #pragma omp for | | |||
332 | for (auto j = 0; j < width; j++) { | 328 | for (auto j = 0; j < width; j++) { | ||
333 | p2++; | 329 | p2++; | ||
334 | as[j] += qAlpha(*p2); | 330 | as[j] += qAlpha(*p2); | ||
335 | rs[j] += qRed(*p2); | 331 | rs[j] += qRed(*p2); | ||
336 | gs[j] += qGreen(*p2); | 332 | gs[j] += qGreen(*p2); | ||
337 | bs[j] += qBlue(*p2); | 333 | bs[j] += qBlue(*p2); | ||
338 | } | 334 | } | ||
339 | } | 335 | } | ||
340 | break; | 336 | break; | ||
341 | } | 337 | } | ||
342 | } | 338 | } | ||
343 | 339 | | |||
344 | #pragma omp for | | |||
345 | for (auto i = 0; i < width; ++i) { | 340 | for (auto i = 0; i < width; ++i) { | ||
346 | auto a{0}; | 341 | auto a{0}; | ||
347 | auto r{0}; | 342 | auto r{0}; | ||
348 | auto g{0}; | 343 | auto g{0}; | ||
349 | auto b{0}; | 344 | auto b{0}; | ||
350 | 345 | | |||
351 | auto mx = i - radius; | 346 | auto mx = i - radius; | ||
352 | auto mw = (radius << 1) + 1; | 347 | auto mw = (radius << 1) + 1; | ||
▲ Show 20 Lines • Show All 368 Lines • Show Last 20 Lines |