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

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: 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
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) {
scroggo 2013/11/07 21:43:23 Can we assert that the parameters are not NULL?
djsollen 2013/11/07 21:53:57 Done.
262 int width = baselineLAB->width; 262 int width = baselineLAB->width;
263 int height = baselineLAB->height; 263 int height = baselineLAB->height;
264 int maxLevels = 0; 264 int maxLevels = 0;
265 265
266 // Calculates how many levels to make by how many times the image can be div ided in two 266 // 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; 267 int smallerDimension = width < height ? width : height;
268 for ( ; smallerDimension > 1; smallerDimension /= 2) { 268 for ( ; smallerDimension > 1; smallerDimension /= 2) {
269 maxLevels++; 269 maxLevels++;
270 } 270 }
271 271
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 convolve(&scratchImageL, true, testL.getLayer(levelIndex)); 309 convolve(&scratchImageL, true, testL.getLayer(levelIndex));
310 } 310 }
311 311
312 // Compute F_freq - The elevation f 312 // Compute F_freq - The elevation f
313 for (int levelIndex = 0; levelIndex < maxLevels - 2; levelIndex++) { 313 for (int levelIndex = 0; levelIndex < maxLevels - 2; levelIndex++) {
314 float cpd = cyclesPerDegree[levelIndex]; 314 float cpd = cyclesPerDegree[levelIndex];
315 thresholdFactorFrequency[levelIndex] = contrastSensitivityMax / 315 thresholdFactorFrequency[levelIndex] = contrastSensitivityMax /
316 contrast_sensitivity(cpd, 100.0f) ; 316 contrast_sensitivity(cpd, 100.0f) ;
317 } 317 }
318 318
319 int failures = 0;
320 // Calculate F 319 // Calculate F
321 for (int y = 0; y < height; y++) { 320 for (int y = 0; y < height; y++) {
322 for (int x = 0; x < width; x++) { 321 for (int x = 0; x < width; x++) {
323 float lBaseline; 322 float lBaseline;
324 float lTest; 323 float lTest;
325 baselineL.getLayer(0)->readPixel(x, y, &lBaseline); 324 baselineL.getLayer(0)->readPixel(x, y, &lBaseline);
326 testL.getLayer(0)->readPixel(x, y, &lTest); 325 testL.getLayer(0)->readPixel(x, y, &lTest);
327 326
328 float avgLBaseline; 327 float avgLBaseline;
329 float avgLTest; 328 float avgLTest;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 403 }
405 colorScale *= colorScale; 404 colorScale *= colorScale;
406 405
407 if ((contrastA * contrastA + contrastB * contrastB) * colorScale > F) 406 if ((contrastA * contrastA + contrastB * contrastB) * colorScale > F)
408 { 407 {
409 isFailure = true; 408 isFailure = true;
410 } 409 }
411 } 410 }
412 411
413 if (isFailure) { 412 if (isFailure) {
414 failures++; 413 (*poiCount)++;
415 poi->push()->set(x, y);
416 } 414 }
417 } 415 }
418 } 416 }
419 417
420 SkDELETE_ARRAY(cyclesPerDegree); 418 SkDELETE_ARRAY(cyclesPerDegree);
421 SkDELETE_ARRAY(contrast); 419 SkDELETE_ARRAY(contrast);
422 SkDELETE_ARRAY(thresholdFactorFrequency); 420 SkDELETE_ARRAY(thresholdFactorFrequency);
423 SkDELETE_ARRAY(contrastSensitivityTable); 421 SkDELETE_ARRAY(contrastSensitivityTable);
424 return 1.0 - (double)failures / (width * height); 422 return 1.0 - (double)(*poiCount) / (width * height);
425 } 423 }
426 424
427 const char* SkPMetric::getName() { 425 const char* SkPMetric::getName() {
428 return "perceptual"; 426 return "perceptual";
429 } 427 }
430 428
431 int SkPMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) { 429 bool SkPMetric::diff(SkBitmap* baseline, SkBitmap* test, Result* result) {
432 double startTime = get_seconds(); 430 double startTime = get_seconds();
433 int diffID = fQueuedDiffs.count();
434 QueuedDiff& diff = fQueuedDiffs.push_back();
435 diff.result = 0.0;
436 431
437 // Ensure the images are comparable 432 // Ensure the images are comparable
438 if (baseline->width() != test->width() || baseline->height() != test->height () || 433 if (baseline->width() != test->width() || baseline->height() != test->height () ||
439 baseline->width() <= 0 || baseline->height() <= 0) { 434 baseline->width() <= 0 || baseline->height() <= 0) {
440 diff.finished = true; 435 return false;
441 return diffID;
442 } 436 }
443 437
444 ImageLAB baselineLAB(baseline->width(), baseline->height()); 438 ImageLAB baselineLAB(baseline->width(), baseline->height());
445 ImageLAB testLAB(baseline->width(), baseline->height()); 439 ImageLAB testLAB(baseline->width(), baseline->height());
446 440
447 bitmap_to_cielab(baseline, &baselineLAB); 441 bitmap_to_cielab(baseline, &baselineLAB);
448 bitmap_to_cielab(test, &testLAB); 442 bitmap_to_cielab(test, &testLAB);
449 443
450 diff.result = pmetric(&baselineLAB, &testLAB, &diff.poi); 444 result->poiCount = 0;
445 result->result = pmetric(&baselineLAB, &testLAB, &result->poiCount);
446 result->timeElapsed = get_seconds() - startTime;
451 447
452 SkDebugf("Time: %f\n", (get_seconds() - startTime)); 448 return true;
453
454 return diffID;
455 } 449 }
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/SkDifferentPixelsMetric_opencl.cpp ('K') | « tools/skpdiff/SkPMetric.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698