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

Side by Side Diff: tests/TextureCompressionTest.cpp

Issue 330453005: Texture compression unit tests along with a couple of bug fixes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Code review changes Created 6 years, 6 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
« no previous file with comments | « src/utils/SkTextureCompressor.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkBitmap.h"
9 #include "SkData.h"
10 #include "SkEndian.h"
11 #include "SkImageInfo.h"
12 #include "SkTextureCompressor.h"
13 #include "Test.h"
14
15 static const int kLATCBlockDimension = 4;
16 static const int kLATCEncodedBlockSize = 8;
17
18 /**
19 * Make sure that we properly fail when we don't have multiple of four image dim ensions.
20 */
21 DEF_TEST(CompressLATCFailDimensions, reporter) {
22 SkBitmap bitmap;
23 static const int kWidth = 63;
24 static const int kHeight = 63;
25 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
26 REPORTER_ASSERT(reporter, kWidth % kLATCBlockDimension != 0);
27 REPORTER_ASSERT(reporter, kHeight % kLATCBlockDimension != 0);
28
29 bool setInfoSuccess = bitmap.setInfo(info);
30 REPORTER_ASSERT(reporter, setInfoSuccess);
31
32 bool allocPixelsSuccess = bitmap.allocPixels(info);
33 REPORTER_ASSERT(reporter, allocPixelsSuccess);
34 bitmap.unlockPixels();
35
36 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat;
37 SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat));
38 REPORTER_ASSERT(reporter, NULL == latcData);
39 }
40
41 /**
42 * Make sure that we properly fail when we don't have the correct bitmap type.
43 */
44 DEF_TEST(CompressLATCFailColorType, reporter) {
45 SkBitmap bitmap;
46 static const int kWidth = 64;
47 static const int kHeight = 64;
robertphillips 2014/06/11 19:02:56 // LATC only works for A8 bitmaps ?
krajcevski 2014/06/11 19:11:17 Done.
48 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
49 REPORTER_ASSERT(reporter, kWidth % kLATCBlockDimension == 0);
50 REPORTER_ASSERT(reporter, kHeight % kLATCBlockDimension == 0);
51
52 bool setInfoSuccess = bitmap.setInfo(info);
53 REPORTER_ASSERT(reporter, setInfoSuccess);
54
55 bool allocPixelsSuccess = bitmap.allocPixels(info);
56 REPORTER_ASSERT(reporter, allocPixelsSuccess);
57 bitmap.unlockPixels();
58
59 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat;
60 SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat));
61 REPORTER_ASSERT(reporter, NULL == latcData);
62 }
63
64 /**
65 * Make sure that if we pass in a solid color bitmap that we get the appropriate results
66 */
67 DEF_TEST(CompressLATC, reporter) {
68 SkBitmap bitmap;
69 static const int kWidth = 8;
70 static const int kHeight = 8;
71 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
72
73 bool setInfoSuccess = bitmap.setInfo(info);
74 REPORTER_ASSERT(reporter, setInfoSuccess);
75
76 bool allocPixelsSuccess = bitmap.allocPixels(info);
77 REPORTER_ASSERT(reporter, allocPixelsSuccess);
78 bitmap.unlockPixels();
79
80 REPORTER_ASSERT(reporter, kWidth % kLATCBlockDimension == 0);
81 REPORTER_ASSERT(reporter, kHeight % kLATCBlockDimension == 0);
82 const int numBlocks = (kWidth / kLATCBlockDimension) * (kHeight / kLATCBlock Dimension);
83 const size_t kSizeToBe = static_cast<size_t>(kLATCEncodedBlockSize * numBloc ks);
84
85 for (int lum = 0; lum < 256; ++lum) {
86 bitmap.lockPixels();
87 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
88 REPORTER_ASSERT(reporter, NULL != pixels);
89
90 for (int i = 0; i < kWidth*kHeight; ++i) {
91 pixels[i] = lum;
92 }
93 bitmap.unlockPixels();
94
95 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLA TC_Format;
96 SkAutoDataUnref latcData(
97 SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat));
98 REPORTER_ASSERT(reporter, NULL != latcData);
99 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size());
100
101 // Make sure that it all matches a given block encoding. If the entire b itmap
102 // is a single value, then the lower two bytes of the encoded data shoul d be that
103 // value. The remaining indices can be any value, and since we try to ma tch the pixels
104 // in the chosen palette in increasing index order, each one should be z ero. Hence,
105 // the correct encoding should be just the two luminance values in the b ottom two
106 // bytes of the block encoding.
107 const uint64_t kConstColorEncoding = SkEndian_SwapLE64(lum | (lum << 8)) ;
108 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d ata());
109 for (int i = 0; i < numBlocks; ++i) {
110 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding);
111 }
112 }
113 }
OLDNEW
« no previous file with comments | « src/utils/SkTextureCompressor.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698