static vp3Hoop vp3ReadHoopSection(FILE* file) { vp3Hoop hoop; hoop.right = binaryReadInt32BE(file); hoop.bottom = binaryReadInt32BE(file); hoop.left = binaryReadInt32BE(file); hoop.top = binaryReadInt32BE(file); hoop.unknown1 = binaryReadInt32BE(file); hoop.unknown2 = binaryReadInt32BE(file); hoop.unknown3 = binaryReadInt32BE(file); hoop.numberOfBytesRemaining = binaryReadInt32BE(file); hoop.xOffset = binaryReadInt32BE(file); hoop.yOffset = binaryReadInt32BE(file); hoop.byte1 = binaryReadByte(file); hoop.byte2 = binaryReadByte(file); hoop.byte3 = binaryReadByte(file); /* Centered hoop dimensions */ hoop.right2 = binaryReadInt32BE(file); hoop.left2 = binaryReadInt32BE(file); hoop.bottom2 = binaryReadInt32BE(file); hoop.top2 = binaryReadInt32BE(file); hoop.width = binaryReadInt32BE(file); hoop.height = binaryReadInt32BE(file); return hoop; }
bcf_directory_entry* CompoundFileDirectoryEntry(FILE* file) { bcf_directory_entry* dir = (bcf_directory_entry*)malloc(sizeof(bcf_directory_entry)); if(!dir) { embLog_error("compound-file-directory.c CompoundFileDirectoryEntry(), cannot allocate memory for dir\n"); } /* TODO: avoid crashing. null pointer will be accessed */ memset(dir->directoryEntryName, 0, 32); parseDirectoryEntryName(file, dir); dir->next = 0; dir->directoryEntryNameLength = binaryReadUInt16(file); dir->objectType = (unsigned char)binaryReadByte(file); if( (dir->objectType != ObjectTypeStorage) && (dir->objectType != ObjectTypeStream) && (dir->objectType != ObjectTypeRootEntry)) { embLog_error("compound-file-directory.c CompoundFileDirectoryEntry(), unexpected object type: %d\n", dir->objectType); return 0; } dir->colorFlag = (unsigned char)binaryReadByte(file); dir->leftSiblingId = binaryReadUInt32(file); dir->rightSiblingId = binaryReadUInt32(file); dir->childId = binaryReadUInt32(file); readCLSID(file, dir); dir->stateBits = binaryReadUInt32(file); dir->creationTime = parseTime(file); dir->modifiedTime = parseTime(file); dir->startingSectorLocation = binaryReadUInt32(file); dir->streamSize = binaryReadUInt32(file); /* This should really be __int64 or long long, but for our uses we should never run into an issue */ dir->streamSizeHigh = binaryReadUInt32(file); /* top portion of int64 */ return dir; }
static vp3Hoop vp3ReadHoopSection(FILE* file) { vp3Hoop hoop; if(!file) { embLog_error("format-vp3.c vp3ReadHoopSection(), file argument is null\n"); return hoop; } hoop.right = binaryReadInt32BE(file); hoop.bottom = binaryReadInt32BE(file); hoop.left = binaryReadInt32BE(file); hoop.top = binaryReadInt32BE(file); hoop.unknown1 = binaryReadInt32BE(file); hoop.unknown2 = binaryReadInt32BE(file); hoop.unknown3 = binaryReadInt32BE(file); hoop.numberOfBytesRemaining = binaryReadInt32BE(file); hoop.xOffset = binaryReadInt32BE(file); hoop.yOffset = binaryReadInt32BE(file); hoop.byte1 = binaryReadByte(file); hoop.byte2 = binaryReadByte(file); hoop.byte3 = binaryReadByte(file); /* Centered hoop dimensions */ hoop.right2 = binaryReadInt32BE(file); hoop.left2 = binaryReadInt32BE(file); hoop.bottom2 = binaryReadInt32BE(file); hoop.top2 = binaryReadInt32BE(file); hoop.width = binaryReadInt32BE(file); hoop.height = binaryReadInt32BE(file); return hoop; }
static vp3Hoop vp3ReadHoopSection(EmbFile* file) { vp3Hoop hoop; if(!file) { embLog_error("format-vp3.c vp3ReadHoopSection(), file argument is null\n"); return hoop; } hoop.right = binaryReadInt32BE(file); hoop.bottom = binaryReadInt32BE(file); hoop.left = binaryReadInt32BE(file); hoop.top = binaryReadInt32BE(file); hoop.threadLength = binaryReadInt32(file); /* yes, it seems this is _not_ big endian */ hoop.unknown2 = binaryReadByte(file); hoop.numberOfColors = binaryReadByte(file); hoop.unknown3 = binaryReadInt16BE(file); hoop.unknown4 = binaryReadInt32BE(file); hoop.numberOfBytesRemaining = binaryReadInt32BE(file); hoop.xOffset = binaryReadInt32BE(file); hoop.yOffset = binaryReadInt32BE(file); hoop.byte1 = binaryReadByte(file); hoop.byte2 = binaryReadByte(file); hoop.byte3 = binaryReadByte(file); /* Centered hoop dimensions */ hoop.right2 = binaryReadInt32BE(file); hoop.left2 = binaryReadInt32BE(file); hoop.bottom2 = binaryReadInt32BE(file); hoop.top2 = binaryReadInt32BE(file); hoop.width = binaryReadInt32BE(file); hoop.height = binaryReadInt32BE(file); return hoop; }
static void ofmReadBlockHeader(EmbFile* file) { int val1, val2, val3, val4, val5, val6, val7, val8, val9, val10; /* TODO: determine what these represent */ unsigned char len; char* s = 0; unsigned short short1; short unknown1 = 0; /* TODO: determine what this represents */ short unknown2 = 0; /* TODO: determine what this represents */ int unknown3 = 0; /* TODO: determine what this represents */ if(!file) { embLog_error("format-ofm.c ofmReadBlockHeader(), file argument is null\n"); return; } unknown1 = binaryReadInt16(file); unknown2 = (short)binaryReadInt32(file); unknown3 = binaryReadInt32(file); /* int v = binaryReadBytes(3); TODO: review */ binaryReadInt16(file); binaryReadByte(file); len = binaryReadByte(file); s = (char*)malloc(2 * len); if(!s) { embLog_error("format-ofm.c ofmReadBlockHeader(), unable to allocate memory for s\n"); return; } binaryReadBytes(file, (unsigned char *)s, 2 * len); /* TODO: check return value */ val1 = binaryReadInt32(file); /* 0 */ val2 = binaryReadInt32(file); /* 0 */ val3 = binaryReadInt32(file); /* 0 */ val4 = binaryReadInt32(file); /* 0 */ val5 = binaryReadInt32(file); /* 1 */ val6 = binaryReadInt32(file); /* 1 */ val7 = binaryReadInt32(file); /* 1 */ val8 = binaryReadInt32(file); /* 0 */ val9 = binaryReadInt32(file); /* 64 */ val10 = binaryReadInt32(file); /* 64 */ short1 = binaryReadInt16(file); /* 0 */ }
static void ofmReadBlockHeader(FILE* file) { int val1, val2, val3, val4, val5, val6, val7, val8, val9, val10; unsigned char len; char* s = 0; unsigned short short1; short unknown1 = binaryReadInt16(file); short unknown2 = (short)binaryReadInt32(file); int unknown3 = binaryReadInt32(file); /* int v = binaryReadBytes(3); TODO: review */ binaryReadInt16(file); binaryReadByte(file); len = binaryReadByte(file); s = (char*)malloc(2 * len); if(!s) { embLog_error("format-ofm.c ofmReadBlockHeader(), unable to allocate memory for s\n"); return; } binaryReadBytes(file, (unsigned char *)s, 2 * len); val1 = binaryReadInt32(file); /* 0 */ val2 = binaryReadInt32(file); /* 0 */ val3 = binaryReadInt32(file); /* 0 */ val4 = binaryReadInt32(file); /* 0 */ val5 = binaryReadInt32(file); /* 1 */ val6 = binaryReadInt32(file); /* 1 */ val7 = binaryReadInt32(file); /* 1 */ val8 = binaryReadInt32(file); /* 0 */ val9 = binaryReadInt32(file); /* 64 */ val10 = binaryReadInt32(file); /* 64 */ short1 = binaryReadInt16(file); /* 0 */ }
/*! 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 */ }
/*! 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 */ }
/*! 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 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 readInf(EmbPattern* pattern, const char* fileName) { int numberOfColors; int i; FILE* file = 0; if(!pattern) { embLog_error("format-inf.c readInf(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-inf.c readInf(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { /* NOTE: The .inf format is an optional color file. Do not log an error if the file does not exist */ return 0; } binaryReadUInt32BE(file); binaryReadUInt32BE(file); binaryReadUInt32BE(file); numberOfColors = binaryReadUInt32BE(file); embThreadList_free(pattern->threadList); pattern->threadList = 0; pattern->lastThread = 0; for(i = 0; i < numberOfColors; i++) { char colorType[50]; char colorDescription[50]; EmbThread t; binaryReadUInt16(file); binaryReadUInt16(file); t.color.r = binaryReadByte(file); t.color.g = binaryReadByte(file); t.color.b = binaryReadByte(file); t.catalogNumber = ""; t.description = ""; embPattern_addThread(pattern, t); binaryReadUInt16(file); binaryReadString(file, colorType, 50); binaryReadString(file, colorDescription, 50); } fclose(file); return 1; }
static void readCLSID(FILE* file, bcf_directory_entry* dir) { int i; unsigned char scratch; const int guidSize = 16; for(i = 0; i < guidSize; ++i) { scratch = binaryReadByte(file); dir->CLSID[i] = scratch; } }
/*! 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 a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int readRgb(EmbPattern* pattern, const char* fileName) { int i, numberOfColors; FILE* file = 0; if(!pattern) { embLog_error("format-rgb.c readRgb(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-rgb.c readRgb(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { /* NOTE: The .rgb format is an optional color file. Do not log an error if the file does not exist */ return 0; } fseek(file, 0x00, SEEK_END); numberOfColors = ftell(file) / 4; embThreadList_free(pattern->threadList); pattern->threadList = 0; pattern->lastThread = 0; fseek(file, 0x00, SEEK_SET); for(i = 0; i < numberOfColors; i++) { EmbThread t; t.color.r = binaryReadByte(file); t.color.g = binaryReadByte(file); t.color.b = binaryReadByte(file); binaryReadByte(file); embPattern_addThread(pattern, t); } fclose(file); return 1; }
static char* ofmReadLibrary(FILE* file) { int stringLength = 0; char* libraryName = 0; /* FF FE FF */ unsigned char leadin[3]; binaryReadBytes(file, leadin, 3); stringLength = binaryReadByte(file); libraryName = (char*)malloc(sizeof(char) * stringLength * 2); if(!libraryName) { embLog_error("format-ofm.c ofmReadLibrary(), unable to allocate memory for libraryName\n"); return 0; } binaryReadBytes(file, (unsigned char*)libraryName, stringLength * 2); return libraryName; }
static void ofmReadThreads(EmbFile* file, EmbPattern* p) { int i, numberOfColors, stringLen, numberOfLibraries; char* primaryLibraryName = 0; char* expandedString = 0; if(!file) { embLog_error("format-ofm.c ofmReadThreads(), file argument is null\n"); return; } if(!p) { embLog_error("format-ofm.c ofmReadThreads(), p argument is null\n"); return; } /* FF FE FF 00 */ binaryReadInt32(file); numberOfColors = binaryReadInt16(file); binaryReadInt16(file); binaryReadInt16(file); stringLen = binaryReadInt16(file); expandedString = (char*)malloc(stringLen); if(!expandedString) { embLog_error("format-ofm.c ofmReadThreads(), unable to allocate memory for expandedString\n"); return; } binaryReadBytes(file, (unsigned char*)expandedString, stringLen); /* TODO: check return value */ for(i = 0; i < numberOfColors; i++) { EmbThread thread; char colorNumberText[10]; int threadLibrary = 0, colorNameLength, colorNumber; char* colorName = 0; int r = binaryReadByte(file); int g = binaryReadByte(file); int b = binaryReadByte(file); binaryReadByte(file); threadLibrary = binaryReadInt16(file); binaryReadInt16(file); colorNumber = binaryReadInt32(file); binaryReadByte(file); binaryReadInt16(file); colorNameLength = binaryReadByte(file); colorName = (char*)malloc(colorNameLength * 2); if(!colorName) { embLog_error("format-ofm.c ofmReadThreads(), unable to allocate memory for colorName\n"); return; } binaryReadBytes(file, (unsigned char*)colorName, colorNameLength*2); /* TODO: check return value */ binaryReadInt16(file); /* itoa(colorNumber, colorNumberText, 10); TODO: never use itoa, it's non-standard, use sprintf: http://stackoverflow.com/questions/5242524/converting-int-to-string-in-c */ thread.color.r = (unsigned char)r; thread.color.g = (unsigned char)g; thread.color.b = (unsigned char)b; thread.catalogNumber = colorNumberText; thread.description = colorName; embPattern_addThread(p, thread); } binaryReadInt16(file); primaryLibraryName = ofmReadLibrary(file); numberOfLibraries = binaryReadInt16(file); for(i = 0; i < numberOfLibraries; i++) { /*libraries.Add( TODO: review */ char* libName = ofmReadLibrary(file); free(libName); libName = 0; } }
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 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; }
static char* ofmReadLibrary(EmbFile* file) { int stringLength = 0; char* libraryName = 0; /* FF FE FF */ unsigned char leadIn[3]; if(!file) { embLog_error("format-ofm.c ofmReadLibrary(), file argument is null\n"); return 0; } binaryReadBytes(file, leadIn, 3); /* TODO: check return value */ stringLength = binaryReadByte(file); libraryName = (char*)malloc(sizeof(char) * stringLength * 2); if(!libraryName) { embLog_error("format-ofm.c ofmReadLibrary(), unable to allocate memory for libraryName\n"); return 0; } binaryReadBytes(file, (unsigned char*)libraryName, stringLength * 2); /* TODO: check return value */ return libraryName; }
/*! 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* 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 readVip(EmbPattern* pattern, const char* fileName) { int fileLength; int i; unsigned char prevByte = 0; unsigned char *attributeData = 0, *decodedColors = 0, *attributeDataDecompressed = 0; unsigned char *xData = 0, *xDecompressed = 0, *yData = 0, *yDecompressed = 0; VipHeader header; EmbFile* file = 0; if(!pattern) { embLog_error("format-vip.c readVip(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-vip.c readVip(), fileName argument is null\n"); return 0; } file = embFile_open(fileName, "rb"); if(!file) { embLog_error("format-vip.c readVip(), cannot open %s for reading\n", fileName); return 0; } embFile_seek(file, 0x0, SEEK_END); fileLength = embFile_tell(file); embFile_seek(file, 0x00, SEEK_SET); header.magicCode = binaryReadInt32(file); header.numberOfStitches = binaryReadInt32(file); header.numberOfColors = binaryReadInt32(file); header.postitiveXHoopSize = binaryReadInt16(file); header.postitiveYHoopSize = binaryReadInt16(file); header.negativeXHoopSize = binaryReadInt16(file); header.negativeYHoopSize = binaryReadInt16(file); header.attributeOffset = binaryReadInt32(file); header.xOffset = binaryReadInt32(file); header.yOffset = binaryReadInt32(file); /*stringVal = (unsigned char*)malloc(sizeof(unsigned char)*8); TODO: review this and uncomment or remove if(!stringVal) { embLog_error("format-vip.c readVip(), cannot allocate memory for stringVal\n"); return 0; } */ binaryReadBytes(file, header.stringVal, 8); /* TODO: check return value */ header.unknown = binaryReadInt16(file); header.colorLength = binaryReadInt32(file); decodedColors = (unsigned char*)malloc(header.numberOfColors*4); if(!decodedColors) { embLog_error("format-vip.c readVip(), cannot allocate memory for decodedColors\n"); return 0; } for(i = 0; i < header.numberOfColors*4; ++i) { unsigned char inputByte = binaryReadByte(file); unsigned char tmpByte = (unsigned char) (inputByte ^ vipDecodingTable[i]); decodedColors[i] = (unsigned char) (tmpByte ^ prevByte); prevByte = inputByte; } for(i = 0; i < header.numberOfColors; i++) { EmbThread thread; int startIndex = i << 2; thread.color.r = decodedColors[startIndex]; thread.color.g = decodedColors[startIndex + 1]; thread.color.b = decodedColors[startIndex + 2]; /* printf("%d\n", decodedColors[startIndex + 3]); */ embPattern_addThread(pattern, thread); } embFile_seek(file, header.attributeOffset, SEEK_SET); attributeData = (unsigned char*)malloc(header.xOffset - header.attributeOffset); if(!attributeData) { embLog_error("format-vip.c readVip(), cannot allocate memory for attributeData\n"); return 0; } binaryReadBytes(file, attributeData, header.xOffset - header.attributeOffset); /* TODO: check return value */ attributeDataDecompressed = vipDecompressData(attributeData, header.xOffset - header.attributeOffset, header.numberOfStitches); embFile_seek(file, header.xOffset, SEEK_SET); xData = (unsigned char*)malloc(header.yOffset - header.xOffset); if(!xData) { embLog_error("format-vip.c readVip(), cannot allocate memory for xData\n"); return 0; } binaryReadBytes(file, xData, header.yOffset - header.xOffset); /* TODO: check return value */ xDecompressed = vipDecompressData(xData, header.yOffset - header.xOffset, header.numberOfStitches); embFile_seek(file, header.yOffset, SEEK_SET); yData = (unsigned char*)malloc(fileLength - header.yOffset); if(!yData) { embLog_error("format-vip.c readVip(), cannot allocate memory for yData\n"); return 0; } binaryReadBytes(file, yData, fileLength - header.yOffset); /* TODO: check return value */ yDecompressed = vipDecompressData(yData, fileLength - header.yOffset, header.numberOfStitches); for(i = 0; i < header.numberOfStitches; i++) { embPattern_addStitchRel(pattern, vipDecodeByte(xDecompressed[i]) / 10.0, vipDecodeByte(yDecompressed[i]) / 10.0, vipDecodeStitchType(attributeDataDecompressed[i]), 1); } embPattern_addStitchRel(pattern, 0, 0, END, 1); embFile_close(file); free(attributeData); attributeData = 0; free(xData); xData = 0; free(yData); yData = 0; free(attributeDataDecompressed); attributeDataDecompressed = 0; free(xDecompressed); xDecompressed = 0; free(yDecompressed); yDecompressed = 0; 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 readJef(EmbPattern* pattern, const char* fileName) { int stitchOffset, formatFlags, numberOfColors, numberOfStitchs; int hoopSize, i; struct hoop_padding bounds, rectFrom110x110, rectFrom50x50, rectFrom200x140, rect_from_custom; int stitchCount; char date[8], time[8]; char dx, dy; FILE* file = 0; if(!pattern) { embLog_error("format-jef.c readJef(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-jef.c readJef(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-jef.c readJef(), cannot open %s for reading\n", fileName); return 0; } stitchOffset = binaryReadInt32(file); formatFlags = binaryReadInt32(file); /* TODO: find out what this means */ binaryReadBytes(file, (unsigned char*) date, 8); binaryReadBytes(file, (unsigned char*) time, 8); numberOfColors = binaryReadInt32(file); numberOfStitchs = binaryReadInt32(file); hoopSize = binaryReadInt32(file); jefSetHoopFromId(pattern, hoopSize); bounds.left = binaryReadInt32(file); bounds.top = binaryReadInt32(file); bounds.right = binaryReadInt32(file); bounds.bottom = binaryReadInt32(file); rectFrom110x110.left = binaryReadInt32(file); rectFrom110x110.top = binaryReadInt32(file); rectFrom110x110.right = binaryReadInt32(file); rectFrom110x110.bottom = binaryReadInt32(file); rectFrom50x50.left = binaryReadInt32(file); rectFrom50x50.top = binaryReadInt32(file); rectFrom50x50.right = binaryReadInt32(file); rectFrom50x50.bottom = binaryReadInt32(file); rectFrom200x140.left = binaryReadInt32(file); rectFrom200x140.top = binaryReadInt32(file); rectFrom200x140.right = binaryReadInt32(file); rectFrom200x140.bottom = binaryReadInt32(file); rect_from_custom.left = binaryReadInt32(file); rect_from_custom.top = binaryReadInt32(file); rect_from_custom.right = binaryReadInt32(file); rect_from_custom.bottom = binaryReadInt32(file); for(i = 0; i < numberOfColors; i++) { embPattern_addThread(pattern, jefThreads[binaryReadInt32(file) % 79]); } fseek(file, stitchOffset, SEEK_SET); stitchCount = 0; while(stitchCount < numberOfStitchs + 100) { int flags = NORMAL; unsigned char b0 = binaryReadByte(file); unsigned char b1 = binaryReadByte(file); if(b0 == 0x80) { if(b1 & 0x01) { b0 = binaryReadByte(file); b1 = binaryReadByte(file); flags = STOP; } else if(b1 == 0x02 || b1 == 0x04) { b0 = binaryReadByte(file); b1 = binaryReadByte(file); flags = TRIM; } else if(b1 == 0x10) { embPattern_addStitchRel(pattern, 0, 0, END, 1); break; } } dx = (char)b0; dy = (char)b1; embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 1); stitchCount++; } 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 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; }
/*! 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; }
int readXxx(EmbPattern* pattern, const char* fileName) { FILE* file = 0; unsigned char b0, b1; int dx = 0, dy = 0; int flags; char endOfStream = 0; int numberOfColors; int paletteOffset; int i; char thisStitchJump = 0; EmbStitchList* lastStitch; EmbStitchList* secondLast = 0; if(!pattern) { embLog_error("format-xxx.c readXxx(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-xxx.c readXxx(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-xxx.c readXxx(), cannot open %s for reading\n", fileName); return 0; } fseek(file, 0x27, SEEK_SET); numberOfColors = binaryReadInt16(file); fseek(file, 0xFC, SEEK_SET); paletteOffset = binaryReadInt32(file); fseek(file, paletteOffset + 6, SEEK_SET); for(i = 0; i < numberOfColors; i++) { EmbThread thread; binaryReadByte(file); thread.color.r = binaryReadByte(file); thread.color.g = binaryReadByte(file); thread.color.b = binaryReadByte(file); embPattern_addThread(pattern, thread); } fseek(file, 0x100, SEEK_SET); for(i = 0; !endOfStream && ftell(file) < paletteOffset; i++) { flags = NORMAL; if(thisStitchJump) flags = TRIM; thisStitchJump = 0; b0 = binaryReadByte(file); b1 = binaryReadByte(file); if(b0 == 0x7E || b0 == 0x7D) /* TODO: ARE THERE OTHER BIG JUMP CODES? */ { dx = b1 + (binaryReadByte(file) << 8); dx = ((short) dx); dy = binaryReadInt16(file); flags = TRIM; } else if(b0 == 0x7F) { if(b1 != 0x17 && b1 != 0x46 && b1 >= 8) /* TODO: LOOKS LIKE THESE CODES ARE IN THE HEADER */ { b0 = 0; b1 = 0; thisStitchJump = 1; flags = STOP; } else if(b1 == 1) { flags = TRIM; b0 = binaryReadByte(file); b1 = binaryReadByte(file); } else { continue; } dx = xxxDecodeByte(b0); dy = xxxDecodeByte(b1); } else { dx = xxxDecodeByte(b0); dy = xxxDecodeByte(b1); } embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 1); } lastStitch = pattern->stitchList; secondLast = 0; if(lastStitch) { while(lastStitch->next) { secondLast = lastStitch; lastStitch=lastStitch->next; } if((!pattern->stitchList) && lastStitch->stitch.flags == STOP && secondLast) { free(lastStitch); secondLast->next = NULL; embPattern_changeColor(pattern, pattern->currentColorIndex - 1); } } embPattern_addStitchRel(pattern, 0, 0, END, 1); fclose(file); 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; }
void readPecStitches(EmbPattern* pattern, EmbFile* file) { int stitchNumber = 0; if(!pattern) { embLog_error("format-pec.c readPecStitches(), pattern argument is null\n"); return; } if(!file) { embLog_error("format-pec.c readPecStitches(), file argument is null\n"); return; } while(!embFile_eof(file)) { int val1 = (int)binaryReadUInt8(file); int val2 = (int)binaryReadUInt8(file); int stitchType = NORMAL; if(val1 == 0xFF && val2 == 0x00) { embPattern_addStitchRel(pattern, 0.0, 0.0, END, 1); break; } if(val1 == 0xFE && val2 == 0xB0) { (void)binaryReadByte(file); embPattern_addStitchRel(pattern, 0.0, 0.0, STOP, 1); stitchNumber++; continue; } /* High bit set means 12-bit offset, otherwise 7-bit signed delta */ if(val1 & 0x80) { if(val1 & 0x20) stitchType = TRIM; if(val1 & 0x10) stitchType = JUMP; val1 = ((val1 & 0x0F) << 8) + val2; /* Signed 12-bit arithmetic */ if(val1 & 0x800) { val1 -= 0x1000; } val2 = binaryReadUInt8(file); } else if(val1 >= 0x40) { val1 -= 0x80; } if(val2 & 0x80) { if(val2 & 0x20) stitchType = TRIM; if(val2 & 0x10) stitchType = JUMP; val2 = ((val2 & 0x0F) << 8) + binaryReadUInt8(file); /* Signed 12-bit arithmetic */ if(val2 & 0x800) { val2 -= 0x1000; } } else if(val2 >= 0x40) { val2 -= 0x80; } embPattern_addStitchRel(pattern, val1 / 10.0, val2 / 10.0, stitchType, 1); stitchNumber++; } }
/*! 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; }