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
/
PixelDataExporter.cs
executable file
·68 lines (57 loc) · 1.99 KB
/
PixelDataExporter.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
//
// 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.Runner;
namespace PixelVision8.Editor
{
public class PixelDataExporter : ImageExporter
{
protected Color maskColor = new Color(255, 0, 255);
protected Color[] paletteColors;
protected int[] pixelData;
public PixelDataExporter(string fileName, int[] pixelData, int width, int height, Color[] paletteColors,
IImageExporter imageExporter, string maskHex) : base(fileName, imageExporter, null, width, height)
{
this.paletteColors = paletteColors;
this.pixelData = pixelData;
maskColor = DisplayTarget.HexToColor(maskHex);
}
public override void CalculateSteps()
{
CurrentStep = 0;
Steps.Add(CopyPixels);
Steps.Add(WriteBytes);
}
protected virtual void CopyPixels()
{
var total = width * height;
colors = new Color[total];
for (var i = 0; i < total; i++)
{
var refID = pixelData[i];
if (refID > -1 && refID < total)
colors[i] = paletteColors[refID];
else
colors[i] = maskColor;
}
CurrentStep++;
}
}
}