Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 | 46 |
| 47 if (prevLevel.fPixmap.addr()) { | 47 if (prevLevel.fPixmap.addr()) { |
| 48 REPORTER_ASSERT(reporter, level.fPixmap.width() <= prevLevel .fPixmap.width()); | 48 REPORTER_ASSERT(reporter, level.fPixmap.width() <= prevLevel .fPixmap.width()); |
| 49 REPORTER_ASSERT(reporter, level.fPixmap.height() <= prevLeve l.fPixmap.height()); | 49 REPORTER_ASSERT(reporter, level.fPixmap.height() <= prevLeve l.fPixmap.height()); |
| 50 } | 50 } |
| 51 prevLevel = level; | 51 prevLevel = level; |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | |
| 57 DEF_TEST(MipMap_DirectLevelAccess, reporter) { | |
|
reed1
2016/01/28 02:06:03
Looking above, perhaps we just could augment the e
cblume
2016/02/01 09:31:07
Sure, I'll do that. Good idea.
In fact, I would l
| |
| 58 // create mipmap with invalid size | |
| 59 { | |
| 60 // SkMipMap current requires the dimensions be greater than 2x2 | |
| 61 SkBitmap bm; | |
| 62 bm.allocN32Pixels(1, 1); | |
| 63 bm.eraseColor(SK_ColorWHITE); | |
| 64 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); | |
| 65 | |
| 66 REPORTER_ASSERT(reporter, mm->countLevels() == 0); | |
| 67 } | |
| 68 | |
| 69 | |
| 70 // check small mipmap's count and levels | |
|
reed1
2016/01/28 02:06:03
can this block be combined with the one below it,
cblume
2016/02/01 09:31:07
Yes, it can. Initial dimensions, the numerator for
| |
| 71 { | |
| 72 SkBitmap bm; | |
| 73 bm.allocN32Pixels(32, 32); | |
| 74 bm.eraseColor(SK_ColorWHITE); | |
| 75 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); | |
| 76 | |
| 77 | |
| 78 const int mipLevelCount = mm->countLevels(); | |
| 79 // There should be 5 mipmap levels generated: | |
| 80 // 16x16, 8x8, 4x4, 2x2, 1x1 | |
| 81 REPORTER_ASSERT(reporter, mipLevelCount == 5); | |
| 82 for (int i = 0; i < mipLevelCount; ++i) { | |
| 83 SkMipMap::Level level; | |
| 84 mm->getLevel(i, &level); | |
| 85 // Make sure the mipmaps contain valid data and that the sizes are | |
| 86 // correct | |
| 87 REPORTER_ASSERT(reporter, level.fPixmap.addr() != nullptr); | |
| 88 | |
| 89 // Add 1 because we are checking mip levels 1-6. | |
| 90 // The bitmap is the 0th mipmap level. | |
| 91 int twoToTheMipLevel = 1 << (i + 1); | |
| 92 int size = 16 / twoToTheMipLevel; | |
| 93 REPORTER_ASSERT(reporter, level.fPixmap.width() == size); | |
| 94 REPORTER_ASSERT(reporter, level.fPixmap.height() == size); | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 | |
| 99 // check large mipmap's count and levels | |
| 100 { | |
| 101 SkBitmap bm; | |
| 102 bm.allocN32Pixels(1000, 1000); | |
| 103 bm.eraseColor(SK_ColorWHITE); | |
| 104 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); | |
| 105 | |
| 106 | |
| 107 const int mipLevelCount = mm->countLevels(); | |
| 108 // There should be 9 mipmap levels generated: | |
| 109 // 500x500, 250x250, 125x125, 62x62, 31x31, 15x15, 7x7, 3x3. 1x1 | |
| 110 REPORTER_ASSERT(reporter, mipLevelCount == 9); | |
| 111 for (int i = 0; i < mipLevelCount; ++i) { | |
| 112 SkMipMap::Level level; | |
| 113 mm->getLevel(i, &level); | |
| 114 // Make sure the mipmaps contain valid data and that the sizes are | |
| 115 // correct | |
| 116 REPORTER_ASSERT(reporter, level.fPixmap.addr() != nullptr); | |
| 117 | |
| 118 // Add 1 because we are checking mip levels 1-9. | |
| 119 // The bitmap is the 0th mipmap level. | |
| 120 int twoToTheMipLevel = 1 << (i + 1); | |
| 121 int size = 500 / twoToTheMipLevel; | |
| 122 REPORTER_ASSERT(reporter, level.fPixmap.width() == size); | |
| 123 REPORTER_ASSERT(reporter, level.fPixmap.height() == size); | |
| 124 } | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 DEF_TEST(MipMap_ComputeLevelCount, reporter) { | |
| 129 // Test mipmaps with negative sizes | |
| 130 int negativeWidthResult = SkMipMap::ComputeLevelCount(-100, 100); | |
| 131 REPORTER_ASSERT(reporter, negativeWidthResult == 0); | |
| 132 | |
| 133 int negativeHeightResult = SkMipMap::ComputeLevelCount(100, -100); | |
| 134 REPORTER_ASSERT(reporter, negativeHeightResult == 0); | |
| 135 | |
| 136 int negativeBothResult = SkMipMap::ComputeLevelCount(-100, -100); | |
| 137 REPORTER_ASSERT(reporter, negativeBothResult == 0); | |
| 138 | |
| 139 | |
| 140 // Test mipmaps with 0, 1, 2 as dimensions | |
| 141 // (SkMipMap::Build requires a min size of 2) | |
| 142 // | |
| 143 // 0 | |
| 144 int zeroWidthResult = SkMipMap::ComputeLevelCount(0, 100); | |
|
reed1
2016/01/28 02:06:03
There is a fair amount of copy/paste here. I wonde
cblume
2016/02/01 09:31:07
I agree that there is a lot of copy/paste/minor ch
| |
| 145 REPORTER_ASSERT(reporter, zeroWidthResult == 0); | |
| 146 | |
| 147 int zeroHeightResult = SkMipMap::ComputeLevelCount(100, 0); | |
| 148 REPORTER_ASSERT(reporter, zeroHeightResult == 0); | |
| 149 | |
| 150 int zeroBothResult = SkMipMap::ComputeLevelCount(0, 0); | |
| 151 REPORTER_ASSERT(reporter, zeroBothResult == 0); | |
| 152 | |
| 153 // 1 | |
| 154 int oneWidthResult = SkMipMap::ComputeLevelCount(1, 100); | |
| 155 REPORTER_ASSERT(reporter, oneWidthResult == 0); | |
| 156 | |
| 157 int oneHeightResult = SkMipMap::ComputeLevelCount(100, 1); | |
| 158 REPORTER_ASSERT(reporter, oneHeightResult == 0); | |
| 159 | |
| 160 int oneBothResult = SkMipMap::ComputeLevelCount(1, 1); | |
| 161 REPORTER_ASSERT(reporter, oneBothResult == 0); | |
| 162 | |
| 163 // 2 | |
| 164 int twoWidthResult = SkMipMap::ComputeLevelCount(2, 100); | |
| 165 REPORTER_ASSERT(reporter, twoWidthResult == 2); | |
| 166 | |
| 167 int twoHeightResult = SkMipMap::ComputeLevelCount(100, 2); | |
| 168 REPORTER_ASSERT(reporter, twoHeightResult == 2); | |
| 169 | |
| 170 int twoBothResult = SkMipMap::ComputeLevelCount(2, 2); | |
| 171 REPORTER_ASSERT(reporter, twoBothResult == 2); | |
| 172 | |
| 173 | |
| 174 // Test a handful of boundaries such as 63x63 and 64x64 | |
| 175 int sixtyThreeResult = SkMipMap::ComputeLevelCount(63, 63); | |
| 176 REPORTER_ASSERT(reporter, sixtyThreeResult == 6); | |
| 177 | |
| 178 int sixtyFourResult = SkMipMap::ComputeLevelCount(64, 64); | |
| 179 REPORTER_ASSERT(reporter, sixtyFourResult == 7); | |
| 180 | |
| 181 int oneHundredTwentySevenResult = SkMipMap::ComputeLevelCount(127, 127); | |
| 182 REPORTER_ASSERT(reporter, oneHundredTwentySevenResult == 7); | |
| 183 | |
| 184 int oneHundredTwentyEightResult = SkMipMap::ComputeLevelCount(128, 128); | |
| 185 REPORTER_ASSERT(reporter, oneHundredTwentyEightResult == 8); | |
| 186 | |
| 187 int twoHundredFiftyFiveResult = SkMipMap::ComputeLevelCount(255, 255); | |
| 188 REPORTER_ASSERT(reporter, twoHundredFiftyFiveResult == 8); | |
| 189 | |
| 190 int twoHundredFiftySixResult = SkMipMap::ComputeLevelCount(256, 256); | |
| 191 REPORTER_ASSERT(reporter, twoHundredFiftySixResult == 9); | |
| 192 | |
| 193 | |
| 194 // Test different dimensions, such as 256x64 | |
| 195 int smallestAxisIsSixtyFourResult = SkMipMap::ComputeLevelCount(64, 129); | |
| 196 REPORTER_ASSERT(reporter, smallestAxisIsSixtyFourResult == 7); | |
| 197 | |
| 198 int smallestAxisIsThirtyTwoResult = SkMipMap::ComputeLevelCount(255, 32); | |
| 199 REPORTER_ASSERT(reporter, smallestAxisIsThirtyTwoResult == 6); | |
| 200 | |
| 201 int smallestAxisIsFiveHundredResult = SkMipMap::ComputeLevelCount(500, 1000) ; | |
| 202 REPORTER_ASSERT(reporter, smallestAxisIsFiveHundredResult == 9); | |
| 203 | |
| 204 // Test a few calls to SkMipMap::Build to make sure it matches | |
| 205 // SkMipMap::ComputeLevelCount | |
| 206 // | |
| 207 // Add 1 to mm->countLevels() because SkMipMap does not contain the base | |
| 208 // mipmap level. | |
| 209 // It contains mipmap levels 1-x, not 0-x. | |
| 210 { | |
| 211 SkBitmap bm; | |
| 212 bm.allocN32Pixels(255, 255); | |
| 213 bm.eraseColor(SK_ColorWHITE); | |
| 214 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); | |
| 215 | |
| 216 REPORTER_ASSERT(reporter, mm->countLevels() + 1 == SkMipMap::ComputeLeve lCount(255, 255)); | |
| 217 } | |
| 218 | |
| 219 { | |
| 220 SkBitmap bm; | |
| 221 bm.allocN32Pixels(32, 32); | |
| 222 bm.eraseColor(SK_ColorWHITE); | |
| 223 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); | |
| 224 | |
| 225 REPORTER_ASSERT(reporter, mm->countLevels() + 1 == SkMipMap::ComputeLeve lCount(32, 32)); | |
| 226 } | |
| 227 | |
| 228 { | |
| 229 SkBitmap bm; | |
| 230 bm.allocN32Pixels(1000, 1000); | |
| 231 bm.eraseColor(SK_ColorWHITE); | |
| 232 SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); | |
| 233 | |
| 234 REPORTER_ASSERT(reporter, mm->countLevels() + 1 == SkMipMap::ComputeLeve lCount(1000, 1000)); | |
| 235 } | |
| 236 } | |
| OLD | NEW |