AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2001.02.20 16:08 "need help", by Chakravarthy Terlapu
2001.02.20 17:19 "Re: need help", by Leonard Rosenthol
2001.03.02 15:12 "doubt", by Chakravarthy Terlapu
2001.03.05 20:54 "erasing pixels within a box using TIFF library", by Chakravarthy Terlapu
2001.03.06 20:47 "Re: erasing pixels within a box using TIFF library", by Chris 'Xenon' Hanson

2001.03.05 20:54 "erasing pixels within a box using TIFF library", by Chakravarthy Terlapu

Hi,

I am writing a program to erase pixels from a tiff image using TIFF library. I am using the point in a polygon test to check whether each pixel lies inside the polygon or not. I am having the problem at setting the pixels inside the polygon to white.

 if(point_value == 1) //if the point is inside the polygon
 {
   //how should i set the values of the pixels to white
   //i have tried using outbuf[j >> 3] = 0xFF but only a portion of the
   // box is getting erased. when i use outbuf[j] = 0XFF it doesnt work.

 }

the code is below. It woudl be great if anyone could help me as I got stuck in my work here from the past 4 days.

Thanks

Chak

linebytes = TIFFScanlineSize(in);

  outbytes = TIFFScanlineSize(out);

inbuf = (unsigned char*)malloc(linebytes); outbuf = (unsigned char*)malloc(outbytes);

    xp[0] = frc[33].lx; yp[0] = frc[33].ly;        
    xp[1] = frc[33].rx; yp[1] = frc[33].ry;
    xp[2] = frc[33].tx; yp[2] = frc[33].ty;
    xp[3] = frc[33].bx; yp[3] = frc[33].by;  

   for(row=0; row<h; row++)

{
   TIFFReadScanline(in, inbuf, row, 0);

      memset(outbuf, 0, outbytes);

     for(j=0; j<w; j++)
    {

        point_value = pnpoly(4, xp, yp, (float)j, (float)row);

       if(point_value == 1)
      {

             outbuf[j>>3] = 0xFF;

            //if( (inbuf[j>>3] & (0x80 >> (j & 0x07))) != 0 )
            //outbuf[j>>3] |= (0x80 >> (j & 0x07));

            //outbuf[j>>3] = 0x80 | 0x7F;
        }
        else
        {

          if( (inbuf[j>>3] & (0x80 >> (j & 0x07))) != 0 )
          outbuf[j>>3] |= (0x80 >> (j & 0x07));
      }

      }

   printf("*");

     TIFFWriteScanline(out, outbuf, row, 0 );
  }

TIFFClose(in);
TIFFClose(out);

  free(inbuf);

    free(outbuf);