Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibRawLite/internal/aahd_demosaic.cpp view on Meta::CPAN
ushort channel_maximum[3], channels_max;
ushort channel_minimum[3];
static const float yuv_coeff[3][3];
static float gammaLUT[0x10000];
float yuv_cam[3][3];
LibRaw &libraw;
enum {
HVSH = 1, HOR = 2, VER = 4, HORSH = HOR | HVSH, VERSH = VER | HVSH, HOT = 8
};
static inline float calc_dist(int c1, int c2) throw () {
return c1 > c2 ? (float) c1 / c2 : (float) c2 / c1;
}
int inline Y(ushort3 &rgb) throw () {
return yuv_cam[0][0] * rgb[0] + yuv_cam[0][1] * rgb[1] + yuv_cam[0][2] * rgb[2];
}
int inline U(ushort3 &rgb) throw () {
return yuv_cam[1][0] * rgb[0] + yuv_cam[1][1] * rgb[1] + yuv_cam[1][2] * rgb[2];
}
int inline V(ushort3 &rgb) throw () {
return yuv_cam[2][0] * rgb[0] + yuv_cam[2][1] * rgb[1] + yuv_cam[2][2] * rgb[2];
}
inline int nr_offset(int row, int col) throw () {
return (row * nr_width + col);
}
~AAHD();
AAHD(LibRaw &_libraw);
void make_ahd_greens();
void make_ahd_gline(int i);
void make_ahd_rb();
void make_ahd_rb_hv(int i);
void make_ahd_rb_last(int i);
void evaluate_ahd();
void combine_image();
void hide_hots();
void refine_hv_dirs();
void refine_hv_dirs(int i, int js);
void refine_ihv_dirs(int i);
void illustrate_dirs();
void illustrate_dline(int i);
};
const float AAHD::yuv_coeff[3][3] = {
// YPbPr
// {
// 0.299f,
// 0.587f,
// 0.114f },
// {
// -0.168736,
// -0.331264f,
// 0.5f },
// {
// 0.5f,
// -0.418688f,
// -0.081312f }
//
// Rec. 2020
// Y'= 0,2627R' + 0,6780G' + 0,0593B'
// U = (B-Y)/1.8814 = (-0,2627R' - 0,6780G' + 0.9407B) / 1.8814 = -0.13963R - 0.36037G + 0.5B
// V = (R-Y)/1.4647 = (0.7373R - 0,6780G - 0,0593B) / 1.4647 = 0.5R - 0.4629G - 0.04049B
{
+0.2627f,
+0.6780f,
+0.0593f },
{
-0.13963f,
-0.36037f,
+0.5f },
{
+0.5034f,
-0.4629f,
-0.0405f }
};
float AAHD::gammaLUT[0x10000] = {
-1.f };
AAHD::AAHD(LibRaw& _libraw) :
libraw(_libraw) {
nr_height = libraw.imgdata.sizes.iheight + nr_margin * 2;
nr_width = libraw.imgdata.sizes.iwidth + nr_margin * 2;
rgb_ahd[0] = (ushort3*) calloc(nr_height * nr_width,
(sizeof(ushort3) * 2 + sizeof(int3) * 2 + 3));
rgb_ahd[1] = rgb_ahd[0] + nr_height * nr_width;
yuv[0] = (int3 *) (rgb_ahd[1] + nr_height * nr_width);
yuv[1] = yuv[0] + nr_height * nr_width;
ndir = (char*) (yuv[1] + nr_height * nr_width);
homo[0] = ndir + nr_height * nr_width;
homo[1] = homo[0] + nr_height * nr_width;
channel_maximum[0] = channel_maximum[1] = channel_maximum[2] = 0;
channel_minimum[0] = libraw.imgdata.image[0][0];
channel_minimum[1] = libraw.imgdata.image[0][1];
channel_minimum[2] = libraw.imgdata.image[0][2];
int iwidth = libraw.imgdata.sizes.iwidth;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j) {
yuv_cam[i][j] = 0;
for (int k = 0; k < 3; ++k)
yuv_cam[i][j] += yuv_coeff[i][k] * libraw.imgdata.color.rgb_cam[k][j];
}
if (gammaLUT[0] < -0.1f) {
float r;
for (int i = 0; i < 0x10000; i++) {
r = (float) i / 0x10000;
gammaLUT[i] = 0x10000 * (r < 0.0181 ? 4.5f * r : 1.0993f * pow(r, 0.45f) - .0993f);
}
}
for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) {
int col_cache[48];
for (int j = 0; j < 48; ++j) {
int c = libraw.COLOR(i, j);
if (c == 3)
c = 1;
col_cache[j] = c;
}
int moff = nr_offset(i + nr_margin, nr_margin);
for (int j = 0; j < iwidth; ++j, ++moff) {
int c = col_cache[j % 48];
unsigned short d = libraw.imgdata.image[i * iwidth + j][c];
( run in 0.672 second using v1.01-cache-2.11-cpan-39bf76dae61 )