如何直接在内存中处理 PNG 的 alpha 透明度?

发布于 2024-10-12 01:13:57 字数 524 浏览 4 评论 0原文

我将感谢你们低级程序员的帮助......我的问题是这样的: 我想将 ARGB8888 格式的位图直接打印到视频内存中。位图的形式没问题,问题是阿尔法通道我不知道如何使用。我在维基百科中看到过像这样覆盖像素的代码:

CompositedPixelColor = Alpha * ForegroundPixelColor + (1 - Alpha) * BackgroundPixelColor

其中颜色从 0 - 1 变化。这是针对每个通道 RGB B 完成的。 我正在做的是使用上面的公式将位图每个像素的每种颜色的每个字节直接复制到视频内存中,但我遗漏了一些东西,因为颜色不能正确呈现自己。

我正在尝试执行类似于此线程中发布的代码的操作: http://www.badadev.com/create-a-photo-editing-应用程序/ 但在这里他们不重视透明度,这是我的问题。谢谢!

I would appreciate the help of you low level programmers... My problem is this:
I want to print a bitmap of format ARGB8888 directly into video memory. The form of the bitmap is alright, the problem is the alpha channel that I can't figure out how to use. I've seen code in wikipedia that overlays the pixels like this:

CompositedPixelColor = Alpha * ForegroundPixelColor + (1 - Alpha) * BackgroundPixelColor

Where a color varies from 0 - 1. This is done for each channel R G B.
What I'm doing is copy each byte for each color of each pixel of my bitmap directly to the video memory using the formula above, but I'm missing something because the colors don't present theirselves alright.

I'm trying to do something like the code posted in this thread:
http://www.badadev.com/create-a-photo-editing-app/
But here they don't treat transparency, and that is my problem. Thanxs!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み青杉依旧 2024-10-19 01:13:57

在您发布的代码中,alpha 被视为 0 到 1 之间的值,如果您将 alpha 通道用作无符号字符,这当然不起作用,如果您想在整数空间中执行此操作,请使用以下内容:

unsigned short background = 0x40;
unsigned short foreground = 0xe0;
unsigned short alpha = 0xc0;
unsigned short compositedcolor = (alpha * foreground + (0xff - alpha) * background) >> 8;

请注意,虽然这些是短整型,值应该全部为 0 - 255,短整型只是需要作为 char * char 产品的计算空间,您也可以使用中间转换,但我只是对所有类型使用无符号短整型,以使其更具可读性。

In the code you posted alpha is treated as a value between 0 and 1, which of course doesn't work if you use you alpha channel as an unsigned char, use the following if you want to do it in integer space:

unsigned short background = 0x40;
unsigned short foreground = 0xe0;
unsigned short alpha = 0xc0;
unsigned short compositedcolor = (alpha * foreground + (0xff - alpha) * background) >> 8;

note that while these are shorts the values should all be 0 - 255, the short is just needed as computational space for the char * char products, you could also use intermediate casts, but I just used unsigned short types for all to make it more readable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文