平均颜色(X11 颜色)
我想用平均颜色填充两个(或更多填充的)矩形的交集。我将每个矩形的颜色存储为无符号整数。如何获得平均颜色?
谢谢你的帮助!
I want to fill the intersection of two(or more filled) rectangles with the average color. I have the colors of each rectangle stored as unsigned ints. How can I get the average color?
Thank you for you help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从技术上讲,您可能在颜色映射设备上运行,这意味着您需要通过 X11 颜色管理来实现所有这些。您需要查询 XColor 以获得两种输入颜色,计算平均值,然后查找最接近的可表示颜色:
在调色板设备上,您还需要在之后释放颜色等 - 这是一团糟, 基本上。
但很可能您使用的是 32 位真彩色设备,这意味着整数只是 r、g、b 和 a 的位域(不一定按此顺序)。您可以这样计算它们的平均值:
Technically, you might be running on a color-map device, which means you need to go through X11 color management for all of this. You need to query the
XColor
for your two input colors, compute the average, then look up the closest representable color:On a paletted device, you also need to free the color afterwards etc. - it's a mess, basically.
But in all likelihood you're on a 32-bit truecolor device, which means the integer is just a bitfield of r, g, b and a (not necessarily in that order). You can compute their average like this:
这是假设您需要完全不透明的平均颜色。
This is assuming that you need a fully opaque average color.