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

Unified Diff: src/utils/SkKTXFile.h

Issue 302333002: Initial KTX file decoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address code review comments Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: src/utils/SkKTXFile.h
diff --git a/src/utils/SkKTXFile.h b/src/utils/SkKTXFile.h
new file mode 100644
index 0000000000000000000000000000000000000000..d841e02fc146888b3eb22fd22107252c3c6469fd
--- /dev/null
+++ b/src/utils/SkKTXFile.h
@@ -0,0 +1,104 @@
+
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#ifndef SkKTXFile_DEFINED
+#define SkKTXFile_DEFINED
+
+#include "SkTypes.h"
+#include "SkTDArray.h"
+#include "SkString.h"
+
+class SkStreamRewindable;
+
+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.
+public:
+ // The ownership of the data remains with the caller. This class is intended
+ // to be used as a logical wrapper around the data in order to properly
+ // access the pixels.
+ SkKTXFile(const uint8_t* data, size_t dataLen)
+ : fSwapBytes(false)
+ {
robertphillips 2014/06/03 13:27:41 this->readKTXFile ?
krajcevski 2014/06/03 14:46:27 Done.
+ fValid = readKTXFile(data, dataLen);
+ }
+
+ bool valid() const { return fValid; }
+
+ int width() const { return static_cast<int>(fHeader.fPixelWidth); }
+ int height() const { return static_cast<int>(fHeader.fPixelHeight); }
+
+ const uint8_t *pixelData(int mipmap = 0) const {
+ 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.
+ return valid()? fPixelData[mipmap].data() : NULL;
+ }
+
+ int numMipmaps() const { return static_cast<int>(fHeader.fNumberOfMipmapLevels); }
+
+ bool isETC1() const;
+ bool isRGBA8() const;
+ bool isRGB8() const;
+
+ static bool is_ktx(const uint8_t *data);
+ static bool is_ktx(SkStreamRewindable* stream);
+
+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.
+ struct Header {
+ uint32_t fGLType;
+ uint32_t fGLTypeSize;
+ uint32_t fGLFormat;
+ uint32_t fGLInternalFormat;
+ uint32_t fGLBaseInternalFormat;
+ uint32_t fPixelWidth;
+ uint32_t fPixelHeight;
+ uint32_t fPixelDepth;
+ uint32_t fNumberOfArrayElements;
+ uint32_t fNumberOfFaces;
+ uint32_t fNumberOfMipmapLevels;
+ uint32_t fBytesOfKeyValueData;
+
+ Header() { memset(this, 0, sizeof(*this)); }
+ void swapBytes();
+ } fHeader;
+
+ class KeyValue {
+ public:
+ KeyValue(size_t size) : fDataSz(size) { }
+ bool readKeyAndValue(const uint8_t *data);
+
+ private:
+ const size_t fDataSz;
+ SkString fKey;
+ SkString fValue;
+ };
+
+ class PixelData {
+ public:
+ PixelData(const uint8_t *ptr, size_t sz) : fDataSz(sz), fDataPtr(ptr) { }
+ const uint8_t *data() const { return fDataPtr; }
+ size_t dataSize() const { return fDataSz; }
+ private:
+ const size_t fDataSz;
+ const uint8_t *fDataPtr;
+ };
+
+ bool readKTXFile(const uint8_t *data, size_t dataLen);
+
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.
+ SkTDArray<KeyValue> fKeyValuePairs;
+ SkTDArray<PixelData> fPixelData;
+ bool fValid;
+
+ // If the endianness of the platform is different than the file,
+ // then we need to do proper byte swapping.
+ bool fSwapBytes;
+
+ // Read an integer from a buffer, advance the buffer, and swap
+ // bytes if fSwapBytes is set
robertphillips 2014/06/03 13:27:41 left justify the '&' ?
krajcevski 2014/06/03 14:46:27 Done.
+ uint32_t readInt(const uint8_t*& buf, size_t &bytesLeft) const;
+};
+
+#endif // SkKTXFile_DEFINED

Powered by Google App Engine
This is Rietveld 408576698