Is it possible to perform this type of rendering?

View: New views
6 Messages — Rating Filter:   Alert me  

Parent Message unknown Is it possible to perform this type of rendering?

by Vinnie-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Dear Group:

I'm drawing a ton of cool-looking controls, sliders, and knobs with agg. Unfortunately all the gradient fills and anti-aliasing comes at the price of some speed. I want to cache certain un-changing elements into an offscreen bitmap. However, these elements have transparency information associated with them....so...

I would first like to get an idea if what I need to do is possible with agg before I go delving in.

Specifically, I want to create a new renderer (I think thats the component I need to modify) that instead of blending color values into the destination map using the coverage information, writes the color as a solid into the destination map, and stores the coverage information in a separate channel.

In other words, produce the equivalent of a Photoshop Layer (red, green, and blue color planes plus one alpha channel for transparency) based on drawing output.

For example if I draw an anti-aliased circle, I would want as my output to be a pure black circle in the RGB channels, with the coverage information going into the fourth channel (value=255 on the interior, and intermediate values 1-254 along the edge holding the coverage information).

Would I do this by providing my own version of renderer_scanline_aa_solid? Is that the right class?

Or does agg perhaps already have the ability to do this by some magic combination of nesting templates?

Thanks!


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Re: Is it possible to perform this type of rendering?

by Petr Kobalíček :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Vinnie,

I don't know if I will help you, but I think that you should study
agg::rasterizer_scanline_aa<> class.

For example I'm doing somethink like this in my library:

// Types
typedef agg::rasterizer_scanline_aa<>         Rasterizer;
typedef agg::scanline_p8                      ScanlineP8;
typedef agg::scanline_u8                      ScanlineU8;

template<int BytesPerPixel, class Rasterizer, class Scanline>
static void FOG_OPTIMIZEDCALL AggRenderScanlines(
  RasterPainterDevice* d, Rasterizer& ras, Scanline& sl)
{
  if (!ras.rewind_scanlines()) return;

  uint8_t* pBase = d->_workRaster;
  uint8_t* pRas;
  uint8_t* pCur;
  sysint_t stride = d->_stride;

  sl.reset(ras.min_x(), ras.max_x());

  int exty1 = d->_clipBox.y1();
  int exty2 = d->_clipBox.y2();

  FillSpan fillSpan = d->_fillFuncs.fillSpan;
  FillSpanM fillSpanM_A8 = d->_fillFuncs.fillSpanM_A8;

  // solid source
  if (1)
  {
    while (ras.sweep_scanline(sl))
    {
      unsigned num_spans = sl.num_spans();
      typename Scanline::const_iterator span = sl.begin();

      // TODO: is this necessary?
      int y = sl.y();
      if (y < exty1) continue;
      if (y >= exty2) break;

      pRas = pBase + y * stride;

      for (;;)
      {
        int x = span->x;
        int len = span->len;

        pCur = pRas + Raster::mul<int, BytesPerPixel>(x);

        if (len > 0)
        {
          fillSpanM_A8(pCur, &d->_source, span->covers, (unsigned)len);
        }
        else
        {
          len = -len;
          FOG_ASSERT(len > 0);

          uint32_t cover = (uint32_t)*(span->covers);
          if (cover == 0xFF)
          {
            fillSpan(pCur, &d->_source, len);
          }
          else
          {
            uint32_t t = Raster::bytemul(d->_source.i, cover);
            fillSpan(pCur, &t, len);
          }
        }

        if (--num_spans == 0) break;
        ++span;
      }
    }
  }
}

You can see that by calling sweep_scanlines() you will gen spans with
coverage informations and you can do what you want with these spans.
I'm using this way to connect antigrain with BlitJit and the speed is
very promising.

Cheers
- Petr

2009/4/27 Vinnie <thevinn@...>:

>
> Dear Group:
>
> I'm drawing a ton of cool-looking controls, sliders, and knobs with agg. Unfortunately all the gradient fills and anti-aliasing comes at the price of some speed. I want to cache certain un-changing elements into an offscreen bitmap. However, these elements have transparency information associated with them....so...
>
> I would first like to get an idea if what I need to do is possible with agg before I go delving in.
>
> Specifically, I want to create a new renderer (I think thats the component I need to modify) that instead of blending color values into the destination map using the coverage information, writes the color as a solid into the destination map, and stores the coverage information in a separate channel.
>
> In other words, produce the equivalent of a Photoshop Layer (red, green, and blue color planes plus one alpha channel for transparency) based on drawing output.
>
> For example if I draw an anti-aliased circle, I would want as my output to be a pure black circle in the RGB channels, with the coverage information going into the fourth channel (value=255 on the interior, and intermediate values 1-254 along the edge holding the coverage information).
>
> Would I do this by providing my own version of renderer_scanline_aa_solid? Is that the right class?
>
> Or does agg perhaps already have the ability to do this by some magic combination of nesting templates?
>
> Thanks!
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> Vector-agg-general mailing list
> Vector-agg-general@...
> https://lists.sourceforge.net/lists/listinfo/vector-agg-general
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Re: Is it possible to perform this type of rendering?

by Lorne Laliberte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You could also just render into a 32-bit buffer (RGBA, BGRA, or
whatever suits your needs) and then blend that buffer onto your final
output surface.

That's what I'm doing in our app for a transparent GUI layer above the
actual scene. It lets us draw whatever we want in the GUI layer
(selection boxes, controls, etc.) without requiring any redraw within
the scene.

I'm using a custom dirty rectangle system to minimize the redraw areas
in general, though.

Lorne Laliberte
Senior Software Developer, Indigo Rose Software



On Mon, Apr 27, 2009 at 1:17 PM, Petr Kobalíček
<kobalicek.petr@...> wrote:

> Hi Vinnie,
>
> I don't know if I will help you, but I think that you should study
> agg::rasterizer_scanline_aa<> class.
>
> For example I'm doing somethink like this in my library:
>
> // Types
> typedef agg::rasterizer_scanline_aa<>         Rasterizer;
> typedef agg::scanline_p8                      ScanlineP8;
> typedef agg::scanline_u8                      ScanlineU8;
>
> template<int BytesPerPixel, class Rasterizer, class Scanline>
> static void FOG_OPTIMIZEDCALL AggRenderScanlines(
>  RasterPainterDevice* d, Rasterizer& ras, Scanline& sl)
> {
>  if (!ras.rewind_scanlines()) return;
>
>  uint8_t* pBase = d->_workRaster;
>  uint8_t* pRas;
>  uint8_t* pCur;
>  sysint_t stride = d->_stride;
>
>  sl.reset(ras.min_x(), ras.max_x());
>
>  int exty1 = d->_clipBox.y1();
>  int exty2 = d->_clipBox.y2();
>
>  FillSpan fillSpan = d->_fillFuncs.fillSpan;
>  FillSpanM fillSpanM_A8 = d->_fillFuncs.fillSpanM_A8;
>
>  // solid source
>  if (1)
>  {
>    while (ras.sweep_scanline(sl))
>    {
>      unsigned num_spans = sl.num_spans();
>      typename Scanline::const_iterator span = sl.begin();
>
>      // TODO: is this necessary?
>      int y = sl.y();
>      if (y < exty1) continue;
>      if (y >= exty2) break;
>
>      pRas = pBase + y * stride;
>
>      for (;;)
>      {
>        int x = span->x;
>        int len = span->len;
>
>        pCur = pRas + Raster::mul<int, BytesPerPixel>(x);
>
>        if (len > 0)
>        {
>          fillSpanM_A8(pCur, &d->_source, span->covers, (unsigned)len);
>        }
>        else
>        {
>          len = -len;
>          FOG_ASSERT(len > 0);
>
>          uint32_t cover = (uint32_t)*(span->covers);
>          if (cover == 0xFF)
>          {
>            fillSpan(pCur, &d->_source, len);
>          }
>          else
>          {
>            uint32_t t = Raster::bytemul(d->_source.i, cover);
>            fillSpan(pCur, &t, len);
>          }
>        }
>
>        if (--num_spans == 0) break;
>        ++span;
>      }
>    }
>  }
> }
>
> You can see that by calling sweep_scanlines() you will gen spans with
> coverage informations and you can do what you want with these spans.
> I'm using this way to connect antigrain with BlitJit and the speed is
> very promising.
>
> Cheers
> - Petr
>
> 2009/4/27 Vinnie <thevinn@...>:
>>
>> Dear Group:
>>
>> I'm drawing a ton of cool-looking controls, sliders, and knobs with agg. Unfortunately all the gradient fills and anti-aliasing comes at the price of some speed. I want to cache certain un-changing elements into an offscreen bitmap. However, these elements have transparency information associated with them....so...
>>
>> I would first like to get an idea if what I need to do is possible with agg before I go delving in.
>>
>> Specifically, I want to create a new renderer (I think thats the component I need to modify) that instead of blending color values into the destination map using the coverage information, writes the color as a solid into the destination map, and stores the coverage information in a separate channel.
>>
>> In other words, produce the equivalent of a Photoshop Layer (red, green, and blue color planes plus one alpha channel for transparency) based on drawing output.
>>
>> For example if I draw an anti-aliased circle, I would want as my output to be a pure black circle in the RGB channels, with the coverage information going into the fourth channel (value=255 on the interior, and intermediate values 1-254 along the edge holding the coverage information).
>>
>> Would I do this by providing my own version of renderer_scanline_aa_solid? Is that the right class?
>>
>> Or does agg perhaps already have the ability to do this by some magic combination of nesting templates?
>>
>> Thanks!
>>
>>
>> ------------------------------------------------------------------------------
>> Crystal Reports - New Free Runtime and 30 Day Trial
>> Check out the new simplified licensign option that enables unlimited
>> royalty-free distribution of the report engine for externally facing
>> server and web deployment.
>> http://p.sf.net/sfu/businessobjects
>> _______________________________________________
>> Vector-agg-general mailing list
>> Vector-agg-general@...
>> https://lists.sourceforge.net/lists/listinfo/vector-agg-general
>>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> Vector-agg-general mailing list
> Vector-agg-general@...
> https://lists.sourceforge.net/lists/listinfo/vector-agg-general
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Re: Is it possible to perform this type of rendering?

by Lorne Laliberte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I should clarify: in practical terms, the anti-aliasing coverage
information is preserved if you output onto a 32-bit surface with a
transparent background, i.e. a buffer that has been cleared with a
transparent color(0,0,0,0).

Lorne Laliberte
Senior Software Developer, Indigo Rose Software



2009/4/27 Lorne Laliberte <lorne@...>:

> You could also just render into a 32-bit buffer (RGBA, BGRA, or
> whatever suits your needs) and then blend that buffer onto your final
> output surface.
>
> That's what I'm doing in our app for a transparent GUI layer above the
> actual scene. It lets us draw whatever we want in the GUI layer
> (selection boxes, controls, etc.) without requiring any redraw within
> the scene.
>
> I'm using a custom dirty rectangle system to minimize the redraw areas
> in general, though.
>
> Lorne Laliberte
> Senior Software Developer, Indigo Rose Software
>
>
>
> On Mon, Apr 27, 2009 at 1:17 PM, Petr Kobalíček
> <kobalicek.petr@...> wrote:
>> Hi Vinnie,
>>
>> I don't know if I will help you, but I think that you should study
>> agg::rasterizer_scanline_aa<> class.
>>
>> For example I'm doing somethink like this in my library:
>>
>> // Types
>> typedef agg::rasterizer_scanline_aa<>         Rasterizer;
>> typedef agg::scanline_p8                      ScanlineP8;
>> typedef agg::scanline_u8                      ScanlineU8;
>>
>> template<int BytesPerPixel, class Rasterizer, class Scanline>
>> static void FOG_OPTIMIZEDCALL AggRenderScanlines(
>>  RasterPainterDevice* d, Rasterizer& ras, Scanline& sl)
>> {
>>  if (!ras.rewind_scanlines()) return;
>>
>>  uint8_t* pBase = d->_workRaster;
>>  uint8_t* pRas;
>>  uint8_t* pCur;
>>  sysint_t stride = d->_stride;
>>
>>  sl.reset(ras.min_x(), ras.max_x());
>>
>>  int exty1 = d->_clipBox.y1();
>>  int exty2 = d->_clipBox.y2();
>>
>>  FillSpan fillSpan = d->_fillFuncs.fillSpan;
>>  FillSpanM fillSpanM_A8 = d->_fillFuncs.fillSpanM_A8;
>>
>>  // solid source
>>  if (1)
>>  {
>>    while (ras.sweep_scanline(sl))
>>    {
>>      unsigned num_spans = sl.num_spans();
>>      typename Scanline::const_iterator span = sl.begin();
>>
>>      // TODO: is this necessary?
>>      int y = sl.y();
>>      if (y < exty1) continue;
>>      if (y >= exty2) break;
>>
>>      pRas = pBase + y * stride;
>>
>>      for (;;)
>>      {
>>        int x = span->x;
>>        int len = span->len;
>>
>>        pCur = pRas + Raster::mul<int, BytesPerPixel>(x);
>>
>>        if (len > 0)
>>        {
>>          fillSpanM_A8(pCur, &d->_source, span->covers, (unsigned)len);
>>        }
>>        else
>>        {
>>          len = -len;
>>          FOG_ASSERT(len > 0);
>>
>>          uint32_t cover = (uint32_t)*(span->covers);
>>          if (cover == 0xFF)
>>          {
>>            fillSpan(pCur, &d->_source, len);
>>          }
>>          else
>>          {
>>            uint32_t t = Raster::bytemul(d->_source.i, cover);
>>            fillSpan(pCur, &t, len);
>>          }
>>        }
>>
>>        if (--num_spans == 0) break;
>>        ++span;
>>      }
>>    }
>>  }
>> }
>>
>> You can see that by calling sweep_scanlines() you will gen spans with
>> coverage informations and you can do what you want with these spans.
>> I'm using this way to connect antigrain with BlitJit and the speed is
>> very promising.
>>
>> Cheers
>> - Petr
>>
>> 2009/4/27 Vinnie <thevinn@...>:
>>>
>>> Dear Group:
>>>
>>> I'm drawing a ton of cool-looking controls, sliders, and knobs with agg. Unfortunately all the gradient fills and anti-aliasing comes at the price of some speed. I want to cache certain un-changing elements into an offscreen bitmap. However, these elements have transparency information associated with them....so...
>>>
>>> I would first like to get an idea if what I need to do is possible with agg before I go delving in.
>>>
>>> Specifically, I want to create a new renderer (I think thats the component I need to modify) that instead of blending color values into the destination map using the coverage information, writes the color as a solid into the destination map, and stores the coverage information in a separate channel.
>>>
>>> In other words, produce the equivalent of a Photoshop Layer (red, green, and blue color planes plus one alpha channel for transparency) based on drawing output.
>>>
>>> For example if I draw an anti-aliased circle, I would want as my output to be a pure black circle in the RGB channels, with the coverage information going into the fourth channel (value=255 on the interior, and intermediate values 1-254 along the edge holding the coverage information).
>>>
>>> Would I do this by providing my own version of renderer_scanline_aa_solid? Is that the right class?
>>>
>>> Or does agg perhaps already have the ability to do this by some magic combination of nesting templates?
>>>
>>> Thanks!
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Crystal Reports - New Free Runtime and 30 Day Trial
>>> Check out the new simplified licensign option that enables unlimited
>>> royalty-free distribution of the report engine for externally facing
>>> server and web deployment.
>>> http://p.sf.net/sfu/businessobjects
>>> _______________________________________________
>>> Vector-agg-general mailing list
>>> Vector-agg-general@...
>>> https://lists.sourceforge.net/lists/listinfo/vector-agg-general
>>>
>>
>> ------------------------------------------------------------------------------
>> Crystal Reports - New Free Runtime and 30 Day Trial
>> Check out the new simplified licensign option that enables unlimited
>> royalty-free distribution of the report engine for externally facing
>> server and web deployment.
>> http://p.sf.net/sfu/businessobjects
>> _______________________________________________
>> Vector-agg-general mailing list
>> Vector-agg-general@...
>> https://lists.sourceforge.net/lists/listinfo/vector-agg-general
>>
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Parent Message unknown Re: Is it possible to perform this type of rendering?

by Vinnie-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> From: Lorne Laliberte <lorne@...>
> You could also just render into a 32-bit buffer (RGBA,
> BGRA, or whatever suits your needs) and then blend that buffer onto
> your final output surface.

Thats exactly what I am trying to accomplish.

> I should clarify: in practical terms, the anti-aliasing
> coverage information is preserved if you output onto a 32-bit
> surface with a transparent background, i.e. a buffer that has
> been cleared with a transparent color(0,0,0,0).

So you are saying that agg already supports the feature I need? Well that will save me time. Just to be clear, I am currently using:

typedef agg::pixfmt_bgr24 pfmt_type;
typedef agg::renderer_base<pfmt_type> rbase_type;
typedef agg::renderer_scanline_aa_solid<rbase_type> rsolid_type;

So all I would need to do is switch to:
typedef agg::pixfmt_bgra32 pfmt_type;

That would be pretty sweet! You just saved me a few days of frustration!

Whats with all the "premultiply" variations? And whats the difference between regular and "plain"?



------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Re: Is it possible to perform this type of rendering?

by Lorne Laliberte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Apr 28, 2009 at 8:27 AM, Vinnie <thevinn@...> wrote:

>
>> From: Lorne Laliberte <lorne@...>
>> I should clarify: in practical terms, the anti-aliasing
>> coverage information is preserved if you output onto a 32-bit
>> surface with a transparent background, i.e. a buffer that has
>> been cleared with a transparent color(0,0,0,0).
>
> So you are saying that agg already supports the feature I need? Well that will save me time. Just to be clear, I am currently using:
>
> typedef agg::pixfmt_bgr24 pfmt_type;
> typedef agg::renderer_base<pfmt_type> rbase_type;
> typedef agg::renderer_scanline_aa_solid<rbase_type> rsolid_type;
>
> So all I would need to do is switch to:
> typedef agg::pixfmt_bgra32 pfmt_type;
>
> That would be pretty sweet! You just saved me a few days of frustration!

:)

> Whats with all the "premultiply" variations? And whats the difference between regular and "plain"?

Ah, that's a million dollar question. The short answer: I'd recommend
doing everything in premultiplied colors (use the _pre versions), and
just use color(r,g,b,a).premultiply() whenever you specify a color.

Longer answer:

You will probably find this post in the mailing list very useful:
http://thread.gmane.org/gmane.comp.graphics.agg/3110/focus=3112

If you're drawing images and doing any kind of filtering or
interpolation on them (resizing, etc.), you'll need to use a
premultiplied image format. For "normal" drawing of solid shapes, you
can choose to use either the regular pixel format or the _pre ones.
Using the regular pixel format lets you specify non-premultiplied
colors, and they'll basically be premultiplied for you as they're
blended in.

You can attach pre and non-pre pixel formats to the same buffer; they
basically affect how (or whether) the alpha channel is applied during
the drawing operation. The result of the draw operation (the contents
of the buffer) is always premultiplied, unless you use the _plain
versions of the pixel formats I believe.

Note that only the pixel format attached to the destination buffer matters.

C++ templates being as they are, I found it simpler overall to just
use premultiplied pixel formats throughout my graphics engine, and
simply enforce a rule that all input colors need to be premultiplied.

Lorne Laliberte
Senior Software Developer, Indigo Rose Software

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general