diff --git a/obj/NiPalette.cpp b/obj/NiPalette.cpp index 1c36095d21bc999a62f5181957cfd95ac1f140a8..8f03f5ae78be31054f445c5e36212b0bd4150608 100644 --- a/obj/NiPalette.cpp +++ b/obj/NiPalette.cpp @@ -34,3 +34,29 @@ const Type & NiPalette::GetType() const { return TYPE; }; +vector<Color4> NiPalette::GetPalette() const { + vector<Color4> color_pal(256); + + for ( uint i = 0; i < 256; ++i ) { + + color_pal[i].r = float(palette[i][0]) / 255.0f; + color_pal[i].g = float(palette[i][1]) / 255.0f; + color_pal[i].b = float(palette[i][2]) / 255.0f; + color_pal[i].a = float(palette[i][3]) / 255.0f; + } + + return color_pal; +} + +void NiPalette::SetPalette( const vector<Color4> & new_pal ) { + if ( new_pal.size() != 256 ) { + throw runtime_error( "Palette size must be 256" ); + } + + for ( uint i = 0; i < 256; ++i ) { + palette[i][0] = int( new_pal[i].r * 255.0f ); + palette[i][1] = int( new_pal[i].g * 255.0f ); + palette[i][2] = int( new_pal[i].b * 255.0f ); + palette[i][3] = int( new_pal[i].a * 255.0f ); + } +} diff --git a/obj/NiPalette.h b/obj/NiPalette.h index ecd59668610b833e3cf8c763fbdb996315dccb68..7a907bc05d2ececc0995dd6fe82ad515ca9fc38d 100644 --- a/obj/NiPalette.h +++ b/obj/NiPalette.h @@ -27,6 +27,18 @@ public: virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version ); virtual list<NiObjectRef> GetRefs() const; virtual const Type & GetType() const; + + /*! Retrieves the palette data from this palette block. + * \return A vector containing the the colors stored in the palette. + * \sa NiPalette::SetPalette + */ + vector<Color4> GetPalette() const; + + /*! Sets the palette data for this palette block. + * \param new_apl A vector containing the the new colors to be stored in the palette. + * \sa NiPalette::GetPalette + */ + void SetPalette( const vector<Color4> & new_pal ); protected: NI_PALETTE_MEMBERS };