AGG第四十二课 Blitting an image over another with transparency


问题:I’ve managed to blit a loaded p_w_picpath onto another through the method”copy_from(…)” of renderer_base.I’d like to know how can i blit the same p_w_picpath and also specifying a colorthat will NOT overwrite the pixels of the destination p_w_picpath ( a color thatwill then result transparent ).I complete my question by specifying that the source p_w_picpath is a BMP andtherefore doesn’t support transparency and alpha channel in the pixelvalues.Any suggestion is appreciated回答:Yes, your simple question isn’t actually that simple. I could add thisfunctionality to copy_from, but I don’t know what exactly to add. Do youneed to make transparent only one color? Or a number of colors? Or maybe itshould be some volume in RGB with transparency determined by the distancefrom a certain point. OK, suppose you need only one color, bu someone elsemay want to make a number of colors translucent. And so on. We need a kindof a general solution.
For now you can try to use a method similar to the one inexamples/p_w_picpath_alpha.cppSee class span_conv_brightness_alpha_rgb8 and modify it as you want.But it’s a transformer, so that, works slower than copy_from. Besides, withany kind of a filter (bilinear and such) the colors are not exact, so, it’sprobably makes sense to use span_p_w_picpath_filter_rgb_nn instead ofspan_p_w_picpath_filter_rgb_bilinear.
Maybe it makes sense to add some functor to copy_from(), but I have no ideahow to do that in a general way and without losing performance. Perhapsthere should be another function more like blend_from(). Any ideas?答复:Actually I’ve gone for a “specialized” solution, that just solves my case.In detail, I created a new renderer that’s o开发云主机域名nly suitable to copy bitmaps oneover another with 1 transparent color.I only have ported the “copy_from” method from renderer_base along with allthe clipping helper methods and obejcts of your original rendere_base.I added a method that sets a trasparency color:
setTransaprentColor(color_type color) { … }
In the “copy_from” method, I get the color of the source bitmap with the”pixel(x,y)” method, check it against “transparentColor” and, if equal, Isimply skip the point with a “continue” statement.Else, I call “copy_pixel” on the underlying rendering_buffer with the exactvalue of the source bitmap pixel.
It’s evident that it can be easily extended to a generic “array” oftransparent colors, with the cost of cycling through all of them to see ifone of them matches the source color. Even better, one could even imagine to”map” some source color with some other colors (along with its own alphachannel) once the source RGB values are matched against the RGB values ofthe “transformer” object. I thought about it and it is not difficult to codesuch a transformer object and pass it to a renderer. But that would be toomuch for my special case and also kind of “expensive” in terms ofperformance, so I just left it “for future expansions” ;-)

相关推荐: CentOS6.2系统安装和基本软件环境配置过程

本篇内容介绍了“CentOS6.2系统安装和基本软件环境配置过程”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一、安装CentOS6.2系统1、选择Deskto…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 04/11 11:30
下一篇 04/11 11:30