1////////////////////////////////////////////////////////////////////////////////
2//
3//	File: LoadPalette.cpp
4//
5//	Date: December 1999
6//
7//	Author: Daniel Switkin
8//
9//	Copyright 2003 (c) by Daniel Switkin. This file is made publically available
10//	under the BSD license, with the stipulations that this complete header must
11//	remain at the top of the file indefinitely, and credit must be given to the
12//	original author in any about box using this software.
13//
14////////////////////////////////////////////////////////////////////////////////
15
16// Additional authors:	John Scipione, <jscipione@gmail.com>
17
18
19#include "LoadPalette.h"
20
21#include <GraphicsDefs.h>
22#include <ByteOrder.h>
23
24
25LoadPalette::LoadPalette() {
26	backgroundindex = 0;
27	usetransparent = false;
28	transparentindex = 0;
29	size = size_in_bits = 0;
30}
31
32
33uint32
34LoadPalette::ColorForIndex(int index)
35{
36	// never index into pal directly - this function is safe
37	if (index >= 0 && index <= size) {
38		if (usetransparent && index == transparentindex)
39			return B_TRANSPARENT_MAGIC_RGBA32;
40		else
41			return data[index];
42	} else
43		return B_BENDIAN_TO_HOST_INT32(0x000000ff);
44}
45
46
47void
48LoadPalette::SetColor(int index, uint8 red, uint8 green, uint8 blue)
49{
50	if (index < 0 || index > 255)
51		return;
52
53	data[index] = (blue << 24) + (green << 16) + (red << 8) + 0xff;
54	data[index] = B_BENDIAN_TO_HOST_INT32(data[index]);
55}
56