Login  Register

Re: How to determine inverse color?

Posted by Gabriel Landini on Jan 10, 2006; 10:30pm
URL: http://imagej.273.s1.nabble.com/How-to-determine-inverse-color-tp3704104p3704107.html

Hi,
The macro to draw the contrasted line supporting rgb images is below (mind the
line breaks).
Perhaps the function "drawXORLine" should be renamed as it is not a XOR
function.

Cheers.

Gabriel


-------------------------
   if (nImages==0)
       newImage("Test","8-bit Ramp",512,512,1);
   r = minOf(getWidth, getHeight)/2;
   x1=getWidth/2; y1=getHeight/2;
   for (a=0; a<4*PI; a+=PI/100) {
       x2 = r*sin(a) + x1;
       y2 = r*cos(a) + y1;
       drawXORLine(x1,y1,x2,y2);
       wait(35);
       drawXORLine(x1,y1,x2,y2);
   }

   function drawXORLine(x1, y1, x2, y2) {
       if (bitDepth==8)
           value = 255;
       else if (bitDepth==16)
           value = 65535;
       else
           value = -1;
       autoUpdate(false);
       dx = x2-x1;
       dy = y2-y1;
       if (abs(dy)>abs(dx))
           n = abs(dy); else n = abs(dx);
       n++;
       xinc = dx/n;
       yinc = dy/n;
       if (bitDepth()==24){
         do {
             p=getPixel(x1,y1);
             red=((p&0xff0000>>16)+128) % 256;
             green=((p&0x00ff00>>8) +128) % 256;
             blue= (p&0x0000ff+128) % 256;
             putPixel(x1, y1, ((red & 0xff) <<16)+ ((green & 0xff) << 8) +
(blue & 0xff));
             x1 += xinc;
             y1 += yinc;
             n--;
         } while (n>0);
       }
       else{
        do {
             putPixel(x1, y1, ((getPixel(x1, y1)+128)%256));
             x1 += xinc;
             y1 += yinc;
             n--;
         } while (n>0);
       }
       updateDisplay();
   }

-----------------