OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 #include <cmath> | 6 #include <cmath> |
7 #include <iomanip> | 7 #include <iomanip> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 const int src_w = 640, src_h = 480, checker_rect_w = 4, checker_rect_h = 8; | 488 const int src_w = 640, src_h = 480, checker_rect_w = 4, checker_rect_h = 8; |
489 const SkColor checker_color1 = SK_ColorRED, checker_color2 = SK_ColorBLUE; | 489 const SkColor checker_color1 = SK_ColorRED, checker_color2 = SK_ColorBLUE; |
490 | 490 |
491 const int dest_w = src_w / (4 * checker_rect_w); | 491 const int dest_w = src_w / (4 * checker_rect_w); |
492 const int dest_h = src_h / (2 * checker_rect_h); | 492 const int dest_h = src_h / (2 * checker_rect_h); |
493 | 493 |
494 // Compute the expected (average) color | 494 // Compute the expected (average) color |
495 const SkColor colors[] = { checker_color1, checker_color2 }; | 495 const SkColor colors[] = { checker_color1, checker_color2 }; |
496 const SkColor average_color = AveragePixel(colors, arraysize(colors)); | 496 const SkColor average_color = AveragePixel(colors, arraysize(colors)); |
497 | 497 |
498 // RESIZE_SUBPIXEL is only supported on Linux/non-GTV platforms. | |
499 static const TestedResizeMethod tested_methods[] = { | 498 static const TestedResizeMethod tested_methods[] = { |
500 { skia::ImageOperations::RESIZE_GOOD, "GOOD", 0.0f }, | 499 { skia::ImageOperations::RESIZE_GOOD, "GOOD", 0.0f }, |
501 { skia::ImageOperations::RESIZE_BETTER, "BETTER", 0.0f }, | 500 { skia::ImageOperations::RESIZE_BETTER, "BETTER", 0.0f }, |
502 { skia::ImageOperations::RESIZE_BEST, "BEST", 0.0f }, | 501 { skia::ImageOperations::RESIZE_BEST, "BEST", 0.0f }, |
503 { skia::ImageOperations::RESIZE_BOX, "BOX", 0.0f }, | 502 { skia::ImageOperations::RESIZE_BOX, "BOX", 0.0f }, |
504 { skia::ImageOperations::RESIZE_HAMMING1, "HAMMING1", 0.0f }, | 503 { skia::ImageOperations::RESIZE_HAMMING1, "HAMMING1", 0.0f }, |
505 { skia::ImageOperations::RESIZE_LANCZOS2, "LANCZOS2", 0.0f }, | 504 { skia::ImageOperations::RESIZE_LANCZOS2, "LANCZOS2", 0.0f }, |
506 { skia::ImageOperations::RESIZE_LANCZOS3, "LANCZOS3", 0.0f }, | 505 { skia::ImageOperations::RESIZE_LANCZOS3, "LANCZOS3", 0.0f }, |
507 #if defined(OS_LINUX) && !defined(GTV) | |
508 // SUBPIXEL has slightly worse performance than the other filters: | |
509 // 6.324 Bottom left/right corners | |
510 // 5.099 Top left/right corners | |
511 // 2.828 Bottom middle | |
512 // 1.414 Top/Left/Right middle, center | |
513 // | |
514 // This is expected since, in order to judge RESIZE_SUBPIXEL accurately, | |
515 // we'd need to compute distances for each sub-pixel, and potentially | |
516 // tweak the test parameters so that expectations were realistic when | |
517 // looking at sub-pixels in isolation. | |
518 // | |
519 // Rather than going to these lengths, we added the "max_distance_override" | |
520 // field in TestedResizeMethod, intended for RESIZE_SUBPIXEL. It allows | |
521 // us to to enable its testing without having to lower the success criteria | |
522 // for the other methods. This procedure is distateful but defining | |
523 // a distance limit for each tested pixel for each method was judged to add | |
524 // unneeded complexity. | |
525 { skia::ImageOperations::RESIZE_SUBPIXEL, "SUBPIXEL", 6.4f }, | |
526 #endif | |
527 }; | 506 }; |
528 | 507 |
529 // Create our source bitmap. | 508 // Create our source bitmap. |
530 SkBitmap src; | 509 SkBitmap src; |
531 DrawCheckerToBitmap(src_w, src_h, | 510 DrawCheckerToBitmap(src_w, src_h, |
532 checker_color1, checker_color2, | 511 checker_color1, checker_color2, |
533 checker_rect_w, checker_rect_h, | 512 checker_rect_w, checker_rect_h, |
534 &src); | 513 &src); |
535 | 514 |
536 // For each method, downscale by 16 in each dimension, | 515 // For each method, downscale by 16 in each dimension, |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 EXPECT_LE(fabs(SkColorGetA(dst_color) - a), 1.5f); | 696 EXPECT_LE(fabs(SkColorGetA(dst_color) - a), 1.5f); |
718 EXPECT_LE(fabs(SkColorGetR(dst_color) - r), 1.5f); | 697 EXPECT_LE(fabs(SkColorGetR(dst_color) - r), 1.5f); |
719 EXPECT_LE(fabs(SkColorGetG(dst_color) - g), 1.5f); | 698 EXPECT_LE(fabs(SkColorGetG(dst_color) - g), 1.5f); |
720 EXPECT_LE(fabs(SkColorGetB(dst_color) - b), 1.5f); | 699 EXPECT_LE(fabs(SkColorGetB(dst_color) - b), 1.5f); |
721 if (HasFailure()) { | 700 if (HasFailure()) { |
722 return; | 701 return; |
723 } | 702 } |
724 } | 703 } |
725 } | 704 } |
726 } | 705 } |
OLD | NEW |