Commits

Christopher De Vries committed 1400d1c

Modified code to make it faster?

Comments (0)

Files changed (1)

pov_sketch_bm/pov_sketch_bm.pde

   for(i=0;i<STRANDS;i++) {
     pix_column = strand_pos[i]-x;
     if(pix_column>-1 && pix_column<pov_image.nx) {
-      for(j=0;j<pov_image.ny;j++) {
-        if(i%2!=0) {
-          set_pixel(&strand_image,0,strand_start[i]+j,get_pixel(&pov_image,pix_column,j));
+      if(i%2!=0) {
+        for(j=0;j<pov_image.ny;j++) {
+            set_pixel(&strand_image,0,strand_start[i]+j,get_pixel(&pov_image,pix_column,j));
         }
-        else {
+      }
+      else {
+        for(j=0;j<pov_image.ny;j++) {
           set_pixel(&strand_image,0,strand_start[i]+pov_image.ny-j-1,get_pixel(&pov_image,pix_column,j));
         }
       }
     }
   }
 
-  lightStrand_SendEmptyFrame();
-  for(i=0;i<STRANDS*pov_image.ny+rabbit_length;i++) {
-    get_pixel_rgb(&strand_image,0,i,&red,&green,&blue);
-    lightStrand_SendColor(red,green,blue);
-  }
-  lightStrand_SendEmptyFrame();
+  send_strand_image(&strand_image);
 }
 
 void error_state() {
   }
 }
 
+void send_strand_image(struct image *bit_image) {
+  int pixint;
+  int i;
+  int j;
+  int jmax;
+  byte red;
+  byte green;
+  byte blue;
+
+  lightStrand_SendEmptyFrame();
+
+  for(i=0;i<bit_image->ny_int;i++) {
+    pixint = bit_image->data[i];
+    if(i==bit_image->ny_int-1) {
+      jmax = bit_image->ny%5;
+      if(jmax==0) jmax = 5;
+    }
+    else {
+      jmax = 5;
+    }
+
+    for(j=0;j<jmax;j++) {
+      if(pixint&red) {
+        red = 0xff;
+      }
+      else {
+        red = 0x00;
+      }
+
+      if(pixint&green) {
+        green=0xff;
+      }
+      else {
+        green = 0x00;
+      }
+
+      if(pixint&blue) {
+        blue = 0xff;
+      }
+      else {
+        blue = 0x00;
+      }
+
+      pixint>>=3;
+      lightStrand_SendColor(red,green,blue);
+    }
+  }
+  
+  lightStrand_SendEmptyFrame();
+}
+
 void allocate_image(struct image *bit_image, int x, int y) {
   bit_image->ny_int = ((y-1)/5)+1;