git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1186 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
55
OpenRa.Game/HardwarePalette.cs
Normal file
55
OpenRa.Game/HardwarePalette.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BluntDirectX.Direct3D;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using OpenRa.FileFormats;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
class HardwarePalette
|
||||
{
|
||||
const int maxEntries = 16; // dont need anything like this many,
|
||||
// but the hardware likes square textures better
|
||||
|
||||
Bitmap bitmap = new Bitmap(256, maxEntries);
|
||||
GraphicsDevice device;
|
||||
int allocated = 0;
|
||||
|
||||
Texture paletteTexture;
|
||||
|
||||
public HardwarePalette(GraphicsDevice device)
|
||||
{
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
public void Resolve()
|
||||
{
|
||||
const string filename = "../../../palette-cache.png";
|
||||
bitmap.Save(filename);
|
||||
|
||||
using (Stream s = File.OpenRead(filename))
|
||||
paletteTexture = Texture.Create(s, device);
|
||||
}
|
||||
|
||||
public Texture PaletteTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (paletteTexture == null)
|
||||
Resolve();
|
||||
|
||||
return paletteTexture;
|
||||
}
|
||||
}
|
||||
|
||||
public int AddPalette(Palette p)
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
bitmap.SetPixel(i, allocated, p.GetColor(i));
|
||||
|
||||
return allocated++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user