kopia lustrzana https://github.com/njcrawford/EmbroideryReader
Attempt to optimize design drawing code a little, capture more info about each stitch as it is read from the file, increment project versions in prep for a beta release
rodzic
39cdbbda3f
commit
ea38b44295
|
@ -180,6 +180,8 @@ namespace PesFile
|
||||||
int colorNum = -1;
|
int colorNum = -1;
|
||||||
int colorIndex = 0;
|
int colorIndex = 0;
|
||||||
List<Stitch> tempStitches = new List<Stitch>();
|
List<Stitch> tempStitches = new List<Stitch>();
|
||||||
|
Stitch prevStitch = null;
|
||||||
|
bool firstStitchOfBlock = true;
|
||||||
while (!thisPartIsDone)
|
while (!thisPartIsDone)
|
||||||
{
|
{
|
||||||
byte val1;
|
byte val1;
|
||||||
|
@ -215,13 +217,14 @@ namespace PesFile
|
||||||
curBlock.colorIndex = colorIndex;
|
curBlock.colorIndex = colorIndex;
|
||||||
curBlock.color = getColorFromIndex(colorIndex);
|
curBlock.color = getColorFromIndex(colorIndex);
|
||||||
//read useless(?) byte
|
//read useless(?) byte
|
||||||
// The value of this 'useless' byte seems to alternate
|
// The value of this 'useless' byte seems to start with 2 for the first block and
|
||||||
// between 2 and 1 for every other block. The only
|
// alternate between 2 and 1 for every other block after that. The only exception
|
||||||
// exception I've noted is the last block which appears
|
// I've noted is the last block which appears to always be 0.
|
||||||
// to always be 0.
|
|
||||||
curBlock.unknownStartByte = fileIn.ReadByte();
|
curBlock.unknownStartByte = fileIn.ReadByte();
|
||||||
blocks.Add(curBlock);
|
blocks.Add(curBlock);
|
||||||
|
|
||||||
|
firstStitchOfBlock = true;
|
||||||
|
|
||||||
tempStitches = new List<Stitch>();
|
tempStitches = new List<Stitch>();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -229,6 +232,8 @@ namespace PesFile
|
||||||
int deltaX = 0;
|
int deltaX = 0;
|
||||||
int deltaY = 0;
|
int deltaY = 0;
|
||||||
int extraBits1 = 0x00;
|
int extraBits1 = 0x00;
|
||||||
|
Stitch.MoveBitSize xMoveBits;
|
||||||
|
Stitch.MoveBitSize yMoveBits;
|
||||||
if ((val1 & 0x80) == 0x80)
|
if ((val1 & 0x80) == 0x80)
|
||||||
{
|
{
|
||||||
// Save the top 4 bits to output with debug info
|
// Save the top 4 bits to output with debug info
|
||||||
|
@ -241,6 +246,8 @@ namespace PesFile
|
||||||
// of up to +2047 or -2048.
|
// of up to +2047 or -2048.
|
||||||
deltaX = get12Bit2sComplement(val1, val2);
|
deltaX = get12Bit2sComplement(val1, val2);
|
||||||
|
|
||||||
|
xMoveBits = Stitch.MoveBitSize.TwelveBits;
|
||||||
|
|
||||||
// The X value used both bytes, so read next byte
|
// The X value used both bytes, so read next byte
|
||||||
// for Y value.
|
// for Y value.
|
||||||
val1 = fileIn.ReadByte();
|
val1 = fileIn.ReadByte();
|
||||||
|
@ -251,6 +258,8 @@ namespace PesFile
|
||||||
// of up to +63 or -64.
|
// of up to +63 or -64.
|
||||||
deltaX = get7Bit2sComplement(val1);
|
deltaX = get7Bit2sComplement(val1);
|
||||||
|
|
||||||
|
xMoveBits = Stitch.MoveBitSize.SevenBits;
|
||||||
|
|
||||||
// The X value only used 1 byte, so copy the second
|
// The X value only used 1 byte, so copy the second
|
||||||
// to to the first for Y value.
|
// to to the first for Y value.
|
||||||
val1 = val2;
|
val1 = val2;
|
||||||
|
@ -269,24 +278,71 @@ namespace PesFile
|
||||||
// Read in the next byte to get the full value
|
// Read in the next byte to get the full value
|
||||||
val2 = fileIn.ReadByte();
|
val2 = fileIn.ReadByte();
|
||||||
deltaY = get12Bit2sComplement(val1, val2);
|
deltaY = get12Bit2sComplement(val1, val2);
|
||||||
|
|
||||||
|
yMoveBits = Stitch.MoveBitSize.TwelveBits;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// This is a 7-bit int. Allows for needle movement
|
// This is a 7-bit int. Allows for needle movement
|
||||||
// of up to +63 or -64.
|
// of up to +63 or -64.
|
||||||
deltaY = get7Bit2sComplement(val1);
|
deltaY = get7Bit2sComplement(val1);
|
||||||
|
|
||||||
|
yMoveBits = Stitch.MoveBitSize.SevenBits;
|
||||||
// Finished reading data for this stitch, no more
|
// Finished reading data for this stitch, no more
|
||||||
// bytes needed.
|
// bytes needed.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Stitch.StitchType stitchType;
|
||||||
|
if (deltaX == 0 && deltaY == 0)
|
||||||
|
{
|
||||||
|
// A stitch with zero movement seems to indicate the current and next stitches are movement only.
|
||||||
|
// Almost always occurs at the end of a block.
|
||||||
|
stitchType = Stitch.StitchType.MovementBeginAnchor;
|
||||||
|
}
|
||||||
|
else if (extraBits1 == 0x20 && extraBits2 == 0x20)
|
||||||
|
{
|
||||||
|
// A stitch with extrabits 0x20 seems to indicate the current and next stitches are movement only.
|
||||||
|
// Almost always occurs within a block, not the beginning or end.
|
||||||
|
stitchType = Stitch.StitchType.MovementOnly;
|
||||||
|
}
|
||||||
|
else if (extraBits1 == 0x10 && extraBits2 == 0x10)
|
||||||
|
{
|
||||||
|
// A stitch with extrabits 0x10 seems to indicate the current stitch is movement only.
|
||||||
|
// Almost always occurs at the beginning of a block.
|
||||||
|
stitchType = Stitch.StitchType.MovementEndAnchor;
|
||||||
|
}
|
||||||
|
else if (prevStitch != null &&
|
||||||
|
(prevStitch.stitchType == Stitch.StitchType.MovementOnly ||
|
||||||
|
prevStitch.stitchType == Stitch.StitchType.MovementBeginAnchor))
|
||||||
|
{
|
||||||
|
stitchType = Stitch.StitchType.MovementEndAnchor;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (firstStitchOfBlock)
|
||||||
|
{
|
||||||
|
// First stitch of block is usually a movement to position the needle in the block
|
||||||
|
firstStitchOfBlock = false;
|
||||||
|
stitchType = Stitch.StitchType.MovementEndAnchor;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Assume everything else is a normal stitch
|
||||||
|
stitchType = Stitch.StitchType.NormalStitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add stitch to list
|
// Add stitch to list
|
||||||
tempStitches.Add(
|
prevStitch = new Stitch(
|
||||||
new Stitch(
|
|
||||||
new Point(prevX, prevY),
|
new Point(prevX, prevY),
|
||||||
new Point(prevX + deltaX, prevY + deltaY),
|
new Point(prevX + deltaX, prevY + deltaY),
|
||||||
extraBits1,
|
extraBits1,
|
||||||
extraBits2
|
extraBits2,
|
||||||
)
|
xMoveBits,
|
||||||
);
|
yMoveBits,
|
||||||
|
stitchType
|
||||||
|
);
|
||||||
|
tempStitches.Add(prevStitch);
|
||||||
|
|
||||||
// Calculate new "previous" position
|
// Calculate new "previous" position
|
||||||
prevX = prevX + deltaX;
|
prevX = prevX + deltaX;
|
||||||
|
@ -346,15 +402,18 @@ namespace PesFile
|
||||||
public string saveDebugInfo()
|
public string saveDebugInfo()
|
||||||
{
|
{
|
||||||
string retval = System.IO.Path.ChangeExtension(_filename, ".txt");
|
string retval = System.IO.Path.ChangeExtension(_filename, ".txt");
|
||||||
System.IO.StreamWriter outfile = new System.IO.StreamWriter(retval);
|
using (System.IO.StreamWriter outfile = new System.IO.StreamWriter(retval))
|
||||||
outfile.Write(getDebugInfo());
|
{
|
||||||
outfile.Close();
|
outfile.Write(getDebugInfo());
|
||||||
|
outfile.Close();
|
||||||
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getDebugInfo()
|
public string getDebugInfo()
|
||||||
{
|
{
|
||||||
System.IO.StringWriter outfile = new System.IO.StringWriter();
|
System.IO.StringWriter outfile = new System.IO.StringWriter();
|
||||||
|
outfile.WriteLine(_filename);
|
||||||
outfile.WriteLine("PES header");
|
outfile.WriteLine("PES header");
|
||||||
outfile.WriteLine("PES version:\t" + pesVersion);
|
outfile.WriteLine("PES version:\t" + pesVersion);
|
||||||
|
|
||||||
|
@ -381,7 +440,7 @@ namespace PesFile
|
||||||
outfile.WriteLine("unknown start byte: " + thisBlock.unknownStartByte.ToString("X2"));
|
outfile.WriteLine("unknown start byte: " + thisBlock.unknownStartByte.ToString("X2"));
|
||||||
foreach (Stitch thisStitch in thisBlock.stitches)
|
foreach (Stitch thisStitch in thisBlock.stitches)
|
||||||
{
|
{
|
||||||
string tempLine = thisStitch.a.ToString() + " - " + thisStitch.b.ToString() + ", length " + thisStitch.calcLength();
|
string tempLine = thisStitch.a.ToString() + " - " + thisStitch.b.ToString() + ", length " + thisStitch.calcLength().ToString("F02");
|
||||||
if (thisStitch.extraBits1 != 0x00)
|
if (thisStitch.extraBits1 != 0x00)
|
||||||
{
|
{
|
||||||
tempLine += " (extra bits 1: " + thisStitch.extraBits1.ToString("X2") + ")";
|
tempLine += " (extra bits 1: " + thisStitch.extraBits1.ToString("X2") + ")";
|
||||||
|
@ -390,6 +449,27 @@ namespace PesFile
|
||||||
{
|
{
|
||||||
tempLine += " (extra bits 2: " + thisStitch.extraBits2.ToString("X2") + ")";
|
tempLine += " (extra bits 2: " + thisStitch.extraBits2.ToString("X2") + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(thisStitch.XMoveBits == Stitch.MoveBitSize.SevenBits)
|
||||||
|
{
|
||||||
|
tempLine += " (7 bit X move)";
|
||||||
|
}
|
||||||
|
else if(thisStitch.XMoveBits == Stitch.MoveBitSize.TwelveBits)
|
||||||
|
{
|
||||||
|
tempLine += " (12 bit X move)";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thisStitch.YMoveBits == Stitch.MoveBitSize.SevenBits)
|
||||||
|
{
|
||||||
|
tempLine += " (7 bit Y move)";
|
||||||
|
}
|
||||||
|
else if (thisStitch.YMoveBits == Stitch.MoveBitSize.TwelveBits)
|
||||||
|
{
|
||||||
|
tempLine += " (12 bit Y move)";
|
||||||
|
}
|
||||||
|
|
||||||
|
tempLine += " (type " + thisStitch.stitchType + ")";
|
||||||
|
|
||||||
outfile.WriteLine(tempLine);
|
outfile.WriteLine(tempLine);
|
||||||
}
|
}
|
||||||
blockCount++;
|
blockCount++;
|
||||||
|
@ -458,6 +538,12 @@ namespace PesFile
|
||||||
|
|
||||||
foreach(StitchBlock thisBlock in blocks)
|
foreach(StitchBlock thisBlock in blocks)
|
||||||
{
|
{
|
||||||
|
// Skip this block if it doesn't have stitches, for any reason
|
||||||
|
if(thisBlock.stitches.Length == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Set new color for this block
|
// Set new color for this block
|
||||||
tempPen.Color = thisBlock.color;
|
tempPen.Color = thisBlock.color;
|
||||||
|
|
||||||
|
@ -470,6 +556,30 @@ namespace PesFile
|
||||||
// This stitch is too long, so skip it
|
// This stitch is too long, so skip it
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Style special stitches differently
|
||||||
|
// TODO: Finish figuring out the remaining stitch types
|
||||||
|
/*if (thisStitch.stitchType == Stitch.StitchType.MovementBeginAnchor)
|
||||||
|
{
|
||||||
|
tempPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
|
||||||
|
tempPen.Width = tempThreadThickness * 0.5f;
|
||||||
|
}
|
||||||
|
else if (thisStitch.stitchType == Stitch.StitchType.MovementOnly)
|
||||||
|
{
|
||||||
|
tempPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
|
||||||
|
tempPen.Width = tempThreadThickness * 0.5f;
|
||||||
|
}
|
||||||
|
else if(thisStitch.stitchType == Stitch.StitchType.MovementEndAnchor)
|
||||||
|
{
|
||||||
|
tempPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
|
||||||
|
tempPen.Width = tempThreadThickness * 0.5f;
|
||||||
|
}
|
||||||
|
else if (thisStitch.stitchType == Stitch.StitchType.NormalStitch)
|
||||||
|
{
|
||||||
|
tempPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
|
||||||
|
tempPen.Width = tempThreadThickness;
|
||||||
|
}*/
|
||||||
|
|
||||||
Point tempA = new Point((int)(thisStitch.a.X * scale), (int)(thisStitch.a.Y * scale));
|
Point tempA = new Point((int)(thisStitch.a.X * scale), (int)(thisStitch.a.Y * scale));
|
||||||
Point tempB = new Point((int)(thisStitch.b.X * scale), (int)(thisStitch.b.Y * scale));
|
Point tempB = new Point((int)(thisStitch.b.X * scale), (int)(thisStitch.b.Y * scale));
|
||||||
xGraph.DrawLine(tempPen, tempA, tempB);
|
xGraph.DrawLine(tempPen, tempA, tempB);
|
||||||
|
|
|
@ -55,5 +55,5 @@ using System.Runtime.InteropServices;
|
||||||
//
|
//
|
||||||
// You can specify all the values or you can default the Revision and Build Numbers
|
// You can specify all the values or you can default the Revision and Build Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("1.3.0.0")]
|
[assembly: AssemblyVersion("1.4.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.3.0.0")]
|
[assembly: AssemblyFileVersion("1.4.0.0")]
|
||||||
|
|
|
@ -29,11 +29,31 @@ namespace PesFile
|
||||||
{
|
{
|
||||||
public class Stitch
|
public class Stitch
|
||||||
{
|
{
|
||||||
|
public enum MoveBitSize
|
||||||
|
{
|
||||||
|
Unknown,
|
||||||
|
SevenBits,
|
||||||
|
TwelveBits
|
||||||
|
};
|
||||||
|
|
||||||
|
public enum StitchType
|
||||||
|
{
|
||||||
|
Unknown,
|
||||||
|
NormalStitch,
|
||||||
|
MovementBeginAnchor,
|
||||||
|
MovementEndAnchor,
|
||||||
|
MovementOnly
|
||||||
|
}
|
||||||
|
|
||||||
public Point a;
|
public Point a;
|
||||||
public Point b;
|
public Point b;
|
||||||
// Extra bits to output with debug info
|
// Extra bits to output with debug info
|
||||||
public int extraBits1;
|
public int extraBits1;
|
||||||
public int extraBits2;
|
public int extraBits2;
|
||||||
|
// Was this stitch represented as 7 bit move or 12 bit move in the file
|
||||||
|
public MoveBitSize XMoveBits;
|
||||||
|
public MoveBitSize YMoveBits;
|
||||||
|
public StitchType stitchType;
|
||||||
|
|
||||||
public Stitch(Point pointA, Point pointB)
|
public Stitch(Point pointA, Point pointB)
|
||||||
{
|
{
|
||||||
|
@ -41,12 +61,15 @@ namespace PesFile
|
||||||
this.b = pointB;
|
this.b = pointB;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stitch(Point pointA, Point pointB, int extraBits1, int extraBits2)
|
public Stitch(Point pointA, Point pointB, int extraBits1, int extraBits2, MoveBitSize XMoveBits, MoveBitSize YMoveBits, StitchType stitchType)
|
||||||
{
|
{
|
||||||
this.a = pointA;
|
this.a = pointA;
|
||||||
this.b = pointB;
|
this.b = pointB;
|
||||||
this.extraBits1 = extraBits1;
|
this.extraBits1 = extraBits1;
|
||||||
this.extraBits2 = extraBits2;
|
this.extraBits2 = extraBits2;
|
||||||
|
this.XMoveBits = XMoveBits;
|
||||||
|
this.YMoveBits = YMoveBits;
|
||||||
|
this.stitchType = stitchType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double calcLength()
|
public double calcLength()
|
||||||
|
|
|
@ -53,5 +53,5 @@ using System.Runtime.InteropServices;
|
||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
[assembly: AssemblyVersion("1.0.1.0")]
|
[assembly: AssemblyVersion("1.1.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.1.0")]
|
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||||
|
|
|
@ -54,5 +54,5 @@ using System.Runtime.InteropServices;
|
||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
[assembly: AssemblyVersion("2.1.0.0")]
|
[assembly: AssemblyVersion("2.1.1.0")]
|
||||||
[assembly: AssemblyFileVersion("2.1.0.0")]
|
[assembly: AssemblyFileVersion("2.1.1.0")]
|
||||||
|
|
Ładowanie…
Reference in New Issue