Changeset View
Changeset View
Standalone View
Standalone View
imagelib/effects/blitz.cpp
Show First 20 Lines • Show All 177 Lines • ▼ Show 20 Line(s) | 174 | for(i=0; i < 256; ++i){ | |||
---|---|---|---|---|---|
178 | map[i] = intensity; | 178 | map[i] = intensity; | ||
179 | } | 179 | } | ||
180 | 180 | | |||
181 | low = map[0]; | 181 | low = map[0]; | ||
182 | high = map[255]; | 182 | high = map[255]; | ||
183 | memset(equalize_map, 0, 256*sizeof(CharPixel)); | 183 | memset(equalize_map, 0, 256*sizeof(CharPixel)); | ||
184 | for(i=0; i < 256; ++i){ | 184 | for(i=0; i < 256; ++i){ | ||
185 | if(high.red != low.red) | 185 | if(high.red != low.red) | ||
186 | equalize_map[i].red=(unsigned char) | 186 | equalize_map[i].red = static_cast<unsigned char> | ||
187 | ((255*(map[i].red-low.red))/(high.red-low.red)); | 187 | ((255*(map[i].red-low.red))/(high.red-low.red)); | ||
188 | if(high.green != low.green) | 188 | if(high.green != low.green) | ||
189 | equalize_map[i].green=(unsigned char) | 189 | equalize_map[i].green = static_cast<unsigned char> | ||
190 | ((255*(map[i].green-low.green))/(high.green-low.green)); | 190 | ((255*(map[i].green-low.green))/(high.green-low.green)); | ||
191 | if(high.blue != low.blue) | 191 | if(high.blue != low.blue) | ||
192 | equalize_map[i].blue=(unsigned char) | 192 | equalize_map[i].blue = static_cast<unsigned char> | ||
193 | ((255*(map[i].blue-low.blue))/(high.blue-low.blue)); | 193 | ((255*(map[i].blue-low.blue))/(high.blue-low.blue)); | ||
194 | } | 194 | } | ||
195 | 195 | | |||
196 | // stretch the histogram and write | 196 | // stretch the histogram and write | ||
197 | dest = (QRgb *)img.bits(); | 197 | dest = (QRgb *)img.bits(); | ||
198 | if(img.format() == QImage::Format_ARGB32_Premultiplied){ | 198 | if(img.format() == QImage::Format_ARGB32_Premultiplied){ | ||
199 | for(i=0; i < count; ++i, ++dest){ | 199 | for(i=0; i < count; ++i, ++dest){ | ||
200 | pixel = convertFromPremult(*dest); | 200 | pixel = convertFromPremult(*dest); | ||
201 | r = (low.red != high.red) ? equalize_map[qRed(pixel)].red : | 201 | r = static_cast<unsigned char> ((low.red != high.red) ? | ||
202 | qRed(pixel); | 202 | equalize_map[qRed(pixel)].red : qRed(pixel)); | ||
203 | g = (low.green != high.green) ? equalize_map[qGreen(pixel)].green : | 203 | | ||
204 | qGreen(pixel); | 204 | g = static_cast<unsigned char> ((low.green != high.green) ? | ||
205 | b = (low.blue != high.blue) ? equalize_map[qBlue(pixel)].blue : | 205 | equalize_map[qGreen(pixel)].green : qGreen(pixel)); | ||
206 | qBlue(pixel); | 206 | | ||
207 | b = static_cast<unsigned char> ((low.blue != high.blue) ? | ||||
208 | equalize_map[qBlue(pixel)].blue : qBlue(pixel)); | ||||
209 | | ||||
207 | *dest = convertToPremult(qRgba(r, g, b, qAlpha(pixel))); | 210 | *dest = convertToPremult(qRgba(r, g, b, qAlpha(pixel))); | ||
208 | } | 211 | } | ||
209 | } | 212 | } | ||
210 | else{ | 213 | else{ | ||
211 | for(i=0; i < count; ++i){ | 214 | for(i=0; i < count; ++i){ | ||
212 | pixel = *dest; | 215 | pixel = *dest; | ||
213 | r = (low.red != high.red) ? equalize_map[qRed(pixel)].red : | 216 | r = static_cast<unsigned char> ((low.red != high.red) ? | ||
214 | qRed(pixel); | 217 | equalize_map[qRed(pixel)].red : qRed(pixel)); | ||
215 | g = (low.green != high.green) ? equalize_map[qGreen(pixel)].green : | 218 | | ||
216 | qGreen(pixel); | 219 | g = static_cast<unsigned char> ((low.green != high.green) ? | ||
217 | b = (low.blue != high.blue) ? equalize_map[qBlue(pixel)].blue : | 220 | equalize_map[qGreen(pixel)].green : qGreen(pixel)); | ||
218 | qBlue(pixel); | 221 | | ||
222 | b = static_cast<unsigned char> ((low.blue != high.blue) ? | ||||
223 | equalize_map[qBlue(pixel)].blue : qBlue(pixel)); | ||||
224 | | ||||
219 | *dest++ = qRgba(r, g, b, qAlpha(pixel)); | 225 | *dest++ = qRgba(r, g, b, qAlpha(pixel)); | ||
220 | } | 226 | } | ||
221 | } | 227 | } | ||
222 | 228 | | |||
223 | delete[] histogram; | 229 | delete[] histogram; | ||
224 | delete[] map; | 230 | delete[] map; | ||
225 | delete[] equalize_map; | 231 | delete[] equalize_map; | ||
226 | return(true); | 232 | return(true); | ||
Show All 34 Lines | 264 | for(y = 0; y < h; y++){ | |||
261 | if(my < 0){ | 267 | if(my < 0){ | ||
262 | mh += my; | 268 | mh += my; | ||
263 | my = 0; | 269 | my = 0; | ||
264 | } | 270 | } | ||
265 | if((my + mh) > h) | 271 | if((my + mh) > h) | ||
266 | mh = h - my; | 272 | mh = h - my; | ||
267 | 273 | | |||
268 | p1 = (QRgb *)buffer.scanLine(y); | 274 | p1 = (QRgb *)buffer.scanLine(y); | ||
269 | memset(as, 0, w * sizeof(int)); | 275 | memset(as, 0, static_cast<unsigned int> (w) * sizeof(int)); | ||
270 | memset(rs, 0, w * sizeof(int)); | 276 | memset(rs, 0, static_cast<unsigned int> (w) * sizeof(int)); | ||
271 | memset(gs, 0, w * sizeof(int)); | 277 | memset(gs, 0, static_cast<unsigned int> (w) * sizeof(int)); | ||
272 | memset(bs, 0, w * sizeof(int)); | 278 | memset(bs, 0, static_cast<unsigned int> (w) * sizeof(int)); | ||
273 | 279 | | |||
274 | if(img.format() == QImage::Format_ARGB32_Premultiplied){ | 280 | if(img.format() == QImage::Format_ARGB32_Premultiplied){ | ||
275 | QRgb pixel; | 281 | QRgb pixel; | ||
276 | for(yy = 0; yy < mh; yy++){ | 282 | for(yy = 0; yy < mh; yy++){ | ||
277 | p2 = (QRgb *)img.scanLine(yy + my); | 283 | p2 = (QRgb *)img.scanLine(yy + my); | ||
278 | for(x = 0; x < w; x++, p2++){ | 284 | for(x = 0; x < w; x++, p2++){ | ||
279 | pixel = convertFromPremult(*p2); | 285 | pixel = convertFromPremult(*p2); | ||
280 | as[x] += qAlpha(pixel); | 286 | as[x] += qAlpha(pixel); | ||
281 | rs[x] += qRed(pixel); | 287 | rs[x] += qRed(pixel); | ||
282 | gs[x] += qGreen(pixel); | 288 | gs[x] += qGreen(pixel); | ||
283 | bs[x] += qBlue(pixel); | 289 | bs[x] += qBlue(pixel); | ||
284 | } | 290 | } | ||
285 | } | 291 | } | ||
286 | } | 292 | } | ||
287 | else if(img.format() == QImage::Format_Indexed8){ | 293 | else if(img.format() == QImage::Format_Indexed8){ | ||
288 | QRgb pixel; | 294 | QRgb pixel; | ||
289 | unsigned char *ptr; | 295 | unsigned char *ptr; | ||
290 | for(yy = 0; yy < mh; yy++){ | 296 | for(yy = 0; yy < mh; yy++){ | ||
291 | ptr = (unsigned char *)img.scanLine(yy + my); | 297 | ptr = img.scanLine(yy + my); | ||
292 | for(x = 0; x < w; x++, ptr++){ | 298 | for(x = 0; x < w; x++, ptr++){ | ||
293 | pixel = colorTable[*ptr]; | 299 | pixel = colorTable[*ptr]; | ||
294 | as[x] += qAlpha(pixel); | 300 | as[x] += qAlpha(pixel); | ||
295 | rs[x] += qRed(pixel); | 301 | rs[x] += qRed(pixel); | ||
296 | gs[x] += qGreen(pixel); | 302 | gs[x] += qGreen(pixel); | ||
297 | bs[x] += qBlue(pixel); | 303 | bs[x] += qBlue(pixel); | ||
298 | } | 304 | } | ||
299 | } | 305 | } | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
343 | } | 349 | } | ||
344 | 350 | | |||
345 | //-------------------------------------------------------------------------------- | 351 | //-------------------------------------------------------------------------------- | ||
346 | 352 | | |||
347 | int defaultConvolveMatrixSize(float radius, float sigma, bool quality) | 353 | int defaultConvolveMatrixSize(float radius, float sigma, bool quality) | ||
348 | { | 354 | { | ||
349 | int i, matrix_size; | 355 | int i, matrix_size; | ||
350 | float normalize, value; | 356 | float normalize, value; | ||
351 | float sigma2 = sigma*sigma*2.0; | 357 | float sigma2 = sigma*sigma*2.0f; | ||
352 | float sigmaSQ2PI = M_SQ2PI*sigma; | 358 | float sigmaSQ2PI = static_cast<float>(M_SQ2PI) * sigma; | ||
353 | int max = quality ? 65535 : 255; | 359 | int max = quality ? 65535 : 255; | ||
354 | 360 | | |||
355 | if(sigma == 0.0){ | 361 | if(sigma == 0.0f){ | ||
356 | qWarning("Blitz::defaultConvolveMatrixSize(): Zero sigma is invalid!"); | 362 | qWarning("Blitz::defaultConvolveMatrixSize(): Zero sigma is invalid!"); | ||
357 | return(5); | 363 | return(5); | ||
358 | } | 364 | } | ||
359 | 365 | | |||
360 | if(radius > 0.0) | 366 | if(radius > 0.0f) | ||
361 | return((int)(2.0*std::ceil(radius)+1.0)); | 367 | return(static_cast<int>(2.0f * std::ceil(radius) + 1.0f)); | ||
362 | 368 | | |||
363 | matrix_size = 5; | 369 | matrix_size = 5; | ||
364 | do{ | 370 | do{ | ||
365 | normalize = 0.0; | 371 | normalize = 0.0; | ||
366 | for(i=(-matrix_size/2); i <= (matrix_size/2); ++i) | 372 | for(i=(-matrix_size/2); i <= (matrix_size/2); ++i) | ||
367 | normalize += std::exp(-((float) i*i)/sigma2) / sigmaSQ2PI; | 373 | normalize += std::exp(-(static_cast<float> (i*i))/sigma2) / sigmaSQ2PI; | ||
368 | i = matrix_size/2; | 374 | i = matrix_size/2; | ||
369 | value = std::exp(-((float) i*i)/sigma2) / sigmaSQ2PI / normalize; | 375 | value = std::exp(-(static_cast<float> (i*i))/sigma2) / sigmaSQ2PI / normalize; | ||
370 | matrix_size += 2; | 376 | matrix_size += 2; | ||
371 | } while((int)(max*value) > 0); | 377 | } while(static_cast<int>(max*value) > 0); | ||
372 | 378 | | |||
373 | matrix_size-=4; | 379 | matrix_size-=4; | ||
374 | return(matrix_size); | 380 | return(matrix_size); | ||
375 | } | 381 | } | ||
376 | 382 | | |||
377 | //-------------------------------------------------------------------------------- | 383 | //-------------------------------------------------------------------------------- | ||
378 | 384 | | |||
379 | QImage convolve(QImage &img, int matrix_size, float *matrix) | 385 | QImage convolve(QImage &img, int matrix_size, float *matrix) | ||
Show All 26 Lines | 386 | { | |||
406 | 412 | | |||
407 | scanblock = new QRgb* [matrix_size]; | 413 | scanblock = new QRgb* [matrix_size]; | ||
408 | normalize_matrix = new float[matrix_size*matrix_size]; | 414 | normalize_matrix = new float[matrix_size*matrix_size]; | ||
409 | 415 | | |||
410 | // create normalized matrix | 416 | // create normalized matrix | ||
411 | normalize = 0.0; | 417 | normalize = 0.0; | ||
412 | for(i=0; i < matrix_size*matrix_size; ++i) | 418 | for(i=0; i < matrix_size*matrix_size; ++i) | ||
413 | normalize += matrix[i]; | 419 | normalize += matrix[i]; | ||
414 | if(std::abs(normalize) <= M_EPSILON) | 420 | if(std::abs(normalize) <= static_cast<float> (M_EPSILON)) | ||
415 | normalize = 1.0; | 421 | normalize = 1.0f; | ||
416 | normalize = 1.0/normalize; | 422 | normalize = 1.0f/normalize; | ||
417 | for(i=0; i < matrix_size*matrix_size; ++i){ | 423 | for(i=0; i < matrix_size*matrix_size; ++i){ | ||
418 | normalize_matrix[i] = normalize*matrix[i]; | 424 | normalize_matrix[i] = normalize*matrix[i]; | ||
419 | } | 425 | } | ||
420 | 426 | | |||
421 | // apply | 427 | // apply | ||
422 | 428 | | |||
423 | { | 429 | { | ||
424 | // | 430 | // | ||
Show All 24 Lines | 454 | while(x+matrix_x < 0){ | |||
449 | CONVOLVE_ACC(*m, *s); | 455 | CONVOLVE_ACC(*m, *s); | ||
450 | ++matrix_x; ++m; | 456 | ++matrix_x; ++m; | ||
451 | } | 457 | } | ||
452 | while(matrix_x <= edge){ | 458 | while(matrix_x <= edge){ | ||
453 | CONVOLVE_ACC(*m, *s); | 459 | CONVOLVE_ACC(*m, *s); | ||
454 | ++matrix_x; ++m; ++s; | 460 | ++matrix_x; ++m; ++s; | ||
455 | } | 461 | } | ||
456 | } | 462 | } | ||
457 | r = r < 0.0 ? 0.0 : r > 255.0 ? 255.0 : r+0.5; | 463 | r = r < 0.0f ? 0.0f : r > 255.0f ? 255.0f : r + 0.5f; | ||
458 | g = g < 0.0 ? 0.0 : g > 255.0 ? 255.0 : g+0.5; | 464 | g = g < 0.0f ? 0.0f : g > 255.0f ? 255.0f : g + 0.5f; | ||
459 | b = b < 0.0 ? 0.0 : b > 255.0 ? 255.0 : b+0.5; | 465 | b = b < 0.0f ? 0.0f : b > 255.0f ? 255.0f : b + 0.5f; | ||
460 | *dest++ = qRgba((unsigned char)r, (unsigned char)g, | 466 | *dest++ = qRgba(static_cast<unsigned char> (r), static_cast<unsigned char> (g), | ||
461 | (unsigned char)b, qAlpha(*src++)); | 467 | static_cast<unsigned char> (b), qAlpha(*src++)); | ||
462 | } | 468 | } | ||
463 | // Okay, now process the middle part where the entire neighborhood | 469 | // Okay, now process the middle part where the entire neighborhood | ||
464 | // is on the image. | 470 | // is on the image. | ||
465 | for(; x+edge < w; ++x){ | 471 | for(; x+edge < w; ++x){ | ||
466 | m = normalize_matrix; | 472 | m = normalize_matrix; | ||
467 | r = g = b = 0.0; | 473 | r = g = b = 0.0; | ||
468 | for(matrix_y = 0; matrix_y < matrix_size; ++matrix_y){ | 474 | for(matrix_y = 0; matrix_y < matrix_size; ++matrix_y){ | ||
469 | s = scanblock[matrix_y] + (x-edge); | 475 | s = scanblock[matrix_y] + (x-edge); | ||
470 | for(matrix_x = -edge; matrix_x <= edge; ++matrix_x, ++m, ++s){ | 476 | for(matrix_x = -edge; matrix_x <= edge; ++matrix_x, ++m, ++s){ | ||
471 | CONVOLVE_ACC(*m, *s); | 477 | CONVOLVE_ACC(*m, *s); | ||
472 | } | 478 | } | ||
473 | } | 479 | } | ||
474 | r = r < 0.0 ? 0.0 : r > 255.0 ? 255.0 : r+0.5; | 480 | r = r < 0.0f ? 0.0f : r > 255.0f ? 255.0f : r + 0.5f; | ||
475 | g = g < 0.0 ? 0.0 : g > 255.0 ? 255.0 : g+0.5; | 481 | g = g < 0.0f ? 0.0f : g > 255.0f ? 255.0f : g + 0.5f; | ||
476 | b = b < 0.0 ? 0.0 : b > 255.0 ? 255.0 : b+0.5; | 482 | b = b < 0.0f ? 0.0f : b > 255.0f ? 255.0f : b + 0.5f; | ||
477 | *dest++ = qRgba((unsigned char)r, (unsigned char)g, | 483 | *dest++ = qRgba(static_cast<unsigned char> (r), static_cast<unsigned char> (g), | ||
478 | (unsigned char)b, qAlpha(*src++)); | 484 | static_cast<unsigned char> (b), qAlpha(*src++)); | ||
479 | } | 485 | } | ||
480 | // Finally process the right part where the neighborhood extends off | 486 | // Finally process the right part where the neighborhood extends off | ||
481 | // the right edge of the image | 487 | // the right edge of the image | ||
482 | for(; x < w; ++x){ | 488 | for(; x < w; ++x){ | ||
483 | r = g = b = 0.0; | 489 | r = g = b = 0.0; | ||
484 | m = normalize_matrix; | 490 | m = normalize_matrix; | ||
485 | for(matrix_y = 0; matrix_y < matrix_size; ++matrix_y){ | 491 | for(matrix_y = 0; matrix_y < matrix_size; ++matrix_y){ | ||
486 | s = scanblock[matrix_y]; | 492 | s = scanblock[matrix_y]; | ||
487 | s += x-edge; | 493 | s += x-edge; | ||
488 | matrix_x = -edge; | 494 | matrix_x = -edge; | ||
489 | while(x+matrix_x < w){ | 495 | while(x+matrix_x < w){ | ||
490 | CONVOLVE_ACC(*m, *s); | 496 | CONVOLVE_ACC(*m, *s); | ||
491 | ++matrix_x, ++m, ++s; | 497 | ++matrix_x, ++m, ++s; | ||
492 | } | 498 | } | ||
493 | --s; | 499 | --s; | ||
494 | while(matrix_x <= edge){ | 500 | while(matrix_x <= edge){ | ||
495 | CONVOLVE_ACC(*m, *s); | 501 | CONVOLVE_ACC(*m, *s); | ||
496 | ++matrix_x, ++m; | 502 | ++matrix_x, ++m; | ||
497 | } | 503 | } | ||
498 | } | 504 | } | ||
499 | r = r < 0.0 ? 0.0 : r > 255.0 ? 255.0 : r+0.5; | 505 | r = r < 0.0f ? 0.0f : r > 255.0f ? 255.0f : r + 0.5f; | ||
500 | g = g < 0.0 ? 0.0 : g > 255.0 ? 255.0 : g+0.5; | 506 | g = g < 0.0f ? 0.0f : g > 255.0f ? 255.0f : g + 0.5f; | ||
501 | b = b < 0.0 ? 0.0 : b > 255.0 ? 255.0 : b+0.5; | 507 | b = b < 0.0f ? 0.0f : b > 255.0f ? 255.0f : b + 0.5f; | ||
502 | *dest++ = qRgba((unsigned char)r, (unsigned char)g, | 508 | *dest++ = qRgba(static_cast<unsigned char> (r), static_cast<unsigned char> (g), | ||
503 | (unsigned char)b, qAlpha(*src++)); | 509 | static_cast<unsigned char> (b), qAlpha(*src++)); | ||
504 | } | 510 | } | ||
505 | } | 511 | } | ||
506 | } | 512 | } | ||
507 | 513 | | |||
508 | delete[] scanblock; | 514 | delete[] scanblock; | ||
509 | delete[] normalize_matrix; | 515 | delete[] normalize_matrix; | ||
510 | return(buffer); | 516 | return(buffer); | ||
511 | } | 517 | } | ||
512 | 518 | | |||
513 | //-------------------------------------------------------------------------------- | 519 | //-------------------------------------------------------------------------------- | ||
514 | 520 | | |||
515 | QImage Blitz::gaussianSharpen(QImage &img, float radius, float sigma) | 521 | QImage Blitz::gaussianSharpen(QImage &img, float radius, float sigma) | ||
516 | { | 522 | { | ||
517 | if(sigma == 0.0){ | 523 | if(sigma == 0.0f){ | ||
518 | qWarning("Blitz::gaussianSharpen(): Zero sigma is invalid!"); | 524 | qWarning("Blitz::gaussianSharpen(): Zero sigma is invalid!"); | ||
519 | return(img); | 525 | return(img); | ||
520 | } | 526 | } | ||
521 | 527 | | |||
522 | int matrix_size = defaultConvolveMatrixSize(radius, sigma, true); | 528 | int matrix_size = defaultConvolveMatrixSize(radius, sigma, true); | ||
523 | int len = matrix_size*matrix_size; | 529 | int len = matrix_size*matrix_size; | ||
524 | float alpha, *matrix = new float[len]; | 530 | float alpha, *matrix = new float[len]; | ||
525 | float sigma2 = sigma*sigma*2.0; | 531 | float sigma2 = sigma*sigma*2.0f; | ||
526 | float sigmaPI2 = 2.0*M_PI*sigma*sigma; | 532 | float sigmaPI2 = 2.0f*static_cast<float> (M_PI)*sigma*sigma; | ||
527 | 533 | | |||
528 | int half = matrix_size/2; | 534 | int half = matrix_size/2; | ||
529 | int x, y, i=0, j=half; | 535 | int x, y, i=0, j=half; | ||
530 | float normalize=0.0; | 536 | float normalize=0.0; | ||
531 | for(y=(-half); y <= half; ++y, --j){ | 537 | for(y=(-half); y <= half; ++y, --j){ | ||
532 | for(x=(-half); x <= half; ++x, ++i){ | 538 | for(x=(-half); x <= half; ++x, ++i){ | ||
533 | alpha = std::exp(-((float)x*x+y*y)/sigma2); | 539 | alpha = std::exp(-(static_cast<float> (x*x+y*y))/sigma2); | ||
534 | matrix[i] = alpha/sigmaPI2; | 540 | matrix[i] = alpha/sigmaPI2; | ||
535 | normalize += matrix[i]; | 541 | normalize += matrix[i]; | ||
536 | } | 542 | } | ||
537 | } | 543 | } | ||
538 | 544 | | |||
539 | matrix[i/2]=(-2.0)*normalize; | 545 | matrix[i/2]=(-2.0f)*normalize; | ||
540 | QImage result(convolve(img, matrix_size, matrix)); | 546 | QImage result(convolve(img, matrix_size, matrix)); | ||
541 | delete[] matrix; | 547 | delete[] matrix; | ||
542 | return(result); | 548 | return(result); | ||
543 | } | 549 | } | ||
544 | 550 | | |||
545 | //-------------------------------------------------------------------------------- | 551 | //-------------------------------------------------------------------------------- | ||
546 | 552 | | |||
547 | QImage Blitz::emboss(QImage &img, float radius, float sigma) | 553 | QImage Blitz::emboss(QImage &img, float radius, float sigma) | ||
548 | { | 554 | { | ||
549 | if(sigma == 0.0){ | 555 | if(sigma == 0.0f){ | ||
550 | qWarning("Blitz::emboss(): Zero sigma is invalid!"); | 556 | qWarning("Blitz::emboss(): Zero sigma is invalid!"); | ||
551 | return(img); | 557 | return(img); | ||
552 | } | 558 | } | ||
553 | 559 | | |||
554 | int matrix_size = defaultConvolveMatrixSize(radius, sigma, true); | 560 | int matrix_size = defaultConvolveMatrixSize(radius, sigma, true); | ||
555 | int len = matrix_size*matrix_size; | 561 | int len = matrix_size*matrix_size; | ||
556 | 562 | | |||
557 | float alpha, *matrix = new float[len]; | 563 | float alpha, *matrix = new float[len]; | ||
558 | float sigma2 = sigma*sigma*2.0; | 564 | float sigma2 = sigma*sigma*2.0f; | ||
559 | float sigmaPI2 = 2.0*M_PI*sigma*sigma; | 565 | float sigmaPI2 = 2.0f*static_cast<float> (M_PI)*sigma*sigma; | ||
560 | 566 | | |||
561 | int half = matrix_size/2; | 567 | int half = matrix_size/2; | ||
562 | int x, y, i=0, j=half; | 568 | int x, y, i=0, j=half; | ||
563 | for(y=(-half); y <= half; ++y, --j){ | 569 | for(y=(-half); y <= half; ++y, --j){ | ||
564 | for(x=(-half); x <= half; ++x, ++i){ | 570 | for(x=(-half); x <= half; ++x, ++i){ | ||
565 | alpha = std::exp(-((float)x*x+y*y)/sigma2); | 571 | alpha = std::exp(-(static_cast<float> (x*x+y*y))/sigma2); | ||
566 | matrix[i]=((x < 0) || (y < 0) ? -8.0 : 8.0)*alpha/sigmaPI2; | 572 | matrix[i]=((x < 0) || (y < 0) ? -8.0f : 8.0f)*alpha/sigmaPI2; | ||
567 | if(x == j) | 573 | if(x == j) | ||
568 | matrix[i]=0.0; | 574 | matrix[i]=0.0; | ||
569 | } | 575 | } | ||
570 | } | 576 | } | ||
571 | QImage result(convolve(img, matrix_size, matrix)); | 577 | QImage result(convolve(img, matrix_size, matrix)); | ||
572 | delete[] matrix; | 578 | delete[] matrix; | ||
573 | equalize(result); | 579 | equalize(result); | ||
574 | return(result); | 580 | return(result); | ||
Show All 16 Lines | 586 | { | |||
591 | int g1 = ca.green(); int g2 = cb.green(); | 597 | int g1 = ca.green(); int g2 = cb.green(); | ||
592 | int b1 = ca.blue(); int b2 = cb.blue(); | 598 | int b1 = ca.blue(); int b2 = cb.blue(); | ||
593 | int min = 0, max = 255; | 599 | int min = 0, max = 255; | ||
594 | 600 | | |||
595 | QRgb *data, *end; | 601 | QRgb *data, *end; | ||
596 | QVector<QRgb> cTable; | 602 | QVector<QRgb> cTable; | ||
597 | if(img.format() == QImage::Format_Indexed8){ | 603 | if(img.format() == QImage::Format_Indexed8){ | ||
598 | cTable = img.colorTable(); | 604 | cTable = img.colorTable(); | ||
599 | data = (unsigned int *)cTable.data(); | 605 | data = static_cast<unsigned int *> (cTable.data()); | ||
600 | end = data + img.colorCount(); | 606 | end = data + img.colorCount(); | ||
601 | 607 | | |||
602 | } | 608 | } | ||
603 | else{ | 609 | else{ | ||
604 | data = (unsigned int *)img.scanLine(0); | 610 | data = (unsigned int *)img.scanLine(0); | ||
605 | end = data + (img.width()*img.height()); | 611 | end = data + (img.width()*img.height()); | ||
606 | } | 612 | } | ||
607 | 613 | | |||
Show All 16 Lines | 628 | while(ptr != end){ | |||
624 | mean = (qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3; | 630 | mean = (qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3; | ||
625 | min = qMin(min, mean); | 631 | min = qMin(min, mean); | ||
626 | max = qMax(max, mean); | 632 | max = qMax(max, mean); | ||
627 | ++ptr; | 633 | ++ptr; | ||
628 | } | 634 | } | ||
629 | } | 635 | } | ||
630 | 636 | | |||
631 | // conversion factors | 637 | // conversion factors | ||
632 | float sr = ((float) r2 - r1) / (max - min); | 638 | float sr = (static_cast<float> (r2 - r1) / (max - min)); | ||
633 | float sg = ((float) g2 - g1) / (max - min); | 639 | float sg = (static_cast<float> (g2 - g1) / (max - min)); | ||
634 | float sb = ((float) b2 - b1) / (max - min); | 640 | float sb = (static_cast<float> (b2 - b1) / (max - min)); | ||
635 | 641 | | |||
636 | if(img.format() != QImage::Format_ARGB32_Premultiplied){ | 642 | if(img.format() != QImage::Format_ARGB32_Premultiplied){ | ||
637 | while(data != end){ | 643 | while(data != end){ | ||
638 | mean = (qRed(*data) + qGreen(*data) + qBlue(*data)) / 3; | 644 | mean = (qRed(*data) + qGreen(*data) + qBlue(*data)) / 3; | ||
639 | *data = qRgba((unsigned char)(sr * (mean - min) + r1 + 0.5), | 645 | *data = qRgba(static_cast<unsigned char> (sr * (mean - min) + r1 + 0.5f), | ||
640 | (unsigned char)(sg * (mean - min) + g1 + 0.5), | 646 | static_cast<unsigned char> (sg * (mean - min) + g1 + 0.5f), | ||
641 | (unsigned char)(sb * (mean - min) + b1 + 0.5), | 647 | static_cast<unsigned char> (sb * (mean - min) + b1 + 0.5f), | ||
642 | qAlpha(*data)); | 648 | qAlpha(*data)); | ||
643 | ++data; | 649 | ++data; | ||
644 | } | 650 | } | ||
645 | } | 651 | } | ||
646 | else{ | 652 | else{ | ||
647 | QRgb pixel; | 653 | QRgb pixel; | ||
648 | while(data != end){ | 654 | while(data != end){ | ||
649 | pixel = convertFromPremult(*data); | 655 | pixel = convertFromPremult(*data); | ||
650 | mean = (qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3; | 656 | mean = (qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3; | ||
651 | *data = | 657 | *data = | ||
652 | convertToPremult(qRgba((unsigned char)(sr * (mean - min) + r1 + 0.5), | 658 | convertToPremult(qRgba(static_cast<unsigned char> (sr * (mean - min) + r1 + 0.5f), | ||
653 | (unsigned char)(sg * (mean - min) + g1 + 0.5), | 659 | static_cast<unsigned char> (sg * (mean - min) + g1 + 0.5f), | ||
654 | (unsigned char)(sb * (mean - min) + b1 + 0.5), | 660 | static_cast<unsigned char> (sb * (mean - min) + b1 + 0.5f), | ||
655 | qAlpha(*data))); | 661 | qAlpha(*data))); | ||
656 | ++data; | 662 | ++data; | ||
657 | } | 663 | } | ||
658 | } | 664 | } | ||
659 | 665 | | |||
660 | if(img.format() == QImage::Format_Indexed8) | 666 | if(img.format() == QImage::Format_Indexed8) | ||
661 | img.setColorTable(cTable); | 667 | img.setColorTable(cTable); | ||
662 | return(img); | 668 | return(img); | ||
663 | } | 669 | } | ||
664 | 670 | | |||
665 | //-------------------------------------------------------------------------------- | 671 | //-------------------------------------------------------------------------------- |