replaced hardcoded elements with variables and cleaned up Programm
This commit is contained in:
parent
e9d3ddb999
commit
ccfceba21c
59
imageInput.c
59
imageInput.c
@ -7,29 +7,22 @@
|
|||||||
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
||||||
|
|
||||||
|
|
||||||
// Tests passed
|
|
||||||
// Rethink logic
|
|
||||||
// Cleanup Programm
|
|
||||||
// merge with others to test in entirity
|
|
||||||
|
|
||||||
|
|
||||||
// DONE Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
// DONE Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
||||||
unsigned int readStatusInfo(FILE *source, char *const headerString, unsigned int *const imageCount, unsigned int *const imageWidth, unsigned int *const imageHeight, int const amountToRead);
|
unsigned int readStatusInfo (FILE *source, char *const headerString, GrayScaleImageSeries *series, int const sizeToRead, int const amountToRead);
|
||||||
void readImagedata(FILE *source, GrayScaleImageSeries *series, int const amountToRead);
|
void readImagedata (FILE *source, GrayScaleImageSeries *series, int const amountToRead);
|
||||||
unsigned int checkHeaderString(char header[]);
|
unsigned int checkHeaderString (char header[]);
|
||||||
|
|
||||||
|
|
||||||
// DONE Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
// DONE Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||||
GrayScaleImageSeries *readImages(const char *path)
|
GrayScaleImageSeries *readImages(const char *path)
|
||||||
{
|
{
|
||||||
GrayScaleImageSeries *series = NULL;
|
GrayScaleImageSeries *series = NULL;
|
||||||
|
FILE *readSource = 0;
|
||||||
// selbst geschriebene Variablen
|
const unsigned int sizeOfStausInfoElementsInBytes = 2;
|
||||||
FILE *readSource;
|
const unsigned int amountOfStatusInfoToRead = 1;
|
||||||
unsigned int numberOfBytesToRead = 0;
|
unsigned int numberOfBytesToRead = 0;
|
||||||
const unsigned int amountOfStatusInfoToRead = 1;
|
unsigned int expectedHeader = 0;
|
||||||
unsigned int expectedHeader = 0;
|
char headerString[sizeof(FILE_HEADER_STRING)] = "";
|
||||||
char headerString[sizeof(FILE_HEADER_STRING)] = "";
|
|
||||||
|
|
||||||
|
|
||||||
readSource = fopen(path, "rb");
|
readSource = fopen(path, "rb");
|
||||||
@ -39,7 +32,7 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
series = calloc(sizeof(unsigned int) + 3* sizeof(headerString), amountOfStatusInfoToRead);
|
series = calloc(sizeof(unsigned int) + 3* sizeof(headerString), amountOfStatusInfoToRead);
|
||||||
series->images = calloc(2*sizeof(unsigned int) + sizeof(headerString), amountOfStatusInfoToRead);
|
series->images = calloc(2*sizeof(unsigned int) + sizeof(headerString), amountOfStatusInfoToRead);
|
||||||
|
|
||||||
numberOfBytesToRead = readStatusInfo(readSource, headerString, &(series->count), &(series->images->width), &(series->images->height), amountOfStatusInfoToRead);
|
numberOfBytesToRead = readStatusInfo(readSource, headerString, series, sizeOfStausInfoElementsInBytes, amountOfStatusInfoToRead);
|
||||||
|
|
||||||
expectedHeader = checkHeaderString(headerString);
|
expectedHeader = checkHeaderString(headerString);
|
||||||
|
|
||||||
@ -107,19 +100,19 @@ void clearSeries(GrayScaleImageSeries *series)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// reads string, pictureCount, pictureWidth, pictureHight
|
// reads headerString, pictureCount, pictureWidth, pictureHight
|
||||||
unsigned int readStatusInfo(FILE *source, char *const headerString, unsigned int *const imageCount, unsigned int *const imageWidth, unsigned int *const imageHeight, int const amountToRead)
|
unsigned int readStatusInfo(FILE *source, char *const headerString, GrayScaleImageSeries *series, int const sizeToRead, int const amountToRead)
|
||||||
{
|
{
|
||||||
unsigned int bytesToRead = 0;
|
unsigned int bytesToRead = 0;
|
||||||
|
|
||||||
|
|
||||||
//unsigned int imageCountBuffer = 0;
|
fread(headerString, sizeof(FILE_HEADER_STRING) - 1, amountToRead, source);
|
||||||
fread(headerString, 27, 1, source);
|
fread(&(series->count), sizeToRead, amountToRead, source);
|
||||||
fread(imageCount, 2, 1, source);
|
fread(&(series->images->width), sizeToRead, amountToRead, source);
|
||||||
fread(imageWidth, 2, 1, source);
|
fread(&(series->images->height), sizeToRead, amountToRead, source);
|
||||||
fread(imageHeight, 2, 1, source);
|
|
||||||
|
bytesToRead = (series->images->width) * (series->images->height);
|
||||||
|
|
||||||
bytesToRead = (*imageWidth) * (*imageHeight);
|
|
||||||
|
|
||||||
return bytesToRead;
|
return bytesToRead;
|
||||||
}
|
}
|
||||||
@ -130,30 +123,32 @@ void readImagedata(FILE *source, GrayScaleImageSeries *series, int const amount
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < series->count ; i++)
|
for (i = 0; i < series->count ; i++)
|
||||||
{
|
{
|
||||||
fread(&(series->images->buffer[i]), 1, amountOfBytes, source);
|
fread(&(series->images->buffer[i]), sizeof(*series->images->buffer), amountOfBytes, source);
|
||||||
fread(&(series->labels[i]), 1, 1, source);
|
fread(&(series->labels[i]), sizeof(*series->images->buffer), sizeof(*series->labels), source);
|
||||||
printf("label: %x\n", series->labels[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// checks if the read headerString matches the expected headerString
|
||||||
unsigned int checkHeaderString(char header[])
|
unsigned int checkHeaderString(char header[])
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int notIdenticall = 0;
|
int notIdenticall = 0;
|
||||||
char expectedHeader[sizeof(FILE_HEADER_STRING)] = FILE_HEADER_STRING;
|
char expectedHeader[sizeof(FILE_HEADER_STRING)] = FILE_HEADER_STRING;
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < sizeof(FILE_HEADER_STRING); i++)
|
for (i = 0; i < sizeof(FILE_HEADER_STRING); i++)
|
||||||
{
|
{
|
||||||
if (header[i] != expectedHeader[i])
|
if (header[i] != expectedHeader[i])
|
||||||
{
|
{
|
||||||
notIdenticall = 1;
|
notIdenticall = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return !notIdenticall;
|
return !notIdenticall;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user