Skip to content

Commit 6877d26

Browse files
fixed write animation flag & misleading layer[y,x] --> layer[x,y]
1 parent 0d3be6b commit 6877d26

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

PPMLib/PPMFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ public static PPMFile Create(PPMAuthor author, List<PPMFrame> frames, byte[] aud
202202
uint animDataSize = (uint)(8 + 4 * frames.Count);
203203

204204
file.AnimationFlags = 0x43;
205-
file.FrameOffsetTableSize = (ushort)(4 * frames.Count);
206-
file.AnimationFlags = BitConverter.ToUInt16(BitConverter.GetBytes(0x00430000), 0);
205+
file.FrameOffsetTableSize = (ushort)(4 * frames.Count);
207206

208207
file.Frames = new PPMFrame[frames.Count];
209208
//SoundEffectFlags = new byte[frames.Count];
@@ -263,6 +262,7 @@ public void Save(string fn)
263262

264263
w.Write(FrameOffsetTableSize);
265264
w.Write((uint)0); // 0x06A2
265+
System.Diagnostics.Debug.WriteLine(AnimationFlags);
266266
w.Write(AnimationFlags);
267267

268268
// Calculate frame offsets & write frame data

PPMLib/PPMFrame.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public byte[] ToByteArray()
3333
return res.ToArray();
3434
}
3535

36-
private void L1PutLine(List<byte> lst, int ln)
36+
private void L1PutLine(List<byte> lst, int y)
3737
{
38-
int compr = (int)Layer1.LinesEncoding(ln);
38+
int compr = (int)Layer1.LinesEncoding(y);
3939
if (compr == 0) return;
4040
if (compr == 1)
4141
{
@@ -45,7 +45,7 @@ private void L1PutLine(List<byte> lst, int ln)
4545
{
4646
byte chunk = 0;
4747
for (int j = 0; j < 8; j++)
48-
if (Layer1[ln, 8 * i + j])
48+
if (Layer1[8 * i + j, y])
4949
chunk |= (byte)(1 << j);
5050
if (chunk != 0x00)
5151
{
@@ -68,7 +68,7 @@ private void L1PutLine(List<byte> lst, int ln)
6868
{
6969
byte chunk = 0;
7070
for (int j = 0; j < 8; j++)
71-
if (Layer1[ln, 8 * i + j])
71+
if (Layer1[8 * i + j, y])
7272
chunk |= (byte)(1 << j);
7373
if (chunk != 0xFF)
7474
{
@@ -90,7 +90,7 @@ private void L1PutLine(List<byte> lst, int ln)
9090
byte chunk = 0;
9191
for (int j = 0; j < 8; j++)
9292
{
93-
if (Layer1[ln, 8 * i + j])
93+
if (Layer1[8 * i + j, y])
9494
chunk |= (byte)(1 << j);
9595
}
9696
lst.Add(chunk);
@@ -99,9 +99,9 @@ private void L1PutLine(List<byte> lst, int ln)
9999
}
100100
}
101101

102-
private void L2PutLine(List<byte> lst, int ln)
102+
private void L2PutLine(List<byte> lst, int y)
103103
{
104-
int compr = (int)Layer2.LinesEncoding(ln);
104+
int compr = (int)Layer2.LinesEncoding(y);
105105
if (compr == 0) return;
106106
if (compr == 1)
107107
{
@@ -111,7 +111,7 @@ private void L2PutLine(List<byte> lst, int ln)
111111
{
112112
byte chunk = 0;
113113
for (int j = 0; j < 8; j++)
114-
if (Layer2[ln, 8 * i + j])
114+
if (Layer2[8 * i + j, y])
115115
chunk |= (byte)(1 << j);
116116
if (chunk != 0x00)
117117
{
@@ -134,7 +134,7 @@ private void L2PutLine(List<byte> lst, int ln)
134134
{
135135
byte chunk = 0;
136136
for (int j = 0; j < 8; j++)
137-
if (Layer2[ln, 8 * i + j])
137+
if (Layer2[8 * i + j, y])
138138
chunk |= (byte)(1 << j);
139139
if (chunk != 0xFF)
140140
{
@@ -156,7 +156,7 @@ private void L2PutLine(List<byte> lst, int ln)
156156
byte chunk = 0;
157157
for (int j = 0; j < 8; j++)
158158
{
159-
if (Layer2[ln, 8 * i + j])
159+
if (Layer2[8 * i + j, y])
160160
chunk |= (byte)(1 << j);
161161
}
162162
lst.Add(chunk);

PPMLib/PPMLayer.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ public void setLinesEncoding(int lineIndex, LineEncoding value)
2929
/// <summary>
3030
/// Set the line encoding for the whole layer
3131
/// </summary>
32-
/// <param name="index">Line Index</param>
32+
/// <param name="y">Line Index</param>
3333
/// <returns>New encoding type for the line</returns>
34-
public LineEncoding SetLineEncodingForWholeLayer(int index) // Set?
34+
public LineEncoding SetLineEncodingForWholeLayer(int y) // Set?
3535
{
3636
var _0chks = 0;
3737
var _1chks = 0;
3838
for (var x = 0; x <= 32; x++)
3939
{
40-
var c = 8 * index;
40+
var c = 8 * y;
4141
var n0 = 0;
4242
var n1 = 0;
4343
for (var x_ = 0; x_ <= 8; x_++)
4444
{
45-
if (this[index, c + x_])
45+
if (this[c + x_, y])
4646
{
4747
n1 += 1;
4848
}
@@ -72,11 +72,11 @@ public LineEncoding SetLineEncodingForWholeLayer(int index) // Set?
7272
/// Insert a line in current layer
7373
/// </summary>
7474
/// <param name="lineData">Line Data</param>
75-
/// <param name="index">Index Of Line</param>
76-
private void InsertLineInLayer(List<byte> lineData, int index)
75+
/// <param name="y">Index Of Line</param>
76+
private void InsertLineInLayer(List<byte> lineData, int y)
7777
{
7878
List<byte> chks = new List<byte>();
79-
switch (LinesEncoding(index))
79+
switch (LinesEncoding(y))
8080
{
8181
case 0:
8282
{
@@ -91,12 +91,12 @@ private void InsertLineInLayer(List<byte> lineData, int index)
9191
byte chunk = 0;
9292
for (var x_ = 0; x_ <= 8; x_++)
9393
{
94-
if (this[index, 8 * x + x_])
94+
if (this[8 * x + x_, y])
9595
{
9696
chunk = (byte)(chunk | (byte)(1 << x_));
9797
}
9898
}
99-
if (chunk != ((LinesEncoding(index) == (PPMLib.LineEncoding)1) ? 0x0 : 0xFF))
99+
if (chunk != ((LinesEncoding(y) == (PPMLib.LineEncoding)1) ? 0x0 : 0xFF))
100100
{
101101
flag |= (1U << (31 - x));
102102
chks.Add(chunk);
@@ -116,7 +116,7 @@ private void InsertLineInLayer(List<byte> lineData, int index)
116116
byte chunk = 0;
117117
for (var x_ = 0; x_ <= 8; x_++)
118118
{
119-
if (this[index, 8 * x + x_])
119+
if (this[8 * x + x_, y])
120120
{
121121
chunk = (byte)(chunk | (byte)(1 << x_));
122122
}
@@ -150,7 +150,7 @@ public byte this[int p]
150150
set => _layerData[p] = value;
151151
}
152152

153-
public bool this[int y, int x]
153+
public bool this[int x, int y]
154154
{
155155
get
156156
{

PPMLib/WPF/PPMRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static WriteableBitmap GetFrameBitmap(PPMFrame frame)
9797
{
9898
for (int y = 0; y < 192; y++)
9999
{
100-
if (frame.Layer1[y, x])
100+
if (frame.Layer1[x, y])
101101
{
102102
int b = 256 * y + x;
103103
int p = 3 - b % 4;
@@ -111,7 +111,7 @@ public static WriteableBitmap GetFrameBitmap(PPMFrame frame)
111111
{
112112
for (int y = 0; y < 192; y++)
113113
{
114-
if (frame.Layer2[y, x])
114+
if (frame.Layer2[x, y])
115115
{
116116
int b = 256 * y + x;
117117
int p = 3 - b % 4;

PPMLib/Winforms/PPMRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static Bitmap GetFrameBitmap(PPMFrame frame)
9494
{
9595
for (var x = 0; x <= 255; x++)
9696
{
97-
if (frame.Layer1[y, x])
97+
if (frame.Layer1[x, y])
9898
{
9999
if (frame.Layer1.PenColor != PenColor.Inverted)
100100
{
@@ -107,7 +107,7 @@ public static Bitmap GetFrameBitmap(PPMFrame frame)
107107
}
108108
else
109109
{
110-
if (frame.Layer2[y, x])
110+
if (frame.Layer2[x, y])
111111
{
112112
if (frame.Layer2.PenColor != PenColor.Inverted)
113113
{

0 commit comments

Comments
 (0)