/
WorkingImage.cs
83 lines (71 loc) · 2.55 KB
/
WorkingImage.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
namespace MZXImageResampler
{
public static class WorkingImage
{
public static EnhancedBitmap BaseImage;
public static Character[,] CharacterImage;
public static PaletteEntry[,] PaletteImage;
public static DitheringEngine Ditherer = DitheringEngine.Custom;
public static int CharacterX, CharacterY;
private static int PixelX, PixelY;
public static void Init(string fileName)
{
PixelX = CharacterX*8;
PixelY = CharacterY*14;
ImageImport.SourceFile = fileName;
ImageImport.X = PixelX;
ImageImport.Y = PixelY;
BaseImage = new EnhancedBitmap(ImageImport.GetByDitherer(Ditherer));
CharacterImage = PixelatedImage;
}
public static Bitmap UIImage
{
get
{
var pixels = CharacterImage;
Bitmap bmp = new Bitmap(pixels.GetLength(0) * 8 * Tuning.CharacterExpansion, pixels.GetLength(1) * 14 * Tuning.CharacterExpansion);
using (Graphics g = Graphics.FromImage(bmp))
{
for (int i = 0; i < pixels.GetLength(0); i++)
for (int j = 0; j < pixels.GetLength(1); j++)
g.DrawImage(pixels[i, j].Display, i*8*Tuning.CharacterExpansion, j*14*Tuning.CharacterExpansion);
}
return bmp;
}
}
public static Character[,] PixelatedImage
{
get
{
var thisImage = new Character[CharacterX, CharacterY];
BaseImage.LockImage();
for (int i = 0; i < CharacterX; i++)
for (int j = 0; j < CharacterY; j++)
{
thisImage[i, j] = SliceAt(i, j);
}
BaseImage.UnlockImage();
return thisImage;
}
}
static Character SliceAt(int x, int y)
{
var thisChar = new Character();
for (int i = 0; i < 8; i++)
for (int j = 0; j < 14; j++)
{
var thisColor = BaseImage.GetPixel((x * 8) + i, (y * 14) + j);
if (thisColor.GetBrightness() < .5)
thisChar.Off(i, j);
else
thisChar.On(i, j);
}
return thisChar;
}
}
}