3434#include <time.h>
3535#include <unistd.h>
3636
37- dt_imageio_retval_t dt_imageio_open_pfm (dt_image_t * img , const char * filename , dt_mipmap_buffer_t * mbuf )
37+ dt_imageio_retval_t dt_imageio_open_pfm (dt_image_t * img ,
38+ const char * filename ,
39+ dt_mipmap_buffer_t * mbuf )
3840{
3941 const char * ext = filename + strlen (filename );
40- while (* ext != '.' && ext > filename ) ext -- ;
41- if (strcasecmp (ext , ".pfm" )) return DT_IMAGEIO_LOAD_FAILED ;
42+
43+ while (* ext != '.' && ext > filename )
44+ ext -- ;
45+
46+ if (strcasecmp (ext , ".pfm" ))
47+ return DT_IMAGEIO_LOAD_FAILED ;
4248
4349 FILE * f = g_fopen (filename , "rb" );
44- if (!f ) return DT_IMAGEIO_FILE_NOT_FOUND ;
50+ if (!f )
51+ return DT_IMAGEIO_FILE_NOT_FOUND ;
4552
4653 int ret = 0 ;
4754 int cols = 3 ;
4855 float scale_factor ;
4956 char head [2 ] = { 'X' , 'X' };
57+
5058 ret = fscanf (f , "%c%c\n" , head , head + 1 );
51- if (ret != 2 || head [0 ] != 'P' ) goto error_corrupt ;
59+
60+ if (ret != 2 || head [0 ] != 'P' )
61+ goto error_corrupt ;
62+
5263 if (head [1 ] == 'F' )
5364 cols = 3 ;
5465 else if (head [1 ] == 'f' )
@@ -59,26 +70,34 @@ dt_imageio_retval_t dt_imageio_open_pfm(dt_image_t *img, const char *filename, d
5970 char width_string [10 ] = { 0 };
6071 char height_string [10 ] = { 0 };
6172 char scale_factor_string [64 ] = { 0 };
73+
6274 ret = fscanf (f , "%9s %9s %63s%*[^\n]" , width_string , height_string , scale_factor_string );
63- if (ret != 3 ) goto error_corrupt ;
75+
76+ if (ret != 3 )
77+ goto error_corrupt ;
6478
6579 errno = 0 ;
6680 img -> width = strtol (width_string , NULL , 0 );
6781 img -> height = strtol (height_string , NULL , 0 );
6882 scale_factor = g_ascii_strtod (scale_factor_string , NULL );
69- if (errno != 0 ) goto error_corrupt ;
70- if (img -> width <= 0 || img -> height <= 0 ) goto error_corrupt ;
83+
84+ if (errno != 0 )
85+ goto error_corrupt ;
86+ if (img -> width <= 0 || img -> height <= 0 )
87+ goto error_corrupt ;
7188
7289 ret = fread (& ret , sizeof (char ), 1 , f );
73- if (ret != 1 ) goto error_corrupt ;
90+ if (ret != 1 )
91+ goto error_corrupt ;
7492 ret = 0 ;
7593
7694 int swap_byte_order = (scale_factor >= 0.0 ) ^ (G_BYTE_ORDER == G_BIG_ENDIAN );
7795
7896 img -> buf_dsc .channels = 4 ;
7997 img -> buf_dsc .datatype = TYPE_FLOAT ;
8098 float * buf = (float * )dt_mipmap_cache_alloc (mbuf , img );
81- if (!buf ) goto error_cache_full ;
99+ if (!buf )
100+ goto error_cache_full ;
82101
83102 const size_t npixels = (size_t )img -> width * img -> height ;
84103
0 commit comments