continued debugging 'readStatusInfo()' in 'imageInput.c' not yet working correctly, see comment
This commit is contained in:
parent
a2c2aae0fb
commit
f403d4ffa8
47
imageInput.c
47
imageInput.c
@ -10,8 +10,9 @@
|
||||
// übersichtlich aufgeteilt werden!
|
||||
|
||||
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
||||
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);
|
||||
//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);
|
||||
|
||||
|
||||
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||
@ -23,20 +24,24 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
FILE *readSource;
|
||||
unsigned int numberOfBytesToRead = 0;
|
||||
const unsigned int amountOfStatusInfoToRead = 1;
|
||||
char headerString[sizeof("__info2_image_file_format__")];
|
||||
char headerString[sizeof("__info2_image_file_format__")] = "__info2_image_file_format__";
|
||||
|
||||
//speicher allocaten weil *series auf null zeigt !!!!!!!!
|
||||
|
||||
readSource = fopen(path, "rb");
|
||||
|
||||
if (readSource != NULL)
|
||||
{
|
||||
printf("hier\n");
|
||||
numberOfBytesToRead = readStatusInfo(&readSource, headerString, &series->count, &series->images->width, &series->images->height, amountOfStatusInfoToRead);
|
||||
|
||||
series = calloc(sizeof(GrayScaleImageSeries), amountOfStatusInfoToRead);
|
||||
series->images = calloc(sizeof(GrayScaleImage), amountOfStatusInfoToRead);
|
||||
|
||||
numberOfBytesToRead = readStatusInfo(readSource, headerString, &(series->count), &(series->images->width), &(series->images->height), amountOfStatusInfoToRead);
|
||||
|
||||
series->images->buffer = calloc((series->count) * numberOfBytesToRead, sizeof(GrayScalePixelType));
|
||||
series->labels = calloc((series->count), sizeof(&(series->labels)));
|
||||
|
||||
readImagedata(&readSource, series->images->buffer, series->labels, series->count, numberOfBytesToRead);
|
||||
readImagedata(readSource, series->images->buffer, series->labels, series->count, numberOfBytesToRead);
|
||||
}
|
||||
|
||||
fclose(readSource);
|
||||
@ -79,29 +84,35 @@ void clearSeries(GrayScaleImageSeries *series)
|
||||
|
||||
|
||||
// reads string, pictureCount, pictureWidth, pictureHight
|
||||
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, unsigned int *const imageCount, unsigned int *const imageWidth, unsigned int *const imageHeight, int const amountToRead)
|
||||
{
|
||||
int bytesToRead = 0;
|
||||
|
||||
fread(headerString, sizeof(*headerString), amountToRead, *source);
|
||||
fread(imageCount, sizeof(*imageCount), amountToRead, *source);
|
||||
fread(imageWidth, sizeof(*imageWidth), amountToRead, *source);
|
||||
fread(imageHeight, sizeof(*imageHeight), amountToRead, *source);
|
||||
|
||||
unsigned int bytesToRead = 0;
|
||||
|
||||
fread(headerString, sizeof(*headerString), amountToRead, source);
|
||||
fread(imageCount, sizeof(*imageCount), amountToRead, source);
|
||||
fread(imageWidth, sizeof(*imageWidth), amountToRead, source);
|
||||
fread(imageHeight, sizeof(*imageHeight), amountToRead, source);
|
||||
|
||||
bytesToRead = (*imageWidth) * (*imageHeight);
|
||||
|
||||
// state of debugging:
|
||||
// stopped here,
|
||||
// read width and height
|
||||
// return nonsensical numbers
|
||||
// is the sizeof() command correct??
|
||||
printf("hier\n");
|
||||
printf("bytes to read = %u", bytesToRead);
|
||||
return bytesToRead;
|
||||
}
|
||||
|
||||
// reads the imagebytes and the label of all images
|
||||
void readImagedata(FILE **source, unsigned char *const imageBuffer, unsigned char *const labelBuffer,int const imageCount , int const amountOfBytes)
|
||||
void readImagedata(FILE *source, unsigned char *const imageBuffer, unsigned char *const labelBuffer,int const imageCount , int const amountOfBytes)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i <= imageCount; i++)
|
||||
{
|
||||
fread((imageBuffer + i * amountOfBytes), sizeof(&(imageBuffer)), amountOfBytes, *source);
|
||||
fread((labelBuffer + i), sizeof(&(labelBuffer)), 1, *source);
|
||||
fread((imageBuffer + i * amountOfBytes), sizeof(&(imageBuffer)), amountOfBytes, source);
|
||||
fread((labelBuffer + i), sizeof(&(labelBuffer)), 1, source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user