So, this is the source of cr2hdr to solve the bad pixels... it's just it a1ex? I can place it after the chroma smooth operations and compile?
static void find_and_fix_bad_pixels(int dark_noise, int bright_noise, int* raw2ev, int* ev2raw)
{
int w = raw_info.width;
int h = raw_info.height;
int black = raw_info.black_level;
//~ int white = raw_info.white_level;
printf("Looking for hot/cold pixels...\n");
/* hot pixel map */
unsigned short* hotpixel = malloc(w * h * sizeof(unsigned short));
memset(hotpixel, 0, w * h * sizeof(unsigned short));
int hot_pixels = 0;
int cold_pixels = 0;
int x,y;
for (y = 6; y < h-6; y ++)
{
for (x = 6; x < w-6; x ++)
{
int p = raw_get_pixel(x, y);
int is_hot = 0;
int is_cold = 0;
/* really dark pixels (way below the black level) are probably noise */
is_cold = (p < black - dark_noise*8);
/* we don't have no hot pixels on the bright exposure */
/* but we may have cold pixels */
if (!BRIGHT_ROW || is_cold)
{
/* let's look at the neighbours: is this pixel clearly brigher? (isolated) */
int neighbours[100];
int k = 0;
int i,j;
int fc0 = FC(x, y);
int b0 = is_bright[y%4];
for (i = -4; i <= 4; i++)
{
for (j = -4; j <= 4; j++)
{
if (i == 0 && j == 0)
continue;
/* only look at pixels of the same brightness */
if (is_bright[(y+i)%4] != b0)
continue;
/* only look at pixels of the same color */
if (FC(x+j, y+i) != fc0)
continue;
int p = raw_get_pixel(x+j, y+i);
neighbours[k++] = -p;
}
}
if (k <= 4) /* not enough data to draw a conclusion */
continue;
int max = -kth_smallest_int(neighbours, k, 1);
is_hot = (raw2ev[p] - raw2ev[max] > EV_RESOLUTION) && (max > black + 8*dark_noise);
if (fix_bad_pixels == 2) /* aggressive */
{
int second_max = -kth_smallest_int(neighbours, k, 2);
is_hot = ((raw2ev[p] - raw2ev[max] > EV_RESOLUTION/4) && (max > black + 8*dark_noise))
|| (raw2ev[p] - raw2ev[second_max] > EV_RESOLUTION/2);
}
if (is_hot)
{
hot_pixels++;
hotpixel[x + y*w] = -kth_smallest_int(neighbours, k, 2);
}
if (is_cold)
{
cold_pixels++;
hotpixel[x + y*w] = -median_int_wirth(neighbours, k);
}
}
}
}
/* apply the correction */
for (y = 0; y < h; y ++)
for (x = 0; x < w; x ++)
if (hotpixel[x + y*w])
raw_set_pixel16(x, y, debug_bad_pixels ? black : hotpixel[x + y*w]);
if (hot_pixels)
printf("Hot pixels : %d\n", hot_pixels);
if (cold_pixels)
printf("Cold pixels : %d\n", cold_pixels);
free(hotpixel);
}
edit: I analyse the non-demosaicing data, and it's just a dark pixel (ohhh, really?), the chroma artefacts is the effect of interpolation algorithm... but seems really simple to resolve it, but I am not a programmer. I will try.