int readMax(EmbPattern* pattern, const char* fileName) { int i; unsigned char b[8]; double dx = 0, dy = 0; int flags = 0; int stitchCount; FILE* file; file = fopen(fileName, "rb"); if(file == 0) { return 0; } fseek(file, 0xD5, SEEK_SET); stitchCount = binaryReadUInt32(file); /* READ STITCH RECORDS */ for(i = 0; i < stitchCount; i++) { flags = NORMAL; if(fread(b, 1, 8, file) != 8) break; dx = maxDecode(b[0], b[1], b[2]); dy = maxDecode(b[4], b[5], b[6]); embPattern_addStitchAbs(pattern, dx / 10.0, dy / 10.0, flags, 1); } embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); fclose(file); return 1; }
/*! Writes the data from \a pattern to a file with the given \a fileName. * Returns \c true if successful, otherwise returns \c false. */ int writePec(EmbPattern* pattern, const char* fileName) { EmbFile* file = 0; if(!embStitchList_count(pattern->stitchList)) { embLog_error("format-pec.c writePec(), pattern contains no stitches\n"); return 0; } /* Check for an END stitch and add one if it is not present */ if(pattern->lastStitch->stitch.flags != END) embPattern_addStitchRel(pattern, 0, 0, END, 1); file = embFile_open(fileName, "wb"); if(!file) { embLog_error("format-pec.c writePec(), cannot open %s for writing\n", fileName); return 0; } embPattern_flipVertical(pattern); /* TODO: There needs to be a matching flipVertical() call after the write to ensure multiple writes from the same pattern work properly */ embPattern_fixColorCount(pattern); embPattern_correctForMaxStitchLength(pattern,12.7, 204.7); embPattern_scale(pattern, 10.0); binaryWriteBytes(file, "#PEC0001", 8); writePecStitches(pattern, file, fileName); embFile_close(file); return 1; }
/*! Reads a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int readPec(EmbPattern* pattern, const char* fileName) { unsigned int graphicsOffset; unsigned char colorChanges; int i; EmbFile* file = 0; if(!pattern) { embLog_error("format-pec.c readPec(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-pec.c readPec(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-pec.c readPec(), cannot open %s for reading\n", fileName); return 0; } embFile_seek(file, 0x38, SEEK_SET); colorChanges = (unsigned char)binaryReadByte(file); for(i = 0; i <= colorChanges; i++) { embPattern_addThread(pattern, pecThreads[binaryReadByte(file) % 65]); } /* Get Graphics offset */ embFile_seek(file, 0x20A, SEEK_SET); graphicsOffset = (unsigned int)(binaryReadUInt8(file)); graphicsOffset |= (binaryReadUInt8(file) << 8); graphicsOffset |= (binaryReadUInt8(file) << 16); (void)binaryReadByte(file); /* 0x31 */ (void)binaryReadByte(file); /* 0xFF */ (void)binaryReadByte(file); /* 0xF0 */ /* Get X and Y size in .1 mm */ /* 0x210 */ binaryReadInt16(file); /* x size */ binaryReadInt16(file); /* y size */ binaryReadInt16(file); /* 0x01E0 */ binaryReadInt16(file); /* 0x01B0 */ binaryReadInt16(file); /* distance left from start */ binaryReadInt16(file); /* distance up from start */ /* Begin Stitch Data */ /* 0x21C */ /*unsigned int end = graphicsOffset + 0x208; */ readPecStitches(pattern, file); embFile_close(file); /* Check for an END stitch and add one if it is not present */ if(pattern->lastStitch->stitch.flags != END) embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); return 1; }
int readPhb(EmbPattern* pattern, const char* fileName) { unsigned int fileOffset; short colorCount; FILE* file = 0; int i; file = fopen(fileName, "rb"); if(!file) { return 0; } fseek(file, 0x71, SEEK_SET); colorCount = binaryReadInt16(file); for(i = 0; i < colorCount; i++) { EmbThread t = pecThreads[binaryReadByte(file)]; embPattern_addThread(pattern, t); } /* TODO: check that file begins with #PHB */ fseek(file, 0x54, SEEK_SET); fileOffset = 0x52; fileOffset += binaryReadUInt32(file); fseek(file, fileOffset, SEEK_SET); fileOffset += binaryReadUInt32(file) + 2; fseek(file, fileOffset, SEEK_SET); fileOffset += binaryReadUInt32(file); fseek(file, fileOffset + 14, SEEK_SET); /* 28 */ colorCount = (short)binaryReadByte(file); for(i = 0; i< colorCount; i++) { binaryReadByte(file); } binaryReadInt32(file); /* bytes to end of file */ binaryReadInt32(file); binaryReadByte(file); binaryReadInt16(file); binaryReadInt16(file); binaryReadInt16(file); binaryReadInt16(file); binaryReadInt16(file); binaryReadInt16(file); readPecStitches(pattern, file); embPattern_addStitchRel(pattern, 0.0, 0.0, END, 1); fclose(file); embPattern_flipVertical(pattern); return 1; /*TODO: finish ReadPhb */ }
/*! Writes the data from \a pattern to a file with the given \a fileName. * Returns \c true if successful, otherwise returns \c false. */ int writePes(EmbPattern* pattern, const char* fileName) { int pecLocation; FILE* file = 0; if(!pattern) { embLog_error("format-pes.c writePes(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-pes.c writePes(), fileName argument is null\n"); return 0; } file = fopen(fileName, "wb"); if(!file) { embLog_error("format-pes.c writePes(), cannot open %s for writing\n", fileName); return 0; } if(!pattern->stitchList || embStitchList_count(pattern->stitchList) == 0) /* TODO: review this. seems like only embStitchList_count should be needed. */ { embLog_error("format-pes.c writePes(), pattern contains no stitches\n"); return 0; } embPattern_flipVertical(pattern); embPattern_scale(pattern, 10.0); binaryWriteBytes(file, "#PES0001", 8); /* WRITE PECPointer 32 bit int */ binaryWriteInt(file, 0x00); binaryWriteShort(file, 0x01); binaryWriteShort(file, 0x01); /* Write object count */ binaryWriteShort(file, 0x01); binaryWriteShort(file, 0xFFFF); /* command */ binaryWriteShort(file, 0x00); /* unknown */ pesWriteEmbOneSection(pattern, file); pesWriteSewSegSection(pattern, file); pecLocation = ftell(file); fseek(file, 0x08, SEEK_SET); binaryWriteByte(file, (unsigned char)(pecLocation & 0xFF)); binaryWriteByte(file, (unsigned char)(pecLocation >> 8) & 0xFF); binaryWriteByte(file, (unsigned char)(pecLocation >> 16) & 0xFF); fseek(file, 0x00, SEEK_END); writePecStitches(pattern, file, fileName); fclose(file); return 1; }
/*! Reads a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int readPhc(EmbPattern* pattern, const char* fileName) { int colorChanges, version, bytesInSection2; unsigned short pecOffset, bytesInSection, bytesInSection3; char pecAdd; FILE* file = 0; int i; if(!pattern) { embLog_error("format-phc.c readPhc(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-phc.c readPhc(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-phc.c readPhc(), cannot open %s for reading\n", fileName); return 0; } fseek(file, 0x07, SEEK_SET); version = binaryReadByte(file) - 0x30; /* converting from ansi number */ fseek(file, 0x4D, SEEK_SET); colorChanges = binaryReadUInt16(file); for(i = 0; i < colorChanges; i++) { EmbThread t = pecThreads[(int)binaryReadByte(file)]; embPattern_addThread(pattern, t); } fseek(file, 0x2B, SEEK_SET); pecAdd = binaryReadByte(file); binaryReadUInt32(file); /* file length */ pecOffset = binaryReadUInt16(file); fseek(file, pecOffset + pecAdd, SEEK_SET); bytesInSection = binaryReadUInt16(file); fseek(file, bytesInSection, SEEK_CUR); bytesInSection2 = binaryReadUInt32(file); fseek(file, bytesInSection2, SEEK_CUR); bytesInSection3 = binaryReadUInt16(file); fseek(file, bytesInSection3 + 0x12, SEEK_CUR); readPecStitches(pattern, file); fclose(file); /* Check for an END stitch and add one if it is not present */ if(pattern->lastStitch->stitch.flags != END) embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); return 1; /*TODO: finish ReadPhc */ }
/*! Reads a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int readPes(EmbPattern* pattern, const char* fileName) { int pecstart, numColors, x; FILE* file = 0; if(!pattern) { embLog_error("format-pes.c readPes(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-pes.c readPes(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-pes.c readPes(), cannot open %s for reading\n", fileName); return 0; } fseek(file, 8, SEEK_SET); pecstart = binaryReadInt32(file); fseek(file, pecstart + 48, SEEK_SET); numColors = fgetc(file) + 1; for(x = 0; x < numColors; x++) { embPattern_addThread(pattern, pecThreads[(unsigned char) fgetc(file)]); } fseek(file, pecstart + 532, SEEK_SET); readPecStitches(pattern, file); embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); fclose(file); return 1; }
/*! Writes the data from \a pattern to a file with the given \a fileName. * Returns \c true if successful, otherwise returns \c false. */ int writeVp3(EmbPattern* pattern, const char* fileName) { EmbFile *file = 0; EmbRect bounds; int remainingBytesPos, remainingBytesPos2; int colorSectionStitchBytes; int first = 1; int numberOfColors = 0; EmbColor color; EmbStitchList *mainPointer = 0, *pointer = 0; if(!pattern) { embLog_error("format-vp3.c writeVp3(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-vp3.c writeVp3(), fileName argument is null\n"); return 0; } if(!embStitchList_count(pattern->stitchList)) { embLog_error("format-vp3.c writeVp3(), pattern contains no stitches\n"); return 0; } bounds = embPattern_calcBoundingBox(pattern); file = embFile_open(fileName, "wb"); if(!file) { embLog_error("format-vp3.c writeVp3(), cannot open %s for writing\n", fileName); return 0; } embPattern_correctForMaxStitchLength(pattern, 3200.0, 3200.0); /* VP3 can encode signed 16bit deltas */ embPattern_flipVertical(pattern); binaryWriteBytes(file, "%vsm%", 5); binaryWriteByte(file, 0); vp3WriteString(file, "Embroidermodder"); binaryWriteByte(file, 0); binaryWriteByte(file, 2); binaryWriteByte(file, 0); remainingBytesPos = embFile_tell(file); binaryWriteInt(file, 0); /* placeholder */ vp3WriteString(file, ""); binaryWriteIntBE(file, bounds.right * 1000); binaryWriteIntBE(file, bounds.bottom * 1000); binaryWriteIntBE(file, bounds.left * 1000); binaryWriteIntBE(file, bounds.top * 1000); binaryWriteInt(file, 0); /* this would be some (unknown) function of thread length */ binaryWriteByte(file, 0); numberOfColors = 0; mainPointer = pattern->stitchList; while(mainPointer) { int flag; EmbColor newColor; pointer = mainPointer; flag = pointer->stitch.flags; newColor = embThreadList_getAt(pattern->threadList, pointer->stitch.color).color; if(newColor.r != color.r || newColor.g != color.g || newColor.b != color.b) { numberOfColors++; color.r = newColor.r; color.g = newColor.g; color.b = newColor.b; } else if(flag & END || flag & STOP) { numberOfColors++; } while(pointer && (flag == pointer->stitch.flags)) { pointer = pointer->next; } mainPointer = pointer; } binaryWriteByte(file, numberOfColors); binaryWriteByte(file, 12); binaryWriteByte(file, 0); binaryWriteByte(file, 1); binaryWriteByte(file, 0); binaryWriteByte(file, 3); binaryWriteByte(file, 0); remainingBytesPos2 = embFile_tell(file); binaryWriteInt(file, 0); /* placeholder */ binaryWriteIntBE(file, 0); /* origin X */ binaryWriteIntBE(file, 0); /* origin Y */ binaryWriteByte(file, 0); binaryWriteByte(file, 0); binaryWriteByte(file, 0); binaryWriteIntBE(file, bounds.right * 1000); binaryWriteIntBE(file, bounds.bottom * 1000); binaryWriteIntBE(file, bounds.left * 1000); binaryWriteIntBE(file, bounds.top * 1000); binaryWriteIntBE(file, (bounds.right - bounds.left) * 1000); binaryWriteIntBE(file, (bounds.bottom - bounds.top) * 1000); vp3WriteString(file, ""); binaryWriteShortBE(file, 25700); binaryWriteIntBE(file, 4096); binaryWriteIntBE(file, 0); binaryWriteIntBE(file, 0); binaryWriteIntBE(file, 4096); binaryWriteBytes(file, "xxPP\x01\0", 6); vp3WriteString(file, ""); binaryWriteShortBE(file, numberOfColors); mainPointer = pattern->stitchList; while(mainPointer) { char colorName[8] = { 0 }; double lastX, lastY; int colorSectionLengthPos; EmbStitch s; int lastColor; if(!first) binaryWriteByte(file, 0); binaryWriteByte(file, 0); binaryWriteByte(file, 5); binaryWriteByte(file, 0); colorSectionLengthPos = embFile_tell(file); binaryWriteInt(file, 0); /* placeholder */ pointer = mainPointer; color = embThreadList_getAt(pattern->threadList, pointer->stitch.color).color; if(first && pointer->stitch.flags & JUMP && pointer->next->stitch.flags & JUMP) pointer = pointer->next; s = pointer->stitch; embLog_print("format-vp3.c DEBUG %d, %lf, %lf\n", s.flags, s.xx, s.yy); binaryWriteIntBE(file, s.xx * 1000); binaryWriteIntBE(file, -s.yy * 1000); pointer = pointer->next; first = 0; lastX = s.xx; lastY = s.yy; lastColor = s.color; binaryWriteByte(file, 1); binaryWriteByte(file, 0); embLog_print("format-vp3.c writeVp3(), switching to color (%d, %d, %d)\n", color.r, color.g, color.b); binaryWriteByte(file, color.r); binaryWriteByte(file, color.g); binaryWriteByte(file, color.b); binaryWriteByte(file, 0); binaryWriteByte(file, 0); binaryWriteByte(file, 0); binaryWriteByte(file, 5); binaryWriteByte(file, 40); vp3WriteString(file, ""); sprintf(colorName, "#%02x%02x%02x", color.b, color.g, color.r); vp3WriteString(file, colorName); vp3WriteString(file, ""); binaryWriteIntBE(file, 0); binaryWriteIntBE(file, 0); vp3WriteStringLen(file, "\0", 1); colorSectionStitchBytes = embFile_tell(file); binaryWriteInt(file, 0); /* placeholder */ binaryWriteByte(file, 10); binaryWriteByte(file, 246); binaryWriteByte(file, 0); while(pointer) { int dx, dy; EmbStitch s = pointer->stitch; if(s.color != lastColor) break; if(s.flags & END || s.flags & STOP) break; dx = (s.xx - lastX) * 10; dy = (s.yy - lastY) * 10; lastX = lastX + dx / 10.0; /* output is in ints, ensure rounding errors do not sum up */ lastY = lastY + dy / 10.0; if(dx < -127 || dx > 127 || dy < -127 || dy > 127) { binaryWriteByte(file, 128); binaryWriteByte(file, 1); binaryWriteShortBE(file, dx); binaryWriteShortBE(file, dy); binaryWriteByte(file, 128); binaryWriteByte(file, 2); } else { binaryWriteByte(file, dx); binaryWriteByte(file, dy); } pointer = pointer->next; } vp3PatchByteCount(file, colorSectionStitchBytes, -4); vp3PatchByteCount(file, colorSectionLengthPos, -3); mainPointer = pointer; } vp3PatchByteCount(file, remainingBytesPos2, -4); vp3PatchByteCount(file, remainingBytesPos, -4); embFile_close(file); embPattern_flipVertical(pattern); return 1; }
/*! Reads a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int readVp3(EmbPattern* pattern, const char* fileName) { unsigned char magicString[5]; unsigned char some; unsigned char* softwareVendorString = 0; unsigned char v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18; unsigned char* anotherSoftwareVendorString = 0; int numberOfColors; long colorSectionOffset; unsigned char magicCode[6]; short someShort; unsigned char someByte; int bytesRemainingInFile; unsigned char* fileCommentString = 0; /* some software writes used settings here */ int hoopConfigurationOffset; unsigned char* anotherCommentString = 0; int i; EmbFile* file = 0; if(!pattern) { embLog_error("format-vp3.c readVp3(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-vp3.c readVp3(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-vp3.c readVp3(), cannot open %s for reading\n", fileName); return 0; } binaryReadBytes(file, magicString, 5); /* %vsm% */ /* TODO: check return value */ some = binaryReadByte(file); /* 0 */ softwareVendorString = vp3ReadString(file); someShort = binaryReadInt16(file); someByte = binaryReadByte(file); bytesRemainingInFile = binaryReadInt32(file); fileCommentString = vp3ReadString(file); hoopConfigurationOffset = (int)embFile_tell(file); vp3ReadHoopSection(file); anotherCommentString = vp3ReadString(file); /* TODO: review v1 thru v18 variables and use emb_unused() if needed */ v1 = binaryReadByte(file); v2 = binaryReadByte(file); v3 = binaryReadByte(file); v4 = binaryReadByte(file); v5 = binaryReadByte(file); v6 = binaryReadByte(file); v7 = binaryReadByte(file); v8 = binaryReadByte(file); v9 = binaryReadByte(file); v10 = binaryReadByte(file); v11 = binaryReadByte(file); v12 = binaryReadByte(file); v13 = binaryReadByte(file); v14 = binaryReadByte(file); v15 = binaryReadByte(file); v16 = binaryReadByte(file); v17 = binaryReadByte(file); v18 = binaryReadByte(file); binaryReadBytes(file, magicCode, 6); /* 0x78 0x78 0x55 0x55 0x01 0x00 */ /* TODO: check return value */ anotherSoftwareVendorString = vp3ReadString(file); numberOfColors = binaryReadInt16BE(file); embLog_error("format-vp3.c Number of Colors: %d\n", numberOfColors); colorSectionOffset = (int)embFile_tell(file); for(i = 0; i < numberOfColors; i++) { EmbThread t; char tableSize; int startX, startY, offsetToNextColorX, offsetToNextColorY; unsigned char* threadColorNumber, *colorName, *threadVendor; int unknownThreadString, numberOfBytesInColor; embFile_seek(file, colorSectionOffset, SEEK_SET); embLog_error("format-vp3.c Color Check Byte #1: 0 == %d\n", binaryReadByte(file)); embLog_error("format-vp3.c Color Check Byte #2: 5 == %d\n", binaryReadByte(file)); embLog_error("format-vp3.c Color Check Byte #3: 0 == %d\n", binaryReadByte(file)); colorSectionOffset = binaryReadInt32BE(file); colorSectionOffset += embFile_tell(file); startX = binaryReadInt32BE(file); startY = binaryReadInt32BE(file); embPattern_addStitchAbs(pattern, startX / 1000, -startY / 1000, JUMP, 0); tableSize = binaryReadByte(file); binaryReadByte(file); t.color.r = binaryReadByte(file); t.color.g = binaryReadByte(file); t.color.b = binaryReadByte(file); embPattern_addThread(pattern, t); embFile_seek(file, 6*tableSize - 1, SEEK_CUR); threadColorNumber = vp3ReadString(file); colorName = vp3ReadString(file); threadVendor = vp3ReadString(file); offsetToNextColorX = binaryReadInt32BE(file); offsetToNextColorY = binaryReadInt32BE(file); unknownThreadString = binaryReadInt16BE(file); embFile_seek(file, unknownThreadString, SEEK_CUR); numberOfBytesInColor = binaryReadInt32BE(file); embFile_seek(file, 0x3, SEEK_CUR); while(embFile_tell(file) < colorSectionOffset - 1) { int lastFilePosition = embFile_tell(file); int x = vp3Decode(binaryReadByte(file)); int y = vp3Decode(binaryReadByte(file)); if(x == 0x80) { switch (y) { case 0x00: case 0x03: break; case 0x01: x = vp3DecodeInt16(binaryReadInt16BE(file)); y = vp3DecodeInt16(binaryReadInt16BE(file)); binaryReadInt16BE(file); embPattern_addStitchRel(pattern, x/ 10.0, y / 10.0, TRIM, 1); break; default: break; } } else { embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, NORMAL, 1); } if(embFile_tell(file) == lastFilePosition) { embLog_error("format-vp3.c could not read stitch block in entirety\n"); return 0; } } if(i + 1 < numberOfColors) embPattern_addStitchRel(pattern, 0, 0, STOP, 1); } embFile_close(file); /* Check for an END stitch and add one if it is not present */ if(pattern->lastStitch->stitch.flags != END) embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); return 1; }
/*! Reads a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int readStx(EmbPattern* pattern, const char* fileName) { int i, threadCount; unsigned char* gif = 0; /* public Bitmap Image; */ StxThread* stxThreads = 0; unsigned char headerBytes[7]; char* header = 0; char filetype[4], version[5]; int paletteLength, imageLength, something1, stitchDataOffset, something3, threadDescriptionOffset, stitchCount, left, right, colors; int val1, val2, val3, val4, val5, val6; int vala1, vala2, vala3, vala4, vala5, vala6; int bottom,top; EmbFile* file = 0; if(!pattern) { embLog_error("format-stx.c readStx(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-stx.c readStx(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-stx.c readStx(), cannot open %s for reading\n", fileName); return 0; } binaryReadBytes(file, headerBytes, 7); header = (char*)headerBytes; memcpy(filetype, &header[0], 3); memcpy(version, &header[3], 4); filetype[3] = '\0'; version[4] = '\0'; binaryReadByte(file); paletteLength = binaryReadInt32(file); imageLength = binaryReadInt32(file); something1 = binaryReadInt32(file); stitchDataOffset = binaryReadInt32(file); something3 = binaryReadInt32(file); threadDescriptionOffset = binaryReadInt32(file); stitchCount = binaryReadInt32(file); colors = binaryReadInt32(file); right = binaryReadInt16(file); left = binaryReadInt16(file); bottom = binaryReadInt16(file); top = binaryReadInt16(file); gif = (unsigned char*)malloc(imageLength); if(!gif) { embLog_error("format-stx.c readStx(), unable to allocate memory for gif\n"); return 0; } binaryReadBytes(file, gif, imageLength); /*Stream s2 = new MemoryStream(gif); */ /*Image = new Bitmap(s2); */ threadCount = binaryReadInt16(file); stxThreads = (StxThread*)malloc(sizeof(StxThread) * threadCount); if(!stxThreads) { embLog_error("format-stx.c readStx(), unable to allocate memory for stxThreads\n"); return 0; } for(i = 0; i < threadCount; i++) { EmbThread t; StxThread st; stxReadThread(&st, file); t.color.r = st.StxColor.r; t.color.g = st.StxColor.g; t.color.b = st.StxColor.b; t.description = st.ColorName; t.catalogNumber = st.ColorCode; embPattern_addThread(pattern, t); stxThreads[i] = st; } binaryReadInt32(file); binaryReadInt32(file); binaryReadInt32(file); binaryReadInt16(file); binaryReadUInt8(file); val1 = binaryReadInt16(file); val2 = binaryReadInt16(file); val3 = binaryReadInt16(file); val4 = binaryReadInt16(file); val5 = binaryReadInt16(file); /* 0 */ val6 = binaryReadInt16(file); /* 0 */ vala1 = binaryReadInt16(file); vala2 = binaryReadInt16(file); vala3 = binaryReadInt16(file); vala4 = binaryReadInt16(file); vala5 = binaryReadInt16(file); /* 0 */ vala6 = binaryReadInt16(file); /* 0 */ binaryReadInt32(file); /* 0 */ binaryReadInt32(file); /* 0 */ /* br.BaseStream.Position = stitchDataOffset; */ for(i = 1; i < stitchCount; ) { char b0 = binaryReadByte(file); char b1 = binaryReadByte(file); if(b0 == -128) { switch (b1) { case 1: b0 = binaryReadByte(file); b1 = binaryReadByte(file); /*embPattern_addStitchRel(b0, b1, STOP);*/ i++; break; case 2: b0 = binaryReadByte(file); b1 = binaryReadByte(file); embPattern_addStitchRel(pattern, b0 / 10.0, b1 / 10.0, JUMP, 1); i++; break; case -94: /* NOTE: Is this a syncronize */ break; default: /*Debugger.Break(); */ break; } } else { embPattern_addStitchRel(pattern, b0 / 10.0, b1 / 10.0, NORMAL, 1); i++; } } embFile_close(file); /* Check for an END stitch and add one if it is not present */ if(pattern->lastStitch->stitch.flags != END) embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); return 1; }
int readShv(EmbPattern* pattern, const char* fileName) { int i; char inJump = 0; unsigned char fileNameLength, designWidth, designHeight; char halfDesignWidth, halfDesignHeight, halfDesignWidth2, halfDesignHeight2; char* headerText = "Embroidery disk created using software licensed from Viking Sewing Machines AB, Sweden"; char dx = 0, dy = 0; char numberOfColors; unsigned short magicCode; int something; short left,top,right,bottom; char something2, numberOfSections, something3; FILE* file = 0; file = fopen(fileName, "rb"); if(!file) { return 0; } fseek(file, strlen(headerText), SEEK_SET); fileNameLength = binaryReadUInt8(file); fseek(file, fileNameLength, SEEK_CUR); designWidth = binaryReadUInt8(file); designHeight = binaryReadUInt8(file); halfDesignWidth = binaryReadUInt8(file); halfDesignHeight = binaryReadUInt8(file); halfDesignWidth2 = binaryReadUInt8(file); halfDesignHeight2 = binaryReadUInt8(file); if((designHeight % 2) == 1) fseek(file, ((designHeight + 1)*designWidth)/2, SEEK_CUR); else fseek(file, (designHeight*designWidth)/2, SEEK_CUR); numberOfColors = binaryReadUInt8(file); magicCode = binaryReadUInt16(file); binaryReadByte(file); something = binaryReadInt32(file); left = binaryReadInt16(file); top = binaryReadInt16(file); right = binaryReadInt16(file); bottom = binaryReadInt16(file); something2 = binaryReadByte(file); numberOfSections = binaryReadUInt8(file); something3 = binaryReadByte(file); for(i = 0; i < numberOfColors; i++) { unsigned char colorNumber; binaryReadUInt16(file); binaryReadUInt16(file); colorNumber = binaryReadUInt8(file); embPattern_addThread(pattern, jefThreads[colorNumber]); fseek(file, 9, SEEK_CUR); } fseek(file, -2, SEEK_CUR); for(i = 0; !feof(file); i++) { unsigned char b0, b1; int flags; if(inJump) flags = JUMP; else flags = NORMAL; b0 = binaryReadUInt8(file); b1 = binaryReadUInt8(file); if(b0 == 0 && b1 == 0 && i > 0) flags = STOP; if(b0 == 0x80) { if(b1 == 3) { /*embPattern_addStitchRel(pattern, 0, 0, STOP); TODO: review this */ continue; } else if(b1 == 0x02) { inJump = 0; continue; } else if(b1 == 0x01) { unsigned short sx, sy; sx = binaryReadUInt8(file); sx = (unsigned short)(sx << 8 | binaryReadUInt8(file)); sy = binaryReadUInt8(file); sy = (unsigned short)(sy << 8 | binaryReadUInt8(file)); flags = TRIM; inJump = 1; embPattern_addStitchRel(pattern, shvDecodeShort(sx) / 10.0, shvDecodeShort(sy) / 10.0, flags, 1); continue; } } dx = shvDecode(b0); dy = shvDecode(b1); embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 1); } embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); fclose(file); return 1; }
/*! Reads a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int readPhb(EmbPattern* pattern, const char* fileName) { unsigned int fileOffset; short colorCount; FILE* file = 0; int i; if(!pattern) { embLog_error("format-phb.c readPhb(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-phb.c readPhb(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-phb.c readPhb(), cannot open %s for reading\n", fileName); return 0; } fseek(file, 0x71, SEEK_SET); colorCount = binaryReadInt16(file); for(i = 0; i < colorCount; i++) { EmbThread t = pecThreads[(int)binaryReadByte(file)]; embPattern_addThread(pattern, t); } /* TODO: check that file begins with #PHB */ fseek(file, 0x54, SEEK_SET); fileOffset = 0x52; fileOffset += binaryReadUInt32(file); fseek(file, fileOffset, SEEK_SET); fileOffset += binaryReadUInt32(file) + 2; fseek(file, fileOffset, SEEK_SET); fileOffset += binaryReadUInt32(file); fseek(file, fileOffset + 14, SEEK_SET); /* 28 */ colorCount = (short)binaryReadByte(file); for(i = 0; i< colorCount; i++) { binaryReadByte(file); } binaryReadInt32(file); /* bytes to end of file */ binaryReadInt32(file); binaryReadByte(file); binaryReadInt16(file); binaryReadInt16(file); binaryReadInt16(file); binaryReadInt16(file); binaryReadInt16(file); binaryReadInt16(file); readPecStitches(pattern, file); fclose(file); /* Check for an END stitch and add one if it is not present */ if(pattern->lastStitch->stitch.flags != END) embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); return 1; /*TODO: finish ReadPhb */ }
/*! Reads a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int readVp3(EmbPattern* pattern, const char* fileName) { unsigned char magicString[5]; unsigned char some; unsigned char* someString = 0; unsigned char v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18; unsigned char* unknownString3 = 0; int numberOfColors; long colorSectionOffset; unsigned char magicCode[6]; short someShort; unsigned char someByte; int bytesRemainingInFile; unsigned char* unknownByteString = 0; int hoopConfigurationOffset; unsigned char* unknownString2 = 0; int i; FILE* file = 0; if(!pattern) { embLog_error("format-vp3.c readVp3(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-vp3.c readVp3(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-vp3.c readVp3(), cannot open %s for reading\n", fileName); return 0; } binaryReadBytes(file, magicString, 5); /* %vsm% */ some = binaryReadByte(file); /* 0 */ someString = vp3ReadString(file); someShort = binaryReadInt16(file); someByte = binaryReadByte(file); bytesRemainingInFile = binaryReadInt32(file); unknownByteString = vp3ReadString(file); hoopConfigurationOffset =(int) ftell(file); vp3ReadHoopSection(file); unknownString2 = vp3ReadString(file); /* TODO: review v1 thru v18 variables and use emb_unused() if needed */ v1 = binaryReadByte(file); v2 = binaryReadByte(file); v3 = binaryReadByte(file); v4 = binaryReadByte(file); v5 = binaryReadByte(file); v6 = binaryReadByte(file); v7 = binaryReadByte(file); v8 = binaryReadByte(file); v9 = binaryReadByte(file); v10 = binaryReadByte(file); v11 = binaryReadByte(file); v12 = binaryReadByte(file); v13 = binaryReadByte(file); v14 = binaryReadByte(file); v15 = binaryReadByte(file); v16 = binaryReadByte(file); v17 = binaryReadByte(file); v18 = binaryReadByte(file); binaryReadBytes(file, magicCode, 6); /* 0x78 0x78 0x55 0x55 0x01 0x00 */ unknownString3 = vp3ReadString(file); numberOfColors = binaryReadInt16BE(file); colorSectionOffset = (int) ftell(file); for(i = 0; i < numberOfColors; i++) { EmbThread t; char tableSize; int unknownX, unknownY, unknownX2, unknownY2; unsigned char* str1, *str2, *str3; int unknownThreadString, numberOfBytesInColor; fseek(file, 0x03 + colorSectionOffset, SEEK_SET); colorSectionOffset = binaryReadInt32BE(file); colorSectionOffset += ftell(file); unknownX = binaryReadInt32BE(file); unknownY = binaryReadInt32BE(file); /* TODO: review commented section below pattern.embPattern_addStitchAbsolute(-unknownX / 100, -unknownY/ 100, StitchType.Jump, false); fs.Seek(0x08, SeekOrigin.Current); */ tableSize = binaryReadByte(file); binaryReadByte(file); t.color.r = binaryReadByte(file); t.color.g = binaryReadByte(file); t.color.b = binaryReadByte(file); embPattern_addThread(pattern, t); fseek(file, 6*tableSize - 1, SEEK_CUR); str1 = vp3ReadString(file); str2 = vp3ReadString(file); str3 = vp3ReadString(file); unknownX2 = binaryReadInt32BE(file); unknownY2 = binaryReadInt32BE(file); /*fs.Seek(0x02, SeekOrigin.Current); */ unknownThreadString = binaryReadInt16BE(file); fseek(file, unknownThreadString, SEEK_CUR); numberOfBytesInColor = binaryReadInt32BE(file); fseek(file, 0x3, SEEK_CUR); while(ftell(file) < colorSectionOffset - 1) { int x = vp3Decode(binaryReadByte(file)); int y = vp3Decode(binaryReadByte(file)); if(x == 0x80) { switch (y) { case 0x00: case 0x03: break; case 0x01: x = vp3DecodeInt16(binaryReadInt16BE(file)); y = vp3DecodeInt16(binaryReadInt16BE(file)); binaryReadInt16BE(file); embPattern_addStitchRel(pattern, x/ 10.0, y / 10.0, TRIM, 1); break; default: break; } } else { embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, NORMAL, 1); } } if(i + 1 < numberOfColors) embPattern_addStitchRel(pattern, 0, 0, STOP, 1); } fclose(file); /* Check for an END stitch and add one if it is not present */ if(pattern->lastStitch->stitch.flags != END) embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); return 1; }
/*! Reads a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int readInb(EmbPattern* pattern, const char* fileName) { EmbFile* file = 0; unsigned char fileDescription[8]; unsigned char nullVal; int stitchCount; short width; short height; short colorCount; short unknown3; short unknown2; short imageWidth; short imageHeight; unsigned char bytesUnknown[300]; short nullbyte; short left; short right; short top; short bottom; int x = 0; int y = 0; int i; int fileLength; if(!pattern) { embLog_error("format-inb.c readInb(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-inb.c readInb(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-inb.c readInb(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); embFile_seek(file, 0, SEEK_END); fileLength = embFile_tell(file); binaryReadBytes(file, fileDescription, 8); nullVal = binaryReadByte(file); binaryReadInt16(file); stitchCount = binaryReadInt32(file); width = binaryReadInt16(file); height = binaryReadInt16(file); colorCount = binaryReadInt16(file); unknown3 = binaryReadInt16(file); unknown2 = binaryReadInt16(file); imageWidth = binaryReadInt16(file); imageHeight = binaryReadInt16(file); binaryReadBytes(file, bytesUnknown, 300); nullbyte = binaryReadInt16(file); left = binaryReadInt16(file); right = binaryReadInt16(file); top = binaryReadInt16(file); bottom = binaryReadInt16(file); embFile_seek(file, 0x2000, SEEK_SET); /* Calculate stitch count since header has been seen to be blank */ stitchCount = (int)((fileLength - 0x2000) / 3); for(i = 0; i < stitchCount; i++) { unsigned char type; int stitch = NORMAL; x = binaryReadByte(file); y = binaryReadByte(file); type = binaryReadByte(file); if((type & 0x40) > 0) x = -x; if((type & 0x10) > 0) y = -y; if((type & 1) > 0) stitch = STOP; if((type & 2) > 0) stitch = TRIM; embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, stitch, 1); } embFile_close(file); /* Check for an END stitch and add one if it is not present */ if(pattern->lastStitch->stitch.flags != END) embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); return 1; }
int readVp3(EmbPattern* pattern, const char* fileName) { unsigned char magicString[5]; unsigned char some; unsigned char* someString = 0; unsigned char v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18; unsigned char* unknownString3 = 0; int numberOfColors; long colorSectionOffset; unsigned char magicCode[6]; short someShort; unsigned char someByte; int bytesRemainingInFile; unsigned char* unknownByteString = 0; int hoopConfigurationOffset; unsigned char* unknownString2 = 0; int i; FILE* file = 0; file = fopen(fileName, "rb"); if(!file) { /*TODO: set messages here "Error opening VP3 file for read:" */ return 0; } binaryReadBytes(file, magicString, 5); /* %vsm% */ some = binaryReadByte(file); /* 0 */ someString = ReadString(file); someShort = binaryReadInt16(file); someByte = binaryReadByte(file); bytesRemainingInFile = binaryReadInt32(file); unknownByteString = ReadString(file); hoopConfigurationOffset =(int) ftell(file); vp3ReadHoopSection(file); unknownString2 = ReadString(file); v1 = binaryReadByte(file); v2 = binaryReadByte(file); v3 = binaryReadByte(file); v4 = binaryReadByte(file); v5 = binaryReadByte(file); v6 = binaryReadByte(file); v7 = binaryReadByte(file); v8 = binaryReadByte(file); v9 = binaryReadByte(file); v10 = binaryReadByte(file); v11 = binaryReadByte(file); v12 = binaryReadByte(file); v13 = binaryReadByte(file); v14 = binaryReadByte(file); v15 = binaryReadByte(file); v16 = binaryReadByte(file); v17 = binaryReadByte(file); v18 = binaryReadByte(file); binaryReadBytes(file, magicCode, 6); /* 0x78 0x78 0x55 0x55 0x01 0x00 */ unknownString3 = ReadString(file); numberOfColors = binaryReadInt16BE(file); colorSectionOffset = (int) ftell(file); for(i = 0; i < numberOfColors; i++) { EmbThread t; char tableSize; int unknownX, unknownY, unknownX2, unknownY2; unsigned char* str1, *str2, *str3; int unknownThreadString, numberOfBytesInColor; fseek(file, 0x03 + colorSectionOffset, SEEK_SET); colorSectionOffset = binaryReadInt32BE(file); colorSectionOffset += ftell(file); unknownX = binaryReadInt32BE(file); unknownY = binaryReadInt32BE(file); /* TODO: review commented section below pattern.embPattern_addStitchAbsolute(-unknownX / 100, -unknownY/ 100, StitchType.Jump, false); fs.Seek(0x08, SeekOrigin.Current); */ tableSize = binaryReadByte(file); t.color.b = binaryReadByte(file); t.color.r = binaryReadByte(file); t.color.g = binaryReadByte(file); embPattern_addThread(pattern, t); fseek(file, 6*tableSize, SEEK_CUR); str1 = ReadString(file); str2 = ReadString(file); str3 = ReadString(file); unknownX2 = binaryReadInt32BE(file); unknownY2 = binaryReadInt32BE(file); /*fs.Seek(0x02, SeekOrigin.Current); */ unknownThreadString = binaryReadInt16BE(file); fseek(file, unknownThreadString, SEEK_CUR); numberOfBytesInColor = binaryReadInt32BE(file); fseek(file, 0x3, SEEK_CUR); while(ftell(file) < colorSectionOffset - 1) { int x = vp3Decode(binaryReadByte(file)); int y = vp3Decode(binaryReadByte(file)); if(x == 0x80) { switch (y) { case 0x00: case 0x03: break; case 0x01: x = vp3DecodeInt16(binaryReadInt16BE(file)); y = vp3DecodeInt16(binaryReadInt16BE(file)); binaryReadInt16BE(file); embPattern_addStitchRel(pattern, x/ 10.0, y / 10.0, TRIM, 1); break; default: break; } } else { embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, NORMAL, 1); } } if(i + 1 < numberOfColors) embPattern_addStitchRel(pattern, 0, 0, STOP, 1); } embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); fclose(file); return 1; }