47 int bytes_needed = (img->
width + 7) / 8;
48 uint8_t *line = calloc(bytes_needed,
sizeof(uint8_t));
50 float *buf_iter = buf;
51 for(
size_t y = 0; y < img->
height; y++)
53 if(fread(line,
sizeof(uint8_t), (
size_t)bytes_needed,
f) != bytes_needed)
58 for(
size_t x = 0;
x < bytes_needed;
x++)
60 uint8_t
byte = line[
x] ^ 0xff;
61 for(
int bit = 0; bit < 8 &&
x * 8 + bit < img->
width; bit++)
63 float value = ((
byte & 0x80) >> 7) * 1.0;
64 buf_iter[0] = buf_iter[1] = buf_iter[2] =
value;
83 int ret = fscanf(
f,
"%u", &
max);
88 uint8_t *line = calloc(img->
width,
sizeof(uint8_t));
90 float *buf_iter = buf;
91 for(
size_t y = 0; y < img->
height; y++)
93 if(fread(line,
sizeof(uint8_t), (
size_t)img->
width,
f) != img->
width)
98 for(
size_t x = 0;
x < img->
width;
x++)
100 float value = (float)line[
x] / (
float)
max;
101 buf_iter[0] = buf_iter[1] = buf_iter[2] =
value;
110 uint16_t *line = calloc(img->
width,
sizeof(uint16_t));
112 float *buf_iter = buf;
113 for(
size_t y = 0; y < img->
height; y++)
115 if(fread(line,
sizeof(uint16_t), (
size_t)img->
width,
f) != img->
width)
120 for(
size_t x = 0;
x < img->
width;
x++)
122 uint16_t intvalue = line[
x];
123 if(G_BYTE_ORDER != G_BIG_ENDIAN)
124 intvalue = GUINT16_SWAP_LE_BE(intvalue);
125 float value = (float)intvalue / (
float)
max;
126 buf_iter[0] = buf_iter[1] = buf_iter[2] =
value;
143 int ret = fscanf(
f,
"%u", &
max);
148 uint8_t *line = calloc((
size_t)3 * img->
width,
sizeof(uint8_t));
150 float *buf_iter = buf;
151 for(
size_t y = 0; y < img->
height; y++)
153 if(fread(line, 3 *
sizeof(uint8_t), (
size_t)img->
width,
f) != img->
width)
158 for(
size_t x = 0;
x < img->
width;
x++)
160 for(
int c = 0; c < 3; c++)
162 float value = (float)line[
x * 3 + c] / (
float)
max;
172 uint16_t *line = calloc((
size_t)3 * img->
width,
sizeof(uint16_t));
174 float *buf_iter = buf;
175 for(
size_t y = 0; y < img->
height; y++)
177 if(fread(line, 3 *
sizeof(uint16_t), (
size_t)img->
width,
f) != img->
width)
182 for(
size_t x = 0;
x < img->
width;
x++)
184 for(
int c = 0; c < 3; c++)
186 uint16_t intvalue = line[
x * 3 + c];
188 if(G_BYTE_ORDER != G_BIG_ENDIAN)
189 intvalue = GUINT16_SWAP_LE_BE(intvalue);
190 float value = (float)intvalue / (
float)
max;
204 const char *ext = filename + strlen(filename);
205 while(*ext !=
'.' && ext > filename) ext--;
207 FILE *
f = g_fopen(filename,
"rb");
212 char head[2] = {
'X',
'X' };
213 ret = fscanf(
f,
"%c%c ", head, head + 1);
214 if(ret != 2 || head[0] !=
'P')
goto end;
216 char width_string[10] = { 0 };
217 char height_string[10] = { 0 };
218 ret = fscanf(
f,
"%9s %9s ", width_string, height_string);
219 if(ret != 2)
goto end;
222 img->
width = strtol(width_string, NULL, 0);
223 img->
height = strtol(height_string, NULL, 0);
224 if(errno != 0 || img->
width <= 0 || img->
height <= 0)
goto end;
228 img->
dsc.
bpp = 4 *
sizeof(float);
231 img->
flags &= ~DT_IMAGE_RAW;
232 img->
flags &= ~DT_IMAGE_S_RAW;
233 img->
flags &= ~DT_IMAGE_HDR;
253 else if(head[1] ==
'5')
255 else if(head[1] ==
'6')
const dt_aligned_pixel_t f
static const dt_aligned_pixel_simd_t value
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
@ DT_IMAGEIO_FILE_CORRUPTED
static dt_imageio_retval_t _read_pgm(dt_image_t *img, FILE *f, float *buf)
dt_imageio_retval_t dt_imageio_open_pnm(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
static dt_imageio_retval_t _read_pbm(dt_image_t *img, FILE *f, float *buf)
static dt_imageio_retval_t _read_ppm(dt_image_t *img, FILE *f, float *buf)
void * dt_mipmap_cache_alloc(dt_mipmap_buffer_t *buf, const dt_image_t *img)
dt_iop_buffer_type_t datatype