使用正确的结构将 BMP 读入内存
我目前正在做一个隐写术项目(为我自己)。我已经完成了一些代码,但经过思考,我知道有更好的方法可以完成我想要的事情。
另外 - 这是我第一次使用动态内存分配和二进制文件 I/O。
这是我在 BMP 图像中隐藏文本文件的代码: 代码链接
另请注意,我在此代码中,不使用 LSB 存储消息,而是替换 alpha 字节,假设它是每像素 32 位 (bbp) 图像。这就是为什么如果图像中有 1、4、8、16、24 bpp,这将不是很灵活的另一个原因。例如,如果是 24 bbp,则 Alpha 通道将是 6 位,而不是 1 字节。
我的问题是使用结构将整个 BMP 读入内存的最佳方法是什么?
这就是我的看法:
- 读取 BITMAPFILEHEADER
- 读取 BITMAPINFOHEADER
- 读取 ColorTable(如果有的话)
- 读取 PixelArray
我知道如何读取两个标题,但是 ColorTable 让我感到困惑,我不知道 ColorTable 的大小是多少,或者图像中是否存在这样的图像。
另外,在 PixelArray 之后,维基百科说可能有 ICC 颜色配置文件,我如何知道它是否存在? 链接到 BMP 文件格式(维基百科)
另一件事,因为我需要按顺序知道标题信息要知道 PixelArray 从哪里开始,我需要像上面所示的那样进行多次读取,对吗?
很抱歉提出了所有问题,但我现在真的不确定该怎么做。
I'm currently doing a steganography project (for myself). I have done a bit of code already but after thinking about it, I know there are better ways of doing what I want.
Also - this is my first time using dynamic memory allocation and binary file I/O.
Here is my code to hide a text file within a BMP image: Link to code
Also note that I'm not using the LSB to store the message in this code, but rather replacing the alpha byte, assuming its a 32 bit per pixel (bbp) image. Which is another reason why this won't be very flexible if there are 1, 4, 8, 16, 24 bpp in the image. For example if it were 24 bbp, the alpha channel will be 6 bits, not 1 byte.
My question is what is the best way to read the entire BMP into memory using structures?
This is how I see it:
- Read BITMAPFILEHEADER
- Read BITMAPINFOHEADER
- Read ColorTable (if there is one)
- Read PixelArray
I know how I to read in the two headers, but the ColorTable is confusing me, I don't know what size the ColorTable is, or if there is one in an image at all.
Also, after the PixelArray, Wikipedia says that there could be an ICC Color Profile, how do I know one exists? Link to BMP File Format (Wikipedia)
Another thing, since I need to know the header info in order to know where the PixelArray starts, I would need to make multiple reads like I showed above, right?
Sorry for all the questions in one, but I'm really unsure at the moment on what to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
颜色表的大小由
bV5ClrUsed
决定。仅当
bV5CSType == PROFILE_EMBEDDED
时,文件中才会存在 ICC 颜色配置文件。此处的文档提供了所有这些信息。
那么,24位颜色意味着8个红色,8个绿色,8个蓝色,0个alpha。您必须将其转换为 32 位 RGBA 才能拥有任何 Alpha 通道。
最后,Alpha 通道确实会影响图像的显示,因此您不能随意使用它进行隐写术。使用所有通道的最低有效位(也许不是所有像素)确实会更好。
The size of the color table is determined by
bV5ClrUsed
.An ICC color profile is present in the file only if
bV5CSType == PROFILE_EMBEDDED
.The documentation here provides all that information.
Then, 24-bit color means 8 red, 8 green, 8 blue, 0 alpha. You'd have to convert that to 32-bit RGBA in order to have any alpha channel at all.
Finally, the alpha channel DOES affect the display of the image, so you can't use it freely for steganography. You really are better off using the least significant bits of all channels (and maybe not from all pixels).