2001.02.20 16:08 "need help", by Chakravarthy Terlapu

2001.03.02 15:12 "doubt", by Chakravarthy Terlapu

Hi,

I dont know where I am going wrong..I think I am close to the solution. I am getting a black image. I am trying to erase pixels within the box. I have declared the prototypes in a header file...

I am using for(i=0; i< number; i++) for different boxes coordinates. Could anyone please check the error. I am using the point in a polygon test.

Chak

void image_box(finalRectangleCoords *frc, int number)
{
  int i, j, point_value, linebytes, outbytes;
  uint32 w, h, row;
  unsigned char *inbuf, *outbuf;
  TIFF *in, *out;
  float xp[4], yp[4];

  printf("The program is running: ");
  fflush(stdout);

  in = TIFFOpen("street.tif", "r");
  out = TIFFOpen("street_box.tif", "w");

  TIFFGetField(in, TIFFTAG_IMAGELENGTH, &h);
  TIFFGetField(in, TIFFTAG_IMAGELENGTH, &w);

  TIFFSetField(out, TIFFTAG_IMAGELENGTH, h);
  TIFFSetField(out, TIFFTAG_IMAGEWIDTH, w);
  TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 1);
  TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 1);
  TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
  TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
  TIFFSetField(out, TIFFTAG_ORIENTATION, 1);

  linebytes = TIFFScanlineSize(in);
  outbytes=TIFFScanlineSize(out);

  inbuf = (unsigned char*)malloc(linebytes);
  outbuf = (unsigned char*)malloc(outbytes);
  for(i=0;i<outbytes;i++) outbuf[i]=0;

  for(i=0; i< number; i++)
  {
    xp[0] = frc[i].lx; yp[0] = frc[i].ly;
    xp[1] = frc[i].rx; yp[1] = frc[i].ry;
    xp[2] = frc[i].tx; yp[2] = frc[i].ty;
    xp[3] = frc[i].bx; yp[3] = frc[i].by;

    printf("*");

    for(row=0; row<h; row++)
    {
      TIFFReadScanline(in, inbuf, row, 0);
      for(j=0; j<w; j++)
      {
        point_value = pnpoly(4, xp, yp, row, j);
        if(point_value == 1)
        {
          //Here I have to set the pixels within the box to white
           if( (inbuf[j>>3] & (0x80 >> (j & 0x07))) != 0 )
            outbuf[j>>3] |= (0x80 >> (j & 0x07));
        }
        else
        {
           //Here the other pixels outside the box I have to just copy
           them as it is
        }
      }
      TIFFWriteScanline(out, outbuf, row, 0 );
    }
  }
    TIFFClose(in);
    TIFFClose(out);
    free(inbuf); }

int pnpoly(int npol, float *xp, float *yp, float x, float y)
{
  int i, j, c = 0;

  for (i = 0, j = npol-1; i < npol; j = i++)
  {
    if ((((yp[i]<=y) && (y<yp[j])) || ((yp[j]<=y) && (y<yp[i]))) && (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
          c = !c;
  }
      return c;
}