| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkSwizzler.h" | 8 #include "SkSwizzler.h" |
| 9 #include "Test.h" | 9 #include "Test.h" |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 uint8_t* imageData = storage.get() + offset; | 35 uint8_t* imageData = storage.get() + offset; |
| 36 uint8_t* imageStart = imageData + rowBytes * startRow; | 36 uint8_t* imageStart = imageData + rowBytes * startRow; |
| 37 | 37 |
| 38 // Fill image with the fill value starting at the indicated row | 38 // Fill image with the fill value starting at the indicated row |
| 39 SkSwizzler::Fill(imageStart, imageInfo, rowBytes, endRow - startRow + 1, col
orOrIndex, | 39 SkSwizzler::Fill(imageStart, imageInfo, rowBytes, endRow - startRow + 1, col
orOrIndex, |
| 40 colorTable); | 40 colorTable); |
| 41 | 41 |
| 42 // Ensure that the pixels are filled properly | 42 // Ensure that the pixels are filled properly |
| 43 // The bots should catch any memory corruption | 43 // The bots should catch any memory corruption |
| 44 uint8_t* indexPtr = imageData + startRow * rowBytes; | 44 uint8_t* indexPtr = imageData + startRow * rowBytes; |
| 45 uint8_t* grayPtr = indexPtr; |
| 45 uint32_t* colorPtr = (uint32_t*) indexPtr; | 46 uint32_t* colorPtr = (uint32_t*) indexPtr; |
| 46 for (uint32_t y = startRow; y <= endRow; y++) { | 47 for (uint32_t y = startRow; y <= endRow; y++) { |
| 47 for (int32_t x = 0; x < imageInfo.width(); x++) { | 48 for (int32_t x = 0; x < imageInfo.width(); x++) { |
| 48 if (kIndex_8_SkColorType == imageInfo.colorType()) { | 49 switch (imageInfo.colorType()) { |
| 49 REPORTER_ASSERT(r, kFillIndex == indexPtr[x]); | 50 case kIndex_8_SkColorType: |
| 50 } else { | 51 REPORTER_ASSERT(r, kFillIndex == indexPtr[x]); |
| 51 REPORTER_ASSERT(r, kFillColor == colorPtr[x]); | 52 break; |
| 53 case kN32_SkColorType: |
| 54 REPORTER_ASSERT(r, kFillColor == colorPtr[x]); |
| 55 break; |
| 56 case kGray_8_SkColorType: |
| 57 // We always fill kGray with black |
| 58 REPORTER_ASSERT(r, (uint8_t) kFillColor == grayPtr[x]); |
| 59 break; |
| 60 default: |
| 61 REPORTER_ASSERT(r, false); |
| 62 break; |
| 52 } | 63 } |
| 53 } | 64 } |
| 54 indexPtr += rowBytes; | 65 indexPtr += rowBytes; |
| 55 colorPtr = (uint32_t*) indexPtr; | 66 colorPtr = (uint32_t*) indexPtr; |
| 56 } | 67 } |
| 57 } | 68 } |
| 58 | 69 |
| 59 // Test Fill() with different combinations of dimensions, alignment, and padding | 70 // Test Fill() with different combinations of dimensions, alignment, and padding |
| 60 DEF_TEST(SwizzlerFill, r) { | 71 DEF_TEST(SwizzlerFill, r) { |
| 61 // Set up a color table | 72 // Set up a color table |
| (...skipping 13 matching lines...) Expand all Loading... |
| 75 const uint32_t paddings[] = { 0, 1, 2, 3, 4 }; | 86 const uint32_t paddings[] = { 0, 1, 2, 3, 4 }; |
| 76 | 87 |
| 77 // Iterate over test dimensions | 88 // Iterate over test dimensions |
| 78 for (uint32_t width : widths) { | 89 for (uint32_t width : widths) { |
| 79 for (uint32_t height : heights) { | 90 for (uint32_t height : heights) { |
| 80 | 91 |
| 81 // Create image info objects | 92 // Create image info objects |
| 82 const SkImageInfo colorInfo = SkImageInfo::MakeN32(width, height, | 93 const SkImageInfo colorInfo = SkImageInfo::MakeN32(width, height, |
| 83 kUnknown_SkAlphaType); | 94 kUnknown_SkAlphaType); |
| 84 const SkImageInfo indexInfo = colorInfo.makeColorType(kIndex_8_SkCol
orType); | 95 const SkImageInfo indexInfo = colorInfo.makeColorType(kIndex_8_SkCol
orType); |
| 96 const SkImageInfo grayInfo = colorInfo.makeColorType(kGray_8_SkColor
Type); |
| 85 | 97 |
| 86 for (uint32_t padding : paddings) { | 98 for (uint32_t padding : paddings) { |
| 87 | 99 |
| 88 // Calculate row bytes | 100 // Calculate row bytes |
| 89 size_t colorRowBytes = SkColorTypeBytesPerPixel(kN32_SkColorType
) * width + | 101 size_t colorRowBytes = SkColorTypeBytesPerPixel(kN32_SkColorType
) * width + |
| 90 padding; | 102 padding; |
| 91 size_t indexRowBytes = width + padding; | 103 size_t indexRowBytes = width + padding; |
| 104 size_t grayRowBytes = indexRowBytes; |
| 92 | 105 |
| 93 // If there is padding, we can invent an offset to change the me
mory alignment | 106 // If there is padding, we can invent an offset to change the me
mory alignment |
| 94 for (uint32_t offset = 0; offset <= padding; offset++) { | 107 for (uint32_t offset = 0; offset <= padding; offset++) { |
| 95 | 108 |
| 96 // Test all possible start rows with all possible end rows | 109 // Test all possible start rows with all possible end rows |
| 97 for (uint32_t startRow = 0; startRow < height; startRow++) { | 110 for (uint32_t startRow = 0; startRow < height; startRow++) { |
| 98 for (uint32_t endRow = startRow; endRow < height; endRow
++) { | 111 for (uint32_t endRow = startRow; endRow < height; endRow
++) { |
| 99 | 112 |
| 100 // Fill with an index that we use to look up a color | 113 // Fill with an index that we use to look up a color |
| 101 check_fill(r, colorInfo, startRow, endRow, colorRowB
ytes, offset, | 114 check_fill(r, colorInfo, startRow, endRow, colorRowB
ytes, offset, |
| 102 kFillIndex, colorTable); | 115 kFillIndex, colorTable); |
| 103 | 116 |
| 104 // Fill with a color | 117 // Fill with a color |
| 105 check_fill(r, colorInfo, startRow, endRow, colorRowB
ytes, offset, | 118 check_fill(r, colorInfo, startRow, endRow, colorRowB
ytes, offset, |
| 106 kFillColor, NULL); | 119 kFillColor, NULL); |
| 107 | 120 |
| 108 // Fill with an index | 121 // Fill with an index |
| 109 check_fill(r, indexInfo, startRow, endRow, indexRowB
ytes, offset, | 122 check_fill(r, indexInfo, startRow, endRow, indexRowB
ytes, offset, |
| 110 kFillIndex, NULL); | 123 kFillIndex, NULL); |
| 124 |
| 125 // Fill a grayscale image |
| 126 check_fill(r, grayInfo, startRow, endRow, grayRowByt
es, offset, |
| 127 kFillColor, NULL); |
| 111 } | 128 } |
| 112 } | 129 } |
| 113 } | 130 } |
| 114 } | 131 } |
| 115 } | 132 } |
| 116 } | 133 } |
| 117 } | 134 } |
| OLD | NEW |