/src/libraw/src/utils/phaseone_processing.cpp
Line | Count | Source |
1 | | /* -*- C++ -*- |
2 | | * Copyright 2019-2024 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/libraw_cxx_defs.h" |
20 | | |
21 | | |
22 | | void LibRaw::phase_one_allocate_tempbuffer() |
23 | 4.12k | { |
24 | | // Allocate temp raw_image buffer |
25 | 4.12k | if (imgdata.process_warnings & LIBRAW_WARN_RAWSPEED3_PROCESSED) |
26 | 0 | { |
27 | | // Processed by RawSpeed, raw_image contains ptr to rawspeed internals |
28 | 0 | imgdata.rawdata.raw_alloc = imgdata.rawdata.raw_image; // save for data processing and future reuse |
29 | 0 | } |
30 | 4.12k | imgdata.rawdata.raw_image = (ushort *)malloc(S.raw_pitch * S.raw_height); |
31 | 4.12k | } |
32 | | void LibRaw::phase_one_free_tempbuffer() |
33 | 4.12k | { |
34 | 4.12k | free(imgdata.rawdata.raw_image); |
35 | 4.12k | imgdata.rawdata.raw_image = (ushort *)imgdata.rawdata.raw_alloc; |
36 | 4.12k | if (imgdata.process_warnings & LIBRAW_WARN_RAWSPEED3_PROCESSED) |
37 | 0 | imgdata.rawdata.raw_alloc = 0; |
38 | 4.12k | } |
39 | | |
40 | | int LibRaw::phase_one_subtract_black(ushort *src, ushort *dest) |
41 | 4.12k | { |
42 | | |
43 | 4.12k | try |
44 | 4.12k | { |
45 | 4.12k | if (O.user_black < 0 && O.user_cblack[0] <= -1000000 && |
46 | 3.07k | O.user_cblack[1] <= -1000000 && O.user_cblack[2] <= -1000000 && |
47 | 3.07k | O.user_cblack[3] <= -1000000) |
48 | 3.07k | { |
49 | 3.07k | if (!imgdata.rawdata.ph1_cblack || !imgdata.rawdata.ph1_rblack) |
50 | 2.57k | { |
51 | 2.57k | int bl = imgdata.color.phase_one_data.t_black; |
52 | 1.08M | for (int row = 0; row < S.raw_height; row++) |
53 | 1.08M | { |
54 | 1.08M | checkCancel(); |
55 | 81.5M | for (int col = 0; col < S.raw_width; col++) |
56 | 80.4M | { |
57 | 80.4M | int idx = row * S.raw_width + col; |
58 | 80.4M | int val = int(src[idx]) - bl; |
59 | 80.4M | dest[idx] = val > 0 ? val : 0; |
60 | 80.4M | } |
61 | 1.08M | } |
62 | 2.57k | } |
63 | 502 | else |
64 | 502 | { |
65 | 502 | int bl = imgdata.color.phase_one_data.t_black; |
66 | 110k | for (int row = 0; row < S.raw_height; row++) |
67 | 110k | { |
68 | 110k | checkCancel(); |
69 | 21.8M | for (int col = 0; col < S.raw_width; col++) |
70 | 21.7M | { |
71 | 21.7M | int idx = row * S.raw_width + col; |
72 | 21.7M | int val = |
73 | 21.7M | int(src[idx]) - bl + |
74 | 21.7M | imgdata.rawdata |
75 | 21.7M | .ph1_cblack[row][col >= imgdata.rawdata.color.phase_one_data |
76 | 21.7M | .split_col] + |
77 | 21.7M | imgdata.rawdata |
78 | 21.7M | .ph1_rblack[col][row >= imgdata.rawdata.color.phase_one_data |
79 | 21.7M | .split_row]; |
80 | 21.7M | dest[idx] = val > 0 ? val : 0; |
81 | 21.7M | } |
82 | 110k | } |
83 | 502 | } |
84 | 3.07k | } |
85 | 1.05k | else // black set by user interaction |
86 | 1.05k | { |
87 | | // Black level in cblack! |
88 | 380k | for (int row = 0; row < S.raw_height; row++) |
89 | 379k | { |
90 | 379k | checkCancel(); |
91 | 379k | unsigned short cblk[16]; |
92 | 6.44M | for (int cc = 0; cc < 16; cc++) |
93 | 6.06M | cblk[cc] = C.cblack[fcol(row, cc)]; |
94 | 20.0M | for (int col = 0; col < S.raw_width; col++) |
95 | 19.6M | { |
96 | 19.6M | int idx = row * S.raw_width + col; |
97 | 19.6M | ushort val = src[idx]; |
98 | 19.6M | ushort bl = cblk[col & 0xf]; |
99 | 19.6M | dest[idx] = val > bl ? val - bl : 0; |
100 | 19.6M | } |
101 | 379k | } |
102 | 1.05k | } |
103 | 4.12k | return 0; |
104 | 4.12k | } |
105 | 4.12k | catch (const LibRaw_exceptions& ) |
106 | 4.12k | { |
107 | 0 | return LIBRAW_CANCELLED_BY_CALLBACK; |
108 | 0 | } |
109 | 4.12k | } |