I think I got the palettes read
This commit is contained in:
+8
-11
@@ -32,26 +32,23 @@ namespace fxl.codes.kisekae.Models
|
|||||||
|
|
||||||
public string FileName { get; }
|
public string FileName { get; }
|
||||||
public string Comment { get; }
|
public string Comment { get; }
|
||||||
|
public Color[] Colors { get; set; }
|
||||||
public Color[] Colors { get; private set; }
|
|
||||||
|
|
||||||
public void ParseColors(byte[] bytes, int depth)
|
|
||||||
{
|
|
||||||
Colors = new Color[0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Color
|
public class Color
|
||||||
{
|
{
|
||||||
public Color(int red, int green, int blue)
|
public Color(int red, int green, int blue, int group, int depth)
|
||||||
{
|
{
|
||||||
Red = red;
|
var multiplier = depth == 12 ? 16 : 1;
|
||||||
Green = green;
|
Red = red * multiplier;
|
||||||
Blue = blue;
|
Green = green * multiplier;
|
||||||
|
Blue = blue * multiplier;
|
||||||
|
Group = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Red { get; }
|
public int Red { get; }
|
||||||
public int Green { get; }
|
public int Green { get; }
|
||||||
public int Blue { get; }
|
public int Blue { get; }
|
||||||
|
public int Group { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,9 @@ export default class Main {
|
|||||||
init() {
|
init() {
|
||||||
let main = document.querySelector("main")
|
let main = document.querySelector("main")
|
||||||
let directories = main.querySelector("ul")
|
let directories = main.querySelector("ul")
|
||||||
|
|
||||||
|
if (!directories) return
|
||||||
|
|
||||||
let links = directories.querySelectorAll("a")
|
let links = directories.querySelectorAll("a")
|
||||||
|
|
||||||
links.forEach(link => {
|
links.forEach(link => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.IsolatedStorage;
|
using System.IO.IsolatedStorage;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -31,8 +32,51 @@ namespace fxl.codes.kisekae.Services
|
|||||||
var header = Encoding.ASCII.GetBytes("KiSS");
|
var header = Encoding.ASCII.GetBytes("KiSS");
|
||||||
if (buffer[..header.Length].SequenceEqual(header))
|
if (buffer[..header.Length].SequenceEqual(header))
|
||||||
{
|
{
|
||||||
// Matching header I guess?
|
// Verify palette mark?
|
||||||
|
if (buffer[4] != 16) throw new InvalidDataException("File provided is not a valid palette file");
|
||||||
|
var colorDepth = Convert.ToInt32(buffer[5]);
|
||||||
|
var colorsPerGroup = BitConverter.ToInt16(buffer, 8);
|
||||||
|
var groups = BitConverter.ToInt16(buffer, 10);
|
||||||
|
|
||||||
|
palette.Colors = GetColors(new BitArray(buffer[32..]), colorDepth, colorsPerGroup, groups);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
palette.Colors = GetColors(new BitArray(buffer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color[] GetColors(BitArray bitArray, int depth = 12, int colorsPerGroup = 16, int groups = 10)
|
||||||
|
{
|
||||||
|
_logger.LogTrace($"Converting bit array to colors");
|
||||||
|
var colorCounter = 0;
|
||||||
|
var colors = new Color[colorsPerGroup * groups];
|
||||||
|
var data = new bool[bitArray.Length];
|
||||||
|
bitArray.CopyTo(data, 0);
|
||||||
|
|
||||||
|
var length = depth / 3;
|
||||||
|
for (var index = 0; index < colorsPerGroup * groups; index += depth)
|
||||||
|
{
|
||||||
|
var greenStart = index + length;
|
||||||
|
var blueStart = index + length * 2;
|
||||||
|
|
||||||
|
var red = GetValue(data[index..greenStart]);
|
||||||
|
var green = GetValue(data[greenStart..blueStart]);
|
||||||
|
var blue = GetValue(data[blueStart..(index + depth)]);
|
||||||
|
colors[colorCounter] = new Color(red, green, blue, colorCounter / colorsPerGroup, depth);
|
||||||
|
colorCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int GetValue(bool[] data)
|
||||||
|
{
|
||||||
|
var bits = new BitArray(data);
|
||||||
|
var value = new int[1];
|
||||||
|
bits.CopyTo(value, 0);
|
||||||
|
|
||||||
|
return value[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user