Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 | |
| 2 /* | |
| 3 * Copyright 2014 Google Inc. | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 */ | |
| 8 | |
| 9 | |
| 10 #ifndef SkKTXFile_DEFINED | |
| 11 #define SkKTXFile_DEFINED | |
| 12 | |
| 13 #include "SkTypes.h" | |
| 14 #include "SkTDArray.h" | |
| 15 #include "SkString.h" | |
| 16 | |
| 17 class SkStreamRewindable; | |
| 18 | |
| 19 class SkKTXFile { | |
|
tfarina
2014/06/03 03:52:46
could you add a high-level class doc comment? For
hal.canary
2014/06/03 13:48:00
// http://www.khronos.org/opengles/sdk/tools/KTX/f
krajcevski
2014/06/03 14:46:27
Done.
| |
| 20 public: | |
| 21 // The ownership of the data remains with the caller. This class is intended | |
| 22 // to be used as a logical wrapper around the data in order to properly | |
| 23 // access the pixels. | |
| 24 SkKTXFile(const uint8_t* data, size_t dataLen) | |
| 25 : fSwapBytes(false) | |
| 26 { | |
|
robertphillips
2014/06/03 13:27:41
this->readKTXFile ?
krajcevski
2014/06/03 14:46:27
Done.
| |
| 27 fValid = readKTXFile(data, dataLen); | |
| 28 } | |
| 29 | |
| 30 bool valid() const { return fValid; } | |
| 31 | |
| 32 int width() const { return static_cast<int>(fHeader.fPixelWidth); } | |
| 33 int height() const { return static_cast<int>(fHeader.fPixelHeight); } | |
| 34 | |
| 35 const uint8_t *pixelData(int mipmap = 0) const { | |
| 36 SkASSERT(!valid() || mipmap < fPixelData.count()); | |
|
robertphillips
2014/06/03 13:27:41
this->valid ?
missing space before '?' ?
krajcevski
2014/06/03 14:46:27
Done.
| |
| 37 return valid()? fPixelData[mipmap].data() : NULL; | |
| 38 } | |
| 39 | |
| 40 int numMipmaps() const { return static_cast<int>(fHeader.fNumberOfMipmapLeve ls); } | |
| 41 | |
| 42 bool isETC1() const; | |
| 43 bool isRGBA8() const; | |
| 44 bool isRGB8() const; | |
| 45 | |
| 46 static bool is_ktx(const uint8_t *data); | |
| 47 static bool is_ktx(SkStreamRewindable* stream); | |
| 48 | |
| 49 private: | |
|
robertphillips
2014/06/03 13:27:41
// This header captures all the data from the KTX
krajcevski
2014/06/03 14:46:27
Done.
| |
| 50 struct Header { | |
| 51 uint32_t fGLType; | |
| 52 uint32_t fGLTypeSize; | |
| 53 uint32_t fGLFormat; | |
| 54 uint32_t fGLInternalFormat; | |
| 55 uint32_t fGLBaseInternalFormat; | |
| 56 uint32_t fPixelWidth; | |
| 57 uint32_t fPixelHeight; | |
| 58 uint32_t fPixelDepth; | |
| 59 uint32_t fNumberOfArrayElements; | |
| 60 uint32_t fNumberOfFaces; | |
| 61 uint32_t fNumberOfMipmapLevels; | |
| 62 uint32_t fBytesOfKeyValueData; | |
| 63 | |
| 64 Header() { memset(this, 0, sizeof(*this)); } | |
| 65 void swapBytes(); | |
| 66 } fHeader; | |
| 67 | |
| 68 class KeyValue { | |
| 69 public: | |
| 70 KeyValue(size_t size) : fDataSz(size) { } | |
| 71 bool readKeyAndValue(const uint8_t *data); | |
| 72 | |
| 73 private: | |
| 74 const size_t fDataSz; | |
| 75 SkString fKey; | |
| 76 SkString fValue; | |
| 77 }; | |
| 78 | |
| 79 class PixelData { | |
| 80 public: | |
| 81 PixelData(const uint8_t *ptr, size_t sz) : fDataSz(sz), fDataPtr(ptr) { } | |
| 82 const uint8_t *data() const { return fDataPtr; } | |
| 83 size_t dataSize() const { return fDataSz; } | |
| 84 private: | |
| 85 const size_t fDataSz; | |
| 86 const uint8_t *fDataPtr; | |
| 87 }; | |
| 88 | |
| 89 bool readKTXFile(const uint8_t *data, size_t dataLen); | |
| 90 | |
|
robertphillips
2014/06/03 13:27:41
KeyValue isn't POD, is it ? Can we actually use Sk
krajcevski
2014/06/03 14:58:35
Done.
| |
| 91 SkTDArray<KeyValue> fKeyValuePairs; | |
| 92 SkTDArray<PixelData> fPixelData; | |
| 93 bool fValid; | |
| 94 | |
| 95 // If the endianness of the platform is different than the file, | |
| 96 // then we need to do proper byte swapping. | |
| 97 bool fSwapBytes; | |
| 98 | |
| 99 // Read an integer from a buffer, advance the buffer, and swap | |
| 100 // bytes if fSwapBytes is set | |
|
robertphillips
2014/06/03 13:27:41
left justify the '&' ?
krajcevski
2014/06/03 14:46:27
Done.
| |
| 101 uint32_t readInt(const uint8_t*& buf, size_t &bytesLeft) const; | |
| 102 }; | |
| 103 | |
| 104 #endif // SkKTXFile_DEFINED | |
| OLD | NEW |