/src/libraw/src/demosaic/xtrans_demosaic.cpp
Line | Count | Source |
1 | | /* -*- C++ -*- |
2 | | * Copyright 2019-2026 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_defs.h" |
20 | | |
21 | 4.11G | #define fcol(row, col) xtrans[(row + 6) % 6][(col + 6) % 6] |
22 | | /* |
23 | | Frank Markesteijn's algorithm for Fuji X-Trans sensors |
24 | | */ |
25 | | void LibRaw::xtrans_interpolate(int passes) |
26 | 3.40k | { |
27 | 3.40k | int cstat[4] = {0, 0, 0, 0}; |
28 | 3.40k | int ndir; |
29 | 3.40k | static const short orth[12] = {1, 0, 0, 1, -1, 0, 0, -1, 1, 0, 0, 1}, |
30 | 3.40k | patt[2][16] = {{0, 1, 0, -1, 2, 0, -1, 0, 1, 1, 1, -1, 0, |
31 | 3.40k | 0, 0, 0}, |
32 | 3.40k | {0, 1, 0, -2, 1, 0, -2, 0, 1, 1, -2, -2, 1, |
33 | 3.40k | -1, -1, 1}}, |
34 | 3.40k | dir[4] = {1, LIBRAW_AHD_TILE, LIBRAW_AHD_TILE + 1, |
35 | 3.40k | LIBRAW_AHD_TILE - 1}; |
36 | 3.40k | short allhex[3][3][2][8]; |
37 | 3.40k | ushort sgrow = 0, sgcol = 0; |
38 | | |
39 | 3.40k | if (width < LIBRAW_AHD_TILE || height < LIBRAW_AHD_TILE || filters != 9) |
40 | 645 | throw LIBRAW_EXCEPTION_IO_CORRUPT; // too small image |
41 | | /* Check against right pattern */ |
42 | 19.2k | for (int row = 0; row < 6; row++) |
43 | 115k | for (int col = 0; col < 6; col++) |
44 | 99.2k | cstat[(unsigned)fcol(row, col)]++; |
45 | | |
46 | 2.75k | if (cstat[0] < 6 || cstat[0] > 10 || cstat[1] < 16 || cstat[1] > 24 || |
47 | 2.66k | cstat[2] < 6 || cstat[2] > 10 || cstat[3]) |
48 | 111 | throw LIBRAW_EXCEPTION_IO_CORRUPT; |
49 | | |
50 | | // Init allhex table to unreasonable values |
51 | 10.5k | for (int i = 0; i < 3; i++) |
52 | 31.7k | for (int j = 0; j < 3; j++) |
53 | 71.4k | for (int k = 0; k < 2; k++) |
54 | 428k | for (int l = 0; l < 8; l++) |
55 | 380k | allhex[i][j][k][l] = 32700; |
56 | | |
57 | 2.64k | cielab(0, 0); |
58 | 2.64k | ndir = 4 << int(passes > 1); |
59 | | |
60 | 2.64k | int minv = 0, maxv = 0, minh = 0, maxh = 0; |
61 | | /* Map a green hexagon around each non-green pixel and vice versa: */ |
62 | 10.5k | for (int row = 0; row < 3; row++) |
63 | 31.7k | for (int col = 0; col < 3; col++) |
64 | 142k | for (int ng = 0, d = 0; d < 10; d += 2) |
65 | 119k | { |
66 | 119k | int g = fcol(row, col) == 1; |
67 | 119k | if (fcol(row + orth[d], col + orth[d + 2]) == 1) |
68 | 41.8k | ng = 0; |
69 | 77.1k | else |
70 | 77.1k | ng++; |
71 | 119k | if (ng == 4) |
72 | 2.98k | { |
73 | 2.98k | sgrow = row; |
74 | 2.98k | sgcol = col; |
75 | 2.98k | } |
76 | 119k | if (ng == g + 1) |
77 | 33.3k | { |
78 | 33.3k | int c; |
79 | 33.3k | FORC(8) |
80 | 266k | { |
81 | 266k | int v = orth[d] * patt[g][c * 2] + orth[d + 1] * patt[g][c * 2 + 1]; |
82 | 266k | int h = orth[d + 2] * patt[g][c * 2] + orth[d + 3] * patt[g][c * 2 + 1]; |
83 | 266k | minv = MIN(v, minv); |
84 | 266k | maxv = MAX(v, maxv); |
85 | 266k | minh = MIN(h, minh); |
86 | 266k | maxh = MAX(h, maxh); |
87 | 266k | allhex[row][col][0][c ^ (g * 2 & d)] = h + v * width; |
88 | 266k | allhex[row][col][1][c ^ (g * 2 & d)] = h + v * LIBRAW_AHD_TILE; |
89 | 266k | } |
90 | 33.3k | } |
91 | 119k | } |
92 | | |
93 | | // Check allhex table initialization |
94 | 10.4k | for (int i = 0; i < 3; i++) |
95 | 31.4k | for (int j = 0; j < 3; j++) |
96 | 70.6k | for (int k = 0; k < 2; k++) |
97 | 424k | for (int l = 0; l < 8; l++) |
98 | 376k | if (allhex[i][j][k][l] > maxh + maxv * width + 1 || |
99 | 376k | allhex[i][j][k][l] < minh + minv * width - 1) |
100 | 34 | throw LIBRAW_EXCEPTION_IO_CORRUPT; |
101 | 2.61k | int retrycount = 0; |
102 | | |
103 | | /* Set green1 and green3 to the minimum and maximum allowed values: */ |
104 | 1.07M | for (int row = 2; row < height - 2; row++) |
105 | 1.07M | { |
106 | 1.07M | int col; |
107 | 1.07M | ushort min, max; |
108 | 577M | for (col = 2, max = 0u, min = 0xffffu; col < int(width) - 2; col++) |
109 | 576M | { |
110 | 576M | if (fcol(row, col) == 1 && (min = ~(max = 0))) |
111 | 297M | continue; |
112 | 279M | ushort(*pix)[4]; |
113 | 279M | pix = image + row * width + col; |
114 | 279M | short* hex = allhex[row % 3][col % 3][0]; |
115 | 279M | if (!max) |
116 | 209M | { |
117 | 209M | int c; |
118 | 209M | FORC(6) |
119 | 1.25G | { |
120 | 1.25G | int val = pix[hex[c]][1]; |
121 | 1.25G | if (min > val) |
122 | 267M | min = val; |
123 | 1.25G | if (max < val) |
124 | 191M | max = val; |
125 | 1.25G | } |
126 | 209M | } |
127 | 279M | pix[0][1] = min; |
128 | 279M | pix[0][3] = max; |
129 | 279M | switch ((row - sgrow) % 3) |
130 | 279M | { |
131 | 76.3M | case 1: |
132 | 76.3M | if (row < height - 3) |
133 | 75.9M | { |
134 | 75.9M | row++; |
135 | 75.9M | col--; |
136 | 75.9M | } |
137 | 76.3M | break; |
138 | 76.0M | case 2: |
139 | 76.0M | if ((min = ~(max = 0)) && (col += 2) < width - 3 && row > 2) |
140 | 75.6M | { |
141 | 75.6M | row--; |
142 | 75.6M | if (retrycount++ > width * height) |
143 | 43 | throw LIBRAW_EXCEPTION_IO_CORRUPT; |
144 | 75.6M | } |
145 | 279M | } |
146 | 279M | } |
147 | 1.07M | } |
148 | | |
149 | 17.3k | for (int row = 3; row < 9 && row < height - 3; row++) |
150 | 103k | for (int col = 3; col < 9 && col < width - 3; col++) |
151 | 88.8k | { |
152 | 88.8k | if ((fcol(row, col)) == 1) |
153 | 41.9k | continue; |
154 | 46.9k | short* hex = allhex[row % 3][col % 3][0]; |
155 | 46.9k | int c; |
156 | 46.9k | FORC(2) |
157 | 93.8k | { |
158 | 93.8k | int idx3 = 3 * hex[4 + c] + row * width + col; |
159 | 93.8k | int idx4 = -3 * hex[4 + c] + row * width + col; |
160 | 93.8k | int maxidx = width * height; |
161 | 93.8k | if (idx3 < 0 || idx3 >= maxidx) |
162 | 57 | throw LIBRAW_EXCEPTION_IO_CORRUPT; |
163 | 93.8k | if (idx4 < 0 || idx4 >= maxidx) |
164 | 66 | throw LIBRAW_EXCEPTION_IO_CORRUPT; |
165 | 93.8k | } |
166 | 46.9k | } |
167 | | |
168 | | #if defined(LIBRAW_USE_OPENMP) |
169 | | int buffer_count = omp_get_max_threads(); |
170 | | #else |
171 | 2.44k | int buffer_count = 1; |
172 | 2.44k | #endif |
173 | | |
174 | 2.44k | size_t buffer_size = LIBRAW_AHD_TILE * LIBRAW_AHD_TILE * (ndir * 11 + 6); |
175 | 2.44k | char** buffers = malloc_omp_buffers(buffer_count, buffer_size); |
176 | 2.44k | INT64 allocate_sz = (INT64(iheight) + 6) * (INT64(iwidth) + 6) * sizeof(ushort)*4LL; |
177 | 2.44k | ushort (*destimage)[4] = (ushort(*)[4])calloc(allocate_sz, 1); |
178 | | // For border interpolate: keep original pixels |
179 | 2.44k | memmove(destimage,image,allocate_sz); |
180 | | |
181 | | #if defined(LIBRAW_USE_OPENMP) |
182 | | # pragma omp parallel for schedule(dynamic) default(none) firstprivate(buffers, allhex, passes, sgrow, sgcol, ndir) shared(dir, destimage) |
183 | | #endif |
184 | 5.21k | for (int top = 3; top < height - 19; top += LIBRAW_AHD_TILE - 16) |
185 | 2.76k | { |
186 | | #if defined(LIBRAW_USE_OPENMP) |
187 | | char* buffer = buffers[omp_get_thread_num()]; |
188 | | #else |
189 | 2.76k | char* buffer = buffers[0]; |
190 | 2.76k | #endif |
191 | | |
192 | 2.76k | ushort(*rgb)[LIBRAW_AHD_TILE][LIBRAW_AHD_TILE][3], (*rix)[3]; |
193 | 2.76k | short(*lab)[LIBRAW_AHD_TILE][3], (*lix)[3]; |
194 | 2.76k | float(*drv)[LIBRAW_AHD_TILE][LIBRAW_AHD_TILE]; |
195 | 2.76k | char(*homo)[LIBRAW_AHD_TILE][LIBRAW_AHD_TILE]; |
196 | | |
197 | 2.76k | rgb = (ushort(*)[LIBRAW_AHD_TILE][LIBRAW_AHD_TILE][3])buffer; |
198 | 2.76k | lab = (short(*)[LIBRAW_AHD_TILE][3])( |
199 | 2.76k | buffer + LIBRAW_AHD_TILE * LIBRAW_AHD_TILE * (ndir * 6)); |
200 | 2.76k | drv = (float(*)[LIBRAW_AHD_TILE][LIBRAW_AHD_TILE])( |
201 | 2.76k | buffer + LIBRAW_AHD_TILE * LIBRAW_AHD_TILE * (ndir * 6 + 6)); |
202 | 2.76k | homo = (char(*)[LIBRAW_AHD_TILE][LIBRAW_AHD_TILE])( |
203 | 2.76k | buffer + LIBRAW_AHD_TILE * LIBRAW_AHD_TILE * (ndir * 10 + 6)); |
204 | | |
205 | 6.55k | for (int left = 3; left < width - 19; left += LIBRAW_AHD_TILE - 16) |
206 | 3.79k | { |
207 | 3.79k | int mrow = MIN(top + LIBRAW_AHD_TILE, height - 3); |
208 | 3.79k | int mcol = MIN(left + LIBRAW_AHD_TILE, width - 3); |
209 | 1.78M | for (int row = top; row < mrow; row++) |
210 | 679M | for (int col = left; col < mcol; col++) |
211 | 677M | memcpy(rgb[0][row - top][col - left], image[row * width + col], 6); |
212 | 3.79k | int c; |
213 | 11.3k | FORC3 memcpy(rgb[c + 1], rgb[0], sizeof * rgb); |
214 | | |
215 | | /* Interpolate green horizontally, vertically, and along both diagonals: |
216 | | */ |
217 | 3.79k | int color[3][8]; |
218 | 1.78M | for (int row = top; row < mrow; row++) |
219 | 679M | for (int col = left; col < mcol; col++) |
220 | 677M | { |
221 | 677M | int f; |
222 | 677M | if ((f = fcol(row, col)) == 1) |
223 | 319M | continue; |
224 | 358M | ushort (*pix)[4] = image + row * width + col; |
225 | 358M | short* hex = allhex[row % 3][col % 3][0]; |
226 | 358M | color[1][0] = 174 * (pix[hex[1]][1] + pix[hex[0]][1]) - |
227 | 358M | 46 * (pix[2 * hex[1]][1] + pix[2 * hex[0]][1]); |
228 | 358M | color[1][1] = 223 * pix[hex[3]][1] + pix[hex[2]][1] * 33 + |
229 | 358M | 92 * (pix[0][f] - pix[-hex[2]][f]); |
230 | 358M | FORC(2) |
231 | 717M | color[1][2 + c] = 164 * pix[hex[4 + c]][1] + |
232 | 717M | 92 * pix[-2 * hex[4 + c]][1] + |
233 | 717M | 33 * (2 * pix[0][f] - pix[3 * hex[4 + c]][f] - |
234 | 717M | pix[-3 * hex[4 + c]][f]); |
235 | 1.43G | FORC4 rgb[c ^ !((row - sgrow) % 3)][row - top][col - left][1] = |
236 | 1.43G | LIM(color[1][c] >> 8, pix[0][1], pix[0][3]); |
237 | 358M | } |
238 | | |
239 | 13.6k | for (int pass = 0; pass < passes; pass++) |
240 | 9.85k | { |
241 | 9.85k | if (pass == 1) |
242 | 3.03k | memcpy(rgb += 4, buffer, 4 * sizeof * rgb); |
243 | | |
244 | | /* Recalculate green from interpolated values of closer pixels: */ |
245 | 9.85k | if (pass) |
246 | 6.06k | { |
247 | 2.82M | for (int row = top + 2; row < mrow - 2; row++) |
248 | 1.06G | for (int col = left + 2; col < mcol - 2; col++) |
249 | 1.06G | { |
250 | 1.06G | int f; |
251 | 1.06G | if ((f = fcol(row, col)) == 1) |
252 | 499M | continue; |
253 | 564M | ushort(*pix)[4] = image + row * width + col; |
254 | 564M | short* hex = allhex[row % 3][col % 3][1]; |
255 | 2.25G | for (int d = 3; d < 6; d++) |
256 | 1.69G | { |
257 | 1.69G | rix = |
258 | 1.69G | &rgb[(d - 2) ^ !((row - sgrow) % 3)][row - top][col - left]; |
259 | 1.69G | int val = rix[-2 * hex[d]][1] + 2 * rix[hex[d]][1] - |
260 | 1.69G | rix[-2 * hex[d]][f] - 2 * rix[hex[d]][f] + 3 * rix[0][f]; |
261 | 1.69G | rix[0][1] = LIM(val / 3, pix[0][1], pix[0][3]); |
262 | 1.69G | } |
263 | 564M | } |
264 | 6.06k | } |
265 | | |
266 | | /* Interpolate red and blue values for solitary green pixels: */ |
267 | 1.53M | for (int row = (top - sgrow + 4) / 3 * 3 + sgrow; row < mrow - 2; row += 3) |
268 | 82.0M | for (int col = (left - sgcol + 4) / 3 * 3 + sgcol; col < mcol - 2; col += 3) |
269 | 81.3M | { |
270 | 81.3M | rix = &rgb[0][row - top][col - left]; |
271 | 81.3M | int h = fcol(row, col + 1); |
272 | | |
273 | 81.3M | if (h == 1) // Incorrect pattern |
274 | 856k | break; |
275 | | |
276 | 80.5M | float diff[6]; |
277 | 80.5M | memset(diff, 0, sizeof diff); |
278 | 563M | for (int i = 1, d = 0; d < 6; d++, i ^= LIBRAW_AHD_TILE ^ 1, h ^= 2) |
279 | 483M | { |
280 | 1.44G | for (c = 0; c < 2; c++, h ^= 2) |
281 | 966M | { |
282 | 966M | int g = 2 * rix[0][1] - rix[i << c][1] - rix[-i << c][1]; |
283 | 966M | color[h][d] = g + rix[i << c][h] + rix[-i << c][h]; |
284 | 966M | if (d > 1) |
285 | 644M | diff[d] += SQR((float)rix[i << c][1] - (float)rix[-i << c][1] - |
286 | 644M | (float)rix[i << c][h] + (float)rix[-i << c][h]) + SQR((float)g); |
287 | 966M | } |
288 | 483M | if (d > 1 && (d & 1)) |
289 | 161M | if (diff[d - 1] < diff[d]) |
290 | 189M | FORC(2) color[c * 2][d] = color[c * 2][d - 1]; |
291 | 483M | if (d < 2 || (d & 1)) |
292 | 322M | { |
293 | 644M | FORC(2) rix[0][c * 2] = CLIP(color[c * 2][d] / 2); |
294 | 322M | rix += LIBRAW_AHD_TILE * LIBRAW_AHD_TILE; |
295 | 322M | } |
296 | 483M | } |
297 | 80.5M | } |
298 | | |
299 | | /* Interpolate red for blue pixels and vice versa: */ |
300 | 4.56M | for (int row = top + 3; row < mrow - 3; row++) |
301 | 1.71G | for (int col = left + 3; col < mcol - 3; col++) |
302 | 1.71G | { |
303 | 1.71G | int f; |
304 | 1.71G | if ((f = 2 - fcol(row, col)) == 1) |
305 | 804M | continue; |
306 | 907M | rix = &rgb[0][row - top][col - left]; |
307 | 907M | c = (row - sgrow) % 3 ? LIBRAW_AHD_TILE : 1; |
308 | 907M | int h = 3 * (c ^ LIBRAW_AHD_TILE ^ 1); |
309 | 4.53G | for (int d = 0; d < 4; d++, rix += LIBRAW_AHD_TILE * LIBRAW_AHD_TILE) |
310 | 3.63G | { |
311 | 3.63G | int i = d > 1 || ((d ^ c) & 1) || |
312 | 907M | ((ABS(rix[0][1] - rix[c][1]) + |
313 | 907M | ABS(rix[0][1] - rix[-c][1])) < |
314 | 907M | 2 * (ABS(rix[0][1] - rix[h][1]) + |
315 | 907M | ABS(rix[0][1] - rix[-h][1]))) |
316 | 3.63G | ? c |
317 | 3.63G | : h; |
318 | 3.63G | rix[0][f] = CLIP((rix[i][f] + rix[-i][f] + 2 * rix[0][1] - |
319 | 3.63G | rix[i][1] - rix[-i][1]) / |
320 | 3.63G | 2); |
321 | 3.63G | } |
322 | 907M | } |
323 | | |
324 | | /* Fill in red and blue for 2x2 blocks of green: */ |
325 | 4.58M | for (int row = top + 2; row < mrow - 2; row++) |
326 | 4.57M | if ((row - sgrow) % 3) |
327 | 1.15G | for (int col = left + 2; col < mcol - 2; col++) |
328 | 1.15G | if ((col - sgcol) % 3) |
329 | 769M | { |
330 | 769M | rix = &rgb[0][row - top][col - left]; |
331 | 769M | short* hex = allhex[row % 3][col % 3][1]; |
332 | 3.84G | for (int d = 0; d < 8; |
333 | 3.07G | d += 2, rix += LIBRAW_AHD_TILE * LIBRAW_AHD_TILE) |
334 | 3.07G | if (hex[d] + hex[d + 1]) |
335 | 1.85G | { |
336 | 1.85G | int g = 3 * rix[0][1] - 2 * rix[hex[d]][1] - rix[hex[d + 1]][1]; |
337 | 5.55G | for (c = 0; c < 4; c += 2) |
338 | 3.70G | rix[0][c] = CLIP( |
339 | 1.85G | (g + 2 * rix[hex[d]][c] + rix[hex[d + 1]][c]) / 3); |
340 | 1.85G | } |
341 | 1.22G | else |
342 | 1.22G | { |
343 | 1.22G | int g = 2 * rix[0][1] - rix[hex[d]][1] - rix[hex[d + 1]][1]; |
344 | 3.66G | for (c = 0; c < 4; c += 2) |
345 | 2.44G | rix[0][c] = |
346 | 2.44G | CLIP((g + rix[hex[d]][c] + rix[hex[d + 1]][c]) / 2); |
347 | 1.22G | } |
348 | 769M | } |
349 | 9.85k | } |
350 | 3.79k | rgb = (ushort(*)[LIBRAW_AHD_TILE][LIBRAW_AHD_TILE][3])buffer; |
351 | 3.79k | mrow -= top; |
352 | 3.79k | mcol -= left; |
353 | | |
354 | | /* Convert to CIELab and differentiate in all directions: */ |
355 | | // no effect |
356 | 31.0k | for (int d = 0; d < ndir; d++) |
357 | 27.2k | { |
358 | 12.7M | for (int row = 2; row < mrow - 2; row++) |
359 | 4.79G | for (int col = 2; col < mcol - 2; col++) |
360 | 4.78G | cielab(rgb[d][row][col], lab[row][col]); |
361 | 12.6M | for (int f = dir[d & 3], row = 3; row < mrow - 3; row++) |
362 | 4.75G | for (int col = 3; col < mcol - 3; col++) |
363 | 4.74G | { |
364 | 4.74G | lix = &lab[row][col]; |
365 | 4.74G | int g = 2 * lix[0][0] - lix[f][0] - lix[-f][0]; |
366 | 4.74G | drv[d][row][col] = |
367 | 4.74G | float( |
368 | 4.74G | SQR(g) + |
369 | 4.74G | SQR((2 * lix[0][1] - lix[f][1] - lix[-f][1] + g * 500 / 232)) + |
370 | 4.74G | SQR((2 * lix[0][2] - lix[f][2] - lix[-f][2] - g * 500 / 580)) |
371 | 4.74G | ); |
372 | 4.74G | } |
373 | 27.2k | } |
374 | | |
375 | | /* Build homogeneity maps from the derivatives: */ |
376 | 3.79k | memset(homo, 0, ndir * LIBRAW_AHD_TILE * LIBRAW_AHD_TILE); |
377 | 1.74M | for (int row = 4; row < mrow - 4; row++) |
378 | 653M | for (int col = 4; col < mcol - 4; col++) |
379 | 652M | { |
380 | 652M | int d; |
381 | 652M | float tr; |
382 | 5.34G | for (tr = FLT_MAX, d = 0; d < ndir; d++) |
383 | 4.69G | if (tr > drv[d][row][col]) |
384 | 1.19G | tr = drv[d][row][col]; |
385 | 652M | tr *= 8; |
386 | 5.34G | for (int dd = 0; dd < ndir; dd++) |
387 | 18.7G | for (int v = -1; v <= 1; v++) |
388 | 56.3G | for (int h = -1; h <= 1; h++) |
389 | 42.2G | if (drv[dd][row + v][col + h] <= tr) |
390 | 25.8G | homo[dd][row][col]++; |
391 | 652M | } |
392 | | |
393 | | /* Average the most homogeneous pixels for the final result: */ |
394 | 3.79k | if (height - top < LIBRAW_AHD_TILE + 4) |
395 | 3.46k | mrow = height - top + 2; |
396 | 3.79k | if (width - left < LIBRAW_AHD_TILE + 4) |
397 | 2.76k | mcol = width - left + 2; |
398 | 1.75M | for (int row = MIN(top, 8); row < mrow - 8; row++) |
399 | 653M | for (int col = MIN(left, 8); col < mcol - 8; col++) |
400 | 651M | { |
401 | 651M | int v; |
402 | 651M | int hm[8]; |
403 | 5.34G | for (int d = 0; d < ndir; d++) |
404 | 28.1G | for (v = -2, hm[d] = 0; v <= 2; v++) |
405 | 140G | for (int h = -2; h <= 2; h++) |
406 | 117G | hm[d] += homo[d][row + v][col + h]; |
407 | 2.73G | for (int d = 0; d < ndir - 4; d++) |
408 | 2.08G | if (hm[d] < hm[d + 4]) |
409 | 684M | hm[d] = 0; |
410 | 1.40G | else if (hm[d] > hm[d + 4]) |
411 | 731M | hm[d + 4] = 0; |
412 | 651M | ushort max; |
413 | 651M | int d; |
414 | 4.69G | for (d = 1, max = hm[0]; d < ndir; d++) |
415 | 4.04G | if (max < hm[d]) |
416 | 599M | max = hm[d]; |
417 | 651M | max -= max >> 3; |
418 | | |
419 | 651M | int avg[4]; |
420 | 651M | memset(avg, 0, sizeof avg); |
421 | 5.34G | for (int dd = 0; dd < ndir; dd++) |
422 | 4.69G | if (hm[dd] >= max) |
423 | 2.43G | { |
424 | 7.31G | FORC3 avg[c] += rgb[dd][row][col][c]; |
425 | 2.43G | avg[3]++; |
426 | 2.43G | } |
427 | 1.95G | FORC3 destimage[(row + top) * width + col + left][c] = avg[c] / avg[3]; |
428 | 651M | } |
429 | 3.79k | } |
430 | 2.76k | } |
431 | | |
432 | | #ifdef LIBRAW_USE_OPENMP |
433 | | #pragma omp barrier |
434 | | #endif |
435 | | |
436 | 2.44k | free_omp_buffers(buffers, buffer_count); |
437 | 2.44k | free(image); |
438 | 2.44k | image = destimage; |
439 | | |
440 | 2.44k | border_interpolate(8); |
441 | 2.44k | } |
442 | | #undef fcol |