diff --git a/imageInput.c b/imageInput.c index f6ff8b1..a581da5 100644 --- a/imageInput.c +++ b/imageInput.c @@ -8,24 +8,32 @@ // TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei -void helpFunction +static void readPictureData(const char *path,const short ptrPicturesCount, const short ptrPictureWidth, const short ptrPictureHeigth) { - GrayScalePixelType *bufferRead; - GrayScalePixelType *bufferWrite; - bufferRead = fopen(*path, "rb"); - unsigned char header = strlen(FILE_HEADER_STRING); + unsigned int header = strlen(FILE_HEADER_STRING); - bufferWrite = createMatrix(1,header + 3); + FILE *file = fopen(path,"rb"); + if (file == NULL){ + perror("failed open file"); + return; + } - fread(bufferWrite,sizeof(GrayScalePixelType),, bufferRead); + fseek(file, header, SEEK_SET); -pictures = *bufferRead + header; + fread(ptrPicturesCount, sizeof(unsigned short), 1, file); + fread(ptrPictureWidth, sizeof(unsigned short), 1, file); + fread(ptrPictureHeight, sizeof(unsigned short), 1, file); + + fclose(file); } // TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen GrayScaleImageSeries *readImages(const char *path) { + unsigned short picturesCount, pictureWidth, pictureHeight; + Matrix labels = creatmatrix(1,picturesCount); + Matrix images = creatmatrix(1,picturesCount); @@ -37,4 +45,18 @@ GrayScaleImageSeries *readImages(const char *path) // TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt void clearSeries(GrayScaleImageSeries *series) { +} + + MatrixChar createMatrix(unsigned int rows, unsigned int cols) +{ + if(rows <= 0 || cols <= 0){ + Matrix matrix = { 0 , 0 , UNDEFINED_MATRIX_VALUE }; + return matrix; + } + + MatrixChar matrix = { rows , cols }; + + matrix.buffer = malloc((sizeof(char)*rows*cols)); + + return matrix; } \ No newline at end of file diff --git a/imageInput.h b/imageInput.h index 656e213..00872ec 100644 --- a/imageInput.h +++ b/imageInput.h @@ -17,6 +17,12 @@ typedef struct unsigned int count; } GrayScaleImageSeries; +typedef struct{ + unsigned int rows; + unsigned int cols; + MatrixType *buffer; +}MatrixChar; + GrayScaleImageSeries *readImages(const char *path); void clearSeries(GrayScaleImageSeries *series); diff --git a/matrix.c b/matrix.c index 8df1d37..2d33b96 100644 --- a/matrix.c +++ b/matrix.c @@ -114,8 +114,4 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) } return result; -} - - //Für imageInput.c - //size_t fread(void *buffer, size_t elementSize, size_t count, FILE *FILE_HEADER_STRING) - //elementSize = width * height; \ No newline at end of file +} \ No newline at end of file