只有0-255级的alpha通道

> Only you don‘t see it, because the
> color_alpha->calculate
> function just always returns *covers. In my case, I
> was using
> a combined alpha (source x shape)...

Ah, I see. Well, the division by 255 is too expensive.
The usual technique there is to add 128 to the
intermediate result:

v + (((r - v) * alpha + 0x80) >> 8);

But it also requires the alpha to be in range 0...256
(not 255), so that it‘s not an easy issue, because I
use 0...255. Besides, sometimes I use precalculated
alpha in range 0...255*255.

The very same issue is applicable to the calculation
of the color_alpha->calculate().

Anyway, you can try to play with these formulas and
I‘d appreciate if someone could help me to systematize
these things.
> The problem is with the bilinear filter. I implemented
> it separately from the general arbitrary filtering
> algorithm because it works about 40% faster. But if
> you take the "image_filters" example and play with it
> you will see that the bilinear filter darkenes the
> image.

Well, the image_filters example would have the same problem
I witnessed in my case; pixel_formats_rgb24_image::span does
the same kind of shifting, I guess.

Only you don‘t see it, because the color_alpha->calculate
function just always returns *covers. In my case, I was using
a combined alpha (source x shape)...
Well, the problem is even worse than just "speed up"
(BTW, it doesn‘t matter much because the most time
consuming code is interpolation itself)
The problem is with the bilinear filter. I implemented
it separately from the general arbitrary filtering
algorithm because it works about 40% faster. But if
you take the "image_filters" example and play with it
you will see that the bilinear filter darkenes the
image. 

Then if you comment out "case 1"

/*
        case 1:
            {
                typedef
agg::image_transform_attr<agg::null_distortions, 
                                                 
agg::null_color_alpha, 
                                                 
agg::null_gradient_alpha> attr_type;

                typedef
agg::span_null_interpolator<attr_type>
span_interpolator;
                typedef
agg::pixfmt_bgr24_image_bilinear<attr_type>
span_renderer;
                typedef
agg::renderer_scanline<span_interpolator,
span_renderer> renderer;

                agg::null_distortions    distortions; 
                agg::null_color_alpha    color_alpha;
                agg::null_gradient_alpha
gradient_alpha;

                attr_type attr(rbuf_img(1), img_mtx,
distortions, color_alpha, gradient_alpha);
                renderer ri(rbuf_img(0));
                ri.attribute(attr);
                ras.add_path(tr);
                ras.render(ri);
            }
            break;
*/
nd uncomment // case 1: below, the bilinear
interpolation will be done through the general method.
In this case everything is fine. I honestly don‘t know
why, but there‘s something wrong with rounding off,
that is, the probability of rounding to the floor is
higher than to the ceiling. Perhaps I should use the
array of the precalculated weights rather than compute
them on demand.
I have been playing with the image transform classes, specifically
with the code in agg_pixfmt_rgba32_image.h, and I have noticed a
few problems with the code you are using to handle the alpha values.

There are often places where you multiply values ranging from 0 to
255, but then, finally, divide them by 256 (>> 8).

Here is an example of what I have observed.

In method agg::pixel_formats_rgba32_image_bilinear::span, using class
agg::image_alpha_rgba8 as an alpha provider, if I step through the
code, I see that :

- image_subpixel_mask = 0xff
- weight = 0xfe01
- fg[3]  = 0xfe02ff (source alpha was 0xff)

after fg[3] >>= image_subpixel_shift * 2,

- fg[3]  = 0xfe;  // should be 0xff if divided by 0xff*0xff

- alpha is the calculated on this base :

    0xff * 0xfe => 0xfd02
    0xfd02 >> 8 => 0xfd
so I end up with alpha = 253 rather than 255, and all the nice
speed-up code (alpha == 255) doesn‘t get executed, and some
noise gets added to the output.

Any idea how to fix this in an elegant way (I could just decrease
the threshold for which alpha is considered 100% opaque) ?
时间: 2024-08-12 23:53:25

只有0-255级的alpha通道的相关文章

OpenCV2.3的cvCalcHist函数有问题?255级值总为0,索性自己写一个直方图计算函数,附源码!

欢迎大家加入图像识别技术交流群:271891601,另外,特别欢迎成都从事图像识别工作的朋友交流,我的QQ号248787278 ------------------------------------------- 我在写直方图规定化的代码过程中,发现OpenCV自带的cvCalcHist函数计算出的直方图的第255分量总是为0,测试了几张图都是这样,代码如下: #include <opencv2/opencv.hpp> #include <opencv2/legacy/compat.h

什么是Alpha通道?

图像处理(Alpha通道,RGB,...)祁连山(Adobe 系列教程)施雪扬的UI课程 一个也许很傻的问题,在图像处理中alpha到底是什么?  Alpha通道是计算机图形学中的术语,指的是特别的通道,意思是“非彩色”通道,主要是用来保存选区和编辑选区. 为什么用‘Alpha’代表透明度? l  Alpha 没有透明度的意思,不代表透明度.opacity 和 transparency 才和透明度有关,前者是不透明度,后者是透明度.比如 css 中的「opacity: 0.5」就是设定元素有 5

Alpha通道

 Alpha通道是计算机图形学中的术语,指的是特别的通道,意思是“非彩色”通道,主要是用来保存选区和编辑选区.真正让图片变透明的不是Alpha 实际是Alpha所代表的数值和其他数值做了一次运算  为什么用‘Alpha’代表透明度? l  Alpha 没有透明度的意思,不代表透明度.opacity 和 transparency 才和透明度有关,前者是不透明度,后者是透明度.比如 css 中的「opacity: 0.5」就是设定元素有 50% 的不透明度. l  一个图像的每个像素都有 RGB 三

alpha通道与混合技术

Alpha其作用是要实现一种半透明效果. 假设一种不透明的东西颜色是A,另一种透明的东西颜色是B,那么透过B去看A,看上去的颜色C就是B与A的混合颜色.设置B的透明度为alpha(取值为0-1,0为完全透明,1为不透明) R(C)=alpha*R(B)+(1-alpha)*R(A) G(C)=alpha*G(B)+(1-alpha)*G(A) B(C)=alpha*B(B)+(1-alpha)*B(A) 融合因子 首先,Direct3D中依然是用Alpha通道来实现多个像素颜色值的融合.每个像素

关于Opengl中将24位BMP图片加入?一个alpha通道并实现透明的问题

#include <windows.h>#include <GL/glut.h>#include <GL/glaux.h>#include <stdio.h> #pragma comment( lib, "opengl32.lib" )// 链接时使用OpenGL32.lib#pragma comment( lib, "glu32.lib" )// 链接时使用GLu32.lib  #pragma comment( li

【Unity Shaders】Transparency —— 使用alpha通道创建透明效果

本系列主要参考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同时会加上一点个人理解或拓展. 这里是本书所有的插图.这里是本书所需的代码和资源(当然你也可以从官网下载). ========================================== 分割线 ========================================== 写在前面 从这篇开始是一个全新的章节:透明效果(Transparency).之前在制作LOGO闪光效

PWM调整2个LED的亮度00--FF,255级亮度自动调节 【原创】

把STC12C5A60S2.H .STC12C2052AD.H头文件放到 C:\Keil\C51\INC\ STC单片机头文件[51CTO-->单片机-->STC单片机官方头文件] 下载链接 链接:http://pan.baidu.com/s/1pJKK4w7 密码:a0re 测量2个LED的端的电压 0 ~ 4.8V 逐渐增减变化 /* 工程创建MCU选取,Atmel 89C55 单片机: STC12C5A60S2   晶振:12M 功能:PWM调整2个LED的亮度00--FF,255级亮度

窗体的Alpha通道透明色支持(一旦 Form 被定义为利用 LayeredWindow ,窗口的绘图不再响应沿用多年的 WM_Paint 消息)

参考: http://www.delphibbs.com/delphibbs/dispq.asp?lid=2190768 Windows 2000后,为了支持类似MAC界面的Alpha通道混合效果,提供了GDI+,提供了很多的界面功能函数,可以实现很好的界面效果.例如可以使用UpdateLayeredWindow来实现窗体的颜色透明.但是一旦 Form 被定义为利用 LayeredWindow ,窗口的绘图不再响应沿用多年的 WM_Paint 消息. UpdateLayeredWindow(hw

Unity播放带Alpha通道的视频(unity play channel movie)

最近讨论在unity播放带alpha通道的视频,一开始一点效果也没有,然后搜索各种解决方案,总结出三种不太好的方案,有更好的方案的希望大家提出来. 方案重点两个方面:         1.能否播放带alpha通道的视频         2.播放的视频和三维场景的层级关系 1.剔除 使用一个剔除的shader,不渲染黑色部分 shader代码如下: Shader "AlphaVideo/CullingVideo" { Properties { _MainTex("Base (R