Logo Search packages:      
Sourcecode: djvulibre version File versions  Download package

int GBitmap::rle_get_rect ( GRect rect  )  const

Gets the smallest rectangle enclosing black pixels. Rectangle rect gives the coordinates of the smallest rectangle containing all black pixels. Returns the number of black pixels.

Definition at line 1173 of file GBitmap.cpp.

References GRect::clear(), monitor(), read_run(), GRect::xmax, GRect::xmin, GRect::ymax, and GRect::ymin.

{
  GMonitorLock lock(monitor());
  if (!rle) 
    return 0;
  int area = 0;
  unsigned char *runs = rle;
  rect.xmin = ncolumns;
  rect.ymin = nrows;
  rect.xmax = 0;
  rect.ymax = 0;
  int r = nrows;
  while (--r >= 0)
    {
      int p = 0;
      int c = 0;
      int n = 0;
      while (c < ncolumns)
        {
          const int x=read_run(runs);
          if(x)
            {
              if (p)
                {
                  if (c < rect.xmin) 
                    rect.xmin = c;
                  if ((c += x) > rect.xmax) 
                    rect.xmax = c-1;
                  n += x;
                }
              else
                {
                  c += x;
                }
            }
          p = 1-p;
        }
      area += n;
      if (n)
        {
          rect.ymin = r;
          if (r > rect.ymax) 
            rect.ymax = r;
        }
    }
  if (area==0)
    rect.clear();
  return area;
}


Generated by  Doxygen 1.6.0   Back to index