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 "system/mem_alloc.h"
36#include <glib/gstdio.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40
41DT_MODULE(1)
42
43int write_image(dt_imageio_module_data_t *data, const char *filename, const void *ivoid,
44 dt_colorspaces_color_profile_type_t over_type, const char *over_filename,
45 void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe,
46 const gboolean export_masks)
47{
48 const dt_imageio_module_data_t *const pfm = data;
49 int status = 0;
50 FILE *f = g_fopen(filename, "wb");
51 if(f)
52 {
53 // align pfm header to sse, assuming the file will
54 // be mmapped to page boundaries.
55 char header[1024];
56 snprintf(header, 1024, "PF\n%d %d\n-1.0", pfm->width, pfm->height);
57 size_t len = strlen(header);
58 fprintf(f, "PF\n%d %d\n-1.0", pfm->width, pfm->height);
59 ssize_t off = 0;
60 while((len + 1 + off) & 0xf) off++;
61 while(off-- > 0) fprintf(f, "0");
62 fprintf(f, "\n");
63 void *buf_line = dt_pixelpipe_cache_alloc_align_float_cache((size_t)3 * pfm->width, 0);
64 for(int j = 0; j < pfm->height; j++)
65 {
66 // NOTE: pfm has rows in reverse order
67 const int row_in = pfm->height - 1 - j;
68 const float *in = (const float *)ivoid + 4 * (size_t)pfm->width * row_in;
69 float *out = (float *)buf_line;
70 for(int i = 0; i < pfm->width; i++, in += 4, out += 3)
71 {
72 memcpy(out, in, sizeof(float) * 3);
73 }
74 // INFO: per-line fwrite call seems to perform best. LebedevRI, 18.04.2014
75 int cnt = fwrite(buf_line, sizeof(float) * 3, pfm->width, f);
76 if(cnt != pfm->width)
77 status = 1;
78 else
79 status = 0;
80 }
82 buf_line = NULL;
83 fclose(f);
84 }
85 return status;
86}
87
89{
90 return sizeof(dt_imageio_module_data_t);
91}
92
98
100{
101 dt_free(params);
102}
103
104int set_params(dt_imageio_module_format_t *self, const void *params, int size)
105{
106 if(size != params_size(self)) return 1;
107 return 0;
108}
109
111{
112 return 32;
113}
114
119
121{
122 return "image/x-portable-floatmap";
123}
124
126{
127 return "pfm";
128}
129
130const char *name()
131{
132 return _("PFM (float)");
133}
134
136{
137}
150
151// clang-format off
152// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
153// vim: shiftwidth=2 expandtab tabstop=2 cindent
154// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
155// clang-format on
const float f
const dt_colormatrix_t dt_aligned_pixel_t out
GtkWidget * status
result of the last capture
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
@ IMAGEIO_FLOAT
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
size_t size
Definition mipmap_cache.c:3
#define DT_MODULE(MODVER)
Instantiate the version handshake every module must export. Use once, at file scope,...
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
#define dt_pixelpipe_cache_free_align(mem)
dt_colorspaces_color_profile_type_t