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

Side by Side Diff: ui/gfx/color_analysis_unittest.cc

Issue 2682123003: Remove uses of skia::ReadPixels(PaintCanvas) (Closed)
Patch Set: more readpixels Created 3 years, 10 months 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
« no previous file with comments | « ui/gfx/canvas.cc ('k') | ui/gfx/color_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/gfx/color_analysis.h" 5 #include "ui/gfx/color_analysis.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) { 338 TEST_F(ColorAnalysisTest, ComputeColorCovarianceWithCanvas) {
339 gfx::Canvas canvas(gfx::Size(250, 200), 1.0f, true); 339 gfx::Canvas canvas(gfx::Size(250, 200), 1.0f, true);
340 // The image consists of vertical stripes, with color bands set to 100 340 // The image consists of vertical stripes, with color bands set to 100
341 // in overlapping stripes 150 pixels wide. 341 // in overlapping stripes 150 pixels wide.
342 canvas.FillRect(gfx::Rect(0, 0, 50, 200), SkColorSetRGB(100, 0, 0)); 342 canvas.FillRect(gfx::Rect(0, 0, 50, 200), SkColorSetRGB(100, 0, 0));
343 canvas.FillRect(gfx::Rect(50, 0, 50, 200), SkColorSetRGB(100, 100, 0)); 343 canvas.FillRect(gfx::Rect(50, 0, 50, 200), SkColorSetRGB(100, 100, 0));
344 canvas.FillRect(gfx::Rect(100, 0, 50, 200), SkColorSetRGB(100, 100, 100)); 344 canvas.FillRect(gfx::Rect(100, 0, 50, 200), SkColorSetRGB(100, 100, 100));
345 canvas.FillRect(gfx::Rect(150, 0, 50, 200), SkColorSetRGB(0, 100, 100)); 345 canvas.FillRect(gfx::Rect(150, 0, 50, 200), SkColorSetRGB(0, 100, 100));
346 canvas.FillRect(gfx::Rect(200, 0, 50, 200), SkColorSetRGB(0, 0, 100)); 346 canvas.FillRect(gfx::Rect(200, 0, 50, 200), SkColorSetRGB(0, 0, 100));
347 347
348 SkBitmap bitmap = skia::ReadPixels(canvas.sk_canvas()); 348 gfx::Matrix3F covariance = ComputeColorCovariance(canvas.ToBitmap());
349 gfx::Matrix3F covariance = ComputeColorCovariance(bitmap);
350 349
351 gfx::Matrix3F expected_covariance = gfx::Matrix3F::Zeros(); 350 gfx::Matrix3F expected_covariance = gfx::Matrix3F::Zeros();
352 expected_covariance.set(2400, 400, -1600, 351 expected_covariance.set(2400, 400, -1600,
353 400, 2400, 400, 352 400, 2400, 400,
354 -1600, 400, 2400); 353 -1600, 400, 2400);
355 EXPECT_EQ(expected_covariance, covariance); 354 EXPECT_EQ(expected_covariance, covariance);
356 } 355 }
357 356
358 TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) { 357 TEST_F(ColorAnalysisTest, ApplyColorReductionSingleColor) {
359 // The test runs color reduction on a single-colot image, where results are 358 // The test runs color reduction on a single-colot image, where results are
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 395 }
397 396
398 TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) { 397 TEST_F(ColorAnalysisTest, ApplyColorReductionBlackAndWhite) {
399 // Check with images with multiple colors. This is really different only when 398 // Check with images with multiple colors. This is really different only when
400 // the result is scaled. 399 // the result is scaled.
401 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); 400 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true);
402 401
403 // The image consists of vertical non-overlapping stripes 150 pixels wide. 402 // The image consists of vertical non-overlapping stripes 150 pixels wide.
404 canvas.FillRect(gfx::Rect(0, 0, 150, 200), SkColorSetRGB(0, 0, 0)); 403 canvas.FillRect(gfx::Rect(0, 0, 150, 200), SkColorSetRGB(0, 0, 0));
405 canvas.FillRect(gfx::Rect(150, 0, 150, 200), SkColorSetRGB(255, 255, 255)); 404 canvas.FillRect(gfx::Rect(150, 0, 150, 200), SkColorSetRGB(255, 255, 255));
406 SkBitmap source = skia::ReadPixels(canvas.sk_canvas()); 405 SkBitmap source = canvas.ToBitmap();
407 SkBitmap result; 406 SkBitmap result;
408 result.allocPixels(SkImageInfo::MakeA8(300, 200)); 407 result.allocPixels(SkImageInfo::MakeA8(300, 200));
409 408
410 gfx::Vector3dF transform(1.0f, 0.5f, 0.1f); 409 gfx::Vector3dF transform(1.0f, 0.5f, 0.1f);
411 EXPECT_TRUE(ApplyColorReduction(source, transform, true, &result)); 410 EXPECT_TRUE(ApplyColorReduction(source, transform, true, &result));
412 uint8_t min_gl = 0; 411 uint8_t min_gl = 0;
413 uint8_t max_gl = 0; 412 uint8_t max_gl = 0;
414 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); 413 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
415 414
416 EXPECT_EQ(0, min_gl); 415 EXPECT_EQ(0, min_gl);
(...skipping 16 matching lines...) Expand all
433 432
434 TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) { 433 TEST_F(ColorAnalysisTest, ApplyColorReductionMultiColor) {
435 // Check with images with multiple colors. This is really different only when 434 // Check with images with multiple colors. This is really different only when
436 // the result is scaled. 435 // the result is scaled.
437 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); 436 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true);
438 437
439 // The image consists of vertical non-overlapping stripes 100 pixels wide. 438 // The image consists of vertical non-overlapping stripes 100 pixels wide.
440 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(100, 0, 0)); 439 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(100, 0, 0));
441 canvas.FillRect(gfx::Rect(100, 0, 100, 200), SkColorSetRGB(0, 255, 0)); 440 canvas.FillRect(gfx::Rect(100, 0, 100, 200), SkColorSetRGB(0, 255, 0));
442 canvas.FillRect(gfx::Rect(200, 0, 100, 200), SkColorSetRGB(0, 0, 128)); 441 canvas.FillRect(gfx::Rect(200, 0, 100, 200), SkColorSetRGB(0, 0, 128));
443 SkBitmap source = skia::ReadPixels(canvas.sk_canvas()); 442 SkBitmap source = canvas.ToBitmap();
444 SkBitmap result; 443 SkBitmap result;
445 result.allocPixels(SkImageInfo::MakeA8(300, 200)); 444 result.allocPixels(SkImageInfo::MakeA8(300, 200));
446 445
447 gfx::Vector3dF transform(1.0f, 0.5f, 0.1f); 446 gfx::Vector3dF transform(1.0f, 0.5f, 0.1f);
448 EXPECT_TRUE(ApplyColorReduction(source, transform, false, &result)); 447 EXPECT_TRUE(ApplyColorReduction(source, transform, false, &result));
449 uint8_t min_gl = 0; 448 uint8_t min_gl = 0;
450 uint8_t max_gl = 0; 449 uint8_t max_gl = 0;
451 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); 450 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
452 EXPECT_EQ(12, min_gl); 451 EXPECT_EQ(12, min_gl);
453 EXPECT_EQ(127, max_gl); 452 EXPECT_EQ(127, max_gl);
(...skipping 21 matching lines...) Expand all
475 EXPECT_FALSE(ComputePrincipalComponentImage(source, &result)); 474 EXPECT_FALSE(ComputePrincipalComponentImage(source, &result));
476 } 475 }
477 476
478 TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) { 477 TEST_F(ColorAnalysisTest, ComputePrincipalComponentImage) {
479 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true); 478 gfx::Canvas canvas(gfx::Size(300, 200), 1.0f, true);
480 479
481 // The image consists of vertical non-overlapping stripes 100 pixels wide. 480 // The image consists of vertical non-overlapping stripes 100 pixels wide.
482 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(10, 10, 10)); 481 canvas.FillRect(gfx::Rect(0, 0, 100, 200), SkColorSetRGB(10, 10, 10));
483 canvas.FillRect(gfx::Rect(100, 0, 100, 200), SkColorSetRGB(100, 100, 100)); 482 canvas.FillRect(gfx::Rect(100, 0, 100, 200), SkColorSetRGB(100, 100, 100));
484 canvas.FillRect(gfx::Rect(200, 0, 100, 200), SkColorSetRGB(255, 255, 255)); 483 canvas.FillRect(gfx::Rect(200, 0, 100, 200), SkColorSetRGB(255, 255, 255));
485 SkBitmap source = skia::ReadPixels(canvas.sk_canvas()); 484 SkBitmap source = canvas.ToBitmap();
486 SkBitmap result; 485 SkBitmap result;
487 result.allocPixels(SkImageInfo::MakeA8(300, 200)); 486 result.allocPixels(SkImageInfo::MakeA8(300, 200));
488 487
489 // This computation should fail since all colors always vary together. 488 // This computation should fail since all colors always vary together.
490 EXPECT_TRUE(ComputePrincipalComponentImage(source, &result)); 489 EXPECT_TRUE(ComputePrincipalComponentImage(source, &result));
491 490
492 uint8_t min_gl = 0; 491 uint8_t min_gl = 0;
493 uint8_t max_gl = 0; 492 uint8_t max_gl = 0;
494 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl); 493 Calculate8bitBitmapMinMax(result, &min_gl, &max_gl);
495 494
496 EXPECT_EQ(0, min_gl); 495 EXPECT_EQ(0, min_gl);
497 EXPECT_EQ(255, max_gl); 496 EXPECT_EQ(255, max_gl);
498 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0))); 497 EXPECT_EQ(min_gl, SkColorGetA(result.getColor(0, 0)));
499 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199))); 498 EXPECT_EQ(max_gl, SkColorGetA(result.getColor(299, 199)));
500 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0))); 499 EXPECT_EQ(93U, SkColorGetA(result.getColor(150, 0)));
501 } 500 }
502 501
503 } // namespace color_utils 502 } // namespace color_utils
OLDNEW
« no previous file with comments | « ui/gfx/canvas.cc ('k') | ui/gfx/color_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698