Beispiel #1
0
// The purpose of this function is to take r1 and fragment it around r2,
// removing the area that overlaps.  This function can be used by either
// Include() or Exclude(), since it simply fragments r1 (but always checks
// for swapping!)  For Exclusion, r2 is ALWAYS the excluding rect!
void csRectRegion::fragmentRect (csRect &r1, csRect &r2, int mode)
{
  // We may have to fragment r1 into three pieces if an entire edge of r2 is
  // inside r1.
  if (r1.Intersects (r2))
  {
    // Since fragment rect already test for all cases, the ideal method here
    // is to call fragment rect on the intersection of r1 and r2 with r1
    // as the fragmentee.  This creates a properly fragmented system.
    //
    // We know that rect1 is already good, so we simply fragment rect2 and
    // gather it's fragments into the fragment buffer for further consideration.
    //
    // In exclude mode, we don't want to remove parts of r2 from r1, whereas
    // in include mode we want to perform an optimal merge of the two, or
    // remove parts of r1 from r2.
    csRect ri (r1);
    ri.Intersect (r2);

    if (mode == MODE_INCLUDE)
    {
      if (r1.Area () < r2.Area ())
      {
        csRect temp (r1);
        r1.Set (r2);
        r2.Set (temp);
      }

      // Push r1 back into the regions list
      region.Push (r1);

      // Perform fragment and gather.
      markForGather ();
      fragmentContainedRect (r2, ri);
      gatherFragments ();
    }
    else
    {
      // Fragment inclusion rect around intersection (keep)
      fragmentContainedRect (r1, ri);
    }
    return;
  }
}
Beispiel #2
0
void ProctexPDLight::PDMap::ComputeValueBounds (const csRect& area, 
                                                csRGBcolor& maxValue, 
                                                csRect& nonNullArea)
{
  const int width = imageW;
  maxValue.Set (0, 0, 0);
  nonNullArea.Set (INT_MAX, INT_MAX, INT_MIN, INT_MIN);
  
  int mapPitch = width - area.Width ();
  if (imageData->IsGray())
  {
    const uint8* map = 
      static_cast<LumelBufferGray*> ((LumelBufferBase*)imageData)->GetData() 
      + area.ymin * width + area.xmin;
    for (int y = area.ymin; y < area.ymax; y++)
    {
      for (int x = area.xmin; x < area.xmax; x++)
      {
	uint8 v = *map++;
  
	if (v > maxValue.red)
          maxValue.Set (v, v, v);
  
	if (v > 0)
	{
	  nonNullArea.Extend (x, y);
	}
      }
      map += mapPitch;
    }
  }
  else
  {
    const Lumel* map = 
      static_cast<LumelBufferRGB*> ((LumelBufferBase*)imageData)->GetData() 
      + area.ymin * width + area.xmin;
    for (int y = area.ymin; y < area.ymax; y++)
    {
      for (int x = area.xmin; x < area.xmax; x++)
      {
	const Lumel& p = *map++;
  
	if (p.c.red > maxValue.red)
	  maxValue.red = p.c.red;
	if (p.c.green > maxValue.green)
	  maxValue.green = p.c.green;
	if (p.c.blue > maxValue.blue)
	  maxValue.blue = p.c.blue;
  
	if (p.c.red + p.c.green + p.c.blue > 0)
	{
	  nonNullArea.Extend (x, y);
	}
      }
      map += mapPitch;
    }
  }

  // Align line start+end on 2-pixel-boundary (for MMX)
  nonNullArea.xmin &= ~1;
  nonNullArea.xmax = (nonNullArea.xmax+1) & ~1;
}