private int neighborSamples(StitchType type) { int ret; switch (type) { case StitchType.ToSame: ret = numSamples; break; case StitchType.ToLower: ret = numSamples / 2; break; case StitchType.ToHigher: ret = numSamples * 2; break; case StitchType.None: default: Debug.Assert(false, "stitching:attempted to get samples from non-existent neighbor"); ret = 0; break; } return(ret); }
public Stitch(Point pointA, Point pointB, int extraBits1, int extraBits2, MoveBitSize XMoveBits, MoveBitSize YMoveBits, StitchType stitchType) { this.a = pointA; this.b = pointB; this.extraBits1 = extraBits1; this.extraBits2 = extraBits2; this.XMoveBits = XMoveBits; this.YMoveBits = YMoveBits; this.stitchType = stitchType; }
public Stitch(Point pointA, Point pointB, int extraBits1, int extraBits2, MoveBitSize XMoveBits, MoveBitSize YMoveBits, StitchType stitchType) { this.a = pointA; this.b = pointB; this.extraBits1 = extraBits1; this.extraBits2 = extraBits2; this.XMoveBits = XMoveBits; this.YMoveBits = YMoveBits; this.stitchType = stitchType; }
private int neighborSamples(StitchType type) { int ret; switch ( type ) { case StitchType.ToSame: ret = numSamples; break; case StitchType.ToLower: ret = numSamples / 2; break; case StitchType.ToHigher: ret = numSamples * 2; break; case StitchType.None: default: Debug.Assert(false, "stitching:attempted to get samples from non-existent neighbor"); ret = 0; break; } return ret; }
public void LoadFromFile(string path) { if (path == null) { throw new ArgumentNullException("path"); } if (!File.Exists(path)) { throw new FileNotFoundException("File not found.", path); } _threadColors.Clear(); _stitchBlocks.Clear(); _filePath = path; string pesVersion; log.InfoFormat("Reading file: {0}", _filePath); BinaryReader pesData = new BinaryReader(File.OpenRead(_filePath)); string pesHeader = new string(pesData.ReadChars(4)); log.DebugFormat("Header string: {0}", pesHeader); if (pesHeader != "#PES") { throw new FileLoadException("The specified file is not a valid PES file.", _filePath); } pesVersion = new string(pesData.ReadChars(4)); log.DebugFormat("Pes version: {0}", pesVersion); uint pecStart = pesData.ReadUInt32(); log.DebugFormat("Pec start: {0}", pecStart); pesData.BaseStream.Position = pecStart + 3; _designName = new string(pesData.ReadChars(16)); _designName = _designName.Trim(); log.DebugFormat("Internal name: {0}", _designName); pesData.BaseStream.Position = pecStart + 48; int colorCount = pesData.ReadByte() + 1; log.DebugFormat("Color count: {0}", colorCount); log.Info("Reading color data..."); for (int i = 0; i < colorCount; i++) { int colorIndex = pesData.ReadByte(); colorIndex--; if (colorIndex > 63 || colorIndex < 0) { _threadColors.Add(_availableColors[15]); } else { _threadColors.Add(_availableColors[colorIndex]); } log.DebugFormat("Added color {0}", _threadColors[i].Name); } pesData.BaseStream.Position = pecStart + 514; uint pecLength = pesData.ReadUInt16(); uint pecEnd = pecStart + 514 + pecLength; log.DebugFormat("Pec Length: {0}", pecLength); log.DebugFormat("Pec End: {0}", pecEnd); _width = pesData.ReadUInt16(); _height = pesData.ReadUInt16(); pesData.BaseStream.Position = pecStart + 532; int bx, by, dx, dy, x, y, mx, my, nx, ny; bx = by = dx = dy = x = y = mx = my = nx = ny = 0; int c = 0; bool jmp = false; StitchBlock sb = new StitchBlock(_threadColors[c]); while (pesData.BaseStream.Position < pecEnd) { bx = pesData.ReadByte(); by = pesData.ReadByte(); //log.DebugFormat("Bytes x={0}, y={1}", bx, by); if (bx == 255 && by == 0) { //log.Info("End of stitch marker"); _stitchBlocks.Add(sb); break; } else if (bx == 254 && by == 176) { //log.Info("End of color block."); c++; _stitchBlocks.Add(sb); sb = new StitchBlock(_threadColors[c]); pesData.BaseStream.Position++; } else { //Regular stitch dx = dy = 0; if ((bx & 128) == 128)//$80 { //log.Info("Jump stitch on x"); dx = ((bx & 15) * 256) + by; dx = ((dx & 2048) == 2048) ? (int)(dx | 4294963200) : dx; by = pesData.ReadByte(); jmp = true; } else { dx = (bx > 63) ? bx - 128 : bx; } if ((by & 128) == 128)//$80 { //log.Info("Jump stitch on y"); bx = pesData.ReadByte(); dy = ((by & 15) * 256) + bx; dy = ((dy & 2048) == 2048) ? (int)(dy | 4294963200) : dy; jmp = true; } else { //normal stitch dy = (by > 63) ? by - 128 : by; } //log.DebugFormat("Stitch point: dx={0}, dy={1}", dx, dy); x += dx; y += dy; nx = (x < nx) ? x : nx; ny = (y < ny) ? y : ny; mx = (x > mx) ? x : mx; my = (y > my) ? y : my; StitchType type = (jmp) ? StitchType.Jump : StitchType.Normal; sb.AddStitch(new Stitch(new Point(x, y), type)); _stitchCount++; jmp = false; } _pixelWidth = mx - nx; _pixelHeight = my - ny; _xOffset = -nx; _yOffset = -ny; } //log.Info("Closing the file."); pesData.Close(); }
public Stitch(Point point, StitchType type) { _point = point; _type = type; }
public Stitch(Point point, StitchType type) { _point = point; _type = type; }