minor changes for pgm files
This commit is contained in:
parent
8ba83737f5
commit
38fafa672c
1 changed files with 8 additions and 9 deletions
17
image.c
17
image.c
|
|
@ -14,12 +14,13 @@ void big_endian_to_c_uint(const char * bytes, void * target, int size) {
|
||||||
|
|
||||||
void read_until_space_or_newline(char * buff, int maxCount, FILE * fptr){
|
void read_until_space_or_newline(char * buff, int maxCount, FILE * fptr){
|
||||||
int bufferOffset = 0;
|
int bufferOffset = 0;
|
||||||
char c = -1;
|
char c;
|
||||||
|
int counter = 0;
|
||||||
do{
|
do{
|
||||||
c = (char)getc(fptr);
|
c = (char)getc(fptr);
|
||||||
buff[bufferOffset++] = c;
|
buff[bufferOffset++] = c;
|
||||||
|
|
||||||
}while(!feof(fptr) && c != 0 && c != ' ' && c !='\n');
|
}while(!feof(fptr) && c != 0 && c != ' ' && c !='\n' && counter++ < maxCount);
|
||||||
buff[bufferOffset-1] = 0;
|
buff[bufferOffset-1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,8 +30,7 @@ Image * load_pgm_image(char * image_file_string){
|
||||||
image->label = -1;
|
image->label = -1;
|
||||||
|
|
||||||
|
|
||||||
char buffer[100];
|
char buffer[2048];
|
||||||
int magic_number = 0;
|
|
||||||
fgets(buffer, 4, fptr);
|
fgets(buffer, 4, fptr);
|
||||||
if(buffer[0] != 'P' || buffer[1] != '5'){
|
if(buffer[0] != 'P' || buffer[1] != '5'){
|
||||||
printf("Wrong file Format");
|
printf("Wrong file Format");
|
||||||
|
|
@ -40,17 +40,16 @@ Image * load_pgm_image(char * image_file_string){
|
||||||
fgets(buffer, 1024, fptr);
|
fgets(buffer, 1024, fptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int image_width, image_height, image_length, image_white ;
|
int image_width, image_height, image_white ;
|
||||||
read_until_space_or_newline(buffer, 10, fptr);
|
read_until_space_or_newline(buffer, 10, fptr);
|
||||||
image_width = strtol(buffer, NULL, 10);
|
image_width = (int)strtol(buffer, NULL, 10);
|
||||||
|
|
||||||
read_until_space_or_newline(buffer, 10, fptr);
|
read_until_space_or_newline(buffer, 10, fptr);
|
||||||
image_height = strtol(buffer, NULL, 10);
|
image_height = (int)strtol(buffer, NULL, 10);
|
||||||
|
|
||||||
read_until_space_or_newline(buffer, 10, fptr);
|
read_until_space_or_newline(buffer, 10, fptr);
|
||||||
image_white = strtol(buffer, NULL, 10);
|
image_white = (int)strtol(buffer, NULL, 10);
|
||||||
|
|
||||||
image_length = image_width * image_height;
|
|
||||||
|
|
||||||
image->pixel_values = matrix_create(image_height, image_width);
|
image->pixel_values = matrix_create(image_height, image_width);
|
||||||
for(int i = 0; i < image_height; i++){
|
for(int i = 0; i < image_height; i++){
|
||||||
|
|
|
||||||
Reference in a new issue