- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,我在内核上下文中编程,因此不存在现有库。事实上,这段代码将进入我自己的库。
两个问题,一个比另一个重要:
目前我有这段代码:
void BitmapImage::Render24(uint16_t x, uint16_t y, void (*r)(uint16_t, uint16_t, uint32_t))
{
uint32_t imght = Math::AbsoluteValue(this->DIB->GetBitmapHeight());
uint64_t ptr = (uint64_t)this->ActualBMP + this->Header->BitmapArrayOffset;
uint64_t rowsize = ((this->DIB->GetBitsPerPixel() * this->DIB->GetBitmapWidth() + 31) / 32) * 4;
uint64_t oposx = x;
uint64_t posx = oposx;
uint64_t posy = y + (this->DIB->Type == InfoHeaderV1 && this->DIB->GetBitmapHeight() < 0 ? 0 : this->DIB->GetBitmapHeight());
for(uint32_t d = 0; d < imght; d++)
{
for(uint32_t w = 0; w < rowsize / (this->DIB->GetBitsPerPixel() / 8); w++)
{
r(posx, posy, (*((uint32_t*)ptr) & 0xFFFFFF));
ptr += this->DIB->GetBitsPerPixel() / 8;
posx++;
}
posx = oposx;
posy--;
}
}
r 是一个函数指针,指向接受 x、y 和颜色参数的 PutPixel 类事物。显然这段代码非常慢,因为一次绘制一个像素从来都不是一个好主意。
对于我的 32-bpp 渲染代码(我也有一个问题,稍后会详细介绍)我可以轻松地将 Memory::Copy() 位图数组(我在这里加载 bmp 文件)到帧缓冲区。但是,如何使用 24bpp 图像执行此操作?在 24bpp 的显示器上这会很好,但我正在使用 32bpp 的显示器。
我现在能想到的一个解决方案是创建另一个位图数组,它基本上包含 0x00(colour) 的值并使用它来绘制到屏幕上——不过我认为这不是很好,所以我'正在寻找更好的选择。
下一个问题:2. 鉴于显而易见的原因,不能简单地将整个数组立即复制到帧缓冲区中,因此下一个最好的办法是逐行复制它们。
有没有更好的办法?
最佳答案
基本上是这样的:
for (uint32_t l = 0; l < h; ++l) // l line index in pixels
{
// srcPitch is distance between lines in bytes
char* srcLine = (char*)srcBuffer + l * srcPitch;
unsigned* trgLine = ((unsigned*)trgBuffer) + l * trgPitch;
for (uint32_t c = 0; c < w; ++c) // c is column index in pixels
{
// build target pixel. arrange indexes to fit your render target (0, 1, 2)
++(*trgLine) = (srcLine[0] << 16) | (srcLine[1] << 8)
| srcLine[2] | (0xff << 24);
srcLine += 3;
}
}
一些注意事项: - 最好写入与渲染缓冲区不同的缓冲区,以便立即显示图像。 - 像您一样使用函数进行像素放置非常(非常非常)慢。
关于c++ - 如何在 32-bpp 显示器上高效渲染 24-bpp 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20765680/
我的 Android 应用程序使用外部库来进行一些图像处理。处理链的最终输出是单色位图,但保存的是彩色位图(32bpp)。 图像必须上传到云 blob,因此出于带宽问题,我想将其转换为 1bpp G4
图像处理开始工作时会很有趣。到目前为止,我能够将 24 bpp 位图图像转换为 8 bpp 并执行一些技巧。 但我无法将它们更改为 1 bpp,这正是我想要的。我在 .Net4 上工作,我使用一个名为
我们有一个采用 32 bpp 数据的编码器库。我们有一个屏幕捕获库,它也需要支持 16 bpp。每当我需要将新的屏幕截图传递给编码器时,我想将 16bpp 的原始数据转换为 32bpp。如何有效地完成
首先,我在内核上下文中编程,因此不存在现有库。事实上,这段代码将进入我自己的库。 两个问题,一个比另一个重要: 如标题所示,假设我有帧缓冲区的地址,我如何才能有效地将 24-bpp 图像渲染到 32-
我有一张图像,即使用 Windows GDI 调用 (24 bpp) 绘制的图像,我需要将此图像转换为 16 bpp。这是在 Windows Mobile 上。 24 bpp - RGB (rrrr
谁能告诉我如何将 1BPP 、 4BPP 和 8BPP 保存为位图。我在图像中有位,宽度和高度。 请告诉我如何将其保存为位图。 最佳答案 对于 Windows 和 C++,最简单的方法是 Gdiplu
我需要拍摄全彩色 JPG 图像并将其颜色重新映射到索引调色板。调色板将包含从数据库中填充的特定颜色。我需要将图像的每种颜色映射到索引中它的“最接近”值。我确信有不同的算法来比较和计算“最接近”的值。仅
我的程序当前采用 4 bpp(每像素位)TIFF 作为位图,将其转换为图形,添加一些文本字符串,然后再次将其保存为 TIFF 文件。默认情况下,输出 Bitmap.Save() TIFF 文件似乎是
我使用 xlib XGetImage 捕获图像并将其保存到位图,问题是位图是 32 BPP,我必须将该位图转换为 24 BPP,有什么想法吗?也许使 XGetImage 获得 24 BPP 图像或将
我有一个 C++ MFC 项目,我需要在其中翻转可以采用不同格式的位图,然后保存它。我在制作以多种格式保存位图的功能时遇到问题。 当我尝试启用 ATL(Active Template Libraray
每次我运行我的应用程序时颜色都会改变,显示如下 Display = SDL_SetVideoMode(WIDTH, HEIGHT, 16, SDL_HWSURFACE | SDL_DOUBLEBUF
几天以来,我一直在使用 FO-DICOM 处理 DICOM 文件。 我正在使用一组 dicom 文件进行测试,并且我一直在打印“光度解释”和“每像素样本”值,以便更好地了解我正在处理的图像类型。 结果
我正在尝试编写一个 GStreamer (0.10.34) 插件。我需要操纵传入的图像。我将 Sink cap 设置为“video/x-raw-yuv”,这样我就知道我会收到视频。 我无法理解如何使用
在以下情况下我找不到解释像素数组的方法:我在 Windows 7 上使用 MS Paint 创建了一个 2x2 像素的 BMP 图像。将其保存为单色 BMP(我认为这意味着颜色深度为每像素 1 位的
我正在研究一种算法来优化盒子中元素的包装。 我最多可以容纳 20 件元素,需要将它们装在尽可能少的盒子中(6 种可能的盒子尺寸),同时最大限度地减少盒子内浪费的体积。我想过实现 3D BPP 算法的变
我有一张签名图像,我想将其另存为 1 bpp 位图以节省文件空间。完整的 .NET Framework 具有枚举 PixelFormat.Format1bppIndexed,但 .NET Compac
使用 Magick.NET-Q8-AnyCPU。我想将现有 TIFF 图像转换为灰度 8 bpp BMP 图像。我试过这个: byte[] input = ; using (var image = n
我需要在 C++ 程序中打开 16 bpp 灰度 tiff 图像。尝试使用 GDI+ Image 类执行此操作时,我得到 OutOfMemoryException(GDI+ 不支持 16 bpp 格式
我正在尝试将 8-bpp 索引位图转换为 RGB 位图,但我没有成功。 第一个问题是 GetPalette() 返回的调色板不包含 256 个唯一数字。 到目前为止,这是我的代码: BitmapDat
我正在使用 AVCaptureSession 从 iPhone 的前置摄像头捕获帧。我正在尝试更改 AVCaptureVideoDataOutput 的格式,以便它可以捕获 24 bpp 位图。此代码
我是一名优秀的程序员,十分优秀!