Chromium Code Reviews| OLD | NEW |
|---|---|
| (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(CompressLATCFailure, reporter) { | |
| 22 SkBitmap bitmap; | |
|
robertphillips
2014/06/11 18:16:35
kWidth & kHeight ?
krajcevski
2014/06/11 18:51:10
Done.
| |
| 23 static const int width = 63; | |
| 24 static const int height = 63; | |
|
robertphillips
2014/06/11 18:16:35
MakeA8? kOpaque ??
krajcevski
2014/06/11 18:51:10
Done.
| |
| 25 SkImageInfo info = SkImageInfo::Make(width, height, | |
| 26 kAlpha_8_SkColorType, | |
| 27 kOpaque_SkAlphaType); | |
| 28 REPORTER_ASSERT(reporter, width % kLATCBlockDimension != 0); | |
| 29 REPORTER_ASSERT(reporter, height % kLATCBlockDimension != 0); | |
| 30 | |
|
robertphillips
2014/06/11 18:16:36
Make the next two lines one line ?
krajcevski
2014/06/11 18:51:10
Done.
| |
| 31 bool setInfoSuccess = false; | |
| 32 setInfoSuccess = bitmap.setInfo(info); | |
| 33 REPORTER_ASSERT(reporter, setInfoSuccess); | |
| 34 | |
|
robertphillips
2014/06/11 18:16:35
1 line?
krajcevski
2014/06/11 18:51:10
Done.
| |
| 35 bool allocPixelsSuccess = false; | |
| 36 allocPixelsSuccess = bitmap.allocPixels(info); | |
| 37 REPORTER_ASSERT(reporter, allocPixelsSuccess); | |
| 38 bitmap.unlockPixels(); | |
| 39 | |
| 40 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_F ormat; | |
|
robertphillips
2014/06/11 18:16:35
What makes this bitmap white?
krajcevski
2014/06/11 18:51:10
Artifact of copypasta. Fixed.
| |
| 41 SkAutoDataUnref whiteLATC(SkTextureCompressor::CompressBitmapToFormat(bitmap , kLATCFormat)); | |
| 42 REPORTER_ASSERT(reporter, NULL == whiteLATC); | |
| 43 } | |
| 44 | |
| 45 /** | |
| 46 * Make sure that if we pass in a solid color bitmap that we get the appropriate results | |
| 47 */ | |
| 48 DEF_TEST(CompressLATC, reporter) { | |
| 49 SkBitmap bitmap; | |
|
robertphillips
2014/06/11 18:16:35
kWidth, kHeight?
krajcevski
2014/06/11 18:51:11
Done.
| |
| 50 static const int width = 8; | |
| 51 static const int height = 8; | |
|
robertphillips
2014/06/11 18:16:35
Same as above ?
krajcevski
2014/06/11 18:51:11
Done.
| |
| 52 SkImageInfo info = SkImageInfo::Make(width, height, | |
| 53 kAlpha_8_SkColorType, | |
| 54 kOpaque_SkAlphaType); | |
| 55 | |
|
robertphillips
2014/06/11 18:16:36
1 line ?
krajcevski
2014/06/11 18:51:11
Done.
| |
| 56 bool setInfoSuccess = false; | |
| 57 setInfoSuccess = bitmap.setInfo(info); | |
| 58 REPORTER_ASSERT(reporter, setInfoSuccess); | |
| 59 | |
|
robertphillips
2014/06/11 18:16:36
1 line ?
krajcevski
2014/06/11 18:51:10
Done.
| |
| 60 bool allocPixelsSuccess = false; | |
| 61 allocPixelsSuccess = bitmap.allocPixels(info); | |
| 62 REPORTER_ASSERT(reporter, allocPixelsSuccess); | |
| 63 | |
|
robertphillips
2014/06/11 18:16:35
I would just ditch this test here and check it eve
krajcevski
2014/06/11 18:51:10
Done.
| |
| 64 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); | |
| 65 bitmap.unlockPixels(); | |
| 66 REPORTER_ASSERT(reporter, NULL != pixels); | |
| 67 | |
| 68 REPORTER_ASSERT(reporter, width % kLATCBlockDimension == 0); | |
| 69 REPORTER_ASSERT(reporter, height % kLATCBlockDimension == 0); | |
| 70 int numBlocks = (width / kLATCBlockDimension) * (height / kLATCBlockDimensio n); | |
| 71 | |
| 72 for (int lum = 0; lum < 256; ++lum) { | |
|
robertphillips
2014/06/11 18:16:36
regrab the pixels in here ?
krajcevski
2014/06/11 18:51:11
Done.
| |
| 73 bitmap.lockPixels(); | |
| 74 for (int i = 0; i < width*height; ++i) { | |
| 75 pixels[i] = lum; | |
| 76 } | |
| 77 bitmap.unlockPixels(); | |
| 78 | |
| 79 const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLA TC_Format; | |
| 80 SkAutoDataUnref latcData( | |
| 81 SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat)); | |
| 82 REPORTER_ASSERT(reporter, NULL != latcData); | |
| 83 | |
|
robertphillips
2014/06/11 18:16:36
Move kSizeToBe out of the loop?
krajcevski
2014/06/11 18:51:11
Done.
| |
| 84 const size_t kSizeToBe = static_cast<size_t>(kLATCEncodedBlockSize * num Blocks); | |
| 85 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size()); | |
| 86 | |
| 87 // Make sure that it all matches a given block encoding. | |
|
robertphillips
2014/06/11 18:16:35
Rename 'encoding' 'encodedConstColorBlock' - or so
krajcevski
2014/06/11 18:51:10
Done.
| |
| 88 const uint64_t encoding = SkEndian_SwapLE64(lum | (lum << 8)); | |
| 89 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d ata()); | |
|
robertphillips
2014/06/11 18:16:36
++i ?
krajcevski
2014/06/11 18:51:11
Done.
| |
| 90 for (int i = 0; i < numBlocks; i++) { | |
| 91 REPORTER_ASSERT(reporter, blockPtr[i] == encoding); | |
| 92 } | |
| 93 } | |
| 94 } | |
| OLD | NEW |