问题标签 [saturation-arithmetic]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
opengl - OpenGL handling float color saturation ("color overflow")?
I'm woking on a scientific visualisation using openGL where I try to basically create a "coloured fog" to illustrate a multidimensional field. I want the hue of the color to represent the direction of the field and the luminosity of the color to correspond to the intensity of the field.
I use GL_BLEND
with glBlendFunc(GL_ONE, GL_ONE)
to achieve additive blending of colors of the surfaces I create. The problem is: in some places the colors get saturated. For example:
(1, 0, 0) + (1, 0, 0) = (2, 0, 0), and when this is rendered it just becomes (1, 0, 0) (i.e. the "overflow" is just chopped off). And this is not the way I would like it to be handled. I would like to handle the overflow by preserving hue and luminocity, i.e.
(2, 0, 0) should be translated into (1, 0.5, 0.5) (i.e. a lighter red, red with twice the luminocity of "pure" red).
Is there any way to achieve this (or something similar) with OpenGL?
css - In CSS, is filter: saturate(100) any slower than saturate(2)?
For CSS filters, would there be any difference is the browser's speed to process saturate(2)
as compared to any of the following:
I am just using saturate
as an example here. Interested in learning the answer for all CSS filters.
java - 如何处理超出整数 MAX_VALUE 和 MIN_VALUE 的加法和减法?
以下是我要实现的一段代码:
但我没有得到令人满意的结果。例如,-2147483640-10 给我 2147483646。
我确信必须有一种更具体的方法来进行饱和。
performance - 快速饱和整数转换?
我想知道是否有任何快速的技巧来进行从 64 位无符号值到 32 位无符号值的饱和转换(如果它被推广到其他宽度会很好,但这是我关心的主要宽度关于)。我在谷歌上搜索到的大部分资源都用于饱和算术运算。
饱和转换将采用 64 位无符号值,如果输入值大于 2^32-1,则将未修改的值返回为 32 位值或 2^32-1。请注意,这不是默认的 C 强制转换截断行为。
我可以想象做类似的事情:
- 测试上半部分是否设置了任何位
- 如果是这样,则创建一个所有位设置的 32 位掩码,否则创建一个所有位未设置的掩码
- 带掩码的按位或下半部分
但我不知道如何快速生成掩码。我在 Godbolt 中尝试了直接的分支实现,看看编译器是否会为我生成一个聪明的无分支实现,但没有运气。
编辑:我的错误,问题是没有设置为使用优化
arm - 使用 ARM Neon 内在函数处理饱和整数乘法溢出的最有效方法是什么?
我在 2 个 16 位向量之间有以下乘法:
如果dx
和dy
都足够大,结果会溢出。
我想钳制 MIN_INT16 和 MAX_INT16 值之间的乘积;
如果不先将值转换为 int32,我还没有找到一种方法。这就是我现在所做的:
有没有办法更有效地实现这一目标?