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__"
|
||||
|
||||
|
||||
// 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
|
||||
unsigned int readStatusInfo(FILE *source, char *const headerString, unsigned int *const imageCount, unsigned int *const imageWidth, unsigned int *const imageHeight, int const amountToRead);
|
||||
void readImagedata(FILE *source, GrayScaleImageSeries *series, int const amountToRead);
|
||||
unsigned int checkHeaderString(char header[]);
|
||||
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);
|
||||
unsigned int checkHeaderString (char header[]);
|
||||
|
||||
|
||||
// DONE Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||
GrayScaleImageSeries *readImages(const char *path)
|
||||
{
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
|
||||
// selbst geschriebene Variablen
|
||||
FILE *readSource;
|
||||
unsigned int numberOfBytesToRead = 0;
|
||||
const unsigned int amountOfStatusInfoToRead = 1;
|
||||
unsigned int expectedHeader = 0;
|
||||
char headerString[sizeof(FILE_HEADER_STRING)] = "";
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
FILE *readSource = 0;
|
||||
const unsigned int sizeOfStausInfoElementsInBytes = 2;
|
||||
const unsigned int amountOfStatusInfoToRead = 1;
|
||||
unsigned int numberOfBytesToRead = 0;
|
||||
unsigned int expectedHeader = 0;
|
||||
char headerString[sizeof(FILE_HEADER_STRING)] = "";
|
||||
|
||||
|
||||
readSource = fopen(path, "rb");
|
||||
@ -39,7 +32,7 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
series = calloc(sizeof(unsigned int) + 3* 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);
|
||||
|
||||
@ -107,19 +100,19 @@ void clearSeries(GrayScaleImageSeries *series)
|
||||
}
|
||||
|
||||
|
||||
// reads string, 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)
|
||||
// reads headerString, pictureCount, pictureWidth, pictureHight
|
||||
unsigned int readStatusInfo(FILE *source, char *const headerString, GrayScaleImageSeries *series, int const sizeToRead, int const amountToRead)
|
||||
{
|
||||
unsigned int bytesToRead = 0;
|
||||
|
||||
|
||||
//unsigned int imageCountBuffer = 0;
|
||||
fread(headerString, 27, 1, source);
|
||||
fread(imageCount, 2, 1, source);
|
||||
fread(imageWidth, 2, 1, source);
|
||||
fread(imageHeight, 2, 1, source);
|
||||
fread(headerString, sizeof(FILE_HEADER_STRING) - 1, amountToRead, source);
|
||||
fread(&(series->count), sizeToRead, amountToRead, source);
|
||||
fread(&(series->images->width), sizeToRead, amountToRead, source);
|
||||
fread(&(series->images->height), sizeToRead, amountToRead, source);
|
||||
|
||||
bytesToRead = (series->images->width) * (series->images->height);
|
||||
|
||||
bytesToRead = (*imageWidth) * (*imageHeight);
|
||||
|
||||
return bytesToRead;
|
||||
}
|
||||
@ -130,30 +123,32 @@ void readImagedata(FILE *source, GrayScaleImageSeries *series, int const amount
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
||||
for (i = 0; i < series->count ; i++)
|
||||
{
|
||||
fread(&(series->images->buffer[i]), 1, amountOfBytes, source);
|
||||
fread(&(series->labels[i]), 1, 1, source);
|
||||
printf("label: %x\n", series->labels[i]);
|
||||
fread(&(series->images->buffer[i]), sizeof(*series->images->buffer), amountOfBytes, source);
|
||||
fread(&(series->labels[i]), sizeof(*series->images->buffer), sizeof(*series->labels), source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// checks if the read headerString matches the expected headerString
|
||||
unsigned int checkHeaderString(char header[])
|
||||
{
|
||||
int i = 0;
|
||||
int notIdenticall = 0;
|
||||
int i = 0;
|
||||
int notIdenticall = 0;
|
||||
char expectedHeader[sizeof(FILE_HEADER_STRING)] = FILE_HEADER_STRING;
|
||||
|
||||
|
||||
for (i = 0; i < sizeof(FILE_HEADER_STRING); i++)
|
||||
{
|
||||
if (header[i] != expectedHeader[i])
|
||||
{
|
||||
notIdenticall = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return !notIdenticall;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user