Пример #1
0
Image ProjectExporter::rescaleImageForIcon (Drawable& d, const int size)
{
    if (DrawableImage* drawableImage = dynamic_cast<DrawableImage*> (&d))
    {
        Image im = SoftwareImageType().convert (drawableImage->getImage());

        if (size == im.getWidth() && size == im.getHeight())
            return im;

        // (scale it down in stages for better resampling)
        while (im.getWidth() > 2 * size && im.getHeight() > 2 * size)
            im = im.rescaled (im.getWidth() / 2,
                              im.getHeight() / 2);

        Image newIm (Image::ARGB, size, size, true, SoftwareImageType());
        Graphics g (newIm);
        g.drawImageWithin (im, 0, 0, size, size,
                           RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
        return newIm;
    }

    Image im (Image::ARGB, size, size, true, SoftwareImageType());
    Graphics g (im);
    d.drawWithin (g, im.getBounds().toFloat(), RectanglePlacement::centred, 1.0f);
    return im;
}
Пример #2
0
Image ProjectExporter::rescaleImageForIcon (Image im, const int size)
{
    im = SoftwareImageType().convert (im);

    if (size == im.getWidth() && size == im.getHeight())
        return im;

    // (scale it down in stages for better resampling)
    while (im.getWidth() > 2 * size && im.getHeight() > 2 * size)
        im = im.rescaled (im.getWidth() / 2,
                          im.getHeight() / 2);

    Image newIm (Image::ARGB, size, size, true, SoftwareImageType());
    Graphics g (newIm);
    g.drawImageWithin (im, 0, 0, size, size,
                       RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
    return newIm;
}
Пример #3
0
LayerGraphicsBase::LayerGraphicsBase (
  Graphics& g, Rectangle <int> const& fillBounds)
{
  /* fillBounds cannot be empty. */
  jassert (!fillBounds.isEmpty ());

  LowLevelGraphicsSoftwareRenderer* renderer =
    dynamic_cast <LowLevelGraphicsSoftwareRenderer*> (
      &g.getInternalContext ());
  
  /* If this goes off it means you aren't using the software renderer for your
     Image!. LayerGraphics only works with the software renderer!
  */
  jassert (renderer != nullptr);

  RenderingHelpers::TranslationOrTransform const& transform = renderer->getTransform ();

  /* If this goes off it means you have something other than a simple
     translation in the transform. LayerGraphics does not support transforms other
     than translations!
  */
  jassert (transform.isOnlyTranslated);

  m_base = renderer->getImage ();

  Rectangle <int> const clipBounds (g.getClipBounds ().
    translated (transform.xOffset, transform.yOffset));
  
  jassert (m_base.getBounds ().contains (clipBounds));

  m_fill = Image (Image::ARGB, fillBounds.getWidth (), fillBounds.getHeight (), true);

  m_fillOrigin = fillBounds.getTopLeft ().translated (transform.xOffset, transform.yOffset);

  Rectangle <int> const workBounds =
    clipBounds.getIntersection (fillBounds.translated (transform.xOffset, transform.yOffset));

  jassert (m_base.getBounds ().contains (workBounds));

  m_work = Image (Image::RGB,
                  workBounds.getWidth (),
                  workBounds.getHeight(),
                  false,
                  SoftwareImageType ());

  m_workOrigin = workBounds.getTopLeft ();

  // Calculate the portion of m_fill which corresponds to m_work
  m_fillBounds = workBounds -
    fillBounds.getTopLeft ().translated (transform.xOffset, transform.yOffset);

  jassert (m_fill.getBounds ().contains (m_fillBounds));

  // Copy the base image into the work image.
  copyImage (
    m_work,
    Point <int> (0, 0),
    m_base,
    Rectangle <int> (
      m_workOrigin.getX (), m_workOrigin.getY (),
      m_work.getWidth (), m_work.getHeight ()),
    BlendMode::modeNormal,
    1);
}
ImagePixelData::Ptr NativeImageType::create (Image::PixelFormat format, int width, int height, bool clearImage) const
{
    return SoftwareImageType().create (format, width, height, clearImage);
}