This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
ColorPaletteExporter.cs
executable file
·122 lines (97 loc) · 3.4 KB
/
ColorPaletteExporter.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// Copyright (c) Jesse Freeman, Pixel Vision 8. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) except for a few
// portions of the code. See LICENSE file in the project root for full
// license information. Third-party libraries used by Pixel Vision 8 are
// under their own licenses. Please refer to those libraries for details
// on the license they use.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christina-Antoinette Neofotistou @CastPixel
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
using Microsoft.Xna.Framework;
using PixelVision8.Player;
using System;
using System.Collections.Generic;
namespace PixelVision8.Runner.Exporters
{
public class ColorPaletteExporter : IAbstractExporter
{
protected Color[] colors;
protected PixelDataExporter exporter;
protected string fullFileName;
protected int height;
protected IImageExporter imageExporter;
protected int[] pixels;
protected int total;
protected int width;
public ColorPaletteExporter(string fileName, ColorChip colorChip, IImageExporter imageExporter)
{
fullFileName = fileName;
this.colorChip = colorChip;
this.imageExporter = imageExporter;
}
protected ColorChip colorChip { get; set; }
public int totalSteps => exporter.totalSteps;
public bool completed => exporter.completed;
public void CalculateSteps()
{
var currentDebugMode = colorChip.DebugMode;
// Force the color chip to not replace empty colors with background value
colorChip.DebugMode = true;
ConfigureColors();
// Restore the color chip debug value
colorChip.DebugMode = currentDebugMode;
BuildPixelData();
// Create Pixel Data Exporter
exporter = new PixelDataExporter(fullFileName, pixels, width, height, colors, imageExporter,
colorChip.MaskColor);
// calculate steps for exporter
exporter.CalculateSteps();
}
public void NextStep()
{
exporter.NextStep();
}
public void StepCompleted()
{
exporter.StepCompleted();
}
public void Dispose()
{
exporter.Dispose();
colorChip = null;
exporter = null;
}
public Dictionary<string, object> Response => exporter.Response;
public byte[] Bytes => exporter.Bytes;
public string fileName => exporter.fileName;
public virtual void ConfigureColors()
{
colors = Utilities.ConvertColors(colorChip.HexColors, colorChip.MaskColor, true);
//
// colorChip.colors;
total = colors.Length;
width = 8;
height = (int) Math.Ceiling(total / (float) width);
}
public virtual void BuildPixelData()
{
var totalPixels = width * height;
pixels = new int[totalPixels];
for (var i = 0; i < totalPixels; i++)
if (i < total)
pixels[i] = i;
else
pixels[i] = -1;
}
}
}