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; }