Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
ppm.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010-2011 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, 2020 Pascal Obry.
9 Copyright (C) 2013 Thomas Pryds.
10 Copyright (C) 2013 Ulrich Pegelow.
11 Copyright (C) 2014, 2016 Roman Lebedev.
12 Copyright (C) 2014-2017, 2019-2020 Tobias Ellinghaus.
13 Copyright (C) 2022 Martin Bařinka.
14 Copyright (C) 2025 Aurélien PIERRE.
15
16 darktable is free software: you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation, either version 3 of the License, or
19 (at your option) any later version.
20
21 darktable is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with darktable. If not, see <http://www.gnu.org/licenses/>.
28*/
29#include "system/mem_alloc.h"
34#include <glib/gstdio.h>
35#include <inttypes.h>
36#include <stdio.h>
37#include <stdlib.h>
38
39DT_MODULE(1)
40
47
48int write_image(dt_imageio_module_data_t *ppm, const char *filename, const void *in_tmp,
49 dt_colorspaces_color_profile_type_t over_type, const char *over_filename,
50 void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe,
51 const gboolean export_masks)
52{
53 const uint16_t *in = (const uint16_t *)in_tmp;
54 int status = 0;
55 uint16_t *row = (uint16_t *)in;
56 uint16_t swapped[3];
57 FILE *f = g_fopen(filename, "wb");
58 if(f)
59 {
60 (void)fprintf(f, "P6\n%d %d\n65535\n", ppm->width, ppm->height);
61 for(int y = 0; y < ppm->height; y++)
62 {
63 for(int x = 0; x < ppm->width; x++)
64 {
65 for(int c = 0; c < 3; c++) swapped[c] = (0xff00 & (row[c] << 8)) | (row[c] >> 8);
66 int cnt = fwrite(&swapped, sizeof(uint16_t), 3, f);
67 if(cnt != 3) break;
68 row += 4;
69 }
70 }
71 fclose(f);
72 status = 0;
73 }
74 return status;
75}
76
78{
79 return sizeof(dt_imageio_module_data_t);
80}
81
87
92
93int set_params(dt_imageio_module_format_t *self, const void *params, const int size)
94{
95 if(size != self->params_size(self)) return 1;
96 return 0;
97}
98
100{
101 return 16;
102}
103
108
110{
111 return "image/x-portable-pixmap";
112}
113
115{
116 return "ppm";
117}
118
119const char *name()
120{
121 return _("PPM (16-bit)");
122}
123
124// TODO: some quality/compression stuff?
134// clang-format off
135// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
136// vim: shiftwidth=2 expandtab tabstop=2 cindent
137// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
138// clang-format on
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
static const float x
const float f
static const int row
GtkWidget * status
result of the last capture
int bpp
@ IMAGEIO_INT16
@ IMAGEIO_RGB
#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,...
const char * mime(dt_imageio_module_data_t *data)
Definition ppm.c:109
size_t params_size(dt_imageio_module_format_t *self)
Definition ppm.c:77
void gui_reset(dt_imageio_module_format_t *self)
Definition ppm.c:131
void gui_init(dt_imageio_module_format_t *self)
Definition ppm.c:125
const char * extension(dt_imageio_module_data_t *data)
Definition ppm.c:114
int set_params(dt_imageio_module_format_t *self, const void *params, const int size)
Definition ppm.c:93
const char * name()
Definition ppm.c:119
void cleanup(dt_imageio_module_format_t *self)
Definition ppm.c:44
int levels(dt_imageio_module_data_t *p)
Definition ppm.c:104
void free_params(dt_imageio_module_format_t *self, dt_imageio_module_data_t *params)
Definition ppm.c:88
int write_image(dt_imageio_module_data_t *ppm, const char *filename, const void *in_tmp, 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)
Definition ppm.c:48
void init(dt_imageio_module_format_t *self)
Definition ppm.c:41
void * get_params(dt_imageio_module_format_t *self)
Definition ppm.c:82
void gui_cleanup(dt_imageio_module_format_t *self)
Definition ppm.c:128
dt_colorspaces_color_profile_type_t