Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: tools/skpdiff/SkPMetric.cpp

Issue 60833002: fix multithread related crashes in skpdiff (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: opencl and fixes Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« tools/skpdiff/SkImageDiffer.h ('K') | « tools/skpdiff/SkPMetric.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // As we move down, scroll the row pointers down with us 251 // As we move down, scroll the row pointers down with us
252 for (int y = 0; y < matrixCount - 1; y++) 252 for (int y = 0; y < matrixCount - 1; y++)
253 { 253 {
254 rowPtrs[y] = rowPtrs[y + 1]; 254 rowPtrs[y] = rowPtrs[y + 1];
255 } 255 }
256 rowPtrs[matrixCount - 1] += imageL->width; 256 rowPtrs[matrixCount - 1] += imageL->width;
257 writeRow += imageL->width; 257 writeRow += imageL->width;
258 } 258 }
259 } 259 }
260 260
261 static double pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB, SkTD Array<SkIPoint>* poi) { 261 static double pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB, int* poiCount) {
262 SkASSERT(baselineLAB);
263 SkASSERT(testLAB);
264 SkASSERT(poiCount);
265
262 int width = baselineLAB->width; 266 int width = baselineLAB->width;
263 int height = baselineLAB->height; 267 int height = baselineLAB->height;
264 int maxLevels = 0; 268 int maxLevels = 0;
265 269
266 // Calculates how many levels to make by how many times the image can be div ided in two 270 // Calculates how many levels to make by how many times the image can be div ided in two
267 int smallerDimension = width < height ? width : height; 271 int smallerDimension = width < height ? width : height;
268 for ( ; smallerDimension > 1; smallerDimension /= 2) { 272 for ( ; smallerDimension > 1; smallerDimension /= 2) {
269 maxLevels++; 273 maxLevels++;
270 } 274 }
271 275
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 convolve(&scratchImageL, true, testL.getLayer(levelIndex)); 313 convolve(&scratchImageL, true, testL.getLayer(levelIndex));
310 } 314 }
311 315
312 // Compute F_freq - The elevation f 316 // Compute F_freq - The elevation f
313 for (int levelIndex = 0; levelIndex < maxLevels - 2; levelIndex++) { 317 for (int levelIndex = 0; levelIndex < maxLevels - 2; levelIndex++) {
314 float cpd = cyclesPerDegree[levelIndex]; 318 float cpd = cyclesPerDegree[levelIndex];
315 thresholdFactorFrequency[levelIndex] = contrastSensitivityMax / 319 thresholdFactorFrequency[levelIndex] = contrastSensitivityMax /
316 contrast_sensitivity(cpd, 100.0f) ; 320 contrast_sensitivity(cpd, 100.0f) ;
317 } 321 }
318 322
319 int failures = 0;
320 // Calculate F 323 // Calculate F
321 for (int y = 0; y < height; y++) { 324 for (int y = 0; y < height; y++) {
322 for (int x = 0; x < width; x++) { 325 for (int x = 0; x < width; x++) {
323 float lBaseline; 326 float lBaseline;
324 float lTest; 327 float lTest;
325 baselineL.getLayer(0)->readPixel(x, y, &lBaseline); 328 baselineL.getLayer(0)->readPixel(x, y, &lBaseline);
326 testL.getLayer(0)->readPixel(x, y, &lTest); 329 testL.getLayer(0)->readPixel(x, y, &lTest);
327 330
328 float avgLBaseline; 331 float avgLBaseline;
329 float avgLTest; 332 float avgLTest;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 407 }
405 colorScale *= colorScale; 408 colorScale *= colorScale;
406 409
407 if ((contrastA * contrastA + contrastB * contrastB) * colorScale > F) 410 if ((contrastA * contrastA + contrastB * contrastB) * colorScale > F)
408 { 411 {
409 isFailure = true; 412 isFailure = true;
410 } 413 }
411 } 414 }
412 415
413 if (isFailure) { 416 if (isFailure) {
414 failures++; 417 (*poiCount)++;
415 poi->push()->set(x, y);
416 } 418 }
417 } 419 }
418 } 420 }
419 421
420 SkDELETE_ARRAY(cyclesPerDegree); 422 SkDELETE_ARRAY(cyclesPerDegree);
421 SkDELETE_ARRAY(contrast); 423 SkDELETE_ARRAY(contrast);
422 SkDELETE_ARRAY(thresholdFactorFrequency); 424 SkDELETE_ARRAY(thresholdFactorFrequency);
423 SkDELETE_ARRAY(contrastSensitivityTable); 425 SkDELETE_ARRAY(contrastSensitivityTable);
424 return 1.0 - (double)failures / (width * height); 426 return 1.0 - (double)(*poiCount) / (width * height);
425 } 427 }
426 428
427 const char* SkPMetric::getName() { 429 const char* SkPMetric::getName() {
428 return "perceptual"; 430 return "perceptual";
429 } 431 }
430 432
431 int SkPMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) { 433 bool SkPMetric::diff(SkBitmap* baseline, SkBitmap* test, Result* result) {
432 double startTime = get_seconds(); 434 double startTime = get_seconds();
433 int diffID = fQueuedDiffs.count();
434 QueuedDiff& diff = fQueuedDiffs.push_back();
435 diff.result = 0.0;
436 435
437 // Ensure the images are comparable 436 // Ensure the images are comparable
438 if (baseline->width() != test->width() || baseline->height() != test->height () || 437 if (baseline->width() != test->width() || baseline->height() != test->height () ||
439 baseline->width() <= 0 || baseline->height() <= 0) { 438 baseline->width() <= 0 || baseline->height() <= 0) {
440 diff.finished = true; 439 return false;
441 return diffID;
442 } 440 }
443 441
444 ImageLAB baselineLAB(baseline->width(), baseline->height()); 442 ImageLAB baselineLAB(baseline->width(), baseline->height());
445 ImageLAB testLAB(baseline->width(), baseline->height()); 443 ImageLAB testLAB(baseline->width(), baseline->height());
446 444
447 bitmap_to_cielab(baseline, &baselineLAB); 445 bitmap_to_cielab(baseline, &baselineLAB);
448 bitmap_to_cielab(test, &testLAB); 446 bitmap_to_cielab(test, &testLAB);
449 447
450 diff.result = pmetric(&baselineLAB, &testLAB, &diff.poi); 448 result->poiCount = 0;
449 result->result = pmetric(&baselineLAB, &testLAB, &result->poiCount);
450 result->timeElapsed = get_seconds() - startTime;
451 451
452 SkDebugf("Time: %f\n", (get_seconds() - startTime)); 452 return true;
453
454 return diffID;
455 } 453 }
456
457
458 void SkPMetric::deleteDiff(int id) {
459
460 }
461
462 bool SkPMetric::isFinished(int id) {
463 return fQueuedDiffs[id].finished;
464 }
465
466 double SkPMetric::getResult(int id) {
467 return fQueuedDiffs[id].result;
468 }
469
470 int SkPMetric::getPointsOfInterestCount(int id) {
471 return fQueuedDiffs[id].poi.count();
472 }
473
474 SkIPoint* SkPMetric::getPointsOfInterest(int id) {
475 return fQueuedDiffs[id].poi.begin();
476 }
OLDNEW
« tools/skpdiff/SkImageDiffer.h ('K') | « tools/skpdiff/SkPMetric.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698