Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkKTXFile_DEFINED | 10 #ifndef SkKTXFile_DEFINED |
| 11 #define SkKTXFile_DEFINED | 11 #define SkKTXFile_DEFINED |
| 12 | 12 |
| 13 #include "SkData.h" | 13 #include "SkData.h" |
| 14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 15 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
| 16 #include "SkString.h" | 16 #include "SkString.h" |
| 17 #include "SkRefCnt.h" | 17 #include "SkRefCnt.h" |
| 18 | 18 |
| 19 class SkBitmap; | |
| 19 class SkStreamRewindable; | 20 class SkStreamRewindable; |
| 21 class SkWStream; | |
| 20 | 22 |
| 21 // KTX Image File | 23 // KTX Image File |
| 22 // --- | 24 // --- |
| 23 // KTX is a general texture data storage file format ratified by the Khronos Gro up. As an | 25 // KTX is a general texture data storage file format ratified by the Khronos Gro up. As an |
| 24 // overview, a KTX file contains all of the appropriate values needed to fully s pecify a | 26 // overview, a KTX file contains all of the appropriate values needed to fully s pecify a |
| 25 // texture in an OpenGL application, including the use of compressed data. | 27 // texture in an OpenGL application, including the use of compressed data. |
| 26 // | 28 // |
| 27 // A full format specification can be found here: | 29 // A full format specification can be found here: |
| 28 // http://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/ | 30 // http://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/ |
| 29 | 31 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 42 bool valid() const { return fValid; } | 44 bool valid() const { return fValid; } |
| 43 | 45 |
| 44 int width() const { return static_cast<int>(fHeader.fPixelWidth); } | 46 int width() const { return static_cast<int>(fHeader.fPixelWidth); } |
| 45 int height() const { return static_cast<int>(fHeader.fPixelHeight); } | 47 int height() const { return static_cast<int>(fHeader.fPixelHeight); } |
| 46 | 48 |
| 47 const uint8_t *pixelData(int mipmap = 0) const { | 49 const uint8_t *pixelData(int mipmap = 0) const { |
| 48 SkASSERT(!this->valid() || mipmap < fPixelData.count()); | 50 SkASSERT(!this->valid() || mipmap < fPixelData.count()); |
| 49 return this->valid() ? fPixelData[mipmap].data() : NULL; | 51 return this->valid() ? fPixelData[mipmap].data() : NULL; |
| 50 } | 52 } |
| 51 | 53 |
| 54 // If the decoded KTX file has the following key, then it will | |
| 55 // return the associated value. If not found, the empty string | |
| 56 // is returned. | |
|
robertphillips
2014/06/05 19:12:21
const SkString& key ?
krajcevski
2014/06/05 19:29:44
Done.
| |
| 57 SkString getValueForKey(SkString key) const; | |
| 58 | |
| 52 int numMipmaps() const { return static_cast<int>(fHeader.fNumberOfMipmapLeve ls); } | 59 int numMipmaps() const { return static_cast<int>(fHeader.fNumberOfMipmapLeve ls); } |
| 53 | 60 |
| 54 bool isETC1() const; | 61 bool isETC1() const; |
| 55 bool isRGBA8() const; | 62 bool isRGBA8() const; |
| 56 bool isRGB8() const; | 63 bool isRGB8() const; |
| 57 | 64 |
| 58 static bool is_ktx(const uint8_t *data); | 65 static bool is_ktx(const uint8_t *data); |
| 59 static bool is_ktx(SkStreamRewindable* stream); | 66 static bool is_ktx(SkStreamRewindable* stream); |
| 60 | 67 |
| 68 static bool WriteETC1ToKTX(SkWStream* stream, const uint8_t *etc1Data, | |
| 69 uint32_t width, uint32_t height); | |
| 70 static bool WriteBitmapToKTX(SkWStream* stream, const SkBitmap& bitmap); | |
| 61 private: | 71 private: |
| 62 | 72 |
| 63 // The blob holding the file data. | 73 // The blob holding the file data. |
| 64 SkAutoTUnref<SkData> fData; | 74 SkAutoTUnref<SkData> fData; |
| 65 | 75 |
| 66 // This header captures all of the data that describes the format | 76 // This header captures all of the data that describes the format |
| 67 // of the image data in a KTX file. | 77 // of the image data in a KTX file. |
| 68 struct Header { | 78 struct Header { |
| 69 uint32_t fGLType; | 79 uint32_t fGLType; |
| 70 uint32_t fGLTypeSize; | 80 uint32_t fGLTypeSize; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 81 | 91 |
| 82 Header() { memset(this, 0, sizeof(*this)); } | 92 Header() { memset(this, 0, sizeof(*this)); } |
| 83 } fHeader; | 93 } fHeader; |
| 84 | 94 |
| 85 // A Key Value pair stored in the KTX file. There may be | 95 // A Key Value pair stored in the KTX file. There may be |
| 86 // arbitrarily many of these. | 96 // arbitrarily many of these. |
| 87 class KeyValue { | 97 class KeyValue { |
| 88 public: | 98 public: |
| 89 KeyValue(size_t size) : fDataSz(size) { } | 99 KeyValue(size_t size) : fDataSz(size) { } |
| 90 bool readKeyAndValue(const uint8_t *data); | 100 bool readKeyAndValue(const uint8_t *data); |
| 91 | 101 size_t size() const { return fDataSz; } |
|
robertphillips
2014/06/05 19:12:21
return "const SkString &" ?
krajcevski
2014/06/05 19:29:45
Done.
| |
| 102 SkString key() const { return fKey; } | |
| 103 SkString value() const { return fValue; } | |
| 104 bool writeKeyAndValueForKTX(SkWStream* strm); | |
| 92 private: | 105 private: |
|
robertphillips
2014/06/05 19:12:21
Line up the member variable names ?
krajcevski
2014/06/05 19:29:44
Done.
| |
| 93 const size_t fDataSz; | 106 const size_t fDataSz; |
| 94 SkString fKey; | 107 SkString fKey; |
| 95 SkString fValue; | 108 SkString fValue; |
| 96 }; | 109 }; |
| 97 | 110 |
| 111 static KeyValue CreateKeyValue(const char *key, const char *value); | |
| 112 | |
| 98 // The pixel data for a single mipmap level in an image. Based on how | 113 // The pixel data for a single mipmap level in an image. Based on how |
| 99 // the rest of the data is stored, this may be compressed, a cubemap, etc. | 114 // the rest of the data is stored, this may be compressed, a cubemap, etc. |
| 100 // The header will describe the format of this data. | 115 // The header will describe the format of this data. |
| 101 class PixelData { | 116 class PixelData { |
| 102 public: | 117 public: |
| 103 PixelData(const uint8_t *ptr, size_t sz) : fDataSz(sz), fDataPtr(ptr) { } | 118 PixelData(const uint8_t *ptr, size_t sz) : fDataSz(sz), fDataPtr(ptr) { } |
| 104 const uint8_t *data() const { return fDataPtr; } | 119 const uint8_t *data() const { return fDataPtr; } |
| 105 size_t dataSize() const { return fDataSz; } | 120 size_t dataSize() const { return fDataSz; } |
| 106 private: | 121 private: |
| 107 const size_t fDataSz; | 122 const size_t fDataSz; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 120 // If the endianness of the platform is different than the file, | 135 // If the endianness of the platform is different than the file, |
| 121 // then we need to do proper byte swapping. | 136 // then we need to do proper byte swapping. |
| 122 bool fSwapBytes; | 137 bool fSwapBytes; |
| 123 | 138 |
| 124 // Read an integer from a buffer, advance the buffer, and swap | 139 // Read an integer from a buffer, advance the buffer, and swap |
| 125 // bytes if fSwapBytes is set | 140 // bytes if fSwapBytes is set |
| 126 uint32_t readInt(const uint8_t** buf, size_t* bytesLeft) const; | 141 uint32_t readInt(const uint8_t** buf, size_t* bytesLeft) const; |
| 127 }; | 142 }; |
| 128 | 143 |
| 129 #endif // SkKTXFile_DEFINED | 144 #endif // SkKTXFile_DEFINED |
| OLD | NEW |