摘自:http://article.gmane.org/gmane.comp.graphics.agg/2911/

> I've read the pattern_perspective.cpp sample but I don't understand very
> well how to apply a texture on a shape.
> Could you explain me the stages to do that and what is the role of each
> operation ?Yes, I must admit the example is difficult to read.First, it's better to take pattern_resample.cpp that covers automatic
resampling too.
Now I'll try to explain to you what to do step by step.1. If your pattern has actual alpha channel, the pixels must be
premultiplied. In general, all p_w_picpath transformers work only with
premultiplied colors. If it's RGB or all alphas are 255 you don't need to do
anything. But if you load a PNG p_w_picpath you most probably will have to
premultiply it.2. You get your p_w_picpath somehow, create a rendering buffer and pixel format
for it:typedef agg::pixfmt_bgra32 pixfmt;
typedef agg::pixfmt_bgra32_pre pixfmt_pre;
typedef pixfmt::color_type color_type;In the example agg::rendering_buffer is already created in load_img()
function:
pixfmt img_pixf(rbuf_img(0));
Note that there's no difference if you use pixfmt or pixfmt_pre for the
source p_w_picpath.3. Create a span allocator. It's better to keep it in a class and reuse it
instead of creating/destroying.
typedef agg::span_allocator<color_type> span_alloc_type;
span_alloc_type sa;4. Create a filter LUT
agg::p_w_picpath_filter_bilinear filter_kernel;
agg::p_w_picpath_filter_lut filter(filter_kernel, true);
For some methods there's no need in it. For example,
span_p_w_picpath_filter_rgba_bilinear has hardcoded bilinear filter.5. Create an p_w_picpath accessor that defines the logic of pixel wrapping.
typedef agg::wrap_mode_reflect_auto_pow2 wrap_type;
typedef agg::p_w_picpath_accessor_wrap<pixfmt, wrap_type, wrap_type>
img_source_type;
img_source_type img_src(img_pixf);
The possible variants are:
p_w_picpath_accessor_clip - clips the pixels outside of the source p_w_picpath and
replaces them with a given color.
p_w_picpath_accessor_clone - clones the edge pixels.
p_w_picpath_accessor_wrap - wraps the pixels (it's what actually creates the
repeating pattern)
The wrapper has template arguments of, what to do by X and Y:
wrap_mode_repeat, wrap_mode_reflect, wrap_mode_repeat_pow2,
wrap_mode_reflect_pow2, wrap_mode_repeat_auto_pow2,
wrap_mode_reflect_auto_pow2. If the size of your pattern is power of 2, you
can use a faster _pow2 version (shifts and masking instead of divisions).6. Create an interpolator. For affine transformations you can use a fast
linear interpolator that operates in integers, with a Bresenham-like
algorithm inside. For perspective transformations you can't use linear
interpolator. There are two choices:6.1. exact interpolator:
typedef agg::span_interpolator_trans<agg::trans_perspective>
interpolator_type;
interpolator_type interpolator(tr);
Defines an exact interpolator, works slower because it calculates the points
on every pixel6.2. Subdivision approximation:
typedef agg::span_interpolator_linear_subdiv<agg::trans_perspective>
interpolator_type;
interpolator_type interpolator(tr);
It calculates every 16'th pixel (configurable) and linearly interpolates
between them. Works faster, but on heavily transformed p_w_picpaths there is
considerable inaccuracy.Also, for transformations with automatic resampling (rather slow, but
produces high quality) you need a special version of the interpolator,
because you need to know the local scale at every point:
typedef agg::span_interpolator_persp_lerp<> interpolator_type;
typedef agg::span_subdiv_adaptor<interpolator_type> subdiv_adaptor_type;
interpolator_type interpolator(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
subdiv_adaptor_type subdiv_adaptor(interpolator);7. Then you create a span generator that does the p_w_picpath filtering job. It
can be one of the following:
span_p_w_picpath_filter_rgba_nn - nearest neigbor filter (box). Actually, no
filtering
span_p_w_picpath_filter_rgba_bilinear - hardcoded bilinear filter
span_p_w_picpath_filter_rgba_2x2 - arbitrary filter of fixed size 2x2 pixels
span_p_w_picpath_filter_rgba - arbitrary filter of any size, like bicubic,
gaussian, etc (slow).
span_p_w_picpath_resample_rgba_affine - p_w_picpath resampler for affine
transformations. It can't be used with perspective transformer.
span_p_w_picpath_resample_rgba - p_w_picpath resampler for arbitrary transformer. The
interpolator must provide function to calculate (or interpolate) the local
scale.8. Create and configure the transformer. It can be a simple affine
transformer, or perspective one, or even some nonlinear, like in
distortions.cpp example.
The algorithmic feature is that the transformer must be inverse. That is, it
should map destination pixels onto source ones.9. Finally, you feed the rasterizer with an arbitrary path and draw it, for
example:
g_rasterizer.move_to_d(x1, y1);
g_rasterizer.line_to_d(x2, y2);
g_rasterizer.line_to_d(x3, y3);
g_rasterizer.line_to_d(x4, y4);
typedef span_p_w_picpath_filter_rgba_2x2<img_source_type,interpolator_type> span_gen_type;
span_gen_type sg(img_src, interpolator, filter);
agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);The path can be just a rectangle, or quadrilateral, or whatever. The whole
point is that it will draw perfectly anti-aliased edges. For example, you
can draw a circle with pattern inside.Well, this explanation isn't full, but I hope it will help you together with
working pattern_resample.cppMcSeem

转载于:https://blog.51cto.com/fengyuzaitu/1962733

AGG第三十一课 pattern_perspective样式透明相关推荐

  1. 【问链财经-区块链基础知识系列】 第三十一课 Fabric版本变迁之路从1.1-1.4

    Fabric个版本更新内容 V1.1 ・Node.js链代码支持 - 开发人员现在可以使用世界上最流行的编程语言最流行的框架编写链代码 ・基于通道的事件服务 - 使客户端能够在每个通道的基础上订阅阻止 ...

  2. 爱情三十一课,先信自己

    我们每个人一生都在迎接两个问题的考验:其一,我是否值得被爱:其二,我是否可以成功. 如果某人在这两个问题上的自我认识是"值得"和"可以",无论境遇多遭,都可以获 ...

  3. 第三十一课.矩阵胶囊与EM路由

    矩阵胶囊的前向计算 矩阵胶囊在向量胶囊的基础上改变了胶囊的表示方式,矩阵胶囊由激活概率与姿态矩阵两部分构成一个元组单位.激活概率用于表示矩阵胶囊被激活的概率,姿态矩阵用于表示胶囊的姿态信息.在向量胶囊 ...

  4. python第三十一课--递归(3.递归的弊端)

    演示递归的弊端: def mySum(num):if num == 1:return 1return num+mySum(num-1)mySum(998) [注意]:递归可以解决绝大多数循环能干的事情 ...

  5. 新版标准日本语初级_第三十一课

    语法   1. 小句1(动词基本形/ない形)と,小句2:~と用在表述恒常性状态.真理.反复性状态.习惯等内容的复句里,表示小句1是小句2的条件. このボタンを押すと,電源が入ります(按下这个钮,电源就 ...

  6. 第三十一课 ERC1410标准从分析到代码实现

    1,摘要 ERC1410为STO环境中使用的一个以太坊协议标准.辉哥着眼于深度理解和编码实现,从以下几个方面阐述对ERC1410的理解. 1) ERC1410和ERC1411(ERC1400),ERC ...

  7. 前端学习第三十一课(ES6简介和babel的使用)

    目录 1.ECMAScript简介 1.1 ES6 与 ECMAScript 2015 的关系 2.Babel转码器 2.1 安装babel 2.2 配置文件.babelrc 2.3  命令行转码 2 ...

  8. 新版标准日本语中级_第三十一课

    语法   1. 男性用语:在男性之间的对话中,称呼.句尾形式.打招呼或应答等有时会使用一些很有特点的说法.这些说法比较随便,只用于关系亲近的人之间.   1) 称呼:称自己おれ,称对方おまえ. おれは ...

  9. 实践数据湖iceberg 第三十七课 kakfa写入iceberg的 icberg表的 enfource ,not enfource测试

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

最新文章

  1. Idea如何方便的查看Java字节码文件,你是怎么做的
  2. 数塔问题和最长上升子序列问题
  3. 常用排序算法以及算法性能测试(完整C/C++代码实现)
  4. Go 都在什么时候触发GC,能手动触发GC吗?
  5. python爬虫百度图片_python实现爬取百度图片的方法示例
  6. 解决金蝶未检测到K/3许可文件,并且该账套已超过演示版期限问题
  7. 游戏王计算机兽,游戏王星杯卡——迅猛龙,再生圣经,入侵蠕虫,鼹鼠,幽世之血樱...
  8. 使用VS2012 C++ 进行单元测试
  9. 升级核心产品,不和用户竞争,UCloud进军产业互联网差异化路线
  10. android textview adapter,Android在FragmentPagerAdapter中的Fragment中设置TextView文本
  11. [转载] Python十大装B语法
  12. 人脸检测(五)--adaboost总结,整理
  13. 硬软链接的区别 节点 以及重定向和管道
  14. freemarker转PDF,分页,页眉和页脚,画图
  15. 对线性系统用matlab进行仿真,基于线性系统稳定性分析及MATLAB仿真与应用[1]
  16. JMS 消息传送模式、消息签收以及spring jmsTemplate配置
  17. 松下服务器分频器输出信号与,详解几款常用分频器及音箱分频器电路图
  18. java哨兵模式_哨兵模式详解
  19. java打包跳过test_Maven打包跳过测试的命令
  20. 计算机系统概述学后感,计算机操作系统学习心得体会总结(2)

热门文章

  1. Python 中的 10 个常见安全漏洞,以及如何避免(上)
  2. ssh整合之一spring的单独运行环境
  3. Python将迁移到GitHub
  4. WF4 常用类第二篇
  5. Lync Server 2010企业版系列PART5:生成拓扑
  6. 聚焦国内名企开源!OSCAR 开源先锋日(1020)全部议程首次曝光
  7. 一场360容器圈的武林大会“360互联网技术训练营第九期—360容器技术解密与实践” (附PPT与视频)...
  8. SpringMvc2 使用注解形式发布请求地址
  9. SpringCloud 从菜鸟到大牛之二 服务注册与发现 Sping Cloud Eureka
  10. php-fpm 进程在云服务器cpu分配不均匀