-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSerializerColorBinary.cs
More file actions
64 lines (53 loc) · 2.13 KB
/
Copy pathSerializerColorBinary.cs
File metadata and controls
64 lines (53 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColorBinary : IDMXSerializer
{
const int blockSize = 4; // 10x10 pixels per channel block
const int blocksPerCol = 52; // channels per column
public void Construct() { }
public void Deconstruct() { }
public void InitFrame(ref List<byte> channelValues) { }
public void CompleteFrame(ref Color32[] pixels, ref List<byte> channelValues, int textureWidth, int textureHeight) { }
public void SerializeChannel(ref Color32[] pixels, byte channelValue, int channel, int textureWidth, int textureHeight)
{
//split the value into 8 bits
var bits = new BitArray(new byte[] { channelValue });
List<bool> bitsList = new List<bool>();
for (int i = 0; i < bits.Length; i++)
{
bitsList.Add(bits[i]);
}
bitsList.Add(false); // Add a dummy bit to make it 9 bits, needed for easy interlacing
for (int i = 0; i < bitsList.Count; i += 3)
{
int newChannel = (channel * 3) + i / 3; //3 because we interlace with color
int x = (newChannel / blocksPerCol) * blockSize;
int y = (newChannel % blocksPerCol) * blockSize;
if (x >= textureWidth || y >= textureHeight)
{
continue; // Skip if the calculated pixel is out of bounds
}
//convert the x y to pixel index
//return 4x4 area
var color = new Color32(
(byte)(bitsList[i] ? 255 : 0),
(byte)(bitsList[i + 1] ? 255 : 0),
(byte)(bitsList[i + 2] ? 255 : 0),
Util.GetBlockAlpha(channelValue)
);
TextureWriter.MakeColorBlock(ref pixels, x, y, color, blockSize);
}
}
public void DeserializeChannel(Texture2D tex, ref byte channelValue, int channel, int textureWidth, int textureHeight) => throw new NotImplementedException();
public void ConstructUserInterface(RectTransform rect)
{
}
public void DeconstructUserInterface()
{
}
public void UpdateUserInterface()
{
}
}