Implement header check helper function
This commit is contained in:
parent
522ada29c6
commit
96b3d72848
72
imageInput.c
72
imageInput.c
@ -1,4 +1,4 @@
|
||||
#include <stdio.h>
|
||||
##include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "imageInput.h"
|
||||
@ -6,17 +6,67 @@
|
||||
#define BUFFER_SIZE 100
|
||||
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
||||
|
||||
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
||||
|
||||
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||
GrayScaleImageSeries *readImages(const char *path)
|
||||
{
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
|
||||
return series;
|
||||
/*
|
||||
* Hilfsfunktionen
|
||||
*/
|
||||
|
||||
|
||||
static FILE *openImageFile(const char *path) // Checks if the given filename pointer is valid (not NULL).
|
||||
{
|
||||
if (path == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return fopen(path, "rb"); //opening document in binear
|
||||
}
|
||||
|
||||
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
|
||||
void clearSeries(GrayScaleImageSeries *series)
|
||||
static int readAndCheckHeader(FILE *file) // gets the length of the header text
|
||||
{
|
||||
}
|
||||
size_t headerLength = strlen(FILE_HEADER_STRING);
|
||||
char buffer[BUFFER_SIZE];
|
||||
|
||||
if (headerLength + 1 > BUFFER_SIZE) //checks if buffer is big enough for header size
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fread(buffer, 1, headerLength, file) != headerLength) // Checks if reading the expected number of header bytes from the file succeeded
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
buffer[headerLength] = '\0'; // add string terminator so the header becomes a valid C-string
|
||||
|
||||
if (strcmp(buffer, FILE_HEADER_STRING) != 0) // checks if the expected header matches the header read from the file
|
||||
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1; /* Header ok */
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int readImageMetaData(FILE *file, // reads the metadata (count, width, height) from the file and stores them in the provided pointers
|
||||
unsigned short *count,
|
||||
unsigned short *width,
|
||||
unsigned short *height)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Hauptfunktion
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user