Author: post
Date: 2009-08-17 23:16:07 +0200 (Mon, 17 Aug 2009)
New Revision: 2622

Modified:
   trunk/plugins/denoise/Makefile.am
   trunk/plugins/denoise/floatplanarimage-x86.cpp
   trunk/plugins/denoise/floatplanarimage.cpp
   trunk/plugins/denoise/floatplanarimage.h
Log:
Denoise: WB correction was being applied at the wrong stage, resulting in color 
cast when denoising/sharpening. One assembler function disabled until fixed.

Modified: trunk/plugins/denoise/Makefile.am
===================================================================
--- trunk/plugins/denoise/Makefile.am   2009-08-10 19:58:00 UTC (rev 2621)
+++ trunk/plugins/denoise/Makefile.am   2009-08-17 21:16:07 UTC (rev 2622)
@@ -10,7 +10,7 @@
 INCLUDES = \
        -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
        -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
-       @PACKAGE_CFLAGS@ \
+       @PACKAGE_CFLAGS@ -ffast-math \
        -I../../librawstudio/
 
 lib_LTLIBRARIES = denoise.la

Modified: trunk/plugins/denoise/floatplanarimage-x86.cpp
===================================================================
--- trunk/plugins/denoise/floatplanarimage-x86.cpp      2009-08-10 19:58:00 UTC 
(rev 2621)
+++ trunk/plugins/denoise/floatplanarimage-x86.cpp      2009-08-17 21:16:07 UTC 
(rev 2622)
@@ -22,6 +22,7 @@
 #if defined (__x86_64__)
 
 // Only 64 bits, and only if pixelsize is 4
+// FIXME: Apply R/B correction prior to square root
 void FloatPlanarImage::unpackInterleavedYUV_SSE( const ImgConvertJob* j )
 {  
   RS_IMAGE16* image = j->rs;
@@ -170,12 +171,12 @@
       "addps %%xmm0, %%xmm3\n"        // Add Y to blue
       "addps %%xmm0, %%xmm4\n"        // Add Y to red - xmm 0 free
       "mulps %%xmm1, %%xmm1\n"        // Square green
-      "mulps %%xmm15, %%xmm3\n"        // Multiply blue correction - maybe not 
needed later
-      "mulps %%xmm14, %%xmm4\n"        // Multiply red correction - maybe not 
needed later
       "minps %%xmm9, %%xmm1\n"        // Saturate green
       "mulps %%xmm3, %%xmm3\n"        // Square blue
       "mulps %%xmm4, %%xmm4\n"        // Square red
       "cvtps2dq %%xmm1, %%xmm1\n"     // Convert green to dwords
+      "mulps %%xmm15, %%xmm3\n"        // Multiply blue correction - maybe not 
needed later
+      "mulps %%xmm14, %%xmm4\n"        // Multiply red correction - maybe not 
needed later
       "minps %%xmm9, %%xmm3\n"        // Saturate blue
       "minps %%xmm9, %%xmm4\n"        // Saturate red
       "cvtps2dq %%xmm3, %%xmm3\n"     // Convert blue to dwords
@@ -259,11 +260,11 @@
       "addps %%xmm0, %%xmm3\n"        // Add Y to blue
       "addps %%xmm0, %%xmm4\n"        // Add Y to red - xmm 0 free
       "mulps %%xmm1, %%xmm1\n"        // Square green
-      "mulps %%xmm15, %%xmm3\n"        // Multiply blue correction - maybe not 
needed later
-      "mulps %%xmm14, %%xmm4\n"        // Multiply red correction - maybe not 
needed later
       "mulps %%xmm3, %%xmm3\n"        // Square blue
       "mulps %%xmm4, %%xmm4\n"        // Square red
       "cvtps2dq %%xmm1, %%xmm1\n"     // Convert green to dwords
+      "mulps %%xmm15, %%xmm3\n"        // Multiply blue correction - maybe not 
needed later
+      "mulps %%xmm14, %%xmm4\n"        // Multiply red correction - maybe not 
needed later
       "cvtps2dq %%xmm4, %%xmm4\n"     // Convert red to dwords
       "cvtps2dq %%xmm3, %%xmm3\n"     // Convert blue to dwords
       "packusdw %%xmm1, %%xmm1\n"     // green g3g2 g1g0 g3g2 g1g0
@@ -340,12 +341,12 @@
       "addps %%xmm0, %%xmm3\n"        // Add Y to blue
       "addps %%xmm0, %%xmm4\n"        // Add Y to red - xmm 0 free
       "mulps %%xmm1, %%xmm1\n"        // Square green
-      "mulps 80(%4), %%xmm3\n"        // Multiply blue correction - maybe not 
needed later
-      "mulps 64(%4), %%xmm4\n"        // Multiply red correction - maybe not 
needed later
       "minps %%xmm7, %%xmm1\n"        // Saturate green
       "mulps %%xmm3, %%xmm3\n"        // Square blue
       "mulps %%xmm4, %%xmm4\n"        // Square red
       "cvtps2dq %%xmm1, %%xmm1\n"     // Convert green to dwords
+      "mulps 80(%4), %%xmm3\n"        // Multiply blue correction - maybe not 
needed later
+      "mulps 64(%4), %%xmm4\n"        // Multiply red correction - maybe not 
needed later
       "minps %%xmm7, %%xmm3\n"        // Saturate blue
       "minps %%xmm7, %%xmm4\n"        // Saturate red
       "cvtps2dq %%xmm3, %%xmm3\n"     // Convert blue to dwords

Modified: trunk/plugins/denoise/floatplanarimage.cpp
===================================================================
--- trunk/plugins/denoise/floatplanarimage.cpp  2009-08-10 19:58:00 UTC (rev 
2621)
+++ trunk/plugins/denoise/floatplanarimage.cpp  2009-08-17 21:16:07 UTC (rev 
2622)
@@ -19,7 +19,7 @@
 #include "complexfilter.h"
 #include <math.h>
 
-float FloatPlanarImage::shortToFloat[65536] = {0};
+float FloatPlanarImage::shortToFloat[65536*4] = {0};
 
 FloatPlanarImage::FloatPlanarImage(void) {
   p = 0;
@@ -161,29 +161,29 @@
   RS_IMAGE16* image = j->rs;
   
 #if defined (__x86_64__)
-  if (image->pixelsize == 4)
-    return unpackInterleavedYUV_SSE(j);
+//  if (image->pixelsize == 4)
+//    return unpackInterleavedYUV_SSE(j);
 #endif
 
-  gfloat r1 = 0.299 * redCorrection;
-  gfloat r2 = -0.169 * redCorrection;
-  gfloat r3 = 0.499 * redCorrection;
-  gfloat b1 = 0.114 * blueCorrection;
-  gfloat b2 = 0.499 * blueCorrection;
-  gfloat b3 = -0.0813 * blueCorrection;
+  // We cannot look up more than 65535*4
+  redCorrection = MIN( 4.0f, redCorrection);
+  blueCorrection = MIN( 4.0f, blueCorrection);
 
+  gint redc = (gint)(16384 * redCorrection + 0.5);
+  gint bluec = (gint)(16384 * blueCorrection + 0.5);
+
   for (int y = j->start_y; y < j->end_y; y++ ) {
     const gushort* pix = GET_PIXEL(image,0,y);
     gfloat *Y = p[0]->getAt(ox, y+oy);
     gfloat *Cb = p[1]->getAt(ox, y+oy);
     gfloat *Cr = p[2]->getAt(ox, y+oy);
     for (int x=0; x<image->w; x++) {
-      float r = shortToFloat[(*pix)];
+      float r = shortToFloat[((*pix)*redc)>>14];
       float g = shortToFloat[(*(pix+1))];
-      float b = shortToFloat[(*(pix+2))];
-      *Y++ = r * r1 + g * 0.587 + b * b1 ;
-      *Cb++ = r * r2 + g * -0.331 + b * b2;
-      *Cr++ = r * r3 + g * -0.418 + b * b3;
+      float b = shortToFloat[((*(pix+2))*bluec)>>14];
+      *Y++ = r * 0.299 + g * 0.587 + b * 0.114 ;
+      *Cb++ = r * -0.169 + g * -0.331 + b * 0.499;
+      *Cr++ = r * 0.499 + g * -0.418 + b * -0.0813;
       pix += image->pixelsize;
     }
   }
@@ -237,12 +237,12 @@
     gfloat *Cr = p[2]->getAt(ox, y+oy);
     gushort* out = GET_PIXEL(image,0,y);
     for (int x=0; x<image->w; x++) {
-      float fr = (Y[x] + 1.402 * Cr[x]) * r_factor;
+      float fr = (Y[x] + 1.402 * Cr[x]);
       float fg = Y[x] - 0.344 * Cb[x] - 0.714 * Cr[x];
-      float fb = (Y[x] + 1.772 * Cb[x]) * b_factor;
-      int r = (int)(fr*fr);
+      float fb = (Y[x] + 1.772 * Cb[x]) ;
+      int r = (int)(fr*fr* r_factor);
       int g = (int)(fg*fg);
-      int b = (int)(fb*fb);
+      int b = (int)(fb*fb* b_factor);
       out[0] = clampbits(r,16);
       out[1] = clampbits(g,16);
       out[2] = clampbits(b,16);
@@ -268,7 +268,7 @@
 }
 
 void FloatPlanarImage::initConvTable() {
-  for (int i = 0; i < 65536; i++) {
+  for (int i = 0; i < 65536*4; i++) {
     shortToFloat[i] = sqrt((float)i);
   }
 }

Modified: trunk/plugins/denoise/floatplanarimage.h
===================================================================
--- trunk/plugins/denoise/floatplanarimage.h    2009-08-10 19:58:00 UTC (rev 
2621)
+++ trunk/plugins/denoise/floatplanarimage.h    2009-08-17 21:16:07 UTC (rev 
2622)
@@ -65,7 +65,7 @@
   float blueCorrection;
 
   static void initConvTable();
-  static float shortToFloat[65536];
+  static float shortToFloat[65536*4];
 };
 #endif // floatplanarimage_h__
 


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to