/src/libraw/src/write/apply_profile.cpp
Line | Count | Source |
1 | | /* -*- C++ -*- |
2 | | * Copyright 2019-2025 LibRaw LLC (info@libraw.org) |
3 | | * |
4 | | LibRaw uses code from dcraw.c -- Dave Coffin's raw photo decoder, |
5 | | dcraw.c is copyright 1997-2018 by Dave Coffin, dcoffin a cybercom o net. |
6 | | LibRaw do not use RESTRICTED code from dcraw.c |
7 | | |
8 | | LibRaw is free software; you can redistribute it and/or modify |
9 | | it under the terms of the one of two licenses as you choose: |
10 | | |
11 | | 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 |
12 | | (See file LICENSE.LGPL provided in LibRaw distribution archive for details). |
13 | | |
14 | | 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 |
15 | | (See file LICENSE.CDDL provided in LibRaw distribution archive for details). |
16 | | |
17 | | */ |
18 | | |
19 | | #include "../../internal/dcraw_fileio_defs.h" |
20 | | |
21 | | #ifndef NO_LCMS |
22 | | void LibRaw::apply_profile(const char *input, const char *output) |
23 | 0 | { |
24 | 0 | char *prof; |
25 | 0 | cmsHPROFILE hInProfile = 0, hOutProfile = 0; |
26 | 0 | cmsHTRANSFORM hTransform; |
27 | 0 | FILE *fp; |
28 | 0 | unsigned size; |
29 | |
|
30 | 0 | if (strcmp(input, "embed")) |
31 | 0 | hInProfile = cmsOpenProfileFromFile(input, "r"); |
32 | 0 | else if (profile_length) |
33 | 0 | { |
34 | 0 | hInProfile = cmsOpenProfileFromMem(imgdata.color.profile, profile_length); |
35 | 0 | } |
36 | 0 | else |
37 | 0 | { |
38 | 0 | imgdata.process_warnings |= LIBRAW_WARN_NO_EMBEDDED_PROFILE; |
39 | 0 | } |
40 | 0 | if (!hInProfile) |
41 | 0 | { |
42 | 0 | imgdata.process_warnings |= LIBRAW_WARN_NO_INPUT_PROFILE; |
43 | 0 | return; |
44 | 0 | } |
45 | 0 | if (!output) |
46 | 0 | hOutProfile = cmsCreate_sRGBProfile(); |
47 | 0 | else if ((fp = fopen(output, "rb"))) |
48 | 0 | { |
49 | 0 | fread(&size, 4, 1, fp); |
50 | 0 | fseek(fp, 0, SEEK_SET); |
51 | 0 | oprof = (unsigned *)calloc(size = ntohl(size),1); |
52 | 0 | fread(oprof, 1, size, fp); |
53 | 0 | fclose(fp); |
54 | 0 | if (!(hOutProfile = cmsOpenProfileFromMem(oprof, size))) |
55 | 0 | { |
56 | 0 | free(oprof); |
57 | 0 | oprof = 0; |
58 | 0 | } |
59 | 0 | } |
60 | 0 | if (!hOutProfile) |
61 | 0 | { |
62 | 0 | imgdata.process_warnings |= LIBRAW_WARN_BAD_OUTPUT_PROFILE; |
63 | 0 | goto quit; |
64 | 0 | } |
65 | 0 | RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE, 0, 2); |
66 | 0 | hTransform = cmsCreateTransform(hInProfile, TYPE_RGBA_16, hOutProfile, |
67 | 0 | TYPE_RGBA_16, INTENT_PERCEPTUAL, 0); |
68 | 0 | cmsDoTransform(hTransform, image, image, width * height); |
69 | 0 | raw_color = 1; /* Don't use rgb_cam with a profile */ |
70 | 0 | cmsDeleteTransform(hTransform); |
71 | 0 | cmsCloseProfile(hOutProfile); |
72 | 0 | quit: |
73 | 0 | cmsCloseProfile(hInProfile); |
74 | 0 | RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE, 1, 2); |
75 | 0 | } |
76 | | #endif |