noch probleme bei übergabe von unterfunktion readIndividualImage

This commit is contained in:
sengpielto106561 committed 2026-11-05 15:33:39 +01:00
1 parent 290b0d649e
commit c2a26bc3ad
1 file changed
+12 -8
+12 -8
View File
@@ -10,7 +10,7 @@
static GrayScaleImage *readIndividualImage(unsigned int width, unsigned int height, FILE *file){
char *buf = calloc(width * height, sizeof(char));
GrayScalePixelType *buf = calloc(width * height, sizeof(unsigned char));
if(!buf){
fprintf(stderr, "calloc failed!\n");
return NULL;
@@ -21,7 +21,7 @@ static GrayScaleImage *readIndividualImage(unsigned int width, unsigned int heig
return NULL;
}
GrayScaleImage *gimage = calloc(sizeof(GrayScaleImage, 1));
GrayScaleImage *gimage = calloc(sizeof(GrayScaleImage), 1);
if(gimage == NULL){
fprintf(stderr, "calloc failed!\n");
free(buf);
@@ -45,6 +45,7 @@ GrayScaleImageSeries *readImages(const char *path)
fprintf(stderr, "Couldn't allocate enough space!\n");
return NULL;
}
series->count = 0;
FILE *file = fopen(path, "rb");
if(file == NULL){
@@ -62,29 +63,31 @@ GrayScaleImageSeries *readImages(const char *path)
return NULL;
}
if(bytes = fread(buffer, sizeof(short), 3, file) != (3*szieof(short))){
if((bytes = fread(buffer, sizeof(short), 3, file)) != (3*sizeof(short))){
fprintf(stderr, "Couldn't read number of images/sizes of Images!\n");
clearSeries(series);
return NULL;
}
//Merke menge an Bildern und Länge und Breite der Bilder
series->count = (short)buffer[0];
unsigned int width = (short)buffer[1];
unsigned int height = (short)buffer[2];
series->labels = calloc(count, sizeof(char));
series->labels = calloc(series->count, sizeof(char));
if(series->labels == NULL){
fprintf(stderr, "calloc failed!\n");
clearSeries(series);
return NULL;
}
for (int i = 0; i < count; i++){
if(series->images[i] = readIndividualImage(width, heigth, file) == NULL){
//Lies Bilder aus
for (int i = 0; i < series->count; i++){
if((series->images[i] = *readIndividualImage(width, height, file))){
clearSeries(series);
return NULL;
}
fread(series->labels[i], sizeof(char), 1, file);
fread(&series->labels[i], sizeof(char), 1, file);
}
return series;
@@ -94,7 +97,8 @@ GrayScaleImageSeries *readImages(const char *path)
void clearSeries(GrayScaleImageSeries *series)
{
for(int i = 0; i < series->count; i++){
free(series->GrayScaleImage[i]);
free(&series->images[i]);
}
free(series->labels);
free(series);
}