Example #1
0
void BrushPreview::generateBoundaries()
{
  Brush* brush = getCurrentBrush();

  if (m_brushBoundaries &&
      m_brushGen == brush->gen())
    return;

  bool isFloodfill = m_editor->getCurrentEditorTool()->getPointShape(0)->isFloodFill();
  Image* brushImage = brush->image();
  int w = (isFloodfill ? 1: brushImage->width());
  int h = (isFloodfill ? 1: brushImage->height());

  m_brushGen = brush->gen();
  m_brushWidth = w;
  m_brushHeight = h;

  ImageRef mask;
  if (isFloodfill) {
    mask.reset(Image::create(IMAGE_BITMAP, w, w));
    mask->putPixel(0, 0, (color_t)1);
  }
  else if (brushImage->pixelFormat() != IMAGE_BITMAP) {
    mask.reset(Image::create(IMAGE_BITMAP, w, h));

    LockImageBits<BitmapTraits> bits(mask.get());
    auto pos = bits.begin();
    for (int v=0; v<h; ++v) {
      for (int u=0; u<w; ++u) {
        *pos = get_pixel(brushImage, u, v);
        ++pos;
      }
    }
  }

  m_brushBoundaries.reset(
    new MaskBoundaries(
      (mask ? mask.get(): brushImage)));
}