/*! Moves all of the EmbStitchList data to EmbPolylineObjectList data for pattern (\a p). */ void embPattern_moveStitchListToPolylines(EmbPattern* p) { if(!p) { embLog_error("emb-pattern.c embPattern_moveStitchListToPolylines(), p argument is null\n"); return; } embPattern_copyStitchListToPolylines(p); /* Free the stitchList and threadList since their data has now been transferred to polylines */ embStitchList_free(p->stitchList); p->stitchList = 0; p->lastStitch = 0; embThreadList_free(p->threadList); p->threadList = 0; p->lastThread = 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 readCol(EmbPattern* pattern, const char* fileName) { int numberOfColors, i; FILE* file = 0; if(!pattern) { embLog_error("format-col.c readCol(), pattern argument is null\n"); return 0; } if(!fileName) { embLog_error("format-col.c readCol(), fileName argument is null\n"); return 0; } file = fopen(fileName, "r"); if(!file) { /* NOTE: The .col format is an optional color file. Do not log an error if the file does not exist */ return 0; } embThreadList_free(pattern->threadList); pattern->threadList = 0; pattern->lastThread = 0; /* TODO: replace all scanf code */ if(fscanf(file, "%d\r", &numberOfColors) < 1) /* TODO: needs to work cross-platform - Win: \r\n Mac: \r Linux: \n */ { /* TODO: log error */ return 0; } for(i = 0; i < numberOfColors; i++) { int num, blue, green, red; EmbThread t; char line[30]; /* TODO: replace all scanf code */ if(fscanf(file, "%s\r", line) < 1) /* TODO: needs to work cross-platform - Win: \r\n Mac: \r Linux: \n */ { /* TODO: log error */ return 0; } /* TODO: replace all scanf code */ if(sscanf(line,"%d,%d,%d,%d\n\r", &num, &blue, &green, &red) != 4) /* TODO: needs to work cross-platform - Win: \r\n Mac: \r Linux: \n */ { break; } t.color.r = (unsigned char)red; t.color.g = (unsigned char)green; t.color.b = (unsigned char)blue; t.catalogNumber = ""; t.description = ""; embPattern_addThread(pattern, t); } 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 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; }
/* Frees all memory allocated in the pattern. */ void embPattern_free(EmbPattern* p) { if(!p) { embLog_error("emb-pattern.c embPattern_free(), p argument is null\n"); return; } embStitchList_free(p->stitchList); embThreadList_free(p->threadList); embArcObjectList_free(p->arcObjList); embCircleObjectList_free(p->circleObjList); embEllipseObjectList_free(p->ellipseObjList); embLineObjectList_free(p->lineObjList); /* TODO: embPathObjectList_free(p->pathObjList); */ embPointObjectList_free(p->pointObjList); embPolygonObjectList_free(p->polygonObjList); embPolylineObjectList_free(p->polylineObjList); embRectObjectList_free(p->rectObjList); /* TODO: embSplineObjectList_free(p->splineObjList); */ free(p); p = 0; }
/*! Frees all memory allocated in the pattern (\a p). */ void embPattern_free(EmbPattern* p) { if(!p) { embLog_error("emb-pattern.c embPattern_free(), p argument is null\n"); return; } embStitchList_free(p->stitchList); p->stitchList = 0; p->lastStitch = 0; embThreadList_free(p->threadList); p->threadList = 0; p->lastThread = 0; embArcObjectList_free(p->arcObjList); p->arcObjList = 0; p->lastArcObj = 0; embCircleObjectList_free(p->circleObjList); p->circleObjList = 0; p->lastCircleObj = 0; embEllipseObjectList_free(p->ellipseObjList); p->ellipseObjList = 0; p->lastEllipseObj = 0; embLineObjectList_free(p->lineObjList); p->lineObjList = 0; p->lastLineObj = 0; embPathObjectList_free(p->pathObjList); p->pathObjList = 0; p->lastPathObj = 0; embPointObjectList_free(p->pointObjList); p->pointObjList = 0; p->lastPointObj = 0; embPolygonObjectList_free(p->polygonObjList); p->polygonObjList = 0; p->lastPolygonObj = 0; embPolylineObjectList_free(p->polylineObjList); p->polylineObjList = 0; p->lastPolylineObj = 0; embRectObjectList_free(p->rectObjList); p->rectObjList = 0; p->lastRectObj = 0; /* embSplineObjectList_free(p->splineObjList); p->splineObjList = 0; p->lastSplineObj = 0; TODO: finish this */ free(p); p = 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 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; }