Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Palette.h
1 //
2 // Created by Lectem on 06/11/2016.
3 //
4 
5 #pragma once
6 
7 #include <cstdint>
8 #include <Stream.h>
9 #include <array>
10 
11 namespace WorldStone
12 {
21 struct Palette
22 {
23  struct Color
24  {
25  uint8_t r, g, b, _padding;
26  bool operator==(const Color& rhs) const { return r == rhs.r && g == rhs.g && b == rhs.b; }
27  };
28 
29  struct Color24Bits
30  {
31  uint8_t r, g, b;
32  bool operator==(const Color24Bits& rhs) const
33  {
34  return r == rhs.r && g == rhs.g && b == rhs.b;
35  }
36  };
37  static const size_t colorCount = 256;
38  std::array<Color, colorCount> colors;
39 
40  bool decode(const char* filename);
41  bool decode(IStream* file);
42  uint8_t GetClosestColorIndex(Color color);
43  bool operator==(const Palette& rhs) const { return colors == rhs.colors; }
44 };
45 
47 {
48  std::array<uint8_t, Palette::colorCount> indices;
49 
50  Palette::Color GetTranformedColor(const Palette& palette, uint8_t colorIndex) const
51  {
52  return palette.colors[indices[colorIndex]];
53  }
54 
55  void GetTranformedPalette(Palette& outputPalette, const Palette& basePalette) const
56  {
57  for (size_t i = 0; i < Palette::colorCount; i++)
58  {
59  outputPalette.colors[i] = basePalette.colors[indices[i]];
60  }
61  }
62 };
63 
67 struct PL2
68 {
69  Palette basePalette;
70 
71  PalShiftTransform lightLevelVariations[32];
72  PalShiftTransform invColorVariations[16];
74 
78 
79  // The following 128 palette shifts are the ones specified in states.txt
80  PalShiftTransform hueVariations[111];
81  PalShiftTransform redTones;
82  PalShiftTransform greenTones;
83  PalShiftTransform blueTones;
84  PalShiftTransform unknownColorVariations[14];
85 
86  PalShiftTransform maxComponentBlend[256];
87  PalShiftTransform darkenedColorShift;
88 
89  Palette::Color24Bits textColors[13];
90  PalShiftTransform textColorShifts[13];
91 
92  static std::unique_ptr<PL2> CreateFromPalette(const Palette& palette);
93  static std::unique_ptr<PL2> ReadFromStream(IStream* stream);
94 };
95 
96 } // namespace WorldStone
An interface for a stream of data.
Definition: Stream.h:22
PalShiftTransform additiveBlend[256]
glBlendFunc(GL_ONE, GL_ONE)
Definition: Palette.h:76
PalShiftTransform alphaBlend[3][256]
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
Definition: Palette.h:75
PalShiftTransform multiplicativeBlend[256]
glBlendFunc(GL_ZERO, GL_SRC_COLOR)
Definition: Palette.h:77
Precomputed palette variations in the form of palette shifts.
Definition: Palette.h:67
PalShiftTransform selectedUnitShift
Needs confirmation for usage.
Definition: Palette.h:73
Helper to load a Diablo 2 palette (.pal/.dat format)
Definition: Palette.h:21