[xiph-commits] r12459 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Mon Feb 12 12:25:15 PST 2007


Author: xiphmont
Date: 2007-02-12 12:25:12 -0800 (Mon, 12 Feb 2007)
New Revision: 12459

Modified:
   trunk/sushivision/mapping.c
   trunk/sushivision/mapping.h
   trunk/sushivision/panel-2d.c
   trunk/sushivision/panel-2d.h
Log:
In-progress scaling optimizations; this version is broken, don't use it


Modified: trunk/sushivision/mapping.c
===================================================================
--- trunk/sushivision/mapping.c	2007-02-12 15:22:26 UTC (rev 12458)
+++ trunk/sushivision/mapping.c	2007-02-12 20:25:12 UTC (rev 12459)
@@ -24,80 +24,94 @@
 #include <string.h>
 #include "mapping.h"
 
-static void scalloped_colorwheel(float val, float mul, accolor *r, ccolor *mix){
-  int category = val*12.f;
-  val = (val*12.f - category)*mul;
+// val is .16; lcolor has pigment added in the range [0,mul]
+static void scalloped_colorwheel(int val, int mul, lcolor *r){
+  int category = val*12;
+  if(category<0)return;
   
+  val = ((category & 0xffff)*mul)>>16;
+  category >>= 16;
+  r->a += mul; 
+
   switch(category){
   case 0:
-    r->g+=val;break;
+    r->g += val; break;
   case 1:
-    r->r+=val; r->g+=val; break;
+    r->r += val; r->g += val; break;
   case 2:
-    r->r+=val; r->g+=val*.5f; break;
+    r->r += val; r->g += val>>1; break;
   case 3:
-    r->r+=val; break;
+    r->r += val; break;
   case 4:
-    r->r+=val; r->b+=val*.75f; break;
+    r->r += val; r->b += (val*3+2)>>2; break;
   case 5:
-    r->r+=val*.75; r->b+=val; break;
+    r->r += (val*3+2)>>2; r->b += val; break;
   case 6:
-    r->r+=val*.5f; r->b+=val; break;
+    r->r += val>>1; r->b += val; break;
   case 7:
-    r->b+=val; break;
+    r->b += val; break;
   case 8:
-    r->g+=val*.67f; r->b+=val; break;
+    r->g += (val*3+2)>>2; r->b += val; break;
   case 9:
-    r->g+=val; r->b+=val; break;
+    r->g += val; r->b+=val; break;
   case 10:
-    r->r+=val*.67f; r->g+=val; r->b+=val; break;
+    r->r += val>>1; 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;
+    r->r += val; r->g += val; r->b += val; break;
+  default:
+    r->r += mul; r->g += mul; r->b += mul; break;
   }
 }
 
-static void smooth_colorwheel(float val, float mul, accolor *r, ccolor *mix){
-  if(val<= (4.f/7.f)){
-    if(val<= (2.f/7.f)){
-      if(val<= (1.f/7.f)){
+static void smooth_colorwheel(int val, int mul, lcolor *r){
+  if(val<0)return;
+  r->a += mul;
+  if(val < 37450){ // 4/7
+    if(val < 18725){ // 2/7
+      if(val < 9363){ // 1/7
+
 	// 0->1, 0->g
-	r->g+=7.f*val*mul;
+	r->g+=(7L*val*mul)>>16;
 	
       }else{
+
 	// 1->2, g->rg
-	r->r+=(7.f*val-1.f)*mul;
+	r->r+=((7L*val - 65536)*mul)>>16;
 	r->g+=mul;
 	
       }
     }else{
-      if(val<=(3.f/7.f)){
+      if(val < 28087){ // 3/7
+
 	// 2->3, rg->r
 	r->r+=mul;
-	r->g+=(3.f - 7.f*val)*mul;
+	r->g+=((196608 - 7L*val)*mul)>>16;
 	
       }else{
+
 	// 3->4, r->rb
 	r->r+=mul;
-	r->b+=(7.f*val-3.f)*mul;
+	r->b+=((7L*val - 196608)*mul)>>16;
+
       }
     }
   }else{
-    if(val<= (5.f/7.f)){
+    if(val < 46812){ // 5/7
+
       // 4->5, rb->b
-      r->r+=(5.f - 7.f*val)*mul;
+      r->r+=((327680 - 7L*val)*mul)>>16;
       r->b+=mul;
       
     }else{
-      if(val<= (6.f/7.f)){
+      if(val < 56174){ // 6/7
+
 	// 5->6, b->bg
-	r->g+=(7.f*val-5.f)*mul;
+	r->g+=((7L*val - 327680)*mul)>>16;
 	r->b+=mul;
 	
       }else{
 	// 6->7, bg->rgb
-	r->r+=(7.f*val-6.f)*mul;
+	r->r+=((7L*val - 393216)*mul)>>16;
 	r->g+=mul;
 	r->b+=mul;
 	
@@ -106,92 +120,196 @@
   }
 }
 
-static void grayscale(float val, float mul, accolor *r, ccolor *mix){
-  val*=mul;
+static void white(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += mul;
   r->r += val;
   r->g += val;
   r->b += val;
 }
 
-static void red(float val, float mul, accolor *r, ccolor *mix){
-  r->r += val*mul;
+static void red(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += mul;
+  r->r += val;
 }
 
-static void green(float val, float mul, accolor *r, ccolor *mix){
-  r->g += val*mul;
+static void green(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += mul;
+  r->g += val;
 }
 
-static void blue(float val, float mul, accolor *r, ccolor *mix){
-  r->b += val*mul;
+static void blue(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += mul;
+  r->b += val;
 }
+ 
 
-static void red_overlay(float val, float mul, accolor *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 void white_a(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += val;
+  r->r += val;
+  r->g += val;
+  r->b += val;
 }
 
-static void green_overlay(float val, float mul, accolor *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 void red_a(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += val;
+  r->r += val;
+  r->g += val>>2;
+  r->b += val>>2;
 }
 
-static void blue_overlay(float val, float mul, accolor *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 void green_a(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += val;
+  r->r += val>>2;
+  r->g += val;
+  r->b += val>>2;
 }
 
-static void inactive(float val, float mul, accolor *r, ccolor *mix){
-  r->r += mix->r*mul;
-  r->g += mix->g*mul;
-  r->b += mix->b*mul;
+static void blue_a(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += val;
+  r->r += val>>2;
+  r->g += val>>2;
+  r->b += val;
 }
 
-static void (*mapfunc[])(float, float, accolor *, ccolor *)={
+static void yellow_a(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += val;
+  r->r += val;
+  r->g += val;
+}
+
+static void cyan_a(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += val;
+  r->r += val>>2;
+  r->g += val;
+  r->b += val;
+}
+
+static void purple_a(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += val;
+  r->r += val;
+  r->g += val>>2;
+  r->b += val;
+}
+
+static void gray_a(int val, int mul, lcolor *r){
+  if(val<0)return;
+  val = (val*mul)>>16;
+  r->a += val;
+  r->r += val>>1;
+  r->g += val>>1;
+  r->b += val>>1;
+}
+ 
+static void inactive(int val, int mul, lcolor *r){
+  return;
+}
+
+// premultiplied alpha 
+static ucolor normal_mix(ucolor in, ucolor bg){
+  u_int32_t sa, s1, s2, d1, d2;
+  if(in.c.a==255) return in;
+  
+  // taken from liboil
+  sa = ~(in.u) >> 24;
+  s1 = (in.u) & 0x00ff00ff;
+  d1 = (bg.u) & 0x00ff00ff;
+  d1 *= sa;
+  d1 += 0x00800080;
+  d1 += (d1 >> 8) & 0x00ff00ff;
+  d1 >>= 8;
+  d1 &= 0x00ff00ff;
+  d1 += s1;
+  d1 |= 0x01000100 - ((d1 >> 8) & 0x00ff00ff);
+  d1 &= 0x00ff00ff;
+
+  s2 = ((in.u) >> 8) & 0x00ff00ff;
+  d2 = ((bg.u) >> 8) & 0x00ff00ff;
+  d2 *= sa;
+  d2 += 0x00800080;
+  d2 += (d2 >> 8) & 0x00ff00ff;
+  d2 >>= 8;
+  d2 &= 0x00ff00ff;
+  d2 += s2;
+  d2 |= 0x01000100 - ((d2 >> 8) & 0x00ff00ff);
+  d2 &= 0x00ff00ff;
+
+  return (ucolor)(d1 | (d2 << 8));
+}
+
+static ucolor overlay_mix(ucolor in, ucolor bg){
+  int r = bg.c.r + in.c.r;
+  int g = bg.c.g + in.c.g;
+  int b = bg.c.b + in.c.b;
+  int ro = (r>255 ? r-255 : 0);
+  int go = (g>255 ? g-255 : 0);
+  int bo = (b>255 ? b-255 : 0);
+
+  r-=(go+bo);
+  g-=(ro+bo);
+  b-=(ro+go);
+
+  if(r>255) r = 255;
+  if(g>255) g = 255;
+  if(b>255) b = 255;
+  if(r<0) r = 0;
+  if(g<0) g = 0;
+  if(b<0) b = 0;
+
+  return (ucolor)(u_int32_t)((r<<16) + (g<<8) + b);
+}
+
+static ucolor inactive_mix(ucolor in, ucolor bg){
+  return bg;
+}
+
+static void (*mapfunc[])(int, int, lcolor *)={
   smooth_colorwheel,
   scalloped_colorwheel,
-  grayscale,
+  white,
   red,
   green,
   blue,
-  red_overlay,
-  green_overlay,
-  blue_overlay,
+  red,
+  green,
+  blue,
   inactive
 };
 
+static ucolor (*mixfunc[])(ucolor, ucolor)={
+  normal_mix,
+  normal_mix,
+  normal_mix,
+  normal_mix,
+  normal_mix,
+  normal_mix,
+  overlay_mix,
+  overlay_mix,
+  overlay_mix,
+  inactive_mix
+};
+
 static char *mapnames[]={
   "smooth colorwheel",
   "scalloped colorwheel",
@@ -221,6 +339,7 @@
   m->high = hi;
   m->i_range = 1./(hi-lo);
   m->mapfunc = mapfunc[funcnum];
+  m->mixfunc = mixfunc[funcnum];
 }
 
 void mapping_set_lo(mapping *m, float lo){
@@ -242,6 +361,7 @@
 void mapping_set_func(mapping *m, int funcnum){
   m->mapnum = funcnum;
   m->mapfunc = mapfunc[funcnum];
+  m->mixfunc = mixfunc[funcnum];
 }
 
 float mapping_val(mapping *m, float in){
@@ -252,33 +372,23 @@
   }
 }
 
-void mapping_calcf(mapping *m, float in, float mul, accolor *out, ccolor *mix){
+u_int32_t mapping_calc(mapping *m, float in, u_int32_t mix){
+  lcolor outc = {0,0,0,0};
+  
   if(m->i_range==0){
     if(in<=m->low)
-      m->mapfunc(0.f,mul,out,mix);
+      m->mapfunc(0,255,&outc);
     else
-      m->mapfunc(1.f,mul,out,mix);
+      m->mapfunc(256*256,255,&outc);
   }else{
     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);
+    m->mapfunc(rint(val*65536.f),255,&outc);
   }
-}
 
-u_int32_t mapping_calc(mapping *m, float in, u_int32_t mix){
-  ccolor mixc;
-  accolor outc = {0.f,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);
+  return m->mixfunc( (ucolor)(u_int32_t)((outc.a<<24) + (outc.r<<16) + (outc.g<<8) + outc.b),
+		     (ucolor)mix).u | 0xff000000;
 }
 
 int mapping_inactive_p(mapping *m){
@@ -286,66 +396,30 @@
   return 0;
 }
 
-static void swhite(float val, float mul, accolor *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 void sred(float val, float mul, accolor *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 void sgreen(float val, float mul, accolor *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 void sblue(float val, float mul, accolor *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 void syellow(float val, float mul, accolor *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 void scyan(float val, float mul, accolor *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 void spurple(float val, float mul, accolor *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 void sgray(float val, float mul, accolor *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 void (*solidfunc[])(float, float, accolor *, ccolor *)={
-  swhite,
-  sred,
-  sgreen,
-  sblue,
-  syellow,
-  scyan,
-  spurple,
-  sgray,
+static void (*mapsolid[])(int, int, lcolor *)={
+  white_a,
+  red_a,
+  green_a,
+  blue_a,
+  yellow_a,
+  cyan_a,
+  purple_a,
+  gray_a,
   inactive
 };
 
+static ucolor (*mixsolid[])(ucolor, ucolor)={
+  normal_mix,
+  normal_mix,
+  normal_mix,
+  normal_mix,
+  normal_mix,
+  normal_mix,
+  normal_mix,
+  normal_mix,
+  inactive_mix
+};
+
 static char *solidnames[]={
   "<span foreground=\"white\">white</span>",
   "<span foreground=\"red\">red</span>",
@@ -373,10 +447,11 @@
   m->low = lo;
   m->high = hi;
   m->i_range = 1./(hi-lo);
-  m->mapfunc = solidfunc[funcnum];
+  m->mapfunc = mapsolid[funcnum];
+  m->mixfunc = mixsolid[funcnum];
 }
 
 void solid_set_func(mapping *m, int funcnum){
-  m->mapnum = funcnum;
-  m->mapfunc = solidfunc[funcnum];
+  m->mapfunc = mapsolid[funcnum];
+  m->mixfunc = mixsolid[funcnum];
 }

Modified: trunk/sushivision/mapping.h
===================================================================
--- trunk/sushivision/mapping.h	2007-02-12 15:22:26 UTC (rev 12458)
+++ trunk/sushivision/mapping.h	2007-02-12 20:25:12 UTC (rev 12459)
@@ -21,25 +21,41 @@
 
 #include <sys/types.h>
 
+#if __BYTE_ORDER == __LITTLE_ENDIAN
 typedef struct{
-  float r;
-  float g;
-  float b;
+  unsigned char b;
+  unsigned char g;
+  unsigned char r;
+  unsigned char a;
 } ccolor;
+#else
+typedef struct{
+  unsigned char a;
+  unsigned char r;
+  unsigned char g;
+  unsigned char b;
+} ccolor;
+#endif 
 
+typedef union {
+  ccolor c;
+  u_int32_t u;
+} ucolor;
+
 typedef struct{
-  float a;
-  float r;
-  float g;
-  float b;
-} accolor;
+  long a;
+  long r;
+  long g;
+  long b;
+} lcolor;
 
 typedef struct {
   int mapnum;
   float low;
   float high;
   float i_range;
-  void (*mapfunc)(float val,float mul, accolor *out, ccolor *mix);
+  void (*mapfunc)(int val,int mul, lcolor *out);
+  ucolor (*mixfunc)(ucolor in, ucolor mix);
 } mapping;
 
 extern int num_mappings();
@@ -50,7 +66,6 @@
 extern void mapping_set_func(mapping *m, int funcnum);
 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, accolor *out, ccolor *mix);
 extern int mapping_inactive_p(mapping *m);
 
 extern int num_solids();

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2007-02-12 15:22:26 UTC (rev 12458)
+++ trunk/sushivision/panel-2d.c	2007-02-12 20:25:12 UTC (rev 12459)
@@ -70,16 +70,23 @@
     /* 2d panels currently only care about the Y output value */
     
     /* slider map */
-    for(i=0;i<p2->y_obj_num;i++)
-      c->y_map[i][j] = (float)slider_val_to_del(p2->range_scales[*onum++], c->fout[*obj_y_off++]);      
-
+    for(i=0;i<p2->y_obj_num;i++){
+      float val = (float)slider_val_to_del(p2->range_scales[*onum++], c->fout[*obj_y_off++]);
+      if(isnan(val)){
+	c->y_map[i][j] = -1;
+      }else{
+	if(val<0)val=0;
+	if(val>1)val=1;
+	c->y_map[i][j] = rint(val*65536.f);
+      }
+    }
   }
 
   gdk_threads_enter ();
   if(p2->serialno == serialno){
     for(j=0;j<p2->y_obj_num;j++){
-      float *d = p2->y_map[j] + y*dw;
-      float *td = c->y_map[j];
+      int *d = p2->y_map[j] + y*dw;
+      int *td = c->y_map[j];
       
       memcpy(d,td,dw*sizeof(*d));
       
@@ -188,7 +195,7 @@
 
 /* functions that perform actual graphical rendering */
 
-static void render_checks(int w, int h, ccolor *c){
+static void render_checks(int w, int h, ucolor *c){
   /* default checked background */
   /* 16x16 'mid-checks' */ 
   int x,y,j;
@@ -196,10 +203,10 @@
   for(y=0;y<h;y++){
     int phase = (y>>4)&1;
     for(x=0;x<w;){
-      ccolor phaseval = {.314f, .314f, .314f};
-      if(phase) phaseval = (ccolor){.5f, .5f, .5f};
+      u_int32_t phaseval = 0xff505050UL;
+      if(phase) phaseval = 0xff808080UL;
       for(j=0;j<16 && x<w;j++,x++)
-	c[x] = phaseval;
+	c[x].u = phaseval;
       phase=!phase;
     }
     c += w;
@@ -207,9 +214,9 @@
 }
 
 
-static void resample_helpers_init(scalespace *to, scalespace *from,
-				 float *delA, float *delB, 
-				 int *numA, int *numB){
+static int resample_helpers_init(scalespace *to, scalespace *from,
+				  int *delA, int *delB, 
+				  int *posA, int *posB){
   int i;
   int dw = from->pixels;
   int pw = to->pixels;
@@ -235,8 +242,8 @@
     
     if(del2 > scaleden && bin>=0 && bin<dw){
 
-      delA[i] = ((float)(scaleden - del))/scaleden;
-      numA[i] = bin;
+      delA[i] = scaleden - del;
+      posA[i] = bin;
 
       while(bin+sizeceil>dw){
 	sizeceil--;
@@ -244,60 +251,45 @@
       }
 
       del2 %= scaleden;
-      delB[i] = ((float)del2)/scaleden;
-      numB[i] = bin+sizeceil;
+      delB[i] = del2;
+      posB[i] = bin+sizeceil;
 
     }else{
       if(bin<0 || bin>=dw){
-	delA[i] = 0.f;
-	numA[i] = 0;
-	delB[i] = 0.f;
-	numB[i] = 0;
+	delA[i] = 0;
+	posA[i] = 0;
+	delB[i] = 0;
+	posB[i] = 0;
       }else{
-	delA[i] = ((float)(del2 - del))/scaleden;
-	numA[i] = bin;
-	delB[i] = 0.f;
-	numB[i] = bin+1;
+	delA[i] = del2 - del;
+	posA[i] = bin;
+	delB[i] = 0;
+	posB[i] = bin+1;
       }
     }
 
     bin += sizefloor;
     del = del2;
   }
+  return scaleden;
 }
 
-static inline void l_mapping_calc(mapping *m, float in, float alpha, float mul, accolor *out, ccolor *mix){
-  if(isnan(in) || in<alpha)return;
-  if(m->i_range==0){
-    if(in<=m->low)
-      m->mapfunc(0.f,mul,out,mix);
-    else
-      m->mapfunc(1.f,mul,out,mix);
-  }else{
-    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);
-  }
-  out->a+=mul;
-}
-
 /* the data rectangle is data width/height mapped deltas.  we render
    and subsample at the same time. */
 /* enter with no locks; only data is not replicated local storage. */
 static void resample_render_y_plane(sushiv_panel2d_t *p2, int serialno, 
 				    mapping *map, float obj_alpha,
-				    ccolor *panel, scalespace panelx, scalespace panely,
-				    float *in_data, scalespace datax, scalespace datay){
+				    ucolor *panel, scalespace panelx, scalespace panely,
+				    int *in_data, scalespace datax, scalespace datay){
   int pw = panelx.pixels;
   int dw = datax.pixels;
   int ph = panely.pixels;
   int dh = datay.pixels;
   int i,j;
-
+  int ol_alpha = rint(obj_alpha*65536.f);
   if(!in_data)return;
 
-  float *data = malloc(dw*dh*sizeof(*data));
+  int *data = malloc(dw*dh*sizeof(*data));
   
   gdk_threads_enter ();
   if(serialno != p2->serialno){
@@ -311,23 +303,25 @@
     /* resampled row computation */
 
     /* by column */
-    float x_scaledel = scalespace_scaledel(&panelx,&datax);
-    float xdelA[pw];
-    float xdelB[pw];
+    int   xdelA[pw];
+    int   xdelB[pw];
     int   xnumA[pw];
     int   xnumB[pw];
-    resample_helpers_init(&panelx, &datax, xdelA, xdelB, xnumA, xnumB);
+    int   xnum= scalespace_scalenum(&panelx,&datax);
+    int   xden = resample_helpers_init(&panelx, &datax, xdelA, xdelB, xnumA, xnumB);
 
     /* by row */
-    float y_scaledel = scalespace_scaledel(&panely,&datay);
-    float ydelA[ph];
-    float ydelB[ph];
+    int   y_scaledel = scalespace_scaledel(&panely,&datay);
+    int   ydelA[ph];
+    int   ydelB[ph];
     int   ynumA[ph];
     int   ynumB[ph];
-    resample_helpers_init(&panely, &datay, ydelA, ydelB, ynumA, ynumB);
+    int   ynum= scalespace_scalenum(&panely,&datay);
+    int   yden = resample_helpers_init(&panely, &datay, ydelA, ydelB, ynumA, ynumB);
 
-    float idel = 1./y_scaledel/x_scaledel;
-    ccolor *mix = panel;
+    int den = xden*yden;
+    float idel = 255./(ynum*xnum);
+    ucolor *mix = panel;
 
     /* by row */
     for(i=0;i<ph;i++){
@@ -335,34 +329,36 @@
 	 blending is done; the background for the blend must be taken
 	 from the original line */
 
-      float *dline_start = data + ynumA[i]*dw;
+      int *dline_start = data + ynumA[i]*dw;
       int yend=ynumB[i];
-
+      
       /* by col */
       for(j=0;j<pw;j++){
 	
-	accolor out = (accolor){0.,0.,0.,0.}; 
-	float alpha = y_scaledel * x_scaledel;
-	float ydel = ydelA[i];
-	float *dline = dline_start;
+	lcolor out = (lcolor){0,0,0,0}; 
+	int ydel = ydelA[i];
+	int *dline = dline_start;
 	
 	int x=xnumA[j];
 	int y=ynumA[i];
 	int xend=xnumB[j];
-	float xA = xdelA[j];
-	float xB = xdelB[j];
+	int xA = xdelA[j];
+	int xB = xdelB[j];
 
 	if(y<yend){
 	  // first line
 	  if(x<xend){
-	    l_mapping_calc(map,dline[x],obj_alpha,ydel*xA,&out,mix);
+	    if(dline[x]>=ol_alpha)
+	      map->mapfunc(dline[x],ydel*xA,&out);
 	    x++;
 	    
 	    for(; x < xend-1; x++)
-	      l_mapping_calc(map,dline[x],obj_alpha,ydel,&out,mix);
+	      if(dline[x]>=ol_alpha)
+		map->mapfunc(dline[x],ydel*xden,&out);
 	    
 	    if(x<xend)
-	      l_mapping_calc(map,dline[x],obj_alpha,ydel*xB,&out,mix);
+	      if(dline[x]>=ol_alpha)
+		map->mapfunc(dline[x],ydel*xB,&out);
 	  }
 	  y++;
 	  dline+=dw;
@@ -370,14 +366,18 @@
 	  // mid lines
 	  for(;y<yend-1;y++){
 	    x = xnumA[j];
-	    l_mapping_calc(map,dline[x],obj_alpha,xA,&out,mix);
+	    if(dline[x]>=ol_alpha)
+	      map->mapfunc(dline[x],xA*yden,&out);
 	    x++;
 	    
 	    for(; x < xend-1; x++)
-	      l_mapping_calc(map,dline[x],obj_alpha,1.,&out,mix);
+	      if(dline[x]>=ol_alpha)
+		map->mapfunc(dline[x],den,&out);
 	    
 	    if(x<xend)
-	      l_mapping_calc(map,dline[x],obj_alpha,xB,&out,mix);
+	      if(dline[x]>=ol_alpha)
+		map->mapfunc(dline[x],xB*yden,&out);
+
 	    dline+=dw;
 	  }
 	    
@@ -385,21 +385,25 @@
 	  if(y<yend){
 	    x = xnumA[j];
 	    ydel = ydelB[i];
-	    l_mapping_calc(map,dline[x],obj_alpha,xA*ydel,&out,mix);
+	    if(dline[x]>=ol_alpha)
+	      map->mapfunc(dline[x],xA*ydel,&out);
 	    x++;
 	    
 	    for(; x < xend-1; x++)
-	      l_mapping_calc(map,dline[x],obj_alpha,ydel,&out,mix);
+	      if(dline[x]>=ol_alpha)
+		map->mapfunc(dline[x],ydel*xden,&out);
 	    
 	    if(x<xend)
-	      l_mapping_calc(map,dline[x],obj_alpha,xB*ydel,&out,mix);
+	      if(dline[x]>=ol_alpha)
+		map->mapfunc(dline[x],xB*ydel,&out);
 	  }
 	}
 
-	alpha -= out.a;
-	mix->r = (out.r + mix->r * alpha)*idel;
-	mix->g = (out.g + mix->g * alpha)*idel;
-	mix->b = (out.b + mix->b * alpha)*idel;
+	*mix = map->mixfunc( (ucolor)(((u_int32_t)(out.a*idel)<<24) +
+				      ((u_int32_t)(out.r*idel)<<16) +
+				      ((u_int32_t)(out.g*idel)<<8) +
+				      ((u_int32_t)(out.b*idel))),
+			     *mix);
 	mix++;
 
       }
@@ -407,18 +411,18 @@
   }else{
     /* non-resampling render */
     for(i=0;i<ph;i++){
-      float *dline = data+i*dw;
-
+      int *dline = data+i*dw;
+      
       for(j=0;j<pw;j++){
-	float val = dline[j];
-	if(!isnan(val) && val >= obj_alpha){
-	  accolor out;
-	  l_mapping_calc(map,val,obj_alpha,1.,&out,panel);
-
-	  panel->r = out.r;
-	  panel->g = out.g;
-	  panel->b = out.b;
-
+	if(dline[j]>=ol_alpha){
+	  lcolor out = (lcolor){0,0,0,0};
+	  map->mapfunc(dline[j],255,&out);
+	
+	  *panel = map->mixfunc((ucolor)(((u_int32_t)(out.a)<<24) +
+					 ((u_int32_t)(out.r)<<16) +
+					 ((u_int32_t)(out.g)<<8) +
+					 ((u_int32_t)(out.b))),
+				*panel);
 	  panel++;
 	}
       }
@@ -445,12 +449,12 @@
   scalespace x_v = p2->x_v;
   scalespace y_v = p2->y_v;
 
-  ccolor *c = malloc(x.pixels*y.pixels*sizeof(*c));
+  ucolor *c = malloc(x.pixels*y.pixels*sizeof(*c));
 
   double alphadel[p->objectives];
   mapping mappings[p->objectives];
   int serialno = p2->serialno;
-  float *y_rects[p2->y_obj_num];
+  int *y_rects[p2->y_obj_num];
 
   memcpy(alphadel, p2->alphadel, sizeof(alphadel));
   memcpy(mappings, p2->mappings, sizeof(mappings));
@@ -465,7 +469,7 @@
   
   /* by objective */
   for(i=0;i<p->objectives;i++){
-    
+
     /**** render Y plane */
     int o_ynum = p2->y_obj_from_panel[i];
     resample_render_y_plane(p2, serialno, 
@@ -482,12 +486,9 @@
   gdk_threads_enter ();
   if(serialno == p2->serialno){
     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);
-    }
+    u_int32_t *cp = (u_int32_t *)c;
+    for(i=0;i<pw*ph;i++)
+      dr[i] = cp[i];
   }
   gdk_threads_leave();
   free(c);
@@ -1110,23 +1111,25 @@
       // maintain data planes
       for(i=0;i<p2->y_obj_num;i++){
 	// allocate new storage
-	float *newmap = calloc(sx_v.pixels*sy_v.pixels,sizeof(*newmap));
-	float *oldmap = p2->y_map[i];
+	int *newmap = calloc(sx_v.pixels*sy_v.pixels,sizeof(*newmap));
+	int *oldmap = p2->y_map[i];
 	int j;
 	
 	p2->y_map[i] = NULL;
 	//gdk_threads_leave ();
 	
 	for(j=0;j<sx_v.pixels*sy_v.pixels;j++)
-	  newmap[j]=NAN;
+	  newmap[j]=-1;
 	
 	// zoom scale data in map planes as placeholder for render
+	/* come back once converted to fixed point
 	if(oldmap){
 	  fast_scale(newmap, sx_v, sy_v,
 		     oldmap,old_xv, old_yv);
 	  free(oldmap);
 	}
-	
+	*/
+
 	//gdk_threads_enter ();
 	//if(p2->serialno != serialno){
 	//  gdk_threads_leave();

Modified: trunk/sushivision/panel-2d.h
===================================================================
--- trunk/sushivision/panel-2d.h	2007-02-12 15:22:26 UTC (rev 12458)
+++ trunk/sushivision/panel-2d.h	2007-02-12 20:25:12 UTC (rev 12459)
@@ -35,7 +35,7 @@
 
   /**** Y PLANES ******/
   int y_obj_num;
-  float **y_map; // indirected, dw*dh
+  int **y_map; // indirected, dw*dh
 
   sushiv_objective_t **y_obj_list; // list of objectives with a y plane
   int *y_obj_to_panel; /* maps from position in condensed list to position in full list */
@@ -79,7 +79,7 @@
 typedef struct {
   double *fout; // [function number * outval_number]
 
-  float **y_map; // [y_obj_list[i]][px]
+  int **y_map; // [y_obj_list[i]][px]
 
   int storage_width;
 



More information about the commits mailing list