Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
printprof.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2014-2016, 2020 Pascal Obry.
4 Copyright (C) 2015 Jérémy Rosen.
5 Copyright (C) 2015-2017 Tobias Ellinghaus.
6 Copyright (C) 2016 Roman Lebedev.
7 Copyright (C) 2020 Hubert Kowalski.
8 Copyright (C) 2022 Martin Bařinka.
9
10 darktable is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 darktable is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with darktable. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include "common/darktable.h"
25#include "common/printprof.h"
26#include "common/colorspaces.h"
27#include "lcms2.h"
28#include <glib.h>
29#include <unistd.h>
30
31static cmsUInt32Number ComputeOutputFormatDescriptor (cmsUInt32Number dwInput, int OutColorSpace, int bps)
32{
33 int IsPlanar = T_PLANAR(dwInput);
34 int Channels = 3;
35 int IsFlt = 0;
36 return (FLOAT_SH(IsFlt)|COLORSPACE_SH(OutColorSpace)|PLANAR_SH(IsPlanar)|CHANNELS_SH(Channels)|BYTES_SH(bps));
37}
38
39static cmsUInt32Number ComputeFormatDescriptor (int OutColorSpace, int bps)
40{
41 int IsPlanar = 0;
42 int Channels = 3;
43 int IsFlt = 0;
44 return (FLOAT_SH(IsFlt)|COLORSPACE_SH(OutColorSpace)|PLANAR_SH(IsPlanar)|CHANNELS_SH(Channels)|BYTES_SH(bps));
45}
46
47int dt_apply_printer_profile(void **in, uint32_t width, uint32_t height, int bpp, cmsHPROFILE hInProfile,
48 cmsHPROFILE hOutProfile, int intent, gboolean black_point_compensation)
49{
50 cmsHTRANSFORM hTransform;
51 cmsUInt32Number wInput, wOutput;
52 int OutputColorSpace;
53
54 if(IS_NULL_PTR(hOutProfile) || IS_NULL_PTR(hInProfile))
55 return 1;
56
57 wInput = ComputeFormatDescriptor (PT_RGB, (bpp==8?1:2));
58
59 OutputColorSpace = _cmsLCMScolorSpace(cmsGetColorSpace(hOutProfile));
60 wOutput = ComputeOutputFormatDescriptor(wInput, OutputColorSpace, 1);
61
62 hTransform = cmsCreateTransform
63 (hInProfile, wInput,
64 hOutProfile, wOutput,
65 intent,
66 black_point_compensation ? cmsFLAGS_BLACKPOINTCOMPENSATION : 0);
67
68 if (IS_NULL_PTR(hTransform))
69 {
70 fprintf(stderr, "error printer profile may be corrupted\n");
71 return 1;
72 }
73
74 void *out = (void *)malloc((size_t)3 * width * height);
75
76 if (bpp == 8)
77 {
78 const uint8_t *ptr_in = (uint8_t *)*in;
79 uint8_t *ptr_out = (uint8_t *)out;
81 for (int k=0; k<height; k++)
82 cmsDoTransform(hTransform, (const void *)&ptr_in[k*width*3], (void *)&ptr_out[k*width*3], width);
83 }
84 else
85 {
86 const uint16_t *ptr_in = (uint16_t *)*in;
87 uint8_t *ptr_out = (uint8_t *)out;
89 for (int k=0; k<height; k++)
90 cmsDoTransform(hTransform, (const void *)&ptr_in[k*width*3], (void *)&ptr_out[k*width*3], width);
91 }
92
93 cmsDeleteTransform(hTransform);
94
95 dt_free(*in);
96 *in = out;
97
98 return 0;
99}
100
101// clang-format off
102// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
103// vim: shiftwidth=2 expandtab tabstop=2 cindent
104// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
105// clang-format on
106
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
const dt_colormatrix_t dt_aligned_pixel_t out
#define dt_free(ptr)
Definition darktable.h:456
#define __OMP_PARALLEL_FOR__(...)
Definition darktable.h:258
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition darktable.h:281
int bpp
float *const restrict const size_t k
int dt_apply_printer_profile(void **in, uint32_t width, uint32_t height, int bpp, cmsHPROFILE hInProfile, cmsHPROFILE hOutProfile, int intent, gboolean black_point_compensation)
Definition printprof.c:47
static cmsUInt32Number ComputeOutputFormatDescriptor(cmsUInt32Number dwInput, int OutColorSpace, int bps)
Definition printprof.c:31
static cmsUInt32Number ComputeFormatDescriptor(int OutColorSpace, int bps)
Definition printprof.c:39