Skip to content

Commit f4b83eb

Browse files
committed
Merge branch 'demosaic_54_firstbunch' of https://github.com/jenshannoschwalm/darktable
2 parents c83eb31 + f10cc14 commit f4b83eb

File tree

6 files changed

+196
-186
lines changed

6 files changed

+196
-186
lines changed

data/kernels/demosaic_other.cl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of darktable,
3-
copyright (c) 2015 LebedevRI.
3+
Copyright (C) 2015-2025 darktable developers.
44
55
darktable is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -62,8 +62,13 @@ passthrough_color (__read_only image2d_t in, __write_only image2d_t out, const i
6262
* and writes it to out in float4 format.
6363
*/
6464
__kernel void
65-
clip_and_zoom_demosaic_passthrough_monochrome(__read_only image2d_t in, __write_only image2d_t out, const int width, const int height,
66-
const int r_x, const int r_y, const int rin_wd, const int rin_ht, const float r_scale, const unsigned int filters)
65+
clip_and_zoom_demosaic_passthrough_monochrome(__read_only image2d_t in,
66+
__write_only image2d_t out,
67+
const int width,
68+
const int height,
69+
const int rin_wd,
70+
const int rin_ht,
71+
const float r_scale)
6772
{
6873
// global id is pixel in output image (float4)
6974
const int x = get_global_id(0);
@@ -79,19 +84,19 @@ clip_and_zoom_demosaic_passthrough_monochrome(__read_only image2d_t in, __write_
7984
// how many pixels can be sampled inside that area
8085
const int samples = round(px_footprint);
8186

82-
const float2 f = (float2)((x + r_x) * px_footprint, (y + r_y) * px_footprint);
83-
int2 p = (int2)((int)f.x, (int)f.y);
87+
const float2 f = (float2)(x * px_footprint, y * px_footprint);
88+
const int2 p = (int2)((int)f.x, (int)f.y);
8489
const float2 d = (float2)(f.x - p.x, f.y - p.y);
8590

8691
for(int j=0;j<=samples+1;j++) for(int i=0;i<=samples+1;i++)
8792
{
8893
const int xx = p.x + i;
8994
const int yy = p.y + j;
9095

91-
float xfilter = (i == 0) ? 1.0f - d.x : ((i == samples+1) ? d.x : 1.0f);
92-
float yfilter = (j == 0) ? 1.0f - d.y : ((j == samples+1) ? d.y : 1.0f);
96+
const float xfilter = (i == 0) ? 1.0f - d.x : ((i == samples+1) ? d.x : 1.0f);
97+
const float yfilter = (j == 0) ? 1.0f - d.y : ((j == samples+1) ? d.y : 1.0f);
9398

94-
float px = read_imagef(in, sampleri, (int2)(xx, yy)).x;
99+
const float px = read_imagef(in, sampleri, (int2)(xx, yy)).x;
95100
color += yfilter*xfilter*(float4)(px, px, px, 0.0f);
96101
weight += yfilter*xfilter;
97102
}

data/kernels/demosaic_ppg.cl

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of darktable,
3-
copyright (c) 2009--2010 johannes hanika.
3+
Copyright (C) 2009-2025 darktable developers.
44
55
darktable is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -36,8 +36,13 @@ backtransformf (float2 p, const int r_x, const int r_y, const int r_wd, const in
3636
}
3737

3838
kernel void
39-
green_equilibration_lavg(read_only image2d_t in, write_only image2d_t out, const int width, const int height, const unsigned int filters,
40-
const int r_x, const int r_y, const float thr, local float *buffer)
39+
green_equilibration_lavg(read_only image2d_t in,
40+
write_only image2d_t out,
41+
const int width,
42+
const int height,
43+
const unsigned int filters,
44+
const float thr,
45+
local float *buffer)
4146
{
4247
const int x = get_global_id(0);
4348
const int y = get_global_id(1);
@@ -79,11 +84,11 @@ green_equilibration_lavg(read_only image2d_t in, write_only image2d_t out, const
7984

8085
if(x >= width || y >= height) return;
8186

82-
const int c = FC(y + r_y, x + r_x, filters);
87+
const int c = FC(y, x, filters);
8388
const float maximum = 1.0f;
8489
float o = buffer[0];
8590

86-
if(c == 1 && ((y + r_y) & 1))
91+
if(c == 1 && (y & 1))
8792
{
8893
const float o1_1 = buffer[-1 * stride - 1];
8994
const float o1_2 = buffer[-1 * stride + 1];
@@ -112,8 +117,12 @@ green_equilibration_lavg(read_only image2d_t in, write_only image2d_t out, const
112117

113118

114119
kernel void
115-
green_equilibration_favg_reduce_first(read_only image2d_t in, const int width, const int height,
116-
global float2 *accu, const unsigned int filters, const int r_x, const int r_y, local float2 *buffer)
120+
green_equilibration_favg_reduce_first(read_only image2d_t in,
121+
const int width,
122+
const int height,
123+
global float2 *accu,
124+
const unsigned int filters,
125+
local float2 *buffer)
117126
{
118127
const int x = get_global_id(0);
119128
const int y = get_global_id(1);
@@ -124,11 +133,11 @@ green_equilibration_favg_reduce_first(read_only image2d_t in, const int width, c
124133

125134
const int l = mad24(ylid, xlsz, xlid);
126135

127-
const int c = FC(y + r_y, x + r_x, filters);
136+
const int c = FC(y, x, filters);
128137

129138
const int isinimage = (x < 2 * (width / 2) && y < 2 * (height / 2));
130-
const int isgreen1 = (c == 1 && !((y + r_y) & 1));
131-
const int isgreen2 = (c == 1 && ((y + r_y) & 1));
139+
const int isgreen1 = (c == 1 && !(y & 1));
140+
const int isgreen2 = (c == 1 && (y & 1));
132141

133142
float pixel = read_imagef(in, sampleri, (int2)(x, y)).x;
134143

@@ -194,8 +203,12 @@ green_equilibration_favg_reduce_second(const global float2* input, global float2
194203

195204

196205
kernel void
197-
green_equilibration_favg_apply(read_only image2d_t in, write_only image2d_t out, const int width, const int height, const unsigned int filters,
198-
const int r_x, const int r_y, const float gr_ratio)
206+
green_equilibration_favg_apply(read_only image2d_t in,
207+
write_only image2d_t out,
208+
const int width,
209+
const int height,
210+
const unsigned int filters,
211+
const float gr_ratio)
199212
{
200213
const int x = get_global_id(0);
201214
const int y = get_global_id(1);
@@ -204,9 +217,9 @@ green_equilibration_favg_apply(read_only image2d_t in, write_only image2d_t out,
204217

205218
float pixel = read_imagef(in, sampleri, (int2)(x, y)).x;
206219

207-
const int c = FC(y + r_y, x + r_x, filters);
220+
const int c = FC(y, x, filters);
208221

209-
const int isgreen1 = (c == 1 && !((y + r_y) & 1));
222+
const int isgreen1 = (c == 1 && !(y & 1));
210223

211224
pixel *= (isgreen1 ? gr_ratio : 1.0f);
212225

@@ -461,8 +474,14 @@ clip_and_zoom(read_only image2d_t in, write_only image2d_t out, const int width,
461474
* resamping is done via rank-1 lattices and demosaicing using half-size interpolation.
462475
*/
463476
__kernel void
464-
clip_and_zoom_demosaic_half_size(__read_only image2d_t in, __write_only image2d_t out, const int width, const int height,
465-
const int r_x, const int r_y, const int rin_wd, const int rin_ht, const float r_scale, const unsigned int filters)
477+
clip_and_zoom_demosaic_half_size(__read_only image2d_t in,
478+
__write_only image2d_t out,
479+
const int width,
480+
const int height,
481+
const int rin_wd,
482+
const int rin_ht,
483+
const float r_scale,
484+
const unsigned int filters)
466485
{
467486
// global id is pixel in output image (float4)
468487
const int x = get_global_id(0);
@@ -490,7 +509,7 @@ clip_and_zoom_demosaic_half_size(__read_only image2d_t in, __write_only image2d_
490509

491510

492511
// upper left corner:
493-
const float2 f = (float2)((x + r_x) * px_footprint, (y + r_y) * px_footprint);
512+
const float2 f = (float2)(x * px_footprint, y * px_footprint);
494513
int2 p = (int2)((int)f.x & ~1, (int)f.y & ~1);
495514
const float2 d = (float2)((f.x - p.x)/2.0f, (f.y - p.y)/2.0f);
496515

@@ -504,14 +523,14 @@ clip_and_zoom_demosaic_half_size(__read_only image2d_t in, __write_only image2d_
504523

505524
if(xx + 1 >= rin_wd || yy + 1 >= rin_ht) continue;
506525

507-
float xfilter = (i == 0) ? 1.0f - d.x : ((i == samples+1) ? d.x : 1.0f);
508-
float yfilter = (j == 0) ? 1.0f - d.y : ((j == samples+1) ? d.y : 1.0f);
526+
const float xfilter = (i == 0) ? 1.0f - d.x : ((i == samples+1) ? d.x : 1.0f);
527+
const float yfilter = (j == 0) ? 1.0f - d.y : ((j == samples+1) ? d.y : 1.0f);
509528

510529
// get four mosaic pattern uint16:
511-
float p1 = read_imagef(in, sampleri, (int2)(xx, yy )).x;
512-
float p2 = read_imagef(in, sampleri, (int2)(xx+1, yy )).x;
513-
float p3 = read_imagef(in, sampleri, (int2)(xx, yy+1)).x;
514-
float p4 = read_imagef(in, sampleri, (int2)(xx+1, yy+1)).x;
530+
const float p1 = read_imagef(in, sampleri, (int2)(xx, yy )).x;
531+
const float p2 = read_imagef(in, sampleri, (int2)(xx+1, yy )).x;
532+
const float p3 = read_imagef(in, sampleri, (int2)(xx, yy+1)).x;
533+
const float p4 = read_imagef(in, sampleri, (int2)(xx+1, yy+1)).x;
515534
color += yfilter*xfilter*(float4)(p1, (p2+p3)*0.5f, p4, 0.0f);
516535
weight += yfilter*xfilter;
517536
}
@@ -679,7 +698,7 @@ ppg_demosaic_redblue (read_only image2d_t in, write_only image2d_t out, const in
679698
float4 color = buffer[0];
680699
if(x == 0 || y == 0 || x == (width-1) || y == (height-1))
681700
{
682-
write_imagef (out, (int2)(x, y), fmax(color, 0.0f));
701+
write_imagef (out, (int2)(x, y), fmax(color, 0.0f));
683702
return;
684703
}
685704

data/kernels/demosaic_rcd.cl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of darktable,
3-
Copyright (C) 2020-2024 darktable developers.
3+
Copyright (C) 2020-2025 darktable developers.
44
55
darktable is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -542,3 +542,33 @@ kernel void rcd_border_redblue(read_only image2d_t in, write_only image2d_t out,
542542
write_imagef (out, (int2)(x, y), fmax(color, 0.0f));
543543
}
544544

545+
kernel void demosaic_box3(read_only image2d_t in,
546+
write_only image2d_t out,
547+
const int width,
548+
const int height,
549+
const int sx,
550+
const int sy,
551+
const unsigned int filters,
552+
global const unsigned char (*const xtrans)[6])
553+
{
554+
const int col = get_global_id(0);
555+
const int row = get_global_id(1);
556+
if(col >= width || row >= height) return;
557+
float sum[3] = { 0.0f, 0.0f, 0.0f };
558+
float cnt[3] = { 0.0f, 0.0f, 0.0f };
559+
for(int y = row-1; y < row+2; y++)
560+
{
561+
for(int x = col-1; x < col+2; x++)
562+
{
563+
if(x >= 0 && y >= 0 && x < width && y < height)
564+
{
565+
const int color = (filters == 9u) ? FCxtrans(y+sy, x+sx, xtrans) : FC(y, x, filters);
566+
sum[color] += fmax(0.0f, read_imagef(in, samplerA, (int2)(x, y)).x);
567+
cnt[color] += 1.0f;
568+
}
569+
}
570+
}
571+
const float4 rgb = { sum[0]/fmax(1.0f, cnt[0]), sum[1]/fmax(1.0f, cnt[1]), sum[2]/fmax(1.0f, cnt[2]), 0.0f};
572+
write_imagef(out, (int2)(col, row), rgb);
573+
}
574+

0 commit comments

Comments
 (0)