int readT09(EmbPattern* pattern, const char* fileName) { unsigned char b[3]; FILE* file = 0; file = fopen(fileName, "rb"); if(!file) { return 0; } fseek(file, 0x0C, SEEK_SET); while(fread(b, 1, 3, file) == 3) { int stitchType = NORMAL; int b1 = b[0]; int b2 = b[1]; unsigned char commandByte = b[2]; if(commandByte == 0x00) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } if (commandByte & 0x10) stitchType = STOP; if (commandByte & 0x20) b1 = -b1; if (commandByte & 0x40) b2 = -b2; embPattern_addStitchRel(pattern, b2 / 10.0, b1 / 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; }
/* TODO: It doesn't appear that this function actually clears the polylineObjList so it is more of a copy than a move. */ void movePolylinesToStitchList(EmbPattern* p) { if(p) { EmbPolylineObjectList* polyList = p->polylineObjList; EmbStitchList* currentList = 0; int firstObject = 1; /*int currentColor = polyList->polylineObj->color TODO: polyline color */ while(polyList) { EmbPolylineObject* currentPoly = polyList->polylineObj; EmbPointList* currentPointList = currentPoly->pointList; EmbThread thread; thread.catalogNumber = 0; thread.color = currentPoly->color; thread.description = 0; embPattern_addThread(p, thread); if(!firstObject) { embPattern_addStitchRel(p, currentPointList->point.xx, currentPointList->point.yy, TRIM, 1); embPattern_addStitchRel(p, 0.0, 0.0, STOP, 1); firstObject = 0; } while(currentPointList) { embPattern_addStitchAbs(p, currentPointList->point.xx, currentPointList->point.yy, NORMAL, 1); currentPointList = currentPointList->next; } polyList = polyList->next; } embPattern_addStitchRel(p, 0.0, 0.0, END, 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 readMit(EmbPattern* pattern, const char* fileName) { unsigned char data[2]; EmbFile* file = 0; if(!pattern) { embLog_error("format-mit.c readMit(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-mit.c readMit(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-mit.c readMit(), cannot open %s for reading\n", fileName); return 0; } /* embPattern_loadExternalColorFile(pattern, fileName); TODO: review this and uncomment or remove it */ while(binaryReadBytes(file, data, 2) == 2) { embPattern_addStitchRel(pattern, mitDecodeStitch(data[0]) / 10.0, mitDecodeStitch(data[1]) / 10.0, NORMAL, 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; }
int readZsk(EmbPattern* pattern, const char* fileName) { int b[3]; FILE* file = fopen(fileName, "rb"); if(file == 0) return 0; fseek(file, 512, SEEK_SET); while(fread(b, 1, 3, file) == 3) { if((b[2] & 25) == 0) { if(b[2] & 0x40) b[1] = -b[1]; if(b[2] & 0x20) b[0] = -b[0]; embPattern_addStitchRel(pattern, b[1] / 10.0, b[0] / 10.0, NORMAL, 1); } else { embPattern_addStitchRel(pattern, b[1] / 10.0, b[0] / 10.0, STOP, 1); } } embPattern_addStitchRel(pattern, 0, 0, END, 1); fclose(file); return 1; }
void embPattern_copyPolylinesToStitchList(EmbPattern* p) { EmbPolylineObjectList* polyList = 0; EmbStitchList* currentList = 0; int firstObject = 1; /*int currentColor = polyList->polylineObj->color TODO: polyline color */ if(!p) { embLog_error("emb-pattern.c embPattern_copyPolylinesToStitchList(), p argument is null\n"); return; } polyList = p->polylineObjList; while(polyList) { EmbPolylineObject* currentPoly = polyList->polylineObj; EmbPointList* currentPointList = currentPoly->pointList; EmbThread thread; thread.catalogNumber = 0; thread.color = currentPoly->color; thread.description = 0; embPattern_addThread(p, thread); if(!firstObject) { embPattern_addStitchRel(p, currentPointList->point.xx, currentPointList->point.yy, TRIM, 1); embPattern_addStitchRel(p, 0.0, 0.0, STOP, 1); firstObject = 0; } while(currentPointList) { embPattern_addStitchAbs(p, currentPointList->point.xx, currentPointList->point.yy, NORMAL, 1); currentPointList = currentPointList->next; } polyList = polyList->next; } embPattern_addStitchRel(p, 0.0, 0.0, END, 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; }
/*! 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; }
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 readOfm(EmbPattern* pattern, const char* fileName) { int unknownCount = 0; int key = 0, classNameLength; char* s = 0; FILE* fileCompound = 0; FILE* file = 0; bcf_file* bcfFile = 0; if(!pattern) { embLog_error("format-ofm.c readOfm(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-ofm.c readOfm(), fileName argument is null\n"); return 0; } fileCompound = fopen(fileName, "rb"); if(!fileCompound) { embLog_error("format-ofm.c readOfm(), cannot open %s for reading\n", fileName); return 0; } bcfFile = (bcf_file*)malloc(sizeof(bcf_file)); if(!bcfFile) { embLog_error("format-ofm.c readOfm(), unable to allocate memory for bcfFile\n"); return 0; } bcfFile_read(fileCompound, bcfFile); file = GetFile(bcfFile, fileCompound, "EdsIV Object"); bcf_file_free(bcfFile); bcfFile = 0; fseek(file, 0x1C6, SEEK_SET); ofmReadThreads(file, pattern); fseek(file, 0x110, SEEK_CUR); binaryReadInt32(file); classNameLength = binaryReadInt16(file); s = (char*)malloc(sizeof(char) * classNameLength); if(!s) { embLog_error("format-ofm.c readOfm(), unable to allocate memory for s\n"); return 0; } binaryReadBytes(file, (unsigned char*)s, classNameLength); unknownCount = binaryReadInt16(file); /* unknown count */ binaryReadInt16(file); key = ofmReadClass(file); while(1) { if(key == 0xFEFF) { break; } if(key == 0x809C) { ofmReadExpanded(file, pattern); } else { ofmReadColorChange(file, pattern); } key = binaryReadUInt16(file); if(key == 0xFFFF) { ofmReadClass(file); } } embPattern_addStitchRel(pattern, 0.0, 0.0, END, 1); return 1; }
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; }
/*! 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 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; }
static void ofmReadColorChange(EmbFile* file, EmbPattern* pattern) { if(!file) { embLog_error("format-ofm.c ofmReadColorChange(), file argument is null\n"); return; } if(!pattern) { embLog_error("format-ofm.c ofmReadColorChange(), pattern argument is null\n"); return; } ofmReadBlockHeader(file); embPattern_addStitchRel(pattern, 0.0, 0.0, STOP, 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 writeExp(EmbPattern* pattern, const char* fileName) { #ifdef ARDUINO /* ARDUINO TODO: This is temporary. Remove when complete. */ return 0; /* ARDUINO TODO: This is temporary. Remove when complete. */ #else /* ARDUINO TODO: This is temporary. Remove when complete. */ EmbFile* file = 0; EmbStitchList* stitches = 0; double dx = 0.0, dy = 0.0; double xx = 0.0, yy = 0.0; int flags = 0; unsigned char b[4]; if(!pattern) { embLog_error("format-exp.c writeExp(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-exp.c writeExp(), fileName argument is null\n"); return 0; } if(!embStitchList_count(pattern->stitchList)) { embLog_error("format-exp.c writeExp(), 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-exp.c writeExp(), cannot open %s for writing\n", fileName); return 0; } /* write stitches */ stitches = pattern->stitchList; while(stitches) { dx = stitches->stitch.xx * 10.0 - xx; dy = stitches->stitch.yy * 10.0 - yy; xx = stitches->stitch.xx * 10.0; yy = stitches->stitch.yy * 10.0; flags = stitches->stitch.flags; expEncode(b, (char)roundDouble(dx), (char)roundDouble(dy), flags); if((b[0] == 128) && ((b[1] == 1) || (b[1] == 2) || (b[1] == 4))) { embFile_printf(file, "%c%c%c%c", b[0], b[1], b[2], b[3]); } else { embFile_printf(file, "%c%c", b[0], b[1]); } stitches = stitches->next; } embFile_printf(file, "\x1a"); embFile_close(file); return 1; #endif /* ARDUINO TODO: This is temporary. Remove when complete. */ }
/*! 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 readKsm(EmbPattern* pattern, const char* fileName) { int prevStitchType = NORMAL; char b[3]; EmbFile* file = 0; if(!pattern) { embLog_error("format-ksm.c readKsm(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-ksm.c readKsm(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-ksm.c readKsm(), cannot open %s for reading\n", fileName); return 0; } embFile_seek(file, 0x200, SEEK_SET); while(embFile_read(b, 1, 3, file) == 3) { int flags = NORMAL; if(((prevStitchType & 0x08) == 0x08) && (b[2] & 0x08) == 0x08) { flags = STOP; } else if((b[2] & 0x1F) != 0) { flags = TRIM; } prevStitchType = b[2]; if(b[2] & 0x40) b[1] = -b[1]; if(b[2] & 0x20) b[0] = -b[0]; embPattern_addStitchRel(pattern, b[1] / 10.0, b[0] / 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 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 readU01(EmbPattern* pattern, const char* fileName) { int fileLength, negativeX = 0, negativeY = 0, flags = NORMAL; char dx, dy; unsigned char data[3]; FILE* file = fopen(fileName, "rb"); if(!file) { return 0; } fseek(file, 0, SEEK_END); fileLength = ftell(file); fseek(file, 0x100, SEEK_SET); while(fread(data, 1, 3, file) == 3) { if(data[0] == 0xF8 || data[0] == 0x87 || data[0] == 0x91) { break; } if((data[0] & 0x0F) == 0) { flags = NORMAL; } else if((data[0] & 0x1f) == 1) { flags = JUMP; } else if((data[0] & 0x0F) > 0) { flags = STOP; } negativeX = ((data[0] & 0x20) > 0); negativeY = ((data[0] & 0x40) > 0); dx = (char) data[2]; dy = (char) data[1]; if(negativeX) dx = (char) -dx; if(negativeY) dy = (char) -dy; embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 1); } embPattern_addStitchRel(pattern, 0.0, 0.0, END, 1); fclose(file); return 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; }
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 */ }
int readMit(EmbPattern* pattern, const char* fileName) { unsigned char data[2]; FILE* file = 0; file = fopen(fileName, "rb"); if(!file) { return 0; } /* embPattern_loadExternalColorFile(pattern, fileName); */ while(binaryReadBytes(file, data, 2) == 2) { embPattern_addStitchRel(pattern, decodeMitStitch(data[0]) / 10.0, decodeMitStitch(data[1]) / 10.0, NORMAL, 1); } embPattern_addStitchRel(pattern, 0.0, 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 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; }
/*! Writes the data from \a pattern to a file with the given \a fileName. * Returns \c true if successful, otherwise returns \c false. */ int writeT01(EmbPattern* pattern, const char* fileName) { EmbRect boundingRect; EmbFile* file = 0; int xx, yy, dx, dy, flags; int co = 1, st = 0; int ax, ay, mx, my; EmbStitchList* pointer = 0; if (!embStitchList_count(pattern->stitchList)) { embLog_error("format-t01.c writeDst(), 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-t01.c writet01(), cannot open %s for writing\n", fileName); return 0; } embPattern_correctForMaxStitchLength(pattern, 12.1, 12.1); xx = yy = 0; co = 1; co = embThreadList_count(pattern->threadList); st = 0; st = embStitchList_count(pattern->stitchList); flags = NORMAL; boundingRect = embPattern_calcBoundingBox(pattern); ax = ay = mx = my = 0; xx = yy = 0; pointer = pattern->stitchList; while (pointer) { /* convert from mm to 0.1mm for file format */ dx = roundDouble(pointer->stitch.xx * 10.0) - xx; dy = roundDouble(pointer->stitch.yy * 10.0) - yy; xx = roundDouble(pointer->stitch.xx * 10.0); yy = roundDouble(pointer->stitch.yy * 10.0); flags = pointer->stitch.flags; encode_record(file, dx, dy, flags); pointer = pointer->next; } embFile_close(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 writeU00(EmbPattern* pattern, const char* fileName) { if(!pattern) { embLog_error("format-u00.c writeU00(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-u00.c writeU00(), fileName argument is null\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); /* TODO: embFile_open() needs to occur here after the check for no stitches */ return 0; /*TODO: finish WriteU00 */ }
/*! 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); }