PNG IDAT块数据计算

发布于 2025-02-08 15:26:43 字数 382 浏览 4 评论 0原文

我正在尝试学习,建议用C语言编写自己的PNG文件。 我已经阅读了PNG文件格式规范,现在可以编写基本的PNG(签名,IHDR块,1PX-IDAT块和Iend Chunk)。 但是现在,我想在PNG中写下一系列像素,所有块都在okk,但我不明白如何生成IDAT数据块。 在libpng文档中,他们向deflate()扫描线解释,之前为fileer byte方法。

我对这个问题的理解:

扫描线是水平像素的数组,然后是滤波器方法(0),然后是大小:(3*ScreenWidth + 1) 对于每行(ScreenHeight值),我用Zlib压缩()扫描线,然后将其存储在文件中。

但是在生成PNG之后,它始终是黑色的,在十六进制编辑器中的值始终为0。

我在做什么错?还是生成IDAT数据值的好方法?

I'm trying for learning propose to write my own png file in c language.
I have already read the PNG file format specification and i am now able to write a basic PNG(signature, IHDR CHUNK, 1px-IDAT CHUNK AND IEND CHUNK).
But now i want to write a array of pixels into the PNG, all chunks are going okk but I don't understand how to generate the IDAT data CHUNK.
In libPNG documentation they explain to deflate() the scanline, preced by the filer byte method.

My understanding of this problem:

A scanline is an array of horizontal pixels preceded by the filter method(0) then of size: (3*screenWidth + 1)
for each line (screenHeight value), I compress() the scanline with zlib and store it in a file.

But After generating the png, it is always black and the value is always 0 in hex editor.

what am i doing wrong? or is the the good way to generate IDAT data values?

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

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

发布评论

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

评论(1

唱一曲作罢 2025-02-15 15:26:43

您没有在问题中提出任何代码,因此我们无法知道您实际在做什么。 “我用zlib压缩()扫描线,然后将其存储在文件中。”听起来错误。您需要按照所述组装所有扫描线,然后一次用Zlib压缩整个内容。

You did not put any code in your question, so we have no way of knowing what you're actually doing. "I compress() the scanline with zlib and store it in a file." sounds wrong. You need to assemble all of the scan lines as described, and then compress the entire thing with zlib, once.

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