int read100(EmbPattern* pattern, const char* fileName) { FILE* file; int x,y; int stitchType; unsigned char b[4]; file= fopen(fileName,"rb"); if(file==0) { return 0; } embPattern_loadExternalColorFile(pattern, fileName); while(fread(b, 1, 4, file) == 4) { stitchType = NORMAL; x = (b[2] > 0x80) ? -(b[2] - 0x80) : b[2]; y = (b[3] > 0x80) ? -(b[3] - 0x80) : b[3]; /*if(!(b[0] & 0xFC)) stitchType = JUMP; TODO: review & fix */ if(!(b[0] & 0x01)) stitchType = STOP; if(b[0] == 0x1F) stitchType = END; embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, stitchType, 1); } 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 read100(EmbPattern* pattern, const char* fileName) { FILE* file = 0; int x,y; int stitchType; unsigned char b[4]; if(!pattern) { embLog_error("format-100.c read100(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-100.c read100(), fileName argument is null\n"); return 0; } file = fopen(fileName,"rb"); if(!file) { embLog_error("format-100.c read100(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); while(fread(b, 1, 4, file) == 4) { stitchType = NORMAL; x = (b[2] > 0x80) ? -(b[2] - 0x80) : b[2]; y = (b[3] > 0x80) ? -(b[3] - 0x80) : b[3]; /*if(!(b[0] & 0xFC)) stitchType = JUMP; TODO: review & fix */ if(!(b[0] & 0x01)) stitchType = STOP; if(b[0] == 0x1F) stitchType = END; embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, stitchType, 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); 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 readNew(EmbPattern* pattern, const char* fileName) { unsigned int stitchCount; unsigned char data[3]; FILE* file = 0; if(!pattern) { embLog_error("format-new.c readNew(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-new.c readNew(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-new.c readNew(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); stitchCount = binaryReadUInt16(file); while(binaryReadBytes(file, data, 3) == 3) { int x = decodeNewStitch(data[0]); int y = decodeNewStitch(data[1]); int flag = NORMAL; char val = data[2]; if(data[2] & 0x40) { x = -x; } if(data[2] & 0x20) { y = -y; } if(data[2] & 0x10) { flag = TRIM; } if(data[2] & 0x01) { flag = JUMP; } if((val & 0x1E) == 0x02) { flag = STOP; } /* Unknown values, possibly TRIM 155 = 1001 1011 = 0x9B 145 = 1001 0001 = 0x91 */ /*val = (data[2] & 0x1C); if(val != 0 && data[2] != 0x9B && data[2] != 0x91) { int z = 1; }*/ embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, flag, 1); } embPattern_addStitchRel(pattern, 0.0, 0.0, END, 1); return 1; }
int readDsb(EmbPattern* pattern, const char* fileName) { FILE* file = 0; if(!pattern) { embLog_error("format-dsb.c readDsb(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-dsb.c readDsb(), fileName argument is null\n"); return 0; } file = fopen(fileName,"rb"); if(file==0) { embLog_error("format-dsb.c readDsb(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); /*TODO: READ 512 BYTE HEADER INTO header[] */ /* for(i=0;i<512;i++) { header[i]=fgetc(file); } */ fseek(file, 0x200, SEEK_SET); while(1) { int stitchType = NORMAL; int x, y; unsigned char ctrl =(unsigned char)fgetc(file); if(feof(file)) break; y = fgetc(file); if(feof(file)) break; x = fgetc(file); if(feof(file)) break; if(ctrl & 0x20) x = -x; if(ctrl & 0x40) y = -y; if(ctrl & 0x01) stitchType = TRIM; /* ctrl & 0x02 - Speed change? */ /* ctrl & 0x04 - Clutch? */ if((ctrl & 0x05) == 0x05) { stitchType = STOP; } if(ctrl == 0xF8 || ctrl == 0x91 || ctrl == 0x87) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, stitchType, 1); } 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 read10o(EmbPattern* pattern, const char* fileName) { FILE* file = 0; if(!pattern) { embLog_error("format-10o.c read10o(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-10o.c read10o(), fileName argument is null\n"); return 0; } file = fopen(fileName,"rb"); if(!file) { embLog_error("format-10o.c read10o(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); while(1) { int x, y; int stitchType = NORMAL; unsigned char ctrl = (unsigned char)fgetc(file); if(feof(file)) break; y = fgetc(file); if(feof(file)) break; x = fgetc(file); if(feof(file)) break; if(ctrl & 0x20) x = -x; if(ctrl & 0x40) y = -y; if(ctrl & 0x01) stitchType = TRIM; if((ctrl & 0x5) == 5) { stitchType = STOP; } if(ctrl == 0xF8 || ctrl == 0x91 || ctrl == 0x87) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, stitchType, 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); 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 readSst(EmbPattern* pattern, const char* fileName) { int fileLength; EmbFile* file = 0; if(!pattern) { embLog_error("format-sst.c readSst(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-sst.c readSst(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-sst.c readSst(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); embFile_seek(file, 0, SEEK_END); fileLength = embFile_tell(file); embFile_seek(file, 0xA0, SEEK_SET); /* skip the all zero header */ while(embFile_tell(file) < fileLength) { int stitchType = NORMAL; int b1 = (int) binaryReadByte(file); int b2 = (int) binaryReadByte(file); unsigned char commandByte = binaryReadByte(file); if(commandByte == 0x04) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } if((commandByte & 0x01) == 0x01) stitchType = STOP; if((commandByte & 0x02) == 0x02) stitchType = JUMP; if((commandByte & 0x10) != 0x10) b2 = -b2; if((commandByte & 0x40) == 0x40) b1 = -b1; embPattern_addStitchRel(pattern, b1 / 10.0, b2 / 10.0, stitchType, 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); return 1; /*TODO: finish readSst */ }
int readDat(EmbPattern* pattern, const char* fileName) { int fileLength, stitchesRemaining; FILE* file = 0; file = fopen(fileName, "rb"); if(!file) { return 0; } embPattern_loadExternalColorFile(pattern, fileName); fseek(file, 0x00, SEEK_END); fileLength = ftell(file); fseek(file, 0x02, SEEK_SET); stitchesRemaining = binaryReadUInt16(file); fseek(file, 0x100, SEEK_SET); while(ftell(file)< fileLength) { int b1 = (int)binaryReadUInt8(file); int b2 = (int)binaryReadUInt8(file); unsigned char b0 = binaryReadByte(file); int stitchType = NORMAL; stitchesRemaining--; if((b0 & 0x02) == 0) stitchType = TRIM; if(b0 == 0x87) { stitchType = STOP; } if(b0 == 0xF8) { break; } if(b1 >= 0x80) { b1 = -(b1 & 0x7F); } if(b2 >= 0x80) { b2 = -(b2 & 0x7F); } embPattern_addStitchRel(pattern, b1 / 10.0, b2 / 10.0, stitchType, 1); } fclose(file); embPattern_addStitchRel(pattern, 0, 0, END, 1); return 1; }
int readDsb(EmbPattern* pattern, const char* fileName) { FILE* file= fopen(fileName,"rb"); if(file==0) { /*TODO: set messages here "Error opening DSB file for read:" */ return 0; } embPattern_loadExternalColorFile(pattern, fileName); /*TODO: READ 512 BYTE HEADER INTO header[] */ /* for(i=0;i<512;i++) { header[i]=fgetc(file); } */ fseek(file, 0x200, SEEK_SET); while(1) { int stitchType = NORMAL; int x, y; unsigned char ctrl =(unsigned char)fgetc(file); if(feof(file)) break; y = fgetc(file); if(feof(file)) break; x = fgetc(file); if(feof(file)) break; if(ctrl & 0x20) x = -x; if(ctrl & 0x40) y = -y; if(ctrl & 0x01) stitchType = TRIM; /* ctrl & 0x02 - Speed change? */ /* ctrl & 0x04 - Clutch? */ if((ctrl & 0x05) == 0x05) { stitchType = STOP; } if(ctrl == 0xF8 || ctrl == 0x91 || ctrl == 0x87) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, stitchType, 1); } 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 readFxy(EmbPattern* pattern, const char* fileName) { EmbFile* file = 0; if(!pattern) { embLog_error("format-fxy.c readFxy(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-fxy.c readFxy(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-fxy.c readFxy(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); embFile_seek(file, 0x100, SEEK_SET); /* TODO: review for combining code. This line appears to be the only difference from the GT format. */ while(!embFile_eof(file)) { int stitchType = NORMAL; int b1 = (int)binaryReadByte(file); int b2 = (int)binaryReadByte(file); unsigned char commandByte = binaryReadByte(file); if(commandByte == 0x91) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } if((commandByte & 0x01) == 0x01) stitchType = TRIM; if((commandByte & 0x02) == 0x02) stitchType = STOP; if((commandByte & 0x20) == 0x20) b1 = -b1; if((commandByte & 0x40) == 0x40) b2 = -b2; embPattern_addStitchRel(pattern, b2 / 10.0, b1 / 10.0, stitchType, 1); } embFile_close(file); /* Check for an END stitch and add one if it is not present */ if(pattern->lastStitch && pattern->lastStitch->stitch.flags != END) embPattern_addStitchRel(pattern, 0, 0, END, 1); 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 readDsz(EmbPattern* pattern, const char* fileName) { FILE* file = 0; if(!pattern) { embLog_error("format-dsz.c readDsz(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-dsz.c readDsz(), fileName argument is null\n"); return 0; } file = fopen(fileName,"rb"); if(!file) { embLog_error("format-dsz.c readDsz(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); fseek(file, 0x200, SEEK_SET); while(1) { int x, y; unsigned char ctrl; int stitchType = NORMAL; y = fgetc(file); if(feof(file)) break; x = fgetc(file); if(feof(file)) break; ctrl = (unsigned char) fgetc(file); if(feof(file)) break; if(ctrl & 0x01) stitchType = TRIM; if(ctrl & 0x20) y = -y; if(ctrl & 0x40) x = -x; if(ctrl & 0x0E) { int headNumber = (ctrl & 0x0E) >> 1; stitchType = STOP; } if(ctrl & 0x10) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, stitchType, 1); }
int read10o(EmbPattern* pattern, const char* fileName) { FILE* file = 0; file = fopen(fileName,"rb"); if(!file) { return 0; } embPattern_loadExternalColorFile(pattern, fileName); while(1) { int x, y; int stitchType = NORMAL; unsigned char ctrl = (unsigned char)fgetc(file); if(feof(file)) break; y = fgetc(file); if(feof(file)) break; x = fgetc(file); if(feof(file)) break; if(ctrl & 0x20) x = -x; if(ctrl & 0x40) y = -y; if(ctrl & 0x01) stitchType = TRIM; if((ctrl & 0x5) == 5) { stitchType = STOP; } if(ctrl == 0xF8 || ctrl == 0x91 || ctrl == 0x87) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, stitchType, 1); } 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 readGt(EmbPattern* pattern, const char* fileName) { FILE* file = 0; if(!pattern) { embLog_error("format-gt.c readGt(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-gt.c readGt(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-gt.c readGt(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); fseek(file, 0x200, SEEK_SET); /* TODO: review for combining code. This line appears to be the only difference from the FXY format. */ while(1) { int stitchType = NORMAL; int b1 = (int)binaryReadByte(file); int b2 = (int)binaryReadByte(file); unsigned char commandByte = binaryReadByte(file); if(commandByte == 0x91) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } if((commandByte & 0x01) == 0x01) stitchType = TRIM; if((commandByte & 0x02) == 0x02) stitchType = STOP; if((commandByte & 0x20) == 0x20) b1 = -b1; if((commandByte & 0x40) == 0x40) b2 = -b2; embPattern_addStitchRel(pattern, b2 / 10.0, b1 / 10.0, stitchType, 1); } return 1; }
/*! Reads ZSK file format (.DSZ) */ int readDsz(EmbPattern* pattern, const char* fileName) { FILE* file = fopen(fileName,"rb"); if(file==0) { return 0; } embPattern_loadExternalColorFile(pattern, fileName); fseek(file, 0x200, SEEK_SET); while(1) { int x, y; unsigned char ctrl; int stitchType = NORMAL; y = fgetc(file); if(feof(file)) break; x = fgetc(file); if(feof(file)) break; ctrl = (unsigned char) fgetc(file); if(feof(file)) break; if(ctrl & 0x01) stitchType = TRIM; if(ctrl & 0x20) y = -y; if(ctrl & 0x40) x = -x; if(ctrl & 0x0E) { int headNumber = (ctrl & 0x0E) >> 1; stitchType = STOP; } if(ctrl & 0x10) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, stitchType, 1); }
int readGt(EmbPattern* pattern, const char* fileName) { FILE* file = 0; file = fopen(fileName, "rb"); if(!file) { return 0; } embPattern_loadExternalColorFile(pattern, fileName); fseek(file, 0x200, SEEK_SET); while(1) { int stitchType = NORMAL; int b1 = (int) binaryReadByte(file); int b2 = (int) binaryReadByte(file); unsigned char commandByte = binaryReadByte(file); if(commandByte == 0x91) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } if((commandByte & 0x01) == 0x01) stitchType = TRIM; if((commandByte & 0x02) == 0x02) stitchType = STOP; if((commandByte & 0x20) == 0x20) b1 = -b1; if((commandByte & 0x40) == 0x40) b2 = -b2; embPattern_addStitchRel(pattern, b2 / 10.0, b1 / 10.0, stitchType, 1); } 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 readEmd(EmbPattern* pattern, const char* fileName) { unsigned char b0 = 0, b1 = 0; char dx = 0, dy = 0; int flags = NORMAL; char endOfStream = 0; unsigned char jemd0[6]; int width, height, colors; int i; FILE* file = 0; if(!pattern) { embLog_error("format-emd.c readEmd(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-emd.c readEmd(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-emd.c readEmd(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); binaryReadBytes(file, jemd0, 6); width = binaryReadInt16(file); height = binaryReadInt16(file); colors = binaryReadInt16(file); fseek(file, 0x30, SEEK_SET); for(i = 0; !endOfStream; i++) { flags = NORMAL; b0 = binaryReadUInt8(file); b1 = binaryReadUInt8(file); if(b0 == 0x80) { if(b1 == 0x2A) { embPattern_addStitchRel(pattern, 0, 0, STOP, 1); continue; } else if((b1 == 0x80)) { b0 = binaryReadUInt8(file); b1 = binaryReadUInt8(file); flags = TRIM; } else if(b1 == 0xFD) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } else { continue; } } dx = emdDecode(b0); dy = emdDecode(b1); embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 1); } embPattern_addStitchRel(pattern, 0, 0, END, 1); fclose(file); return 1; }
int readExp(EmbPattern* pattern, const char* fileName) { FILE* file; int i = 0; unsigned char b0 = 0, b1 = 0; char dx = 0, dy = 0; int flags = 0; file = fopen(fileName, "rb"); if(file == 0) { /*TODO: set status here "Error opening EXP file for read:" */ return 0; } embPattern_loadExternalColorFile(pattern, fileName); for(i = 0; !feof(file); i++) { flags = NORMAL; b0 = fgetc(file); if(feof(file)) break; b1 = fgetc(file); if(feof(file)) break; if(b0 == 0x80) { if(b1 & 1) { b0 = fgetc(file); if(feof(file)) break; b1 = fgetc(file); if(feof(file)) break; flags = STOP; } else if((b1 == 2) || (b1 == 4) || b1 == 6) { flags = TRIM; if(b1 == 2) flags = NORMAL; b0 = fgetc(file); if(feof(file)) break; b1 = fgetc(file); if(feof(file)) break; } else if(b1 == 0x80) { b0 = fgetc(file); if(feof(file)) break; b1 = fgetc(file); if(feof(file)) break; /* Seems to be b0=0x07 and b1=0x00 * Maybe used as extension functions */ b0 = 0; b1 = 0; flags = TRIM; } } dx = expDecode(b0); dy = expDecode(b1); embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 1); } embPattern_addStitchRel(pattern, 0, 0, END, 1); 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 readExp(EmbPattern* pattern, const char* fileName) { EmbFile* file = 0; int i = 0; unsigned char b0 = 0, b1 = 0; char dx = 0, dy = 0; int flags = 0; if(!pattern) { embLog_error("format-exp.c readExp(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-exp.c readExp(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-exp.c readExp(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); for(i = 0; !embFile_eof(file); i++) { flags = NORMAL; b0 = (unsigned char)embFile_getc(file); if(embFile_eof(file)) break; b1 = (unsigned char)embFile_getc(file); if(embFile_eof(file)) break; if(b0 == 0x80) { if(b1 & 1) { b0 = (unsigned char)embFile_getc(file); if(embFile_eof(file)) break; b1 = (unsigned char)embFile_getc(file); if(embFile_eof(file)) break; flags = STOP; } else if((b1 == 2) || (b1 == 4) || b1 == 6) { flags = TRIM; if(b1 == 2) flags = NORMAL; b0 = (unsigned char)embFile_getc(file); if(embFile_eof(file)) break; b1 = (unsigned char)embFile_getc(file); if(embFile_eof(file)) break; } else if(b1 == 0x80) { b0 = (unsigned char)embFile_getc(file); if(embFile_eof(file)) break; b1 = (unsigned char)embFile_getc(file); if(embFile_eof(file)) break; /* Seems to be b0=0x07 and b1=0x00 * Maybe used as extension functions */ b0 = 0; b1 = 0; flags = TRIM; } } dx = expDecode(b0); dy = expDecode(b1); embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 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); 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 readBro(EmbPattern* pattern, const char* fileName) { unsigned char x55; short unknown1, unknown2, unknown3, unknown4, moreBytesToEnd; char name[8]; int stitchType; FILE* file = 0; if(!pattern) { embLog_error("format-bro.c readBro(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-bro.c readBro(), fileName argument is null\n"); return 0; } file = fopen(fileName,"rb"); if(!file) { embLog_error("format-bro.c readBro(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); x55 = binaryReadByte(file); unknown1 = binaryReadInt16(file); fread(name, 1, 8, file); unknown2 = binaryReadInt16(file); unknown3 = binaryReadInt16(file); unknown4 = binaryReadInt16(file); moreBytesToEnd = binaryReadInt16(file); fseek(file, 0x100, SEEK_SET); while(1) { short b1, b2; stitchType = NORMAL; b1 = binaryReadByte(file); b2 = binaryReadByte(file); if(b1 == -128) { unsigned char bCode = binaryReadByte(file); b1 = binaryReadInt16(file); b2 = binaryReadInt16(file); if(bCode == 2) { stitchType = STOP; } else if(bCode == 3) { stitchType = TRIM; } else if(bCode == 0x7E) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } } embPattern_addStitchRel(pattern, b1 / 10.0, b2 / 10.0, stitchType, 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); 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 readDst(EmbPattern* pattern, const char* fileName) { char var[3]; /* temporary storage variable name */ char val[512]; /* temporary storage variable value */ int valpos; char prevJump = 0; char thisJump = 0; unsigned char b[3]; char header[512 + 1]; FILE* file = 0; int i; int flags; /* for converting stitches from file encoding */ /* * The header seems to contain information about the design. * Seems to be ASCII text delimited by 0x0D (carriage returns). * This must be in the file for most new software or hardware * to consider it a good file! This is much more important * than I originally believed. The header is 125 bytes in * length and padded out by 0x20 to 512 bytes total. * All entries in the header seem to be 2 ASCII characters * followed by a colon, then it's value trailed by a carriage return. * * char LA[16+1]; First is the 'LA' entry, which is the design name with no * path or extension information. The blank is 16 characters * in total, but the name must not be longer that 8 characters * and padded out with 0x20. * * char ST[7+1]; Next is the stitch count ST, this is a 7 digit number * padded by leading zeros. This is the total stitch count * including color changes, jumps, nups, and special records. * * char CO[3+1]; Next, is CO or colors, a 3 digit number padded by leading * zeros. This is the number of color change records in the file. * * char POSX[5+1]; Next is +X or the positive X extent in centimeters, a 5 * digit non-decimal number padded by leading zeros. * * char NEGX[5+1]; Following is the -X or the negative X extent in millimeters, * a 5 digit non-decimal number padded by leading zeros. * * char POSY[5+1]; Again, the +Y extents. * * char NEGY[5+1]; Again, the -Y extents. * * char AX[6+1]; AX and AY should express the relative coordinates of the * char AY[6+1]; last point from the start point in 0.1 mm. If the start * and last points are the same, the coordinates are (0,0). * * char MX[6+1]; MX and MY should express coordinates of the last point of * char MY[6+1]; the previous file for a multi-volume design. A multi- * volume design means a design consisted of two or more files. * This was used for huge designs that can not be stored in a * single paper tape roll. It is not used so much (almost * never) nowadays. * * char PD[9+1]; PD is also storing some information for multi-volume design. */ /* TODO: review commented code below pattern->clear(); pattern->set_variable("file_name",filename); */ if(!pattern) { embLog_error("format-dst.c readDst(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-dst.c readDst(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-dst.c readDst(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); /* READ 512 BYTE HEADER INTO header[] */ for(i = 0; i < 512; i++) { header[i] = (char)fgetc(file); } /*TODO:It would probably be a good idea to validate file before accepting it. */ /* fill variables from header fields */ for(i = 0; i < 512; i++) { if(header[i] == ':' && i > 1) { var[0] = header[i - 2]; var[1] = header[i - 1]; var[2] = '\0'; valpos = i + 1; for (i++; i < 512; i++) { /* don't accept : without CR because there's a bug below: i-valpos must be > 0 which is not the case if the : is before the third character. */ if(header[i] == 13/*||header[i]==':'*/) /* 0x0d = carriage return */ { if(header[i] == ':') /* : indicates another variable, CR was missing! */ { i -= 2; } strncpy(val, &header[valpos], (size_t)(i - valpos)); val[i - valpos] = '\0'; set_dst_variable(pattern, var, val); break; } } } } while(fread(b, 1, 3, file) == 3) { int x = 0; int y = 0; if(b[0] & 0x01) x += 1; if(b[0] & 0x02) x -= 1; if(b[0] & 0x04) x += 9; if(b[0] & 0x08) x -= 9; if(b[0] & 0x80) y += 1; if(b[0] & 0x40) y -= 1; if(b[0] & 0x20) y += 9; if(b[0] & 0x10) y -= 9; if(b[1] & 0x01) x += 3; if(b[1] & 0x02) x -= 3; if(b[1] & 0x04) x += 27; if(b[1] & 0x08) x -= 27; if(b[1] & 0x80) y += 3; if(b[1] & 0x40) y -= 3; if(b[1] & 0x20) y += 27; if(b[1] & 0x10) y -= 27; if(b[2] & 0x04) x += 81; if(b[2] & 0x08) x -= 81; if(b[2] & 0x20) y += 81; if(b[2] & 0x10) y -= 81; flags = decode_record_flags(b[2]); if(flags == END) { break; } thisJump = flags & JUMP; if(prevJump) { flags |= JUMP; } embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, flags, 1); prevJump = thisJump; } fclose(file); embPattern_addStitchRel(pattern, 0, 0, END, 1); /* combineJumpStitches(pattern, 5); */ 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; }
/*! 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 readT01(EmbPattern* pattern, const char* fileName) { unsigned char b[3]; EmbFile* file = 0; if(!pattern) { embLog_error("format-t01.c readt01(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-t01.c readt01(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-t01.c readt01(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); while(embFile_read(b, 1, 3, file) == 3) { int flags; int x = 0; int y = 0; if(b[0] & 0x01) x += 1; if(b[0] & 0x02) x -= 1; if(b[0] & 0x04) x += 9; if(b[0] & 0x08) x -= 9; if(b[0] & 0x80) y += 1; if(b[0] & 0x40) y -= 1; if(b[0] & 0x20) y += 9; if(b[0] & 0x10) y -= 9; if(b[1] & 0x01) x += 3; if(b[1] & 0x02) x -= 3; if(b[1] & 0x04) x += 27; if(b[1] & 0x08) x -= 27; if(b[1] & 0x80) y += 3; if(b[1] & 0x40) y -= 3; if(b[1] & 0x20) y += 27; if(b[1] & 0x10) y -= 27; if(b[2] & 0x04) x += 81; if(b[2] & 0x08) x -= 81; if(b[2] & 0x20) y += 81; if(b[2] & 0x10) y -= 81; flags = decodeRecordFlags(b[2]); embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, flags, 1); if(flags == END) break; } 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); 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 readEmd(EmbPattern* pattern, const char* fileName) { unsigned char b0 = 0, b1 = 0; char dx = 0, dy = 0; int flags = EM_NORMAL; char endOfStream = 0; unsigned char jemd0[6]; /* TODO: more descriptive name */ int width, height, colors; int i; EmbFile* file = 0; if(!pattern) { embLog_error("format-emd.c readEmd(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-emd.c readEmd(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-emd.c readEmd(), cannot open %s for reading\n", fileName); return 0; } embPattern_loadExternalColorFile(pattern, fileName); binaryReadBytes(file, jemd0, 6); /* TODO: check return value */ width = binaryReadInt16(file); height = binaryReadInt16(file); colors = binaryReadInt16(file); embFile_seek(file, 0x30, SEEK_SET); for(i = 0; !endOfStream; i++) { flags = EM_NORMAL; b0 = binaryReadUInt8(file); b1 = binaryReadUInt8(file); if(b0 == 0x80) { if(b1 == 0x2A) { embPattern_addStitchRel(pattern, 0, 0, STOP, 1); continue; } else if(b1 == 0x80) { b0 = binaryReadUInt8(file); b1 = binaryReadUInt8(file); flags = TRIM; } else if(b1 == 0xFD) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } else { continue; } } dx = emdDecode(b0); dy = emdDecode(b1); embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 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); 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 readPcs(EmbPattern* pattern, const char* fileName) { char allZeroColor = 1; int i = 0; unsigned char b[9]; double dx = 0, dy = 0; int flags = 0, st = 0; unsigned char version, hoopSize; unsigned short colorCount; EmbFile* file = 0; if(!pattern) { embLog_error("format-pcs.c readPcs(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-pcs.c readPcs(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-pcs.c readPcs(), cannot open %s for reading\n", fileName); return 0; } version = binaryReadByte(file); hoopSize = binaryReadByte(file); /* 0 for PCD, 1 for PCQ (MAXI), 2 for PCS with small hoop(80x80), */ /* and 3 for PCS with large hoop (115x120) */ switch(hoopSize) { case 2: pattern->hoop.width = 80.0; pattern->hoop.height = 80.0; break; case 3: pattern->hoop.width = 115; pattern->hoop.height = 120.0; break; } colorCount = binaryReadUInt16(file); for(i = 0; i < colorCount; i++) { EmbThread t; t.color.r = binaryReadByte(file); t.color.g = binaryReadByte(file); t.color.b = binaryReadByte(file); t.catalogNumber = ""; t.description = ""; if(t.color.r || t.color.g || t.color.b) { allZeroColor = 0; } embPattern_addThread(pattern, t); binaryReadByte(file); } if(allZeroColor) embPattern_loadExternalColorFile(pattern, fileName); st = binaryReadUInt16(file); /* READ STITCH RECORDS */ for(i = 0; i < st; i++) { flags = NORMAL; if(embFile_read(b, 1, 9, file) != 9) break; if(b[8] & 0x01) { flags = STOP; } else if(b[8] & 0x04) { flags = TRIM; } else if(b[8] != 0) { /* TODO: ONLY INTERESTED IN THIS CASE TO LEARN MORE ABOUT THE FORMAT */ } dx = pcsDecode(b[1], b[2], b[3]); dy = pcsDecode(b[5], b[6], b[7]); embPattern_addStitchAbs(pattern, dx / 10.0, dy / 10.0, flags, 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); return 1; }