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

Side by Side Diff: tests/MipMapTest.cpp

Issue 2029373004: respect srgb gamma when building mips (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix warning Created 4 years, 6 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 | « src/gpu/SkGr.cpp ('k') | tests/SkResourceCacheTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkMipMap.h" 9 #include "SkMipMap.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
11 #include "Test.h" 11 #include "Test.h"
12 12
13 static void make_bitmap(SkBitmap* bm, int width, int height) { 13 static void make_bitmap(SkBitmap* bm, int width, int height) {
14 bm->allocN32Pixels(width, height); 14 bm->allocN32Pixels(width, height);
15 bm->eraseColor(SK_ColorWHITE); 15 bm->eraseColor(SK_ColorWHITE);
16 } 16 }
17 17
18 DEF_TEST(MipMap, reporter) { 18 DEF_TEST(MipMap, reporter) {
19 SkBitmap bm; 19 SkBitmap bm;
20 SkRandom rand; 20 SkRandom rand;
21 21
22 for (int i = 0; i < 500; ++i) { 22 for (int i = 0; i < 500; ++i) {
23 int width = 1 + rand.nextU() % 1000; 23 int width = 1 + rand.nextU() % 1000;
24 int height = 1 + rand.nextU() % 1000; 24 int height = 1 + rand.nextU() % 1000;
25 make_bitmap(&bm, width, height); 25 make_bitmap(&bm, width, height);
26 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); 26 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, SkSourceGammaTreatment::kI gnore, nullptr));
27 27
28 REPORTER_ASSERT(reporter, mm->countLevels() == SkMipMap::ComputeLevelCou nt(width, height)); 28 REPORTER_ASSERT(reporter, mm->countLevels() == SkMipMap::ComputeLevelCou nt(width, height));
29 REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1, SK_ Scalar1), 29 REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1, SK_ Scalar1),
30 nullptr)); 30 nullptr));
31 REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1 * 2, SK_Scalar1 * 2), 31 REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1 * 2, SK_Scalar1 * 2),
32 nullptr)); 32 nullptr));
33 33
34 SkMipMap::Level prevLevel; 34 SkMipMap::Level prevLevel;
35 sk_bzero(&prevLevel, sizeof(prevLevel)); 35 sk_bzero(&prevLevel, sizeof(prevLevel));
36 36
(...skipping 16 matching lines...) Expand all
53 } 53 }
54 } 54 }
55 } 55 }
56 } 56 }
57 57
58 static void test_mipmap_generation(int width, int height, int expectedMipLevelCo unt, 58 static void test_mipmap_generation(int width, int height, int expectedMipLevelCo unt,
59 skiatest::Reporter* reporter) { 59 skiatest::Reporter* reporter) {
60 SkBitmap bm; 60 SkBitmap bm;
61 bm.allocN32Pixels(width, height); 61 bm.allocN32Pixels(width, height);
62 bm.eraseColor(SK_ColorWHITE); 62 bm.eraseColor(SK_ColorWHITE);
63 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); 63 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, SkSourceGammaTreatment::kIgnor e, nullptr));
64 64
65 const int mipLevelCount = mm->countLevels(); 65 const int mipLevelCount = mm->countLevels();
66 REPORTER_ASSERT(reporter, mipLevelCount == expectedMipLevelCount); 66 REPORTER_ASSERT(reporter, mipLevelCount == expectedMipLevelCount);
67 REPORTER_ASSERT(reporter, mipLevelCount == SkMipMap::ComputeLevelCount(width , height)); 67 REPORTER_ASSERT(reporter, mipLevelCount == SkMipMap::ComputeLevelCount(width , height));
68 for (int i = 0; i < mipLevelCount; ++i) { 68 for (int i = 0; i < mipLevelCount; ++i) {
69 SkMipMap::Level level; 69 SkMipMap::Level level;
70 REPORTER_ASSERT(reporter, mm->getLevel(i, &level)); 70 REPORTER_ASSERT(reporter, mm->getLevel(i, &level));
71 // Make sure the mipmaps contain valid data and that the sizes are corre ct 71 // Make sure the mipmaps contain valid data and that the sizes are corre ct
72 REPORTER_ASSERT(reporter, level.fPixmap.addr()); 72 REPORTER_ASSERT(reporter, level.fPixmap.addr());
73 SkISize size = SkMipMap::ComputeLevelSize(width, height, i); 73 SkISize size = SkMipMap::ComputeLevelSize(width, height, i);
74 REPORTER_ASSERT(reporter, level.fPixmap.width() == size.width()); 74 REPORTER_ASSERT(reporter, level.fPixmap.width() == size.width());
75 REPORTER_ASSERT(reporter, level.fPixmap.height() == size.height()); 75 REPORTER_ASSERT(reporter, level.fPixmap.height() == size.height());
76 76
77 // + 1 because SkMipMap does not include the base mipmap level. 77 // + 1 because SkMipMap does not include the base mipmap level.
78 int twoToTheMipLevel = 1 << (i + 1); 78 int twoToTheMipLevel = 1 << (i + 1);
79 int currentWidth = width / twoToTheMipLevel; 79 int currentWidth = width / twoToTheMipLevel;
80 int currentHeight = height / twoToTheMipLevel; 80 int currentHeight = height / twoToTheMipLevel;
81 REPORTER_ASSERT(reporter, level.fPixmap.width() == currentWidth); 81 REPORTER_ASSERT(reporter, level.fPixmap.width() == currentWidth);
82 REPORTER_ASSERT(reporter, level.fPixmap.height() == currentHeight); 82 REPORTER_ASSERT(reporter, level.fPixmap.height() == currentHeight);
83 } 83 }
84 } 84 }
85 85
86 DEF_TEST(MipMap_DirectLevelAccess, reporter) { 86 DEF_TEST(MipMap_DirectLevelAccess, reporter) {
87 // create mipmap with invalid size 87 // create mipmap with invalid size
88 { 88 {
89 // SkMipMap current requires the dimensions be greater than 2x2 89 // SkMipMap current requires the dimensions be greater than 2x2
90 SkBitmap bm; 90 SkBitmap bm;
91 bm.allocN32Pixels(1, 1); 91 bm.allocN32Pixels(1, 1);
92 bm.eraseColor(SK_ColorWHITE); 92 bm.eraseColor(SK_ColorWHITE);
93 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); 93 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, SkSourceGammaTreatment::kI gnore, nullptr));
94 94
95 REPORTER_ASSERT(reporter, mm == nullptr); 95 REPORTER_ASSERT(reporter, mm == nullptr);
96 } 96 }
97 97
98 // check small mipmap's count and levels 98 // check small mipmap's count and levels
99 // There should be 5 mipmap levels generated: 99 // There should be 5 mipmap levels generated:
100 // 16x16, 8x8, 4x4, 2x2, 1x1 100 // 16x16, 8x8, 4x4, 2x2, 1x1
101 test_mipmap_generation(32, 32, 5, reporter); 101 test_mipmap_generation(32, 32, 5, reporter);
102 102
103 // check large mipmap's count and levels 103 // check large mipmap's count and levels
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 {500, 1000, 1, SkISize::Make(125, 250)}, 195 {500, 1000, 1, SkISize::Make(125, 250)},
196 }; 196 };
197 197
198 for (auto& currentTest : tests) { 198 for (auto& currentTest : tests) {
199 SkISize levelSize = SkMipMap::ComputeLevelSize(currentTest.fBaseWidth, 199 SkISize levelSize = SkMipMap::ComputeLevelSize(currentTest.fBaseWidth,
200 currentTest.fBaseHeight, 200 currentTest.fBaseHeight,
201 currentTest.fLevel); 201 currentTest.fLevel);
202 REPORTER_ASSERT(reporter, currentTest.fExpectedMipMapLevelSize == levelS ize); 202 REPORTER_ASSERT(reporter, currentTest.fExpectedMipMapLevelSize == levelS ize);
203 } 203 }
204 } 204 }
OLDNEW
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | tests/SkResourceCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698