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

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: 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
robertphillips 2014/07/31 15:01:02 SkAutoMalloc ?
krajcevski 2014/07/31 15:12:19 Done.
116 uint8_t* decompBuffer = reinterpret_cast<uint8_t*>(sk_malloc_throw(kWidth*kH eight));
117 REPORTER_ASSERT(reporter, NULL != decompBuffer);
118 if (NULL == decompBuffer) {
119 return;
120 }
121
122 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
123 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor: :Format>(i);
124
125 // ASTC is for RGBA data, and doesn't fit the paradigm of this test.
robertphillips 2014/07/31 15:01:02 // TODO: add ASTC decompression test (when ASTC de
krajcevski 2014/07/31 15:12:19 Done.
126 if (SkTextureCompressor::kASTC_12x12_Format == fmt) {
127 continue;
128 }
129
130 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt));
131 REPORTER_ASSERT(reporter, NULL != data);
132
133 bool decompResult = SkTextureCompressor::DecompressBufferFromFormat(
robertphillips 2014/07/31 15:01:02 tab these guys over a bit (and maybe split across
krajcevski 2014/07/31 15:12:18 Done.
134 decompBuffer, kWidth, data->bytes(), kWidth, kHeight, fmt);
135 REPORTER_ASSERT(reporter, decompResult);
136
137 bitmap.lockPixels();
138 pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
139 REPORTER_ASSERT(reporter, NULL != pixels);
140
141 for (int y = 0; y < kHeight; ++y) {
142 for (int x = 0; x < kWidth; ++x) {
143 bool ok = pixels[y*bitmap.rowBytes() + x] == decompBuffer[y*kWid th + x];
144 REPORTER_ASSERT(reporter, ok);
145 }
146 }
147 }
148
149 sk_free(decompBuffer);
150 }
151
152 /**
78 * Make sure that if we pass in a solid color bitmap that we get the appropriate results 153 * Make sure that if we pass in a solid color bitmap that we get the appropriate results
79 */ 154 */
80 DEF_TEST(CompressLATC, reporter) { 155 DEF_TEST(CompressLATC, reporter) {
81 156
82 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat; 157 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat;
83 static const int kLATCEncodedBlockSize = 8; 158 static const int kLATCEncodedBlockSize = 8;
84 159
85 SkBitmap bitmap; 160 SkBitmap bitmap;
86 static const int kWidth = 8; 161 static const int kWidth = 8;
87 static const int kHeight = 8; 162 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 ) | 209 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37 ) |
135 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49 ) | 210 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49 ) |
136 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61 )); 211 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61 ));
137 212
138 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d ata()); 213 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d ata());
139 for (size_t i = 0; i < (kSizeToBe/8); ++i) { 214 for (size_t i = 0; i < (kSizeToBe/8); ++i) {
140 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); 215 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding);
141 } 216 }
142 } 217 }
143 } 218 }
OLDNEW
« src/utils/SkTextureCompressor_R11EAC.cpp ('K') | « src/utils/SkTextureCompressor_R11EAC.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698