OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkData.h" | 9 #include "SkData.h" |
10 #include "SkEndian.h" | 10 #include "SkEndian.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 bitmap.unlockPixels(); | 68 bitmap.unlockPixels(); |
69 | 69 |
70 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 70 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
71 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 71 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
72 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); | 72 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); |
73 REPORTER_ASSERT(reporter, NULL == data); | 73 REPORTER_ASSERT(reporter, NULL == data); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 /** | 77 /** |
78 * Make sure that if you compress a texture with alternating black/white pixels,
and | |
79 * then decompress it, you get what you started with. | |
80 */ | |
81 DEF_TEST(CompressCheckerboard, reporter) { | |
82 SkBitmap bitmap; | |
83 static const int kWidth = 12; | |
84 static const int kHeight = 12; | |
85 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); | |
86 | |
87 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl
e | |
88 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh
t | |
89 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would | |
90 // need to be updated. | |
91 REPORTER_ASSERT(reporter, kWidth % 12 == 0); | |
92 REPORTER_ASSERT(reporter, kHeight % 12 == 0); | |
93 | |
94 bool setInfoSuccess = bitmap.setInfo(info); | |
95 REPORTER_ASSERT(reporter, setInfoSuccess); | |
96 | |
97 bool allocPixelsSuccess = bitmap.allocPixels(info); | |
98 REPORTER_ASSERT(reporter, allocPixelsSuccess); | |
99 | |
100 bitmap.lockPixels(); | |
101 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); | |
102 REPORTER_ASSERT(reporter, NULL != pixels); | |
103 | |
104 for (int y = 0; y < kHeight; ++y) { | |
105 for (int x = 0; x < kWidth; ++x) { | |
106 if ((x ^ y) & 1) { | |
107 pixels[x] = 0xFF; | |
108 } else { | |
109 pixels[x] = 0; | |
110 } | |
111 } | |
112 pixels += bitmap.rowBytes(); | |
113 } | |
114 bitmap.unlockPixels(); | |
115 | |
116 SkAutoMalloc decompMemory(kWidth*kHeight); | |
117 uint8_t* decompBuffer = reinterpret_cast<uint8_t*>(decompMemory.get()); | |
118 REPORTER_ASSERT(reporter, NULL != decompBuffer); | |
119 if (NULL == decompBuffer) { | |
120 return; | |
121 } | |
122 | |
123 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | |
124 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | |
125 | |
126 // ASTC is for RGBA data, and the decompressed buffer | |
127 // won't match the size and contents of the original. | |
128 // TODO: Create separate tests for RGB and RGBA data once | |
129 // ASTC decompression is implemented. | |
130 if (SkTextureCompressor::kASTC_12x12_Format == fmt) { | |
131 continue; | |
132 } | |
133 | |
134 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); | |
135 REPORTER_ASSERT(reporter, NULL != data); | |
136 | |
137 bool decompResult = | |
138 SkTextureCompressor::DecompressBufferFromFormat( | |
139 decompBuffer, kWidth, | |
140 data->bytes(), | |
141 kWidth, kHeight, fmt); | |
142 REPORTER_ASSERT(reporter, decompResult); | |
143 | |
144 bitmap.lockPixels(); | |
145 pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); | |
146 REPORTER_ASSERT(reporter, NULL != pixels); | |
147 | |
148 for (int y = 0; y < kHeight; ++y) { | |
149 for (int x = 0; x < kWidth; ++x) { | |
150 bool ok = pixels[y*bitmap.rowBytes() + x] == decompBuffer[y*kWid
th + x]; | |
151 REPORTER_ASSERT(reporter, ok); | |
152 } | |
153 } | |
154 } | |
155 } | |
156 | |
157 /** | |
158 * Make sure that if we pass in a solid color bitmap that we get the appropriate
results | 78 * Make sure that if we pass in a solid color bitmap that we get the appropriate
results |
159 */ | 79 */ |
160 DEF_TEST(CompressLATC, reporter) { | 80 DEF_TEST(CompressLATC, reporter) { |
161 | 81 |
162 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F
ormat; | 82 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F
ormat; |
163 static const int kLATCEncodedBlockSize = 8; | 83 static const int kLATCEncodedBlockSize = 8; |
164 | 84 |
165 SkBitmap bitmap; | 85 SkBitmap bitmap; |
166 static const int kWidth = 8; | 86 static const int kWidth = 8; |
167 static const int kHeight = 8; | 87 static const int kHeight = 8; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | | 134 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | |
215 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | | 135 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | |
216 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); | 136 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); |
217 | 137 |
218 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); | 138 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); |
219 for (size_t i = 0; i < (kSizeToBe/8); ++i) { | 139 for (size_t i = 0; i < (kSizeToBe/8); ++i) { |
220 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); | 140 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); |
221 } | 141 } |
222 } | 142 } |
223 } | 143 } |
OLD | NEW |