/*! Reads a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int readVp3(EmbPattern* pattern, const char* fileName) { unsigned char magicString[5]; unsigned char some; unsigned char* someString = 0; unsigned char v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18; unsigned char* unknownString3 = 0; int numberOfColors; long colorSectionOffset; unsigned char magicCode[6]; short someShort; unsigned char someByte; int bytesRemainingInFile; unsigned char* unknownByteString = 0; int hoopConfigurationOffset; unsigned char* unknownString2 = 0; int i; FILE* file = 0; if(!pattern) { embLog_error("format-vp3.c readVp3(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-vp3.c readVp3(), fileName argument is null\n"); return 0; } file = fopen(fileName, "rb"); if(!file) { embLog_error("format-vp3.c readVp3(), cannot open %s for reading\n", fileName); return 0; } binaryReadBytes(file, magicString, 5); /* %vsm% */ some = binaryReadByte(file); /* 0 */ someString = vp3ReadString(file); someShort = binaryReadInt16(file); someByte = binaryReadByte(file); bytesRemainingInFile = binaryReadInt32(file); unknownByteString = vp3ReadString(file); hoopConfigurationOffset =(int) ftell(file); vp3ReadHoopSection(file); unknownString2 = vp3ReadString(file); /* TODO: review v1 thru v18 variables and use emb_unused() if needed */ v1 = binaryReadByte(file); v2 = binaryReadByte(file); v3 = binaryReadByte(file); v4 = binaryReadByte(file); v5 = binaryReadByte(file); v6 = binaryReadByte(file); v7 = binaryReadByte(file); v8 = binaryReadByte(file); v9 = binaryReadByte(file); v10 = binaryReadByte(file); v11 = binaryReadByte(file); v12 = binaryReadByte(file); v13 = binaryReadByte(file); v14 = binaryReadByte(file); v15 = binaryReadByte(file); v16 = binaryReadByte(file); v17 = binaryReadByte(file); v18 = binaryReadByte(file); binaryReadBytes(file, magicCode, 6); /* 0x78 0x78 0x55 0x55 0x01 0x00 */ unknownString3 = vp3ReadString(file); numberOfColors = binaryReadInt16BE(file); colorSectionOffset = (int) ftell(file); for(i = 0; i < numberOfColors; i++) { EmbThread t; char tableSize; int unknownX, unknownY, unknownX2, unknownY2; unsigned char* str1, *str2, *str3; int unknownThreadString, numberOfBytesInColor; fseek(file, 0x03 + colorSectionOffset, SEEK_SET); colorSectionOffset = binaryReadInt32BE(file); colorSectionOffset += ftell(file); unknownX = binaryReadInt32BE(file); unknownY = binaryReadInt32BE(file); /* TODO: review commented section below pattern.embPattern_addStitchAbsolute(-unknownX / 100, -unknownY/ 100, StitchType.Jump, false); fs.Seek(0x08, SeekOrigin.Current); */ tableSize = binaryReadByte(file); binaryReadByte(file); t.color.r = binaryReadByte(file); t.color.g = binaryReadByte(file); t.color.b = binaryReadByte(file); embPattern_addThread(pattern, t); fseek(file, 6*tableSize - 1, SEEK_CUR); str1 = vp3ReadString(file); str2 = vp3ReadString(file); str3 = vp3ReadString(file); unknownX2 = binaryReadInt32BE(file); unknownY2 = binaryReadInt32BE(file); /*fs.Seek(0x02, SeekOrigin.Current); */ unknownThreadString = binaryReadInt16BE(file); fseek(file, unknownThreadString, SEEK_CUR); numberOfBytesInColor = binaryReadInt32BE(file); fseek(file, 0x3, SEEK_CUR); while(ftell(file) < colorSectionOffset - 1) { int x = vp3Decode(binaryReadByte(file)); int y = vp3Decode(binaryReadByte(file)); if(x == 0x80) { switch (y) { case 0x00: case 0x03: break; case 0x01: x = vp3DecodeInt16(binaryReadInt16BE(file)); y = vp3DecodeInt16(binaryReadInt16BE(file)); binaryReadInt16BE(file); embPattern_addStitchRel(pattern, x/ 10.0, y / 10.0, TRIM, 1); break; default: break; } } else { embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, NORMAL, 1); } } if(i + 1 < numberOfColors) embPattern_addStitchRel(pattern, 0, 0, STOP, 1); } fclose(file); /* Check for an END stitch and add one if it is not present */ if(pattern->lastStitch->stitch.flags != END) embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); return 1; }
/*! Reads a file with the given \a fileName and loads the data into \a pattern. * Returns \c true if successful, otherwise returns \c false. */ int 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; }
int readVp3(EmbPattern* pattern, const char* fileName) { unsigned char magicString[5]; unsigned char some; unsigned char* someString = 0; unsigned char v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18; unsigned char* unknownString3 = 0; int numberOfColors; long colorSectionOffset; unsigned char magicCode[6]; short someShort; unsigned char someByte; int bytesRemainingInFile; unsigned char* unknownByteString = 0; int hoopConfigurationOffset; unsigned char* unknownString2 = 0; int i; FILE* file = 0; file = fopen(fileName, "rb"); if(!file) { /*TODO: set messages here "Error opening VP3 file for read:" */ return 0; } binaryReadBytes(file, magicString, 5); /* %vsm% */ some = binaryReadByte(file); /* 0 */ someString = ReadString(file); someShort = binaryReadInt16(file); someByte = binaryReadByte(file); bytesRemainingInFile = binaryReadInt32(file); unknownByteString = ReadString(file); hoopConfigurationOffset =(int) ftell(file); vp3ReadHoopSection(file); unknownString2 = ReadString(file); v1 = binaryReadByte(file); v2 = binaryReadByte(file); v3 = binaryReadByte(file); v4 = binaryReadByte(file); v5 = binaryReadByte(file); v6 = binaryReadByte(file); v7 = binaryReadByte(file); v8 = binaryReadByte(file); v9 = binaryReadByte(file); v10 = binaryReadByte(file); v11 = binaryReadByte(file); v12 = binaryReadByte(file); v13 = binaryReadByte(file); v14 = binaryReadByte(file); v15 = binaryReadByte(file); v16 = binaryReadByte(file); v17 = binaryReadByte(file); v18 = binaryReadByte(file); binaryReadBytes(file, magicCode, 6); /* 0x78 0x78 0x55 0x55 0x01 0x00 */ unknownString3 = ReadString(file); numberOfColors = binaryReadInt16BE(file); colorSectionOffset = (int) ftell(file); for(i = 0; i < numberOfColors; i++) { EmbThread t; char tableSize; int unknownX, unknownY, unknownX2, unknownY2; unsigned char* str1, *str2, *str3; int unknownThreadString, numberOfBytesInColor; fseek(file, 0x03 + colorSectionOffset, SEEK_SET); colorSectionOffset = binaryReadInt32BE(file); colorSectionOffset += ftell(file); unknownX = binaryReadInt32BE(file); unknownY = binaryReadInt32BE(file); /* TODO: review commented section below pattern.embPattern_addStitchAbsolute(-unknownX / 100, -unknownY/ 100, StitchType.Jump, false); fs.Seek(0x08, SeekOrigin.Current); */ tableSize = binaryReadByte(file); t.color.b = binaryReadByte(file); t.color.r = binaryReadByte(file); t.color.g = binaryReadByte(file); embPattern_addThread(pattern, t); fseek(file, 6*tableSize, SEEK_CUR); str1 = ReadString(file); str2 = ReadString(file); str3 = ReadString(file); unknownX2 = binaryReadInt32BE(file); unknownY2 = binaryReadInt32BE(file); /*fs.Seek(0x02, SeekOrigin.Current); */ unknownThreadString = binaryReadInt16BE(file); fseek(file, unknownThreadString, SEEK_CUR); numberOfBytesInColor = binaryReadInt32BE(file); fseek(file, 0x3, SEEK_CUR); while(ftell(file) < colorSectionOffset - 1) { int x = vp3Decode(binaryReadByte(file)); int y = vp3Decode(binaryReadByte(file)); if(x == 0x80) { switch (y) { case 0x00: case 0x03: break; case 0x01: x = vp3DecodeInt16(binaryReadInt16BE(file)); y = vp3DecodeInt16(binaryReadInt16BE(file)); binaryReadInt16BE(file); embPattern_addStitchRel(pattern, x/ 10.0, y / 10.0, TRIM, 1); break; default: break; } } else { embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, NORMAL, 1); } } if(i + 1 < numberOfColors) embPattern_addStitchRel(pattern, 0, 0, STOP, 1); } embPattern_addStitchRel(pattern, 0, 0, END, 1); embPattern_flipVertical(pattern); fclose(file); return 1; }