[xiph-commits] r12436 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Mon Feb 5 18:15:58 PST 2007


Author: xiphmont
Date: 2007-02-05 18:15:57 -0800 (Mon, 05 Feb 2007)
New Revision: 12436

Modified:
   trunk/sushivision/mapping.c
   trunk/sushivision/mapping.h
   trunk/sushivision/panel-2d.c
Log:
In-progress optimization work inside 2dpanel resample



Modified: trunk/sushivision/mapping.c
===================================================================
--- trunk/sushivision/mapping.c	2007-02-06 01:49:26 UTC (rev 12435)
+++ trunk/sushivision/mapping.c	2007-02-06 02:15:57 UTC (rev 12436)
@@ -24,219 +24,165 @@
 #include <string.h>
 #include "mapping.h"
 
-static u_int32_t scalloped_colorwheel(double val, u_int32_t mix){
-  if(val<0.)val=0.;
-  if(val>1.)val=1.;
-  {
-    int r,g,b;
-    
-    int category = val*12;
-    int v = rint((val*12 - category)*255.);
-    
-    switch(category){
-    case 0:
-      r=0;g=v;b=0;break;
-    case 1:
-      r=v;g=v;b=0;break;
-    case 2:
-      r=v;g=(v>>1);b=0;break;
-    case 3:
-      r=v;g=0;b=0;break;
-    case 4:
-      r=v;g=0;b=v*3/4;break;
-    case 5:
-      r=v*3/4;g=0;b=v;break;
-    case 6:
-      r=(v>>1);g=0;b=v;break;
-    case 7:
-      r=0;g=0;b=v;break;
-    case 8:
-      r=0;g=v*2/3;b=v;break;
-    case 9:
-      r=0;g=v;b=v;break;
-    case 10:
-      r=v*2/3;g=v;b=v;break;
-    case 11:
-      r=v;g=v;b=v;break;
-    case 12:
-      r=255;g=255;b=255;break;
-    }
-    
-    return (r<<16) + (g<<8) + b;
+static void scalloped_colorwheel(float val, float mul, ccolor *r, ccolor *mix){
+  int category = val*12.f;
+  val = (val*12.f - category)*mul;
+  
+  switch(category){
+  case 0:
+    r->g+=val;break;
+  case 1:
+    r->r+=val; r->g+=val; break;
+  case 2:
+    r->r+=val; r->g+=val*.5f; break;
+  case 3:
+    r->r+=val; break;
+  case 4:
+    r->r+=val; r->b+=val*.75f; break;
+  case 5:
+    r->r+=val*.75; r->b+=val; break;
+  case 6:
+    r->r+=val*.5f; r->b+=val; break;
+  case 7:
+    r->b+=val; break;
+  case 8:
+    r->g+=val*.67f; r->b+=val; break;
+  case 9:
+    r->g+=val; r->b+=val; break;
+  case 10:
+    r->r+=val*.67f; r->g+=val; r->b+=val; break;
+  case 11:
+    r->r+=val; r->g+=val; r->b+=val; break;
+  case 12:
+    r->r+=mul; r->g+=mul; r->b+=mul; break;
   }
 }
 
-static u_int32_t smooth_colorwheel(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r,g,b;
-
-    if(val<= (4./7.)){
-      if(val<= (2./7.)){
-	if(val<= (1./7.)){
-	  // 0->1, 0->g
-	  r=0;
-	  g= rint(7.*255.*val);
-	  b=0;
-	  
-	}else{
-	  // 1->2, g->rg
-	  r= rint(7.*255.*val-255.);
-	  g=255;
-	  b=0;
-	  
-	}
+static void smooth_colorwheel(float val, float mul, ccolor *r, ccolor *mix){
+  if(val<= (4.f/7.f)){
+    if(val<= (2.f/7.f)){
+      if(val<= (1.f/7.f)){
+	// 0->1, 0->g
+	r->g+=7.f*val*mul;
+	
       }else{
-	if(val<=(3./7.)){
-	  // 2->3, rg->r
-	  r= 255;
-	  g= rint(3.*255. - 7.*255.*val);
-	  b=0;
-
-	}else{
-	  // 3->4, r->rb
-	  r= 255;
-	  g= 0.;
-	  b= rint(7.*255.*val-3.*255.);
-	}
+	// 1->2, g->rg
+	r->r+=(7.f*val-1.f)*mul;
+	r->g+=mul;
+	
       }
     }else{
-      if(val<= (5./7.)){
-	// 4->5, rb->b
-	r= rint(5.*255. - 7.*255.*val);
-	g= 0;
-	b= 255;
-
+      if(val<=(3.f/7.f)){
+	// 2->3, rg->r
+	r->r+=mul;
+	r->g+=(3.f - 7.f*val)*mul;
+	
       }else{
-	if(val<= (6./7.)){
-	  // 5->6, b->bg
-	  r= 0.;
-	  g= rint(7.*255.*val-5.*255.);
-	  b= 255;
-	  
-	}else{
-	  // 6->7, bg->rgb
-	  r= rint(7.*255.*val-6.*255.);
-	  g= 255;
-	  b= 255;
-	  
-	}
+	// 3->4, r->rb
+	r->r+=mul;
+	r->b+=(7.f*val-3.f)*mul;
       }
     }
-    return (r<<16) + (g<<8) + b;
+  }else{
+    if(val<= (5.f/7.f)){
+      // 4->5, rb->b
+      r->r+=(5.f - 7.f*val)*mul;
+      r->b+=mul;
+      
+    }else{
+      if(val<= (6.f/7.f)){
+	// 5->6, b->bg
+	r->g+=(7.f*val-5.f)*mul;
+	r->b+=mul;
+	
+      }else{
+	// 6->7, bg->rgb
+	r->r+=(7.f*val-6.f)*mul;
+	r->g+=mul;
+	r->b+=mul;
+	
+      }
+    }
   }
 }
 
-static u_int32_t grayscale(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int g=rint(val*255.);
-    return (g<<16)+(g<<8)+g;
-  }
+static void grayscale(float val, float mul, ccolor *r, ccolor *mix){
+  val*=mul;
+  r->r += val;
+  r->g += val;
+  r->b += val;
 }
 
-static u_int32_t grayscale_cont(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int g=rint(val*255.);
-    if((g & 0xf) < 0x1) g=0;
-    return (g<<16)+(g<<8)+g;
-  }
+static void red(float val, float mul, ccolor *r, ccolor *mix){
+  r->r += val*mul;
 }
 
-static u_int32_t red(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int g=rint(val*255.);
-    return (g<<16);
-  }
+static void green(float val, float mul, ccolor *r, ccolor *mix){
+  r->g += val*mul;
 }
 
-static u_int32_t green(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int g=rint(val*255.);
-    return (g<<8);
-  }
+static void blue(float val, float mul, ccolor *r, ccolor *mix){
+  r->b += val*mul;
 }
 
-static u_int32_t blue(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int g=rint(val*255.);
-    return (g);
+static void red_overlay(float val, float mul, ccolor *o, ccolor *mix){
+  float r = mix->r + val;
+  float g = mix->g;
+  float b = mix->b;
+  if(r>1.f){
+    g -= r - 1.f;
+    b -= r - 1.f;
+    r  = 1.f;
+    if(g<0.f)g=0.f;
+    if(b<0.f)b=0.f;
   }
+  o->r += r*mul;
+  o->g += g*mul;
+  o->b += b*mul;
 }
 
-static u_int32_t red_overlay(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff) + (unsigned )(val*255.);
-    int g = ((mix>>8) & 0xff);
-    int b = ((mix) & 0xff);
-    if(r>255){
-      g -= (r-255);
-      b -= (r-255);
-      r=255;
-      if(g<0)g=0;
-      if(b<0)b=0;
-    }
-    return  (r<<16)+(g<<8)+b;
+static void green_overlay(float val, float mul, ccolor *o, ccolor *mix){
+  float r = mix->r;
+  float g = mix->g + val;
+  float b = mix->b;
+  if(g>1.f){
+    r -= g - 1.f;
+    b -= g - 1.f;
+    g  = 1.f;
+    if(r<0.f)r=0.f;
+    if(b<0.f)b=0.f;
   }
+  o->r += r*mul;
+  o->g += g*mul;
+  o->b += b*mul;
 }
 
-static u_int32_t green_overlay(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff);
-    int g = ((mix>>8) & 0xff) + (unsigned)(val*255.);
-    int b = ((mix) & 0xff);
-    if(g>255){
-      r -= (g-255);
-      b -= (g-255);
-      g=255;
-      if(r<0)r=0;
-      if(b<0)b=0;
-    }
-    return  (r<<16)+(g<<8)+b;
+static void blue_overlay(float val, float mul, ccolor *o, ccolor *mix){
+  float r = mix->r;
+  float g = mix->g;
+  float b = mix->b + val;
+  if(b>1.f){
+    r -= b - 1.f;
+    g -= b - 1.f;
+    b  = 1.f;
+    if(r<0.f)r=0.f;
+    if(g<0.f)g=0.f;
   }
+  o->r += r*mul;
+  o->g += g*mul;
+  o->b += b*mul;
 }
 
-static u_int32_t blue_overlay(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff);
-    int g = ((mix>>8) & 0xff);
-    int b = ((mix) & 0xff) + (unsigned )(val*255.);
-    if(b>255){
-      r -= (b-255);
-      g -= (b-255);
-      b=255;
-      if(r<0)r=0;
-      if(g<0)g=0;
-    }
-    return  (r<<16)+(g<<8)+b;
-  }
+static void inactive(float val, float mul, ccolor *r, ccolor *mix){
+  r->r += mix->r*mul;
+  r->g += mix->g*mul;
+  r->b += mix->b*mul;
 }
 
-static u_int32_t inactive(double val, u_int32_t mix){
-  return mix;
-}
-
-static u_int32_t (*mapfunc[])(double,u_int32_t)={
+static void (*mapfunc[])(float, float, ccolor *, ccolor *)={
   smooth_colorwheel,
   scalloped_colorwheel,
   grayscale,
-  grayscale_cont,
   red,
   green,
   blue,
@@ -250,7 +196,6 @@
   "smooth colorwheel",
   "scalloped colorwheel",
   "grayscale",
-  "grayscale with contours",
   "red",
   "green",
   "blue",
@@ -271,14 +216,14 @@
   return mapnames[i];
 }
 
-void mapping_setup(mapping *m, double lo, double hi, int funcnum){
+void mapping_setup(mapping *m, float lo, float hi, int funcnum){
   m->low = lo;
   m->high = hi;
   m->i_range = 1./(hi-lo);
   m->mapfunc = mapfunc[funcnum];
 }
 
-void mapping_set_lo(mapping *m, double lo){
+void mapping_set_lo(mapping *m, float lo){
   m->low = lo;
   if(m->high-m->low>0.)
     m->i_range = 1./(m->high-m->low);
@@ -286,7 +231,7 @@
     m->i_range=0;
 }
 
-void mapping_set_hi(mapping *m, double hi){
+void mapping_set_hi(mapping *m, float hi){
   m->high=hi;
   if(m->high-m->low>0.)
     m->i_range = 1./(m->high-m->low);
@@ -299,7 +244,7 @@
   m->mapfunc = mapfunc[funcnum];
 }
 
-double mapping_val(mapping *m, double in){
+float mapping_val(mapping *m, float in){
   if(m->i_range==0){
     return NAN;
   }else{
@@ -307,105 +252,88 @@
   }
 }
 
-u_int32_t mapping_calc(mapping *m, double in, u_int32_t mix){
+void mapping_calcf(mapping *m, float in, float mul, ccolor *out, ccolor *mix){
   if(m->i_range==0){
     if(in<=m->low)
-      return m->mapfunc(0.,mix);
+      m->mapfunc(0.f,mul,out,mix);
     else
-      return m->mapfunc(1.,mix);
+      m->mapfunc(1.f,mul,out,mix);
   }else{
-    double val = (in - m->low) * m->i_range;
-    return m->mapfunc(val,mix);
+    float val = (in - m->low) * m->i_range;
+    if(val<0.f)val=0.f;
+    if(val>1.f)val=1.f;
+    m->mapfunc(val,mul,out,mix);
   }
 }
 
+u_int32_t mapping_calc(mapping *m, float in, u_int32_t mix){
+  ccolor mixc,outc = {0.f,0.f,0.f};
+  mixc.r = ((mix>>16)&0xff) * .0039215686f;
+  mixc.g = ((mix>>8)&0xff) * .0039215686f;
+  mixc.b = ((mix)&0xff) * .0039215686f;
+  
+  mapping_calcf(m,in,1.f,&outc,&mixc);
+
+  return 
+    ((u_int32_t)rint(outc.r * 0xff0000.p0f)&0xff0000) +
+    ((u_int32_t)rint(outc.g *   0xff00.p0f)&0xff00) + 
+     (u_int32_t)rint(outc.b *     0xff.p0f);
+}
+
 int mapping_inactive_p(mapping *m){
   if(m->mapfunc == inactive)return 1;
   return 0;
 }
 
-static u_int32_t swhite(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff) *(1.-val) + (val*0xff);
-    int g = ((mix>>8) & 0xff) *(1.-val) + (val*0xff);
-    int b = ((mix) & 0xff) *(1.-val) + (val*0xff);
-    return  (r<<16)+(g<<8)+b;
-  }
+static void swhite(float val, float mul, ccolor *r, ccolor *mix){
+  r->r += (mix->r * (1.f-val) + val)*mul;
+  r->g += (mix->g * (1.f-val) + val)*mul;
+  r->b += (mix->b * (1.f-val) + val)*mul;
 }
-static u_int32_t sred(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff) *(1.-val) + (val*0xff);
-    int g = ((mix>>8) & 0xff) *(1.-val) + (val*0x60);
-    int b = ((mix) & 0xff) *(1.-val) + (val*0x60);
-    return  (r<<16)+(g<<8)+b;
-  }
+
+static void sred(float val, float mul, ccolor *r, ccolor *mix){
+  r->r += (mix->r * (1.f-val) + val)*mul;
+  r->g += (mix->g * (1.f-val) + val*.376f)*mul;
+  r->b += (mix->b * (1.f-val) + val*.376f)*mul;
 }
-static u_int32_t sgreen(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff) *(1.-val) + (val*0x60);
-    int g = ((mix>>8) & 0xff) *(1.-val) + (val*0xff);
-    int b = ((mix) & 0xff) *(1.-val) + (val*0x60);
-    return  (r<<16)+(g<<8)+b;
-  }
+
+static void sgreen(float val, float mul, ccolor *r, ccolor *mix){
+  r->r += (mix->r * (1.f-val) + val*.376f)*mul;
+  r->g += (mix->g * (1.f-val) + val)*mul;
+  r->b += (mix->b * (1.f-val) + val*.376f)*mul;
 }
-static u_int32_t sblue(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff) *(1.-val) + (val*0x80);
-    int g = ((mix>>8) & 0xff) *(1.-val) + (val*0x80);
-    int b = ((mix) & 0xff) *(1.-val) + (val*0xff);
-    return  (r<<16)+(g<<8)+b;
-  }
+
+static void sblue(float val, float mul, ccolor *r, ccolor *mix){
+  r->r += (mix->r * (1.f-val) + val*.5f)*mul;
+  r->g += (mix->g * (1.f-val) + val*.5f)*mul;
+  r->b += (mix->b * (1.f-val) + val)*mul;
 }
-static u_int32_t syellow(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff) *(1.-val) + (val*0xff);
-    int g = ((mix>>8) & 0xff) *(1.-val) + (val*0xff);
-    int b = ((mix) & 0xff) *(1.-val);
-    return  (r<<16)+(g<<8)+b;
-  }
+
+static void syellow(float val, float mul, ccolor *r, ccolor *mix){
+  r->r += (mix->r * (1.f-val) + val)*mul;
+  r->g += (mix->g * (1.f-val) + val)*mul;
+  r->b += (mix->b * (1.f-val))*mul;
 }
-static u_int32_t scyan(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff) *(1.-val) + (val*0x60);
-    int g = ((mix>>8) & 0xff) *(1.-val) + (val*0xff);
-    int b = ((mix) & 0xff) *(1.-val) + (val*0xff);
-    return  (r<<16)+(g<<8)+b;
-  }
+
+static void scyan(float val, float mul, ccolor *r, ccolor *mix){
+  r->r += (mix->r * (1.f-val) + val*.376f)*mul;
+  r->g += (mix->g * (1.f-val) + val)*mul;
+  r->b += (mix->b * (1.f-val) + val)*mul;
 }
-static u_int32_t spurple(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff) *(1.-val) + (val*0xff);
-    int g = ((mix>>8) & 0xff) *(1.-val) + (val*0x60);
-    int b = ((mix) & 0xff) *(1.-val) + (val*0xff);
-    return  (r<<16)+(g<<8)+b;
-  }
+
+static void spurple(float val, float mul, ccolor *r, ccolor *mix){
+  r->r += (mix->r * (1.f-val) + val)*mul;
+  r->g += (mix->g * (1.f-val) + val*.376f)*mul;
+  r->b += (mix->b * (1.f-val) + val)*mul;
 }
-static u_int32_t sgray(double val, u_int32_t mix){
-  if(val<0)val=0;
-  if(val>1)val=1;
-  {
-    int r = ((mix>>16) & 0xff) *(1.-val) + (val*0xa0);
-    int g = ((mix>>8) & 0xff) *(1.-val) + (val*0xa0);
-    int b = ((mix) & 0xff) *(1.-val) + (val*0xa0);
-    return  (r<<16)+(g<<8)+b;
-  }
+
+static void sgray(float val, float mul, ccolor *r, ccolor *mix){
+  r->r += (mix->r * (1.f-val) + val*.627f)*mul;
+  r->g += (mix->g * (1.f-val) + val*.627f)*mul;
+  r->b += (mix->b * (1.f-val) + val*.627f)*mul;
 }
 
-static u_int32_t (*solidfunc[])(double,u_int32_t)={
+static void (*solidfunc[])(float, float, ccolor *, ccolor *)={
   swhite,
   sred,
   sgreen,
@@ -440,7 +368,7 @@
   return solidnames[i];
 }
 
-void solid_setup(mapping *m, double lo, double hi, int funcnum){
+void solid_setup(mapping *m, float lo, float hi, int funcnum){
   m->low = lo;
   m->high = hi;
   m->i_range = 1./(hi-lo);

Modified: trunk/sushivision/mapping.h
===================================================================
--- trunk/sushivision/mapping.h	2007-02-06 01:49:26 UTC (rev 12435)
+++ trunk/sushivision/mapping.h	2007-02-06 02:15:57 UTC (rev 12436)
@@ -20,25 +20,33 @@
  */
 
 #include <sys/types.h>
+
+typedef struct{
+  float r;
+  float g;
+  float b;
+} ccolor;
+
 typedef struct {
   int mapnum;
-  double low;
-  double high;
-  double i_range;
-  u_int32_t (*mapfunc)(double val,u_int32_t mix);
+  float low;
+  float high;
+  float i_range;
+  void (*mapfunc)(float val,float mul, ccolor *out, ccolor *mix);
 } mapping;
 
 extern int num_mappings();
 extern char *mapping_name(int i);
-extern void mapping_setup(mapping *m, double lo, double hi, int funcnum);
-extern void mapping_set_lo(mapping *m, double lo);
-extern void mapping_set_hi(mapping *m, double hi);
+extern void mapping_setup(mapping *m, float lo, float hi, int funcnum);
+extern void mapping_set_lo(mapping *m, float lo);
+extern void mapping_set_hi(mapping *m, float hi);
 extern void mapping_set_func(mapping *m, int funcnum);
-extern double mapping_val(mapping *m, double in);
-extern u_int32_t mapping_calc(mapping *m, double in, u_int32_t mix);
+extern float mapping_val(mapping *m, float in);
+extern u_int32_t mapping_calc(mapping *m, float in, u_int32_t mix);
+extern void mapping_calcf(mapping *m, float in, float mul, ccolor *out, ccolor *mix);
 extern int mapping_inactive_p(mapping *m);
 
 extern int num_solids();
 extern char *solid_name(int i);
-extern void solid_setup(mapping *m, double lo, double hi, int funcnum);
+extern void solid_setup(mapping *m, float lo, float hi, int funcnum);
 extern void solid_set_func(mapping *m, int funcnum);

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2007-02-06 01:49:26 UTC (rev 12435)
+++ trunk/sushivision/panel-2d.c	2007-02-06 02:15:57 UTC (rev 12436)
@@ -188,86 +188,72 @@
 
 /* functions that perform actual graphical rendering */
 
-static void render_checks(int w, int h, u_int32_t *render){
+static void render_checks(int w, int h, ccolor *c){
   /* default checked background */
   /* 16x16 'mid-checks' */ 
   int x,y,j;
-
+  
   for(y=0;y<h;y++){
     int phase = (y>>4)&1;
     for(x=0;x<w;){
-      u_int32_t phaseval = 0x505050;
-      if(phase) phaseval = 0x808080;
+      ccolor phaseval = {.314f, .314f, .314f};
+      if(phase) phaseval = (ccolor){.5f, .5f, .5f};
       for(j=0;j<16 && x<w;j++,x++)
-	render[x] = phaseval;
+	c[x] = phaseval;
       phase=!phase;
     }
-    render += w;
+    c += w;
   }
 }
 
+
 // called without any locks; all passed in data is locally replicated 
 static void resample_render_y_plane_line(mapping *map, float obj_alpha,
-					 float *r, float *g, float *b, float linedel,
-					 u_int32_t *panel, scalespace panelx,
+					 ccolor *out, float linedel,
+					 ccolor *mix, scalespace panelx, 
+					 float x_scaledel, float x_del, int x_bin,
+					 
 					 float *data, scalespace datax){
   int pw = panelx.pixels;
   int dw = datax.pixels;
   int i;
 
-  float x_scaledel = scalespace_scaledel(&panelx,&datax);
-  float x_del = scalespace_pixel(&datax,scalespace_value(&panelx,-.5))+.5;
-  int x_bin = floor(x_del);
-  x_del -= x_bin; 
-  linedel *= .00392156862745; // 1./255
-  linedel /= x_scaledel;
-  for(i=0;i<pw;i++){
-    float alpha=x_scaledel;
+   for(i=0;i<pw;i++){
     float x_del2 = x_del + x_scaledel;
-    
-    while(x_del2>=1.f){
+    float alpha = x_scaledel * linedel;
+    int flag = 0;
+
+    while(x_del2>1.f){
       if(x_bin >= 0 && x_bin < dw){
-	float addel = (1.f - x_del);
-	float pixdel = addel*linedel;
 	float val = data[x_bin];
-	if(!isnan(val) && val >= obj_alpha){
-	  u_int32_t partial = mapping_calc(map,val,panel[i]);
-	  r[i] += ((partial>>16)&0xff) * pixdel;
-	  g[i] += ((partial>>8)&0xff) * pixdel;
-	  b[i] += ((partial)&0xff) * pixdel;
+	if(!isnan(val) && val>=obj_alpha){
+	  float addel = (1.f - x_del) * linedel;
+	  mapping_calcf(map,val,addel,out+i,mix+i);
 	  alpha -= addel;
 	}
       }
-	
-      x_del2--;
+
+      x_del2-=1.f;
       x_bin++;
       x_del = 0.f;
     }
-    
+        
     if(x_del2>0.f){
       if(x_bin >= 0 && x_bin < dw){
-	float addel = (x_del2 - x_del);
-	float pixdel = addel*linedel;
 	float val = data[x_bin];
-	if(!isnan(val) && val >= obj_alpha){
-	  u_int32_t partial = mapping_calc(map,val,panel[i]);
-	  r[i] += ((partial>>16)&0xff) * pixdel;
-	  g[i] += ((partial>>8)&0xff) * pixdel;
-	  b[i] += ((partial)&0xff) * pixdel;
+	if(!isnan(val) && val>=obj_alpha){
+	  float addel = (x_del2 - x_del)*linedel;
+	  mapping_calcf(map,val,addel,out+i,mix+i);
 	  alpha -= addel;
 	}
       }
     }
+
     x_del = x_del2;
 
-    /* partial pixels need some of the background mixed in */
-    if(alpha>0.f){
-      float pixdel = alpha*linedel;
-      u_int32_t bg = panel[i];
-      r[i] += ((bg>>16)&0xff) * pixdel;
-      g[i] += ((bg>>8)&0xff) * pixdel;
-      b[i] += ((bg)&0xff) * pixdel;
-    }
+    out[i].r += mix[i].r * alpha;
+    out[i].g += mix[i].g * alpha;
+    out[i].b += mix[i].b * alpha;
   }
 }
 
@@ -278,13 +264,13 @@
    against serialno */
 static void resample_render_y_plane(sushiv_panel2d_t *p2, int serialno, 
 				    mapping *map, float obj_alpha,
-				    u_int32_t *panel, scalespace panelx, scalespace panely,
+				    ccolor *panel, scalespace panelx, scalespace panely,
 				    float *data, scalespace datax, scalespace datay){
   int pw = panelx.pixels;
   int dw = datax.pixels;
   int ph = panely.pixels;
   int dh = datay.pixels;
-  u_int32_t *line;
+  ccolor *line;
   float dline[dw];
   int i,j;
 
@@ -293,27 +279,29 @@
   if(ph!=dh || pw!=dw){
     /* resampled row computation */
 
-    /* by line */
+    /* by row */
     float y_scaledel = scalespace_scaledel(&panely,&datay);
     float y_del = scalespace_pixel(&datay,scalespace_value(&panely,-.5))+.5;
     int y_bin = floor(y_del);
     y_del -= y_bin; 
 
+    /* by column */
+    float x_scaledel = scalespace_scaledel(&panelx,&datax);
+    float x_del = scalespace_pixel(&datax,scalespace_value(&panelx,-.5))+.5;
+    int x_bin = floor(x_del);
+    x_del -= x_bin; 
+
+    float idel = 1./y_scaledel/x_scaledel;
+
     for(i=0;i<ph;i++){
       /* render is done into a temporary line because of the way alpha
 	 blending is done; the background for the blend must be taken
 	 from the original line */
-      float r[pw]; 
-      float g[pw]; 
-      float b[pw]; 
+      ccolor out[pw]; 
       float alpha = 1.;
-      float idel = 1./y_scaledel;
       float y_del2 = y_del + y_scaledel;
+      memset(out,0,sizeof(out)); 
 
-      memset(r,0,sizeof(r)); 
-      memset(g,0,sizeof(g)); 
-      memset(b,0,sizeof(b)); 
-
       line=panel+i*pw;
       
       while(y_del2>=1.f){
@@ -326,12 +314,13 @@
 	  gdk_threads_leave ();
 
 	  resample_render_y_plane_line(map,obj_alpha,
-				       r,g,b,addel * idel,
+				       out,addel * idel,
 				       line,
 				       panelx,
+				       x_scaledel,x_del,x_bin,
 				       dline,
 				       datax);
-	  alpha -= addel * idel;
+	  alpha -= addel * idel * x_scaledel;
 	}
 	
 	y_del2--;
@@ -350,12 +339,13 @@
 	  gdk_threads_leave ();
 
 	  resample_render_y_plane_line(map,obj_alpha,
-				       r,g,b,addel * idel,
+				       out,addel * idel,
 				       line,
 				       panelx,
+				       x_scaledel,x_del,x_bin,
 				       dline,
 				       datax);
-	  alpha -= addel * idel;
+	  alpha -= addel * idel * x_scaledel;
 	}
       }
       y_del = y_del2;
@@ -363,19 +353,15 @@
       /* work is finished; replace panel line with it */
       if(alpha>.0001){ // less than a color step of rounding error
 	for(j=0;j<pw;j++){
-	  int ri = rint(r[j]*0xff0000.p0f +  (line[j]&0xff0000) * alpha);
-	  int gi = rint(g[j]*0xff00.p0f +  (line[j]&0xff00) * alpha);
-	  int bi = rint(b[j]*0xff.p0f +  (line[j]&0xff) * alpha);
-	  
-	  line[j] = (ri&0xff0000) + (gi&0xff00) + (bi&0xff);
+	  line[j].r = out[j].r + line[j].r * alpha;
+	  line[j].g = out[j].g + line[j].g * alpha;
+	  line[j].b = out[j].b + line[j].b * alpha;
 	}
       }else{
 	for(j=0;j<pw;j++){
-	  int ri = rint(r[j]*0xff0000.p0f);
-	  int gi = rint(g[j]*0xff00.p0f);
-	  int bi = rint(b[j]*0xff.p0f);
-	  
-	  line[j] = (ri&0xff0000) + (gi&0xff00) + (bi&0xff);
+	  line[j].r = out[j].r;
+	  line[j].g = out[j].g;
+	  line[j].b = out[j].b;
 	}
       }
     }      
@@ -392,8 +378,11 @@
       
       for(j=0;j<pw;j++){
 	float val = dline[j];
-	if(!isnan(val) && val >= obj_alpha)
-	  line[j] = mapping_calc(map,val,line[j]);
+	if(!isnan(val) && val >= obj_alpha){
+	  ccolor out;
+	  mapping_calcf(map,val,1.,&out,line+j);
+	  line[j] = out;
+	}
       }
     }
   }
@@ -416,8 +405,9 @@
   scalespace y = p2->y;
   scalespace x_v = p2->x_v;
   scalespace y_v = p2->y_v;
-  u_int32_t *doublebuff = malloc(x.pixels*y.pixels*sizeof(*doublebuff));
 
+  ccolor *c = malloc(x.pixels*y.pixels*sizeof(*c));
+
   double alphadel[p->objectives];
   mapping mappings[p->objectives];
   int serialno = p2->serialno;
@@ -429,10 +419,10 @@
   
   pw = plot->x.pixels;
   ph = plot->y.pixels;
+  gdk_threads_leave();
   
   /* background checks */
-  render_checks(pw,ph,doublebuff);
-  gdk_threads_leave();
+  render_checks(pw,ph,c);
   
   /* by objective */
   for(i=0;i<p->objectives;i++){
@@ -441,7 +431,7 @@
     int o_ynum = p2->y_obj_from_panel[i];
     resample_render_y_plane(p2, serialno, 
 			    mappings+i, alphadel[i],
-			    doublebuff, x, y,
+			    c, x, y,
 			    y_rects[o_ynum], x_v, y_v);
     
     /**** render Z plane */
@@ -452,11 +442,16 @@
 
   gdk_threads_enter ();
   if(serialno == p2->serialno){
-    plot_replace_data(plot,doublebuff);
-  }else{
-    free(doublebuff);
+    u_int32_t *dr = plot->datarect;
+    ccolor *cp = c;
+    for(i=0;i<pw*ph;i++){
+      *dr    = (u_int32_t)rint(cp  ->r * 0xff.p0f)<<16;
+      *dr   += (u_int32_t)rint(cp  ->g * 0xff.p0f)<<8;
+      *dr++ += (u_int32_t)rint(cp++->b * 0xff.p0f);
+    }
   }
   gdk_threads_leave();
+  free(c);
 }
 
 static void update_legend(sushiv_panel_t *p){  
@@ -1103,7 +1098,7 @@
       
       p2->scaling_in_progress = 0;
       gdk_threads_leave ();
-      _sushiv_panel_dirty_map(p);
+      _sushiv_panel_dirty_map_throttled(p);
       _sushiv_wake_workers();   
       //_sushiv_panel2d_remap(p);
       plot_draw_scales(plot);
@@ -1188,8 +1183,6 @@
 
 static void recompute_callback_2d(void *ptr){
   sushiv_panel_t *p = (sushiv_panel_t *)ptr;
-  Plot *plot = PLOT(p->private->graph);
-  render_checks(plot->x.pixels, plot->y.pixels, plot->datarect);
   _mark_recompute_2d(p);
   _sushiv_panel_cooperative_compute_2d(p,NULL); // initial scale setup
 }



More information about the commits mailing list