+/*
+Mimic the behaviour of wxPalette.GetRGB and the way the TGA image handler
+used it. That is: don't check the return value of GetRGB and continue decoding
+using previous RGB values.
+
+It might be better to check for palette index bounds and stop decoding if
+it's out of range (and add something like wxTGA_DATAERR to indicate unexpected
+pixel data).
+*/
+static
+void Palette_GetRGB(const unsigned char *palette, unsigned int paletteCount,
+ unsigned int index,
+ unsigned char *red, unsigned char *green, unsigned char *blue)
+{
+ if (index >= paletteCount)
+ {
+ return;
+ }
+
+ *red = palette[index];
+ *green = palette[(paletteCount * 1) + index];
+ *blue = palette[(paletteCount * 2) + index];
+}
+
+static
+void Palette_SetRGB(unsigned char *palette, unsigned int paletteCount,
+ unsigned int index,
+ unsigned char red, unsigned char green, unsigned char blue)
+{
+ palette[index] = red;
+ palette[(paletteCount * 1) + index] = green;
+ palette[(paletteCount * 2) + index] = blue;
+}
+