问题:

I've managed to blit a loaded image onto another through the method

"copy_from(...)" of renderer_base.

I'd like to know how can i blit the same image and also specifying a color

that will NOT overwrite the pixels of the destination image ( a color that

will then result transparent ).

I complete my question by specifying that the source image is a BMP and

therefore doesn't support transparency and alpha channel in the pixel

values.

Any suggestion is appreciated

回答:

Yes, your simple question isn't actually that simple. I could add this

functionality to copy_from, but I don't know what exactly to add. Do you

need to make transparent only one color? Or a number of colors? Or maybe it

should be some volume in RGB with transparency determined by the distance

from a certain point. OK, suppose you need only one color, bu someone else

may want to make a number of colors translucent. And so on. We need a kind

of a general solution.

For now you can try to use a method similar to the one in

examples/image_alpha.cpp

See 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, with

any kind of a filter (bilinear and such) the colors are not exact, so, it's

probably makes sense to use span_image_filter_rgb_nn instead of

span_image_filter_rgb_bilinear.

Maybe it makes sense to add some functor to copy_from(), but I have no idea

how to do that in a general way and without losing performance. Perhaps

there 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 only suitable to copy bitmaps one

over another with 1 transparent color.

I only have ported the "copy_from" method from renderer_base along with all

the 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, I

simply skip the point with a "continue" statement.

Else, I call "copy_pixel" on the underlying rendering_buffer with the exact

value of the source bitmap pixel.

It's evident that it can be easily extended to a generic "array" of

transparent colors, with the cost of cycling through all of them to see if

one 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 alpha

channel) once the source RGB values are matched against the RGB values of

the "transformer" object. I thought about it and it is not difficult to code

such a transformer object and pass it to a renderer. But that would be too

much for my special case and also kind of "expensive" in terms of

performance, so I just left it "for future expansions" ;-)

本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/1969721,如需转载请自行联系原作者

AGG第四十二课 Blitting an image over another with transparency相关推荐

  1. 新版标准日本语初级_第四十二课

    语法   1. 小句1(动た形/ない形)まま,小句2或名 + の + まま,小句:表示将理应改变的状态保持着去进行另外的动作. まま前为肯定形式时,用动た形 + まま. まま前为否定形式时,用动ない形 ...

  2. C#之windows桌面软件第十二课:电脑ADC值显示(上位机),记忆上次串口号,并用TrackBar控件显示ADC值

    C#之windows桌面软件第十二课:电脑ADC值显示(上位机),记忆上次串口号,并用TrackBar控件显示ADC值 using System; using System.Collections.G ...

  3. 四十二、深入Java中的文件读取操作

    @Author:Runsen @Date:2020/6/8 作者介绍:Runsen目前大三下学期,专业化学工程与工艺,大学沉迷日语,Python, Java和一系列数据分析软件.导致翘课严重,专业排名 ...

  4. NeHe OpenGL第三十二课:拾取游戏

    NeHe OpenGL第三十二课:拾取游戏 拾取, Alpha混合, Alpha测试, 排序: 这又是一个小游戏,交给的东西会很多,慢慢体会吧   欢迎来到32课. 这课大概是在我所写作已来最大的一课 ...

  5. OpenGL教程翻译 第十二课 透视投影

    第十二课 透视投影 原文地址:http://ogldev.atspace.co.uk/(源码请从原文主页下载) 背景 在这一节中我们将会介绍如何在保持深度外观的情况下将三维世界中的物体投影到二维平面上 ...

  6. 实践数据湖iceberg 第十二课 catalog是什么

    系列文章目录 实践数据湖iceberg 第一课 入门 实践数据湖iceberg 第二课 iceberg基于hadoop的底层数据格式 实践数据湖iceberg 第三课 在sqlclient中,以sql ...

  7. 【C++探索之旅】第一部分第十二课:指针一出,谁与争锋

    内容简介 1.第一部分第十二课:指针一出,谁与争锋 2.第一部分第十三课预告:第一部分小测验 指针一出,谁与争锋 上一课<[C++探索之旅]第一部分第十一课:小练习,猜单词>中,我们用一个 ...

  8. 风炫安全Web安全学习第四十节课 反序列化漏洞攻击利用演示

    风炫安全Web安全学习第四十节课 反序列化漏洞攻击利用演示 0x02 反序列化漏洞利用 反序列化漏洞的成因在于代码中的 unserialize() 接收的参数可控,从上面的例子看,这个函数的参数是一个 ...

  9. NeHe OpenGL教程 第四十八课:轨迹球

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

最新文章

  1. Facebook收购GrokStyle:布局AI零售
  2. 如何搞定分库后数据冗余
  3. 利用运行时设置UITextField 光标颜色
  4. 第3章 变量和表达式
  5. IDEA 设置护眼色RGB值
  6. mvvm模式和mvc的区别_MVC,MVVM,MVP是指什么,它们之间有啥区别
  7. Synology DS213J 群晖NAS git server架设方法!
  8. MySQL JDBC URL中几个重要参数说明
  9. PDF如何编辑,怎么删除空白页面
  10. 8Manage微信CRM:打破传统企业营销套路
  11. CentOS 5.2 LVM 新增加一块硬盘的方法
  12. 算法导论终于看完了~
  13. svn服务器端 忽略文件夹,SVN忽略不需要版本控制的文件或者文件夹
  14. 搜狗输入法关闭快捷键
  15. 五脏与五声 五脏排毒法(五声功)
  16. 失业七个月,面试六十家公司
  17. 获取Excel合并单元格的值
  18. 英特尔的新硬件套装使制作机器人和无人机更加简单
  19. 力扣(leetcode) 1833. 雪糕的最大数量(快速排序待更新......)
  20. 基于博客系统的访客日志记录----代码合集

热门文章

  1. Java Switch语句及性能剖析(转载补充)
  2. Bucket不为空,请检查该Bucket是否包含未删除的Object或者未成功的Multipart碎片
  3. 【算法】2 由股票收益问题再看分治算法和递归式
  4. 12.04 ubuntu 安装微软雅黑的字体
  5. shell脚本批量导出MYSQL数据库日志/按照最近N天的形式导出二进制日志[连载之构建百万访问量电子商务网站]...
  6. 17岁高中生详述如何攻破 GitHub Private Pages 并获$3.5万赏金
  7. Flutter InkWell 动画浅析
  8. 前端存储 (2) - sessionStorage ,localStorage
  9. 阿里云 centos 安装图形化界面
  10. CVPR(IEEE Conference on Computer Vision and Pattern Recognition)