Transparency in the empty space created with perspective transformation.

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

Transparency in the empty space created with perspective transformation.

by Sebastien Lachance :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Let me start by telling the port of this project to C# (AGG-Sharp) is an awesome piece of work. And AGG is in itself a life-saver for me at the moment.
 
I'm using it to apply perspective to a picture (distortion). And it works! But the question I have is this :  
 
When I'm applying perspective, the empty space is filed with a color, i can get any color in it but not transparent. I'm probably missing something but I haven't been able and sure it's pretty easy.  
 
Can someone point me in the correct direction?  It would be greatly appreciated.
 
Thank you very much!
 
Here is the code :  
 
 
public class AddPerspective
{
public List<RasterBuffer> RasterBufferList;
protected PlatformSupport Support;
protected PlatformSpecificWindow SpecificWindow;
 
rasterizer_scanline_aa g_rasterizer;
scanline_packed_8 g_scanline;
double g_x1 = 0;
double g_y1 = 0;
double g_x2 = 0;
double g_y2 = 0;
AGG.UI.polygon_ctrl m_quad;
//AGG.UI.SliderWidget m_blur;
 
public AddPerspective()
{
RasterBufferList = new List<RasterBuffer>();
}
 
public Bitmap Add(Bitmap picture, Point topleft, Point topright, Point bottomleft, Point bottomright)
{
 
g_rasterizer = new rasterizer_scanline_aa();
g_scanline = new scanline_packed_8();
 
 
 
m_quad = new AGG.UI.polygon_ctrl(4, 5.0);
//m_blur = new AGG.UI.SliderWidget(5.0, 5.0 + 15 * 1, 400 - 5, 10.0 + 15 * 1);
 
RasterBuffer newRasterBuffer = new RasterBuffer();
Support = new PlatformSupport(PlatformSupportAbstract.PixelFormats.pix_format_rgba32, PlatformSupportAbstract.ERenderOrigin.OriginTopLeft);
SpecificWindow = new PlatformSpecificWindow(Support, PlatformSupportAbstract.PixelFormats.pix_format_rgba32,
PlatformSupportAbstract.ERenderOrigin.OriginTopLeft);
 
bool goodLoad = SpecificWindow.load_pmap2(picture, 0, newRasterBuffer);
 
RasterBufferList.Add(newRasterBuffer);
 
//huh huh
Support.m_rbuf_window = new RasterBuffer();
SpecificWindow.create_pmap(400, 400, Support.m_rbuf_window);
 
Bitmap bmp = Transform(topleft, topright, bottomleft, bottomright);
return bmp;
 
}
 
 
private Bitmap Transform(Point topleft, Point topright, Point bottomleft, Point bottomright)
{
 
//Get the most left point
int width = 0;
if (topright.X >= bottomright.X)
width = topright.X;
else
{
width = bottomright.X;
}
 
int heigth = 0;
if (bottomleft.Y >= bottomright.Y)
heigth = bottomleft.Y;
else
{
heigth = bottomright.Y;
}
 
//FormatRGBA pixf = new FormatRGBA(rbuf_img(0), new BlenderBGRA());
 
g_x1 = 0.0;
g_y1 = 0.0;
g_x2 = RasterBufferList[0].Width();
g_y2 = RasterBufferList[0].Height();
 
m_quad.SetXN(0, topleft.X);
m_quad.SetYN(0, topleft.Y);// - 150;
m_quad.SetXN(1, topright.X);
m_quad.SetYN(1, topright.Y);// - 110;
m_quad.SetXN(2, bottomright.X);
m_quad.SetYN(2, bottomright.Y);// - 300;
m_quad.SetXN(3, bottomleft.X);
m_quad.SetYN(3, bottomleft.Y);// - 200;
 
 
FormatRGBA pixf_pre = new FormatRGBA(Support.rbuf_window(), new BlenderPreMultBGRA());
FormatClippingProxy clippingProxy_pre = new FormatClippingProxy(pixf_pre);
 
clippingProxy_pre.clear(new RGBA_Bytes(255,255,255,0).GetAsRGBA_Doubles().transparent());
 
g_rasterizer.SetVectorClipBox(0, 0, width, heigth);
g_rasterizer.reset();
 
int b = 0;
 
g_rasterizer.move_to_d(topleft.X, topleft.Y);
g_rasterizer.line_to_d(topright.X, topright.Y);
g_rasterizer.line_to_d(bottomright.X, bottomright.Y);
g_rasterizer.line_to_d(bottomleft.X, bottomleft.Y);
 
//typedef agg::span_allocator<color_type> span_alloc_type;
span_allocator sa = new span_allocator();
image_filter_bilinear filter_kernel = new image_filter_bilinear();
ImageFilterLookUpTable filter = new ImageFilterLookUpTable(filter_kernel, true);
 
//new AlphaMaskByteClipped()
//AlphaMaskAdaptor adaptor = new AlphaMaskAdaptor()
FormatRGBA pixf_img = new FormatRGBA(RasterBufferList[0], new BlenderPreMultBGRA());
RasterBufferAccessorClamp source = new RasterBufferAccessorClamp(pixf_img);
 
 
 
span_interpolator_persp_lerp interpolator = new span_interpolator_persp_lerp(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
span_subdiv_adaptor subdiv_adaptor = new span_subdiv_adaptor(interpolator);
 
if (interpolator.is_valid())
{
 
span_image_resample_rgba sg = new span_image_resample_rgba(source, subdiv_adaptor, filter);
 
//sg.blur(1.0d);
Renderer.GenerateAndRender(g_rasterizer, g_scanline, clippingProxy_pre, sa, sg);
}
 
 
Bitmap newPicture = new Bitmap(width, heigth);
Graphics g = Graphics.FromImage(newPicture);
 
SpecificWindow.m_pmap_window.draw(g);
 
return newPicture;
 
//Bitmap newPicture = Support.GetBitmap();
//return newPicture;
 
 
}
 
 
}
 

Re: Transparency in the empty space created with perspective transformation.

by Stephan Assmus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sebastien Lachance schrieb:

> Let me start by telling the port of this project to C# (AGG-Sharp) is an
> awesome piece of work. And AGG is in itself a life-saver for me at the
> moment.
>  
> I'm using it to apply perspective to a picture (distortion). And it works!
> But the question I have is this :  
>  
> When I'm applying perspective, the empty space is filed with a color, i can
> get any color in it but not transparent. I'm probably missing something but
> I haven't been able and sure it's pretty easy.  
>  
> Can someone point me in the correct direction?  It would be greatly
> appreciated.


> FormatRGBA pixf_pre = new FormatRGBA(Support.rbuf_window(), new
> BlenderPreMultBGRA());
> FormatClippingProxy clippingProxy_pre = new FormatClippingProxy(pixf_pre);
>  
> clippingProxy_pre.clear(new
> RGBA_Bytes(255,255,255,0).GetAsRGBA_Doubles().transparent());

For pre-multiplied colors, this is an invalid color. Have you tried with
RGBA_Bytes(0,0,0,0) instead? I don't know if this would fix your
problem, since I have only used plain AGG in C++ projects. I do know
that you have to use certain pixel format accessors and some versions
allow you to set the clear color (color used outside the image). This
may be what this is above, but I am not 100% sure.

Best regards,
-Stephan

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Re: Transparency in the empty space created with perspective transformation.

by Sebastien Lachance :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In the resulting bitmap, with RGBA_Bytes(0,0,0,0) it give me :
 A: 255
 B: 0
 G: 0
    IsEmpty: false
    IsKnownColor: false
    IsNamedColor: false
    IsSystemColor: false
    Name: "ff000000"
 R: 0

I'm kind of lost right now.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vector-agg-general



Re: Transparency in the empty space created with perspective transformation.

by Jim Barry-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sebastien Lachance wrote:
> When I'm applying perspective, the empty space is filed with a color,
> i can get any color in it but not transparent.

I think this is because pixel_map.create (agg_win32_bmp.cs, line 59) creates a bitmap with Format32bppRgb. You could try changing it to Format32bppPArgb.

- Jim


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general