From 54399af15ccea864b43b7004edf1002a3996dcb2 Mon Sep 17 00:00:00 2001
From: Shon Ferguson <shonferg@users.sourceforge.net>
Date: Thu, 8 Jun 2006 00:39:53 +0000
Subject: [PATCH] Copied over NiPalette functions without change.

---
 obj/NiPalette.cpp | 26 ++++++++++++++++++++++++++
 obj/NiPalette.h   | 12 ++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/obj/NiPalette.cpp b/obj/NiPalette.cpp
index 1c36095d..8f03f5ae 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 ecd59668..7a907bc0 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
 };
-- 
GitLab