-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpriteDisplayer.cs
More file actions
188 lines (159 loc) · 6 KB
/
SpriteDisplayer.cs
File metadata and controls
188 lines (159 loc) · 6 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using RetroDevStudio;
using System;
using System.Collections.Generic;
using System.Text;
namespace RetroDevStudio.Displayer
{
public class SpriteDisplayer
{
public static void DisplayHiResSprite( GR.Memory.ByteBuffer Data, Palette Palette, int Width, int Height, int BGColor, int SpriteColor, GR.Image.IImage TargetImage, int X, int Y )
{
DisplayHiResSprite( Data, Palette, Width, Height, BGColor, SpriteColor, TargetImage, X, Y, false, false );
}
public static void DisplayHiResSprite( GR.Memory.ByteBuffer Data, Palette Palette, int Width, int Height, int BGColor, int SpriteColor, GR.Image.IImage Target, int X, int Y, bool ExpandX, bool ExpandY )
{
int pixelStepX = 1;
int pixelStepY = 1;
if ( ExpandX )
{
pixelStepX = 2;
}
if ( ExpandY )
{
pixelStepY = 2;
}
// single color
for ( int j = 0; j < Height; ++j )
{
for ( int pp = 0; pp < pixelStepY; ++pp )
{
for ( int k = 0; k < Width / 8; ++k )
{
for ( int i = 0; i < 8; ++i )
{
if ( ( Data.ByteAt( j * 3 + k ) & ( 1 << ( 7 - i ) ) ) != 0 )
{
//Data.Image.SetPixel( k * 8 + i, j, m_ColorValues[Data.Color] );
uint color = Palette.ColorValues[SpriteColor];
Target.SetPixel( X + ( k * 8 + i ) * pixelStepX, Y + j * pixelStepY + pp, color );
if ( pixelStepX == 2 )
{
Target.SetPixel( X + ( k * 8 + i ) * pixelStepX + 1, Y + j * pixelStepY + pp, color );
}
}
else
{
uint color = Palette.ColorValues[BGColor];
Target.SetPixel( X + ( k * 8 + i ) * pixelStepX, Y + j * pixelStepY + pp, color );
if ( pixelStepX == 2 )
{
Target.SetPixel( X + ( k * 8 + i ) * pixelStepX + 1, Y + j * pixelStepY + pp, color );
}
}
}
}
}
}
}
public static void DisplayMultiColorSprite( GR.Memory.ByteBuffer Data, Palette Palette, int Width, int Height, int BGColor, int MColor1, int MColor2, int SpriteColor, GR.Image.IImage TargetImage, int X, int Y )
{
DisplayMultiColorSprite( Data, Palette, Width, Height, BGColor, MColor1, MColor2, SpriteColor, TargetImage, X, Y, false, false );
}
public static void DisplayMultiColorSprite( GR.Memory.ByteBuffer Data, Palette Palette, int Width, int Height, int BGColor, int MColor1, int MColor2, int SpriteColor, GR.Image.IImage Target, int X, int Y, bool ExpandX, bool ExpandY )
{
int pixelStepX = 1;
int pixelStepY = 1;
if ( ExpandX )
{
pixelStepX = 2;
}
if ( ExpandY )
{
pixelStepY = 2;
}
// multicolor
for ( int j = 0; j < Height; ++j )
{
for ( int pp = 0; pp < pixelStepY; ++pp )
{
for ( int k = 0; k < Width / 8; ++k )
{
for ( int i = 0; i < 4; ++i )
{
int pixelValue = ( Data.ByteAt( j * 3 + k ) & ( 3 << ( ( 3 - i ) * 2 ) ) ) >> ( ( 3 - i ) * 2 );
switch ( pixelValue )
{
case 0:
pixelValue = BGColor;
break;
case 1:
pixelValue = MColor1;
break;
case 3:
pixelValue = MColor2;
break;
case 2:
pixelValue = SpriteColor;
break;
}
uint color = Palette.ColorValues[pixelValue];
Target.SetPixel( X + k * 8 * pixelStepX + i * 2 * pixelStepX, Y + j * pixelStepY + pp, color );
Target.SetPixel( X + k * 8 * pixelStepX + i * 2 * pixelStepX + 1, Y + j * pixelStepY + pp, color );
if ( pixelStepX == 2 )
{
Target.SetPixel( X + k * 8 * pixelStepX + i * 2 * pixelStepX + 2, Y + j * pixelStepY + pp, color );
Target.SetPixel( X + k * 8 * pixelStepX + i * 2 * pixelStepX + 3, Y + j * pixelStepY + pp, color );
}
}
}
}
}
}
public static void DisplayFCMSprite( GR.Memory.ByteBuffer Data, Palette Palette, int Width, int Height, int BGColor, GR.Image.IImage Target, int X, int Y, bool ExpandX, bool ExpandY )
{
int pixelStepX = 1;
int pixelStepY = 1;
if ( ExpandX )
{
pixelStepX = 2;
}
if ( ExpandY )
{
pixelStepY = 2;
}
int lineBytes = ( Width + 1 ) / 2;
for ( int j = 0; j < Height; ++j )
{
for ( int pp = 0; pp < pixelStepY; ++pp )
{
for ( int i = 0; i < Width; i += 2 )
{
byte pixelDuo = Data.ByteAt( j * lineBytes + i / 2 );
byte colorToUse = (byte)BGColor;
if ( ( pixelDuo >> 4 ) != 0 )
{
colorToUse = (byte)( pixelDuo >> 4 );
}
uint color = Palette.ColorValues[colorToUse];
Target.SetPixel( ( X + i ) * pixelStepX, Y + j * pixelStepY + pp, color );
if ( pixelStepX == 2 )
{
Target.SetPixel( ( X + i ) * pixelStepX + 1, Y + j * pixelStepY + pp, color );
}
colorToUse = (byte)BGColor;
if ( ( pixelDuo & 0x0f ) != 0 )
{
colorToUse = (byte)( pixelDuo & 0x0f );
}
color = Palette.ColorValues[colorToUse];
Target.SetPixel( ( X + i + 1 ) * pixelStepX, Y + j * pixelStepY + pp, color );
if ( pixelStepX == 2 )
{
Target.SetPixel( ( X + i + 1 ) * pixelStepX + 1, Y + j * pixelStepY + pp, color );
}
}
}
}
}
}
}