From a9ac10838221f0ccbc9c5afe863b08f8d1de43c2 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 15 Feb 2016 16:49:58 +0100 Subject: [PATCH] Fully read NiPixelData --- components/nif/data.cpp | 18 +++++++++++------- components/nif/data.hpp | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 08c268dde..751b15097 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -154,7 +154,7 @@ void NiFloatData::read(NIFStream *nif) void NiPixelData::read(NIFStream *nif) { - nif->getInt(); // always 0 or 1 + fmt = (Format)nif->getUInt(); rmask = nif->getInt(); // usually 0xff gmask = nif->getInt(); // usually 0xff00 @@ -169,19 +169,23 @@ void NiPixelData::read(NIFStream *nif) mips = nif->getInt(); // Bytes per pixel, should be bpp * 8 - /*int bytes =*/ nif->getInt(); + /* int bytes = */ nif->getInt(); for(int i=0; igetInt(); - /*int y =*/ nif->getInt(); - /*int offset =*/ nif->getInt(); + Mipmap m; + m.width = nif->getInt(); + m.height = nif->getInt(); + m.dataOffset = nif->getInt(); + mipmaps.push_back(m); } - // Skip the data + // Read the data unsigned int dataSize = nif->getInt(); - nif->skip(dataSize); + data.reserve(dataSize); + for (unsigned i=0; igetChar()); } void NiColorData::read(NIFStream *nif) diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 95f244129..89886b66f 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -105,9 +105,30 @@ public: class NiPixelData : public Record { public: + enum Format + { + NIPXFMT_RGB8, + NIPXFMT_RGBA8, + NIPXFMT_PAL8, + NIPXFMT_DXT1, + NIPXFMT_DXT3, + NIPXFMT_DXT5, + NIPXFMT_DXT5_ALT + }; + Format fmt; + unsigned int rmask, gmask, bmask, amask; int bpp, mips; + struct Mipmap + { + int width, height; + int dataOffset; + }; + std::vector mipmaps; + + std::vector data; + void read(NIFStream *nif); };