| 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 #include "SkPMetricUtil_generated.h" | 6 #include "SkPMetricUtil_generated.h" |
| 7 | 7 |
| 8 struct RGB { | 8 struct RGB { |
| 9 float r, g, b; | 9 float r, g, b; |
| 10 }; | 10 }; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // As we move down, scroll the row pointers down with us | 258 // As we move down, scroll the row pointers down with us |
| 259 for (int y = 0; y < matrixCount - 1; y++) | 259 for (int y = 0; y < matrixCount - 1; y++) |
| 260 { | 260 { |
| 261 rowPtrs[y] = rowPtrs[y + 1]; | 261 rowPtrs[y] = rowPtrs[y + 1]; |
| 262 } | 262 } |
| 263 rowPtrs[matrixCount - 1] += imageL->width; | 263 rowPtrs[matrixCount - 1] += imageL->width; |
| 264 writeRow += imageL->width; | 264 writeRow += imageL->width; |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 static double pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB, SkTD
Array<SkIPoint>* poi) { | 268 static double pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB, int*
poiCount) { |
| 269 SkASSERT(baselineLAB); |
| 270 SkASSERT(testLAB); |
| 271 SkASSERT(poiCount); |
| 272 |
| 269 int width = baselineLAB->width; | 273 int width = baselineLAB->width; |
| 270 int height = baselineLAB->height; | 274 int height = baselineLAB->height; |
| 271 int maxLevels = 0; | 275 int maxLevels = 0; |
| 272 | 276 |
| 273 // Calculates how many levels to make by how many times the image can be div
ided in two | 277 // Calculates how many levels to make by how many times the image can be div
ided in two |
| 274 int smallerDimension = width < height ? width : height; | 278 int smallerDimension = width < height ? width : height; |
| 275 for ( ; smallerDimension > 1; smallerDimension /= 2) { | 279 for ( ; smallerDimension > 1; smallerDimension /= 2) { |
| 276 maxLevels++; | 280 maxLevels++; |
| 277 } | 281 } |
| 278 | 282 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 convolve(&scratchImageL, true, testL.getLayer(levelIndex)); | 326 convolve(&scratchImageL, true, testL.getLayer(levelIndex)); |
| 323 } | 327 } |
| 324 | 328 |
| 325 // Compute F_freq - The elevation f | 329 // Compute F_freq - The elevation f |
| 326 for (int levelIndex = 0; levelIndex < maxLevels - 2; levelIndex++) { | 330 for (int levelIndex = 0; levelIndex < maxLevels - 2; levelIndex++) { |
| 327 float cpd = cyclesPerDegree[levelIndex]; | 331 float cpd = cyclesPerDegree[levelIndex]; |
| 328 thresholdFactorFrequency[levelIndex] = contrastSensitivityMax / | 332 thresholdFactorFrequency[levelIndex] = contrastSensitivityMax / |
| 329 contrast_sensitivity(cpd, 100.0f)
; | 333 contrast_sensitivity(cpd, 100.0f)
; |
| 330 } | 334 } |
| 331 | 335 |
| 332 int failures = 0; | |
| 333 // Calculate F | 336 // Calculate F |
| 334 for (int y = 0; y < height; y++) { | 337 for (int y = 0; y < height; y++) { |
| 335 for (int x = 0; x < width; x++) { | 338 for (int x = 0; x < width; x++) { |
| 336 float lBaseline; | 339 float lBaseline; |
| 337 float lTest; | 340 float lTest; |
| 338 baselineL.getLayer(0)->readPixel(x, y, &lBaseline); | 341 baselineL.getLayer(0)->readPixel(x, y, &lBaseline); |
| 339 testL.getLayer(0)->readPixel(x, y, &lTest); | 342 testL.getLayer(0)->readPixel(x, y, &lTest); |
| 340 | 343 |
| 341 float avgLBaseline; | 344 float avgLBaseline; |
| 342 float avgLTest; | 345 float avgLTest; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 } | 420 } |
| 418 colorScale *= colorScale; | 421 colorScale *= colorScale; |
| 419 | 422 |
| 420 if ((contrastA * contrastA + contrastB * contrastB) * colorScale
> F) | 423 if ((contrastA * contrastA + contrastB * contrastB) * colorScale
> F) |
| 421 { | 424 { |
| 422 isFailure = true; | 425 isFailure = true; |
| 423 } | 426 } |
| 424 } | 427 } |
| 425 | 428 |
| 426 if (isFailure) { | 429 if (isFailure) { |
| 427 failures++; | 430 (*poiCount)++; |
| 428 poi->push()->set(x, y); | |
| 429 } | 431 } |
| 430 } | 432 } |
| 431 } | 433 } |
| 432 | 434 |
| 433 SkDELETE_ARRAY(cyclesPerDegree); | 435 SkDELETE_ARRAY(cyclesPerDegree); |
| 434 SkDELETE_ARRAY(contrast); | 436 SkDELETE_ARRAY(contrast); |
| 435 SkDELETE_ARRAY(thresholdFactorFrequency); | 437 SkDELETE_ARRAY(thresholdFactorFrequency); |
| 436 SkDELETE_ARRAY(contrastSensitivityTable); | 438 SkDELETE_ARRAY(contrastSensitivityTable); |
| 437 return 1.0 - (double)failures / (width * height); | 439 return 1.0 - (double)(*poiCount) / (width * height); |
| 438 } | 440 } |
| 439 | 441 |
| 440 const char* SkPMetric::getName() { | 442 bool SkPMetric::diff(SkBitmap* baseline, SkBitmap* test, bool computeMask, Resul
t* result) const { |
| 441 return "perceptual"; | |
| 442 } | |
| 443 | |
| 444 int SkPMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) { | |
| 445 double startTime = get_seconds(); | 443 double startTime = get_seconds(); |
| 446 int diffID = fQueuedDiffs.count(); | |
| 447 QueuedDiff& diff = fQueuedDiffs.push_back(); | |
| 448 diff.result = 0.0; | |
| 449 | 444 |
| 450 // Ensure the images are comparable | 445 // Ensure the images are comparable |
| 451 if (baseline->width() != test->width() || baseline->height() != test->height
() || | 446 if (baseline->width() != test->width() || baseline->height() != test->height
() || |
| 452 baseline->width() <= 0 || baseline->height() <= 0) { | 447 baseline->width() <= 0 || baseline->height() <= 0) { |
| 453 diff.finished = true; | 448 return false; |
| 454 return diffID; | |
| 455 } | 449 } |
| 456 | 450 |
| 457 ImageLAB baselineLAB(baseline->width(), baseline->height()); | 451 ImageLAB baselineLAB(baseline->width(), baseline->height()); |
| 458 ImageLAB testLAB(baseline->width(), baseline->height()); | 452 ImageLAB testLAB(baseline->width(), baseline->height()); |
| 459 | 453 |
| 460 if (!bitmap_to_cielab(baseline, &baselineLAB) || !bitmap_to_cielab(test, &te
stLAB)) { | 454 if (!bitmap_to_cielab(baseline, &baselineLAB) || !bitmap_to_cielab(test, &te
stLAB)) { |
| 461 return diffID; | 455 return true; |
| 462 } | 456 } |
| 463 | 457 |
| 464 diff.result = pmetric(&baselineLAB, &testLAB, &diff.poi); | 458 result->poiCount = 0; |
| 459 result->result = pmetric(&baselineLAB, &testLAB, &result->poiCount); |
| 460 result->timeElapsed = get_seconds() - startTime; |
| 465 | 461 |
| 466 SkDebugf("Time: %f\n", (get_seconds() - startTime)); | 462 return true; |
| 467 | |
| 468 return diffID; | |
| 469 } | 463 } |
| 470 | |
| 471 | |
| 472 void SkPMetric::deleteDiff(int id) { | |
| 473 | |
| 474 } | |
| 475 | |
| 476 bool SkPMetric::isFinished(int id) { | |
| 477 return fQueuedDiffs[id].finished; | |
| 478 } | |
| 479 | |
| 480 double SkPMetric::getResult(int id) { | |
| 481 return fQueuedDiffs[id].result; | |
| 482 } | |
| 483 | |
| 484 int SkPMetric::getPointsOfInterestCount(int id) { | |
| 485 return fQueuedDiffs[id].poi.count(); | |
| 486 } | |
| 487 | |
| 488 SkIPoint* SkPMetric::getPointsOfInterest(int id) { | |
| 489 return fQueuedDiffs[id].poi.begin(); | |
| 490 } | |
| OLD | NEW |