diff --git a/imageInput.c b/imageInput.c index 691a01e..9be1440 100644 --- a/imageInput.c +++ b/imageInput.c @@ -6,8 +6,6 @@ #define BUFFER_SIZE 100 #define FILE_HEADER_STRING "__info2_image_file_format__" -// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei - int checkString (FILE *file){ //Checks if String at the start of File equals expected Format (0 for wrong 1 for right) if (file == NULL){ //returns 0 for empty file return 0; @@ -32,7 +30,6 @@ int checkString (FILE *file){ //Checks if String at the start of File equals exp void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height); int allocateMemory(GrayScaleImageSeries *series, const int imageCount, const int width, const int height); -// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen GrayScaleImageSeries *readImages(const char *path) @@ -42,7 +39,7 @@ GrayScaleImageSeries *readImages(const char *path) fclose(file); return NULL; } - // TODO open binary file from file name + unsigned int width, height; //uninitialised Variables, will be set by setparamters @@ -62,13 +59,15 @@ GrayScaleImageSeries *readImages(const char *path) for(unsigned int i = 0; i < series->count ; i++){ //Iterating for every image for(unsigned int j = 0; j < width * height; j++){ //Iterating for every pixel fread(&(series->images[i].buffer[j]), sizeof(GrayScalePixelType), 1, file); + printf("Wrote in buffer: %d", series->images[i].buffer[j]); } + fread(&(series->labels[i]), sizeof(unsigned char), 1, file); + printf("Wrote in labels: %d", series->labels[i]); } fclose(file); return series; } -// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt void clearSeries(GrayScaleImageSeries *series) { if (!series) @@ -90,14 +89,12 @@ void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, un char buffer[3]; fseek(file, 27, SEEK_SET); - fread(buffer, 1, 3, file); - if(fread(buffer, 1, 3, file) != 3){ + if(fread(buffer, 1, 3, file) != 3){ // TODO changed some stuff here *imageCount = 0; *width = 0; *height = 0; - - - return;} //Stops if file is too short and clean up + return; + } //Stops if file is too short and clean up *imageCount = (int) buffer[0]; @@ -105,9 +102,6 @@ void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, un *width = (int) buffer[1]; *height = (int) buffer[2]; - // TODO allocate memory for labels array (in imageInput.h) -> Done in allocate Memory - - // TODO read from file and write in 2d arry, write label in labels array, repeat for imageCount -> done in readImages } int allocateMemory(GrayScaleImageSeries *series, const int imageCount, const int width, const int height) { diff --git a/imageInputTests.c b/imageInputTests.c index e8cebdb..1524fc1 100644 --- a/imageInputTests.c +++ b/imageInputTests.c @@ -50,9 +50,7 @@ void test_readImagesReturnsCorrectNumberOfImages(void) TEST_ASSERT_EQUAL_UINT16(expectedNumberOfImages, series->count); clearSeries(series); - printf("Test 1 BP5\n"); remove(path); - printf("Test 1 BP6\n"); } void test_readImagesReturnsCorrectImageWidth(void) @@ -139,7 +137,6 @@ int main() printf("\n============================\nImage input tests\n============================\n"); RUN_TEST(test_readImagesReturnsCorrectNumberOfImages); - printf("BP Check1 complete"); RUN_TEST(test_readImagesReturnsCorrectImageWidth); RUN_TEST(test_readImagesReturnsCorrectImageHeight); RUN_TEST(test_readImagesReturnsCorrectLabels);