简体   繁体   English

在 ImageSharp 中使用调色板/索引图像

[英]Working with palette / indexed images in ImageSharp

for a legacy game I need to load an image in BMP (or PNG) paletted format and change certain well-known indices on the color palette (replace eg a red gradient using indices 0-8 with shades of green, to change the colors of a unit).对于旧版游戏,我需要加载 BMP(或 PNG)调色板格式的图像并更改调色板上的某些众所周知的索引(例如使用绿色阴影替换使用索引 0-8 的红色渐变,以更改 colors一个单位)。 It is not sufficient to do a color replacement alone, as the same color might by used by more than one unit feature.单独进行颜色替换是不够的,因为同一种颜色可能会被多个单元特征使用。

Is it therfore possible to load the paletted image and keep the color indices in ImageSharp?因此是否可以加载调色板图像并将颜色索引保留在 ImageSharp 中? When I load my paletted unit image with Image.Load("FileName") , it is always loaded in Argb32 mode, and the palette is lost.当我使用Image.Load("FileName")加载我的调色板单元图像时,它总是以 Argb32 模式加载,并且调色板丢失了。 In Photoshop, the same image is correctly loaded in indexed mode.在 Photoshop 中,相同的图像在索引模式下正确加载。 Also, I am not sure which properties I might use to see/edit the palette.另外,我不确定可以使用哪些属性来查看/编辑调色板。

I did not find much information on that topic online.我在网上没有找到关于该主题的太多信息。 I see that there is a type IndexedImageFrame<TPixel> in the documentation, but I am not sure if/how that type would help with the above issue.我看到文档中有一个类型IndexedImageFrame<TPixel> ,但我不确定该类型是否/如何有助于解决上述问题。

Thanks for any hints!感谢您的任何提示!

When I load my paletted unit image with Image.Load("FileName") , it is always loaded in Argb32 mode当我使用Image.Load("FileName")加载调色板单元图像时,它始终以 Argb32 模式加载

Actually that'll be Rgba32 if loading a png (though this is subject to future change).实际上,如果加载 png 将是Rgba32 (尽管这可能会在未来发生变化)。 To guarantee a pixel format you should use the generic variant.为了保证像素格式,您应该使用通用变体。

In Photoshop, the same image is correctly loaded in indexed mode.在 Photoshop 中,相同的图像在索引模式下正确加载。

That's not what PhotoShop is doing.那不是 PhotoShop 正在做的事情。 They're capturing the palette and displaying that to you.他们正在捕捉调色板并将其展示给您。 The actual canvas format will be the same for any pixel format.对于任何像素格式,实际的 canvas 格式都是相同的。

ImageSharp does the same. ImageSharp 也是如此。 The decoded image is a 2D buffer of TPixel but we capture metadata upon decode and use that to inform the encoder what pixel format to save encode the image with.解码后的图像是TPixel的 2D 缓冲区,但我们在解码时捕获元数据并使用它来通知编码器以何种像素格式保存对图像进行编码。

That said... Currently I'm afraid there is no support for capturing the current palette upon decode.也就是说......目前恐怕不支持在解码时捕获当前调色板。 If you want to raise an issue in the GitHub repository it is something we could potentially consider for V2.如果您想在GitHub 存储库中提出问题,我们可能会考虑 V2。

If you were had that information to capture then adjusting/saving it would be possible using a PaletteQuantizer with the updated palette during encode of the image.如果您有该信息要捕获然后调整/保存,则可以在图像编码期间使用具有更新调色板的 PaletteQuantizer。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM