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

Side by Side Diff: tests/TextureCompressionTest.cpp

Issue 432503002: Add initial pipeline for decompressors (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Code review comments Created 6 years, 4 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
OLDNEW
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
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
robertphillips 2014/07/31 15:15:13 Don't think you want this here !
krajcevski 2014/07/31 15:28:53 Done.
156 sk_free(decompBuffer);
157 }
158
159 /**
78 * Make sure that if we pass in a solid color bitmap that we get the appropriate results 160 * Make sure that if we pass in a solid color bitmap that we get the appropriate results
79 */ 161 */
80 DEF_TEST(CompressLATC, reporter) { 162 DEF_TEST(CompressLATC, reporter) {
81 163
82 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat; 164 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat;
83 static const int kLATCEncodedBlockSize = 8; 165 static const int kLATCEncodedBlockSize = 8;
84 166
85 SkBitmap bitmap; 167 SkBitmap bitmap;
86 static const int kWidth = 8; 168 static const int kWidth = 8;
87 static const int kHeight = 8; 169 static const int kHeight = 8;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37 ) | 216 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37 ) |
135 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49 ) | 217 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49 ) |
136 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61 )); 218 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61 ));
137 219
138 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d ata()); 220 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d ata());
139 for (size_t i = 0; i < (kSizeToBe/8); ++i) { 221 for (size_t i = 0; i < (kSizeToBe/8); ++i) {
140 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); 222 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding);
141 } 223 }
142 } 224 }
143 } 225 }
OLDNEW
« src/utils/SkTextureCompressor.h ('K') | « src/utils/SkTextureCompressor_R11EAC.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698