xref: /haiku/src/add-ons/translators/gif/LoadPalette.cpp (revision 3e216965baa8d58a67bf7372e2bfa13d999f5a9d)
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 #include "LoadPalette.h"
17 #include <GraphicsDefs.h>
18 #include <ByteOrder.h>
19 
20 LoadPalette::LoadPalette() {
21 	backgroundindex = 0;
22 	usetransparent = false;
23 	transparentindex = 0;
24 	size = size_in_bits = 0;
25 }
26 
27 // Never index into pal directly - this function is safe
28 uint32 LoadPalette::ColorForIndex(int index) {
29 	if (index >= 0 && index <= size) {
30 		if (usetransparent && index == transparentindex) return B_TRANSPARENT_MAGIC_RGBA32;
31 		else return data[index];
32 	} else {
33 		return B_BENDIAN_TO_HOST_INT32(0x000000ff);
34 	}
35 }
36 
37 void LoadPalette::SetColor(int index, uint8 red, uint8 green, uint8 blue) {
38 	if (index < 0 || index > 255) return;
39 	data[index] = (blue << 24) + (green << 16) + (red << 8) + 0xff;
40 	data[index] = B_BENDIAN_TO_HOST_INT32(data[index]);
41 }
42 
43