winapi - 使用多个调色板绘制 4bpp 2D 瓷砖的最佳方法是什么?
问题描述
我正在创建一个通用的 SNES tilemap 编辑器(类似于NES Screen Tool),这意味着我正在绘制很多 4bpp 的图块。但是,我的图形循环运行时间太长,即使使用CachedBitmaps
无法更改其调色板,我可能需要在 8 个之间切换。我可以处理 SNES 格式和事物的大小,但正在努力解决窗边。
// basically the entire graphics drawing routine
case(WM_PAINT):{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
Gdiplus::Graphics graphics(hdc);
graphics.Clear(ARGB1555toARGB8888(CGRAM[0])); // convert 1st 15-bit CGRAM color to 32-bit & clear bkgd
// tileset2[i]->SetPalette(colorpalette); // called in tileset loading to test 1 palette
for(uint16_t i = 0; i < 1024; i++){
tilesetX[i] = new Gdiplus::CachedBitmap(tileset2[i], &graphics);
}
/* struct SNES_Tile{
uint16_t tileIndex: 10,
uint16_t palette: 3,
uint16_t priority: 1, // (irrelevant for this project)
uint16_t horzFlip: 1,
uint16_t vertFlip: 1,
}*/
// I can see each individual tile being drawn
for(int y = 0; y < 32; y++){
for(int x = 0; x < 32; x++){
// assume tilemap is set to 32x32, and not 64x32 or 32x64 or 64x64
graphics.DrawCachedBitmap(tilesetX[BG2[y * 32 + x] & 0x03FF], x * BG2CHRSize, y * BG2CHRSize);
// BG2[y * 32 + x] & 0x03FF : get tile index from VRAM and strip attributes
// tilesetX[...] : get CachedBitmap to draw
}
}
EndPaint(hwnd, &ps);
break;
}
我在我的程序中足够早,重写整个图形例程不会太麻烦。
我应该放弃 GDI+ 并改用 Direct2D 还是其他方式?有没有更快的方法来绘制 4bpp 位图而无需为每个调色板创建副本?
编辑:
我的图形绘制程序如此缓慢的原因是因为我是直接在屏幕上绘制的。绘制到单独的位图作为缓冲区,然后将缓冲区绘制到屏幕上要快得多。在绘制到缓冲区时更新磁贴的调色板会产生非常合理的速度。解决方案
推荐阅读
- python - 如何用文本中的值替换标签
- hash - 汉克雷斯特。如何检查字节数组等于
- java - 如何在 Java 中显示 65687x70562 的 Tif 文件
- c# - 侧边栏中带有标题列表的新闻页面
- swift - 如何在 Swift 4 中修复“发送到实例的无法识别的选择器”
- azure-data-lake - 如何使用代码隐藏在 Visual Studio Azure Data Lake U-SQL 项目中的脚本中设置数据库和架构
- java - Maven - 如何为测试包创建源 jar?
- tensorflow - TensorFlow train.py 找不到
- c# - 在 C# 中使用 USB 网络摄像头自动检测和读取二维码
- regex - 使用 VBA 提取具有名称过滤器的文件