| OLD | NEW |
| 1 #include <cmath> | 1 #include <cmath> |
| 2 | 2 |
| 3 #include "SkBitmap.h" | 3 #include "SkBitmap.h" |
| 4 #include "skpdiff_util.h" | 4 #include "skpdiff_util.h" |
| 5 #include "SkPMetric.h" | 5 #include "SkPMetric.h" |
| 6 | 6 |
| 7 struct RGB { | 7 struct RGB { |
| 8 float r, g, b; | 8 float r, g, b; |
| 9 }; | 9 }; |
| 10 | 10 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 222 } |
| 223 imageL->readPixel(nx, ny, &l); | 223 imageL->readPixel(nx, ny, &l); |
| 224 float weight = matrix[xx + radius]; | 224 float weight = matrix[xx + radius]; |
| 225 lSum += l * weight; | 225 lSum += l * weight; |
| 226 } | 226 } |
| 227 outImageL->writePixel(x, y, lSum); | 227 outImageL->writePixel(x, y, lSum); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 | 231 |
| 232 float pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB) { | 232 float pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB, SkTDArray<Sk
IPoint>* poi) { |
| 233 int width = baselineLAB->width; | 233 int width = baselineLAB->width; |
| 234 int height = baselineLAB->height; | 234 int height = baselineLAB->height; |
| 235 int maxLevels = (int)log2(width < height ? width : height); | 235 int maxLevels = (int)log2(width < height ? width : height); |
| 236 | 236 |
| 237 const float fov = M_PI / 180.0f * 45.0f; | 237 const float fov = M_PI / 180.0f * 45.0f; |
| 238 float contrastSensitivityMax = contrast_sensitivity(3.248f, 100.0f); | 238 float contrastSensitivityMax = contrast_sensitivity(3.248f, 100.0f); |
| 239 float pixelsPerDegree = width / (2.0f * tanf(fov * 0.5f) * 180.0f / M_PI); | 239 float pixelsPerDegree = width / (2.0f * tanf(fov * 0.5f) * 180.0f / M_PI); |
| 240 | 240 |
| 241 ImageL3D baselineL(width, height, maxLevels); | 241 ImageL3D baselineL(width, height, maxLevels); |
| 242 ImageL3D testL(width, height, maxLevels); | 242 ImageL3D testL(width, height, maxLevels); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 colorScale *= colorScale; | 360 colorScale *= colorScale; |
| 361 | 361 |
| 362 if ((contrastA * contrastA + contrastB * contrastB) * colorScale
> F) | 362 if ((contrastA * contrastA + contrastB * contrastB) * colorScale
> F) |
| 363 { | 363 { |
| 364 isFailure = true; | 364 isFailure = true; |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 if (isFailure) { | 368 if (isFailure) { |
| 369 failures++; | 369 failures++; |
| 370 poi->push()->set(x, y); |
| 370 } | 371 } |
| 371 } | 372 } |
| 372 } | 373 } |
| 373 | 374 |
| 374 SkDELETE_ARRAY(cyclesPerDegree); | 375 SkDELETE_ARRAY(cyclesPerDegree); |
| 375 SkDELETE_ARRAY(contrast); | 376 SkDELETE_ARRAY(contrast); |
| 376 SkDELETE_ARRAY(thresholdFactorFrequency); | 377 SkDELETE_ARRAY(thresholdFactorFrequency); |
| 377 return (double)failures; | 378 return (double)failures; |
| 378 } | 379 } |
| 379 | 380 |
| 380 const char* SkPMetric::getName() { | 381 const char* SkPMetric::getName() { |
| 381 return "perceptual"; | 382 return "perceptual"; |
| 382 } | 383 } |
| 383 | 384 |
| 384 int SkPMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) { | 385 int SkPMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) { |
| 385 int diffID = fQueuedDiffs.count(); | 386 int diffID = fQueuedDiffs.count(); |
| 386 double startTime = get_seconds(); | 387 double startTime = get_seconds(); |
| 387 QueuedDiff* diff = fQueuedDiffs.push(); | 388 QueuedDiff& diff = fQueuedDiffs.push_back(); |
| 389 diff.result = 0.0; |
| 388 | 390 |
| 389 // Ensure the images are comparable | 391 // Ensure the images are comparable |
| 390 if (baseline->width() != test->width() || baseline->height() != test->height
() || | 392 if (baseline->width() != test->width() || baseline->height() != test->height
() || |
| 391 baseline->width() <= 0 || baseline->height() <= 0) { | 393 baseline->width() <= 0 || baseline->height() <= 0) { |
| 392 diff->finished = true; | 394 diff.finished = true; |
| 393 diff->result = 0.0; | |
| 394 return diffID; | 395 return diffID; |
| 395 } | 396 } |
| 396 | 397 |
| 397 ImageLAB baselineLAB(baseline->width(), baseline->height()); | 398 ImageLAB baselineLAB(baseline->width(), baseline->height()); |
| 398 ImageLAB testLAB(baseline->width(), baseline->height()); | 399 ImageLAB testLAB(baseline->width(), baseline->height()); |
| 399 | 400 |
| 400 bitmap_to_cielab(baseline, &baselineLAB); | 401 bitmap_to_cielab(baseline, &baselineLAB); |
| 401 bitmap_to_cielab(test, &testLAB); | 402 bitmap_to_cielab(test, &testLAB); |
| 402 | 403 |
| 403 diff->result = pmetric(&baselineLAB, &testLAB); | 404 diff.result = pmetric(&baselineLAB, &testLAB, &diff.poi); |
| 404 | 405 |
| 405 SkDebugf("Time: %f\n", (get_seconds() - startTime)); | 406 SkDebugf("Time: %f\n", (get_seconds() - startTime)); |
| 406 | 407 |
| 407 return diffID; | 408 return diffID; |
| 408 } | 409 } |
| 409 | 410 |
| 410 | 411 |
| 412 void SkPMetric::deleteDiff(int id) { |
| 413 fQueuedDiffs[id].poi.reset(); |
| 414 } |
| 415 |
| 411 bool SkPMetric::isFinished(int id) { | 416 bool SkPMetric::isFinished(int id) { |
| 412 return fQueuedDiffs[id].finished; | 417 return fQueuedDiffs[id].finished; |
| 413 } | 418 } |
| 414 | 419 |
| 415 double SkPMetric::getResult(int id) { | 420 double SkPMetric::getResult(int id) { |
| 416 return fQueuedDiffs[id].result; | 421 return fQueuedDiffs[id].result; |
| 417 } | 422 } |
| 423 |
| 424 int SkPMetric::getPointsOfInterestCount(int id) { |
| 425 return fQueuedDiffs[id].poi.count(); |
| 426 } |
| 427 |
| 428 SkIPoint* SkPMetric::getPointsOfInterest(int id) { |
| 429 return fQueuedDiffs[id].poi.begin(); |
| 430 } |
| OLD | NEW |