Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
imageio/format/pfm.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2009-2011, 2016 johannes hanika.
4 Copyright (C) 2011 Henrik Andersson.
5 Copyright (C) 2012 Richard Wonka.
6 Copyright (C) 2013 Jérémy Rosen.
7 Copyright (C) 2013 Pascal de Bruijn.
8 Copyright (C) 2013 Thomas Pryds.
9 Copyright (C) 2013-2014 Ulrich Pegelow.
10 Copyright (C) 2014, 2016 Roman Lebedev.
11 Copyright (C) 2014-2017, 2019-2020 Tobias Ellinghaus.
12 Copyright (C) 2019, 2025-2026 Aurélien PIERRE.
13 Copyright (C) 2020 Hubert Kowalski.
14 Copyright (C) 2020 Pascal Obry.
15 Copyright (C) 2022 Martin Bařinka.
16
17 darktable is free software: you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation, either version 3 of the License, or
20 (at your option) any later version.
21
22 darktable is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with darktable. If not, see <http://www.gnu.org/licenses/>.
29*/
30#include "common/darktable.h"
31#include "common/imageio.h"
34#include <math.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38
39DT_MODULE(1)
40
41int write_image(dt_imageio_module_data_t *data, const char *filename, const void *ivoid,
42 dt_colorspaces_color_profile_type_t over_type, const char *over_filename,
43 void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe,
44 const gboolean export_masks)
45{
46 const dt_imageio_module_data_t *const pfm = data;
47 int status = 0;
48 FILE *f = g_fopen(filename, "wb");
49 if(f)
50 {
51 // align pfm header to sse, assuming the file will
52 // be mmapped to page boundaries.
53 char header[1024];
54 snprintf(header, 1024, "PF\n%d %d\n-1.0", pfm->width, pfm->height);
55 size_t len = strlen(header);
56 fprintf(f, "PF\n%d %d\n-1.0", pfm->width, pfm->height);
57 ssize_t off = 0;
58 while((len + 1 + off) & 0xf) off++;
59 while(off-- > 0) fprintf(f, "0");
60 fprintf(f, "\n");
61 void *buf_line = dt_pixelpipe_cache_alloc_align_float_cache((size_t)3 * pfm->width, 0);
62 for(int j = 0; j < pfm->height; j++)
63 {
64 // NOTE: pfm has rows in reverse order
65 const int row_in = pfm->height - 1 - j;
66 const float *in = (const float *)ivoid + 4 * (size_t)pfm->width * row_in;
67 float *out = (float *)buf_line;
68 for(int i = 0; i < pfm->width; i++, in += 4, out += 3)
69 {
70 memcpy(out, in, sizeof(float) * 3);
71 }
72 // INFO: per-line fwrite call seems to perform best. LebedevRI, 18.04.2014
73 int cnt = fwrite(buf_line, sizeof(float) * 3, pfm->width, f);
74 if(cnt != pfm->width)
75 status = 1;
76 else
77 status = 0;
78 }
80 buf_line = NULL;
81 fclose(f);
82 }
83 return status;
84}
85
87{
88 return sizeof(dt_imageio_module_data_t);
89}
90
96
101
102int set_params(dt_imageio_module_format_t *self, const void *params, int size)
103{
104 if(size != params_size(self)) return 1;
105 return 0;
106}
107
109{
110 return 32;
111}
112
117
119{
120 return "image/x-portable-floatmap";
121}
122
124{
125 return "pfm";
126}
127
128const char *name()
129{
130 return _("PFM (float)");
131}
132
134{
135}
148
149// clang-format off
150// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
151// vim: shiftwidth=2 expandtab tabstop=2 cindent
152// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
153// clang-format on
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
dt_colorspaces_color_profile_type_t
Definition colorspaces.h:81
const dt_aligned_pixel_t f
const dt_colormatrix_t dt_aligned_pixel_t out
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
Definition darktable.h:447
#define DT_MODULE(MODVER)
Definition darktable.h:140
#define dt_free(ptr)
Definition darktable.h:456
#define dt_pixelpipe_cache_free_align(mem)
Definition darktable.h:453
int bpp
const char * mime(dt_imageio_module_data_t *data)
size_t params_size(dt_imageio_module_format_t *self)
void gui_reset(dt_imageio_module_format_t *self)
void gui_init(dt_imageio_module_format_t *self)
const char * extension(dt_imageio_module_data_t *data)
int write_image(dt_imageio_module_data_t *data, const char *filename, const void *ivoid, dt_colorspaces_color_profile_type_t over_type, const char *over_filename, void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe, const gboolean export_masks)
const char * name()
void cleanup(dt_imageio_module_format_t *self)
int levels(dt_imageio_module_data_t *p)
int set_params(dt_imageio_module_format_t *self, const void *params, int size)
void free_params(dt_imageio_module_format_t *self, dt_imageio_module_data_t *params)
void init(dt_imageio_module_format_t *self)
void * get_params(dt_imageio_module_format_t *self)
void gui_cleanup(dt_imageio_module_format_t *self)
@ IMAGEIO_RGB
Definition imageio.h:70
@ IMAGEIO_FLOAT
Definition imageio.h:66
size_t size
Definition mipmap_cache.c:3