From 5377e0491b7c6137612ff3f3ca4c29d3ee199b30 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Wed, 13 May 2020 01:25:39 +0300 Subject: [PATCH] Adjust NiPixelData loading --- components/nif/data.cpp | 14 +++++--------- components/nif/data.hpp | 3 ++- components/nif/nifstream.hpp | 12 ++++++++++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index eb707e1bf..2c5568397 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -163,11 +163,8 @@ void NiPixelData::read(NIFStream *nif) { fmt = (Format)nif->getUInt(); - rmask = nif->getUInt(); // usually 0xff - gmask = nif->getUInt(); // usually 0xff00 - bmask = nif->getUInt(); // usually 0xff0000 - amask = nif->getUInt(); // usually 0xff000000 or zero - + for (unsigned int i = 0; i < 4; ++i) + colorMask[i] = nif->getUInt(); bpp = nif->getUInt(); // 8 bytes of "Old Fast Compare". Whatever that means. @@ -190,10 +187,9 @@ void NiPixelData::read(NIFStream *nif) } // Read the data - unsigned int dataSize = nif->getUInt(); - data.reserve(dataSize); - for (unsigned i=0; igetChar()); + unsigned int numPixels = nif->getUInt(); + if (numPixels) + nif->getUChars(data, numPixels); } void NiPixelData::post(NIFFile *nif) diff --git a/components/nif/data.hpp b/components/nif/data.hpp index a0d4960e0..39901b584 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -124,7 +124,8 @@ public: }; Format fmt; - unsigned int rmask, gmask, bmask, amask, bpp; + unsigned int colorMask[4]; + unsigned int bpp; NiPalettePtr palette; unsigned int numberOfMipmaps; diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index c78377448..97075c288 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -200,6 +200,18 @@ public: return result; } + void getChars(std::vector &vec, size_t size) + { + vec.resize(size); + readLittleEndianDynamicBufferOfType(inp, vec.data(), size); + } + + void getUChars(std::vector &vec, size_t size) + { + vec.resize(size); + readLittleEndianDynamicBufferOfType(inp, vec.data(), size); + } + void getUShorts(std::vector &vec, size_t size) { vec.resize(size);