Compare commits
2 Commits
84139cae5f
...
14569ad308
| Author | SHA1 | Date | |
|---|---|---|---|
| 14569ad308 | |||
| 8ab69dd403 |
85
imageInput.c
85
imageInput.c
@ -13,6 +13,7 @@
|
||||
//void setupMemory();
|
||||
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, unsigned char *const imageBuffer, unsigned char *const labelBuffer,int const imageCount ,int const amountToRead);
|
||||
unsigned int checkHeaderString(char header[]);
|
||||
|
||||
|
||||
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||
@ -24,17 +25,19 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
FILE *readSource;
|
||||
unsigned int numberOfBytesToRead = 0;
|
||||
const unsigned int amountOfStatusInfoToRead = 1;
|
||||
char headerString[sizeof("__info2_image_file_format__\0")] = "";
|
||||
unsigned int expectedHeader = 0;
|
||||
char headerString[sizeof(FILE_HEADER_STRING)] = "";
|
||||
|
||||
|
||||
/*
|
||||
char curChar = 0;
|
||||
int i = 0;
|
||||
*/
|
||||
|
||||
readSource = fopen(path, "rb");
|
||||
|
||||
if (readSource != NULL)
|
||||
{
|
||||
|
||||
/*
|
||||
// print entire source char by char
|
||||
do
|
||||
{
|
||||
@ -48,22 +51,34 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
i++;
|
||||
} while (curChar != EOF);
|
||||
// print entire source char by char
|
||||
|
||||
*/
|
||||
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->count), &(series->images->width), &(series->images->height), amountOfStatusInfoToRead);
|
||||
|
||||
|
||||
expectedHeader = checkHeaderString(headerString);
|
||||
|
||||
series->images->buffer = calloc((series->count) * numberOfBytesToRead + 1, sizeof(GrayScalePixelType));
|
||||
series->labels = calloc((series->count) + 1, sizeof(&(series->labels)));
|
||||
|
||||
if (expectedHeader)
|
||||
{
|
||||
//printf("%d\n", series->images[0].width);
|
||||
// series->images[1].width is not being set
|
||||
// implement setting several amoundt of status info
|
||||
// for when several images are bing read
|
||||
// also adjust amoung of memory allocated for
|
||||
// staus info based on the number of images to be read
|
||||
//printf("%d\n", series->images[1].width);
|
||||
readImagedata(readSource, series->images->buffer, series->labels, series->count, numberOfBytesToRead);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("unexpected header!\n");
|
||||
}
|
||||
|
||||
series->images->buffer = calloc((series->count) * numberOfBytesToRead, sizeof(GrayScalePixelType));
|
||||
series->labels = calloc((series->count), sizeof(&(series->labels)));
|
||||
printf("%d\n", series->images[0].width);
|
||||
// series->images[1].width is not being set
|
||||
// implement setting several amoundt of status info
|
||||
// for when several images are bing read
|
||||
// also adjust amoung of memory allocated for
|
||||
// staus info based on the number of images to be read
|
||||
printf("%d\n", series->images[1].width);
|
||||
readImagedata(readSource, series->images->buffer, series->labels, series->count, numberOfBytesToRead);
|
||||
|
||||
fclose(readSource);
|
||||
}
|
||||
@ -76,20 +91,24 @@ void clearSeries(GrayScaleImageSeries *series)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
||||
// Write NULL into all memory spaces
|
||||
|
||||
// this first for loop does not work
|
||||
/*
|
||||
for (i = 0; i < ((series->count) * (series->images->width) * (series->images->height)); i++)
|
||||
{
|
||||
{
|
||||
*(series->images->buffer + i * (series->images->width) * (series->images->height)) = '\0';
|
||||
}
|
||||
*/
|
||||
|
||||
for (i = 0; i < (series->count); i++)
|
||||
{
|
||||
*(series->labels + i) = '\0';
|
||||
}
|
||||
|
||||
series->count = 0;
|
||||
series->images->width = 0;
|
||||
series->images->height = 0;
|
||||
|
||||
// Closse all allocated memory
|
||||
// AND write NULL into every pointer
|
||||
// so they can't be accessed
|
||||
@ -110,17 +129,18 @@ unsigned int readStatusInfo(FILE *source, char *const headerString, unsigned int
|
||||
{
|
||||
unsigned int bytesToRead = 0;
|
||||
|
||||
/*
|
||||
int numred = 0;
|
||||
int numred2 = 0;
|
||||
int numred3 = 0;
|
||||
int numred4 = 0;
|
||||
|
||||
*/
|
||||
|
||||
//unsigned int imageCountBuffer = 0;
|
||||
numred = fread(headerString, 27, 1, source);
|
||||
numred2 = fread(imageCount, 2, 1, source);
|
||||
numred3 = fread(imageWidth, 2, 1, source);
|
||||
numred4 = fread(imageHeight, 2, 1, source);
|
||||
/*numred =*/ fread(headerString, 27, 1, source);
|
||||
/*numred2 =*/ fread(imageCount, 2, 1, source);
|
||||
/*numred3 =*/ fread(imageWidth, 2, 1, source);
|
||||
/*numred4 =*/ fread(imageHeight, 2, 1, source);
|
||||
|
||||
bytesToRead = (*imageWidth) * (*imageHeight);
|
||||
/*
|
||||
@ -150,3 +170,22 @@ void readImagedata(FILE *source, unsigned char *const imageBuffer, unsigned char
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int checkHeaderString(char header[])
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
printf("header identical? %d\n", !notIdenticall);
|
||||
|
||||
return !notIdenticall;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user