From 7fff12c9acd3d179507fe063febbac5c1744abb0 Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Mon, 6 Mar 2023 15:06:01 +0100 Subject: [PATCH] Convert loaded images to 256 color palette --- Capy64/Runtime/Libraries/GPU.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Capy64/Runtime/Libraries/GPU.cs b/Capy64/Runtime/Libraries/GPU.cs index 4c8fee1..3068555 100644 --- a/Capy64/Runtime/Libraries/GPU.cs +++ b/Capy64/Runtime/Libraries/GPU.cs @@ -19,6 +19,7 @@ using Capy64.Runtime.Objects; using KeraLua; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using System.IO; @@ -497,6 +498,29 @@ public class GPU : IComponent var data = new uint[texture.Width * texture.Height]; texture.GetData(data); + if (_game.EngineMode == EngineMode.Classic) + { + for (int i = 0; i < data.Length; i++) + { + var value = data[i]; + + // ABGR to RGB + value = + ((value & 0x00_00_00_FFU) << 16) | // move R + (value & 0x00_00_FF_00U) | // move G + ((value & 0x00_FF_00_00U) >> 16); // move B + + value = ColorPalette.GetColor(value); + + // RGB to ABGR + value = + ((value & 0x00_FF_00_00U) >> 16) | // move R + (value & 0x00_00_FF_00U) | // move G + ((value & 0x00_00_00_FFU) << 16) | // move B + 0xFF_00_00_00U; + } + } + ObjectManager.PushObject(L, data); L.SetMetaTable(GPUBuffer.ObjectType); L.PushInteger(texture.Width);