Update of /cvsroot/ufraw/ufraw
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv22286

Modified Files:
        README configure.ac dcraw_api.cc dcraw_api.h dcraw_indi.c 
Log Message:
Better support for FUJIFILM 'X-Trans' sensors. Currently only bilinear 
interpolation is supported. The '--enable-x-trans' configuration switch is 
removed.

Index: configure.ac
===================================================================
RCS file: /cvsroot/ufraw/ufraw/configure.ac,v
retrieving revision 1.179
retrieving revision 1.180
diff -u -d -r1.179 -r1.180
--- configure.ac        6 Oct 2013 05:00:15 -0000       1.179
+++ configure.ac        17 Oct 2013 04:30:17 -0000      1.180
@@ -352,13 +352,6 @@
   enable_contrast=no)
 AC_MSG_RESULT($enable_contrast)
 
-AC_MSG_CHECKING(whether to enable support for the FUJIFILM 'X-Trans' sensor)
-AC_ARG_ENABLE(x_trans,
-  [  --enable-x-trans        enable support for the FUJIFILM 'X-Trans' sensor],
-  AC_DEFINE(UFRAW_X_TRANS, 1, FUJIFILM 'X-Trans' sensor support enabled),
-  enable_x_trans=no)
-AC_MSG_RESULT($enable_x_trans)
-
 AC_MSG_CHECKING(whether to enable 'None' interpolation)
 AC_ARG_ENABLE(interp_none,
   [  --enable-interp-none    enable 'None' interpolation (mostly for 
debugging)],

Index: dcraw_api.h
===================================================================
RCS file: /cvsroot/ufraw/ufraw/dcraw_api.h,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- dcraw_api.h 1 Jan 2013 04:00:16 -0000       1.47
+++ dcraw_api.h 17 Oct 2013 04:30:17 -0000      1.48
@@ -31,7 +31,7 @@
         void *dcraw;
         FILE *ifp;
         int width, height, colors, fourColorFilters, filters, raw_color;
-        int flip, shrink;
+        int top_margin, left_margin, flip, shrink;
         double pixel_aspect;
         dcraw_image_data raw;
         dcraw_image_type thresholds;
@@ -41,7 +41,7 @@
         double fuji_step;
         int toneCurveSize, toneCurveOffset;
         int toneModeSize, toneModeOffset;
-        char *message;
+        char *message, xtrans[6][6];
         float iso_speed, shutter, aperture, focal_len;
         time_t timestamp;
         char make[80], model[80];

Index: dcraw_indi.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/dcraw_indi.c,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -d -r1.110 -r1.111
--- dcraw_indi.c        2 Jun 2013 05:30:14 -0000       1.110
+++ dcraw_indi.c        17 Oct 2013 04:30:17 -0000      1.111
@@ -69,7 +69,9 @@
 #define BAYER(row,col) \
     image[((row) >> shrink)*iwidth + ((col) >> shrink)][FC(row,col)]
 
-int CLASS fcol_INDI(const unsigned filters, const int row, const int col)
+int CLASS fcol_INDI(const unsigned filters, const int row, const int col,
+                    const int top_margin, const int left_margin,
+                    /*const*/ char xtrans[6][6])
 {
     static const char filter[16][16] = {
         { 2, 1, 1, 3, 2, 3, 2, 0, 3, 2, 3, 0, 1, 2, 1, 0 },
@@ -89,24 +91,9 @@
         { 2, 1, 3, 2, 3, 1, 2, 1, 0, 3, 0, 2, 0, 2, 0, 2 },
         { 0, 3, 1, 0, 0, 2, 0, 3, 2, 1, 3, 1, 1, 3, 1, 3 }
     };
-#ifdef UFRAW_X_TRANS
-    static const char filter2[6][6] = {
-        { 1, 1, 0, 1, 1, 2 },
-        { 1, 1, 2, 1, 1, 0 },
-        { 2, 0, 1, 0, 2, 1 },
-        { 1, 1, 2, 1, 1, 0 },
-        { 1, 1, 0, 1, 1, 2 },
-        { 0, 2, 1, 2, 0, 1 }
-    };
-#endif
 
-    /* Assume that we are handling the Leaf CatchLight with
-     * top_margin = 8; left_margin = 18; */
-//  if (filters == 1) return filter[(row+top_margin) & 15][(col+left_margin) & 
15];
-    if (filters == 1) return filter[(row + 8) & 15][(col + 18) & 15];
-#ifdef UFRAW_X_TRANS
-    if (filters == 9) return filter2[(row + 6) % 6][(col + 6) % 6];
-#endif
+    if (filters == 1) return filter[(row + top_margin) & 15][(col + 
left_margin) & 15];
+    if (filters == 9) return xtrans[(row + top_margin + 6) % 6][(col + 
left_margin + 6) % 6];
     return FC(row, col);
 }
 
@@ -268,7 +255,7 @@
 }
 
 void CLASS border_interpolate_INDI(const int height, const int width,
-                                   ushort(*image)[4], const unsigned filters, 
int colors, int border)
+                                   ushort(*image)[4], const unsigned filters, 
int colors, int border, dcraw_data *h)
 {
     int row, col, y, x, f, c, sum[8];
 
@@ -280,37 +267,35 @@
             for (y = row - 1; y != row + 2; y++)
                 for (x = col - 1; x != col + 2; x++)
                     if (y >= 0 && y < height && x >= 0 && x < width) {
-                        f = fcol_INDI(filters, y, x);
+                        f = fcol_INDI(filters, y, x, h->top_margin, 
h->left_margin, h->xtrans);
                         sum[f] += image[y * width + x][f];
                         sum[f + 4]++;
                     }
-            f = fcol_INDI(filters, row, col);
+            f = fcol_INDI(filters, row, col, h->top_margin, h->left_margin, 
h->xtrans);
             FORCC if (c != f && sum[c + 4])
                 image[row * width + col][c] = sum[c] / sum[c + 4];
         }
 }
 
 void CLASS lin_interpolate_INDI(ushort(*image)[4], const unsigned filters,
-                                const int width, const int height, const int 
colors, void *dcraw) /*UF*/
+                                const int width, const int height, const int 
colors, void *dcraw, dcraw_data *h) /*UF*/
 {
     int code[16][16][32], size = 16, *ip, sum[4];
     int f, c, i, x, y, row, col, shift, color;
     ushort *pix;
 
     dcraw_message(dcraw, DCRAW_VERBOSE, _("Bilinear interpolation...\n")); 
/*UF*/
-#ifdef UFRAW_X_TRANS
     if (filters == 9) size = 6;
-#endif
-    border_interpolate_INDI(height, width, image, filters, colors, 1);
+    border_interpolate_INDI(height, width, image, filters, colors, 1, h);
     for (row = 0; row < size; row++) {
         for (col = 0; col < size; col++) {
             ip = code[row][col] + 1;
-            f = fcol_INDI(filters, row, col);
+            f = fcol_INDI(filters, row, col, h->top_margin, h->left_margin, 
h->xtrans);
             memset(sum, 0, sizeof sum);
             for (y = -1; y <= 1; y++)
                 for (x = -1; x <= 1; x++) {
                     shift = (y == 0) + (x == 0);
-                    color = fcol_INDI(filters, row + y, col + x);
+                    color = fcol_INDI(filters, row + y, col + x, 
h->top_margin, h->left_margin, h->xtrans);
                     if (color == f) continue;
                     *ip++ = (width * y + x) * 4 + color;
                     *ip++ = shift;
@@ -352,7 +337,7 @@
    Gradients are numbered clockwise from NW=0 to W=7.
  */
 void CLASS vng_interpolate_INDI(ushort(*image)[4], const unsigned filters,
-                                const int width, const int height, const int 
colors, void *dcraw) /*UF*/
+                                const int width, const int height, const int 
colors, void *dcraw, dcraw_data *h) /*UF*/
 {
     static const signed char *cp, terms[] = {
         -2, -2, +0, -1, 0, 0x01, -2, -2, +0, +0, 1, 0x01, -2, -1, -1, +0, 0, 
0x01,
@@ -384,13 +369,11 @@
     int g, diff, thold, num, c;
     ushort rowtmp[4][width * 4];
 
-    lin_interpolate_INDI(image, filters, width, height, colors, dcraw); /*UF*/
+    lin_interpolate_INDI(image, filters, width, height, colors, dcraw, h); 
/*UF*/
     dcraw_message(dcraw, DCRAW_VERBOSE, _("VNG interpolation...\n")); /*UF*/
 
     if (filters == 1) prow = pcol = 16;
-#ifdef UFRAW_X_TRANS
     if (filters == 9) prow = pcol =  6;
-#endif
     int *ipalloc = ip = (int *) calloc(prow * pcol, 1280);
     merror(ip, "vng_interpolate()");
     for (row = 0; row < prow; row++)           /* Precalculate for VNG */
@@ -403,9 +386,9 @@
                 x2 = *cp++;
                 weight = *cp++;
                 grads = *cp++;
-                color = fcol_INDI(filters, row + y1, col + x1);
-                if (fcol_INDI(filters, row + y2, col + x2) != color) continue;
-                diag = (fcol_INDI(filters, row, col + 1) == color && 
fcol_INDI(filters, row + 1, col) == color) ? 2 : 1;
+                color = fcol_INDI(filters, row + y1, col + x1, h->top_margin, 
h->left_margin, h->xtrans);
+                if (fcol_INDI(filters, row + y2, col + x2, h->top_margin, 
h->left_margin, h->xtrans) != color) continue;
+                diag = (fcol_INDI(filters, row, col + 1, h->top_margin, 
h->left_margin, h->xtrans) == color && fcol_INDI(filters, row + 1, col, 
h->top_margin, h->left_margin, h->xtrans) == color) ? 2 : 1;
                 if (abs(y1 - y2) == diag && abs(x1 - x2) == diag) continue;
                 *ip++ = (y1 * width + x1) * 4 + color;
                 *ip++ = (y2 * width + x2) * 4 + color;
@@ -419,8 +402,8 @@
                 y = *cp++;
                 x = *cp++;
                 *ip++ = (y * width + x) * 4;
-                color = fcol_INDI(filters, row, col);
-                if (fcol_INDI(filters, row + y, col + x) != color && 
fcol_INDI(filters, row + y * 2, col + x * 2) == color)
+                color = fcol_INDI(filters, row, col, h->top_margin, 
h->left_margin, h->xtrans);
+                if (fcol_INDI(filters, row + y, col + x, h->top_margin, 
h->left_margin, h->xtrans) != color && fcol_INDI(filters, row + y * 2, col + x 
* 2, h->top_margin, h->left_margin, h->xtrans) == color)
                     *ip++ = (y * width + x) * 8 + color;
                 else
                     *ip++ = 0;
@@ -430,7 +413,7 @@
 #ifdef _OPENMP
     #pragma omp parallel                               \
     default(none)                                      \
-    shared(image,code,prow,pcol)                       \
+    shared(image,code,prow,pcol,h)                     \
     
private(row,col,g,brow,rowtmp,pix,ip,gval,diff,gmin,gmax,thold,sum,color,num,c,t)
 #endif
     {
@@ -466,7 +449,7 @@
                 }
                 thold = gmin + (gmax >> 1);
                 memset(sum, 0, sizeof sum);
-                color = fcol_INDI(filters, row, col);
+                color = fcol_INDI(filters, row, col, h->top_margin, 
h->left_margin, h->xtrans);
                 for (num = g = 0; g < 8; g++, ip += 2) { /* Average the 
neighbors */
                     if (gval[g] <= thold) {
                         FORCC
@@ -501,13 +484,13 @@
 */
 void CLASS ppg_interpolate_INDI(ushort(*image)[4], const unsigned filters,
                                 const int width, const int height,
-                                const int colors, void *dcraw)
+                                const int colors, void *dcraw, dcraw_data *h)
 {
     int dir[5] = { 1, width, -1, -width, 1 };
     int row, col, diff[2] = { 0, 0 }, guess[2], c, d, i;
     ushort(*pix)[4];
 
-    border_interpolate_INDI(height, width, image, filters, colors, 3);
+    border_interpolate_INDI(height, width, image, filters, colors, 3, h);
     dcraw_message(dcraw, DCRAW_VERBOSE, _("PPG interpolation...\n")); /*UF*/
 
 #ifdef _OPENMP
@@ -572,16 +555,16 @@
     }
 }
 
+#define TS 512         /* Tile Size */
+
 /*
    Adaptive Homogeneity-Directed interpolation is based on
    the work of Keigo Hirakawa, Thomas Parks, and Paul Lee.
  */
-#define TS 512         /* Tile Size */
-
 void CLASS ahd_interpolate_INDI(ushort(*image)[4], const unsigned filters,
                                 const int width, const int height,
                                 const int colors, const float rgb_cam[3][4],
-                                void *dcraw)
+                                void *dcraw, dcraw_data *h)
 {
     int i, j, k, top, left, row, col, tr, tc, c, d, val, hm[2];
     ushort(*pix)[4], (*rix)[3];
@@ -615,7 +598,7 @@
                 for (xyz_cam[i][j] = k = 0; k < 3; k++)
                     xyz_cam[i][j] += xyz_rgb[i][k] * rgb_cam[k][j] / 
d65_white[i];
 
-        border_interpolate_INDI(height, width, image, filters, colors, 5);
+        border_interpolate_INDI(height, width, image, filters, colors, 5, h);
         buffer = (char *) malloc(26 * TS * TS); /* 1664 kB */
         merror(buffer, "ahd_interpolate()");
         rgb  = (ushort(*)[TS][TS][3]) buffer;

Index: README
===================================================================
RCS file: /cvsroot/ufraw/ufraw/README,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -d -r1.69 -r1.70
--- README      6 Oct 2013 05:00:15 -0000       1.69
+++ README      17 Oct 2013 04:30:17 -0000      1.70
@@ -118,8 +118,6 @@
 
 --enable-contrast: enable the contrast setting option.
 
---enable-x-trans: enable support for the FUJIFILM 'X-Trans' sensor.
-
 --enable-interp-none: enable 'None' interpolation (mostly for debugging).
 
 --enable-valgrind: enable debugging with valgrind

Index: dcraw_api.cc
===================================================================
RCS file: /cvsroot/ufraw/ufraw/dcraw_api.cc,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -d -r1.91 -r1.92
--- dcraw_api.cc        1 Jun 2013 18:30:13 -0000       1.91
+++ dcraw_api.cc        17 Oct 2013 04:30:17 -0000      1.92
@@ -35,7 +35,9 @@
 #define FORC4 FORC(4)
 #define FORCC FORC(colors)
 extern "C" {
-    int fcol_INDI(const unsigned filters, const int row, const int col);
+    int fcol_INDI(const unsigned filters, const int row, const int col,
+                  const int top_margin, const int left_margin,
+                  /*const*/ char xtrans[6][6]);
     void wavelet_denoise_INDI(gushort(*image)[4], const int black,
                               const int iheight, const int iwidth, const int 
height, const int width,
                               const int colors, const int shrink, const float 
pre_mul[4],
@@ -45,17 +47,18 @@
                            float pre_mul[4], const unsigned filters, /*const*/ 
gushort white[8][8],
                            const char *ifname_display, void *dcraw);
     void lin_interpolate_INDI(gushort(*image)[4], const unsigned filters,
-                              const int width, const int height, const int 
colors, void *dcraw);
+                              const int width, const int height,
+                              const int colors, void *dcraw, dcraw_data *h);
     void vng_interpolate_INDI(gushort(*image)[4], const unsigned filters,
                               const int width, const int height, const int 
colors, const int rgb_max,
-                              void *dcraw);
+                              void *dcraw, dcraw_data *h);
     void ahd_interpolate_INDI(gushort(*image)[4], const unsigned filters,
                               const int width, const int height, const int 
colors, float rgb_cam[3][4],
-                              void *dcraw);
+                              void *dcraw, dcraw_data *h);
     void color_smooth(gushort(*image)[4], const int width, const int height,
                       const int passes);
     void ppg_interpolate_INDI(gushort(*image)[4], const unsigned filters,
-                              const int width, const int height, const int 
colors, void *dcraw);
+                              const int width, const int height, const int 
colors, void *dcraw, dcraw_data *h);
     void flip_image_INDI(gushort(*image)[4], int *height_p, int *width_p,
                          const int flip);
     void fuji_rotate_INDI(gushort(**image_p)[4], int *height_p, int *width_p,
@@ -91,9 +94,6 @@
             return DCRAW_OPEN_ERROR;
         }
         d->identify();
-#ifndef UFRAW_X_TRANS
-        if (d->filters == 9) d->is_raw = 0;
-#endif
         /* We first check if dcraw recognizes the file, this is equivalent
          * to 'dcraw -i' succeeding */
         if (!d->make[0]) {
@@ -131,6 +131,8 @@
         h->colors = d->colors;
         h->filters = d->filters;
         h->raw_color = d->raw_color;
+        h->top_margin = d->top_margin;
+        h->left_margin = d->left_margin;
         memcpy(h->cam_mul, d->cam_mul, sizeof d->cam_mul);
         // maximum and black might change during load_raw. We need them for the
         // camera-wb. If they'll change we will recalculate the camera-wb.
@@ -168,6 +170,7 @@
         h->raw.image = NULL;
         h->thumbType = unknown_thumb_type;
         h->message = d->messageBuffer;
+        memcpy(h->xtrans, d->xtrans, sizeof d->xtrans);
         return d->lastStatus;
     }
 
@@ -361,13 +364,14 @@
      * always try to index the column and not the row in order to reduce the
      * data cache footprint.
      */
-    static unsigned fcol_sequence(int filters, int row)
+    static unsigned fcol_sequence(int filters, int row, int top_margin,
+                                  int left_margin, char xtrans[6][6])
     {
         unsigned sequence = 0;
         int c;
 
         for (c = 15; c >= 0; --c)
-            sequence = (sequence << 2) | fcol_INDI(filters, row, c);
+            sequence = (sequence << 2) | fcol_INDI(filters, row, c, 
top_margin, left_margin, xtrans);
         return sequence;
     }
 
@@ -470,7 +474,7 @@
             for (r = 0; r < h; ++r) {
                 fseq = (unsigned*) g_malloc(scale * sizeof(unsigned));
                 for (ri = 0; ri < scale; ++ri)
-                    fseq[ri] = fcol_sequence(f4, r + ri);
+                    fseq[ri] = fcol_sequence(f4, r + ri, hh->top_margin, 
hh->left_margin, hh->xtrans);
                 for (c = 0; c < w; ++c) {
                     pixp = f->image[r * w + c];
                     shrink_pixel(pixp, r, c, hh, fseq, scale);
@@ -723,6 +727,8 @@
 
         /* It might be better to report an error here: */
         /* (dcraw also forbids AHD for Fuji rotated images) */
+        if (h->filters == 9)
+            interpolation = dcraw_bilinear_interpolation;
         if (interpolation == dcraw_ahd_interpolation && h->colors > 3)
             interpolation = dcraw_vng_interpolation;
         if (interpolation == dcraw_ppg_interpolation && h->colors > 3)
@@ -730,25 +736,25 @@
         f4 = h->fourColorFilters;
         for (r = 0; r < h->height; r++)
             for (c = 0; c < h->width; c++) {
-                int cc = fcol_INDI(f4, r, c);
-                f->image[r * f->width + c][fcol_INDI(ff, r, c)] =
+                int cc = fcol_INDI(f4, r, c, h->top_margin, h->left_margin, 
h->xtrans);
+                f->image[r * f->width + c][fcol_INDI(ff, r, c, h->top_margin, 
h->left_margin, h->xtrans)] =
                     h->raw.image[r / 2 * h->raw.width + c / 2][cc];
             }
         int smoothPasses = 1;
         if (interpolation == dcraw_bilinear_interpolation)
-            lin_interpolate_INDI(f->image, ff, f->width, f->height, cl, d);
+            lin_interpolate_INDI(f->image, ff, f->width, f->height, cl, d, h);
 #ifdef ENABLE_INTERP_NONE
         else if (interpolation == dcraw_none_interpolation)
             smoothing = 0;
 #endif
         else if (interpolation == dcraw_vng_interpolation)
-            vng_interpolate_INDI(f->image, ff, f->width, f->height, cl, 
0xFFFF, d);
+            vng_interpolate_INDI(f->image, ff, f->width, f->height, cl, 
0xFFFF, d, h);
         else if (interpolation == dcraw_ahd_interpolation) {
             ahd_interpolate_INDI(f->image, ff, f->width, f->height, cl,
-                                 h->rgb_cam, d);
+                                 h->rgb_cam, d, h);
             smoothPasses = 3;
         } else if (interpolation == dcraw_ppg_interpolation && h->filters > 
1000)
-            ppg_interpolate_INDI(f->image, ff, f->width, f->height, cl, d);
+            ppg_interpolate_INDI(f->image, ff, f->width, f->height, cl, d, h);
 
         if (smoothing)
             color_smooth(f->image, f->width, f->height, smoothPasses);


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
ufraw-cvs mailing list
ufraw-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ufraw-cvs

Reply via email to