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 "common/darktable.h"
30#include "common/imageio.h"
33#include <glib/gstdio.h>
34#include <inttypes.h>
35#include <stdio.h>
36#include <stdlib.h>
37
38DT_MODULE(1)
39
46
47int write_image(dt_imageio_module_data_t *ppm, const char *filename, const void *in_tmp,
48 dt_colorspaces_color_profile_type_t over_type, const char *over_filename,
49 void *exif, int exif_len, int32_t imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe,
50 const gboolean export_masks)
51{
52 const uint16_t *in = (const uint16_t *)in_tmp;
53 int status = 0;
54 uint16_t *row = (uint16_t *)in;
55 uint16_t swapped[3];
56 FILE *f = g_fopen(filename, "wb");
57 if(f)
58 {
59 (void)fprintf(f, "P6\n%d %d\n65535\n", ppm->width, ppm->height);
60 for(int y = 0; y < ppm->height; y++)
61 {
62 for(int x = 0; x < ppm->width; x++)
63 {
64 for(int c = 0; c < 3; c++) swapped[c] = (0xff00 & (row[c] << 8)) | (row[c] >> 8);
65 int cnt = fwrite(&swapped, sizeof(uint16_t), 3, f);
66 if(cnt != 3) break;
67 row += 4;
68 }
69 }
70 fclose(f);
71 status = 0;
72 }
73 return status;
74}
75
77{
78 return sizeof(dt_imageio_module_data_t);
79}
80
86
91
92int set_params(dt_imageio_module_format_t *self, const void *params, const int size)
93{
94 if(size != self->params_size(self)) return 1;
95 return 0;
96}
97
99{
100 return 16;
101}
102
107
109{
110 return "image/x-portable-pixmap";
111}
112
114{
115 return "ppm";
116}
117
118const char *name()
119{
120 return _("PPM (16-bit)");
121}
122
123// TODO: some quality/compression stuff?
133// clang-format off
134// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
135// vim: shiftwidth=2 expandtab tabstop=2 cindent
136// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
137// 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
static const int row
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
#define DT_MODULE(MODVER)
Definition darktable.h:140
#define dt_free(ptr)
Definition darktable.h:456
int bpp
@ IMAGEIO_INT16
Definition imageio.h:64
@ IMAGEIO_RGB
Definition imageio.h:70
static const float x
size_t size
Definition mipmap_cache.c:3
const char * mime(dt_imageio_module_data_t *data)
Definition ppm.c:108
size_t params_size(dt_imageio_module_format_t *self)
Definition ppm.c:76
void gui_reset(dt_imageio_module_format_t *self)
Definition ppm.c:130
void gui_init(dt_imageio_module_format_t *self)
Definition ppm.c:124
const char * extension(dt_imageio_module_data_t *data)
Definition ppm.c:113
int set_params(dt_imageio_module_format_t *self, const void *params, const int size)
Definition ppm.c:92
const char * name()
Definition ppm.c:118
void cleanup(dt_imageio_module_format_t *self)
Definition ppm.c:43
int levels(dt_imageio_module_data_t *p)
Definition ppm.c:103
void free_params(dt_imageio_module_format_t *self, dt_imageio_module_data_t *params)
Definition ppm.c:87
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:47
void init(dt_imageio_module_format_t *self)
Definition ppm.c:40
void * get_params(dt_imageio_module_format_t *self)
Definition ppm.c:81
void gui_cleanup(dt_imageio_module_format_t *self)
Definition ppm.c:127