miloyip / svpng Goto Github PK
View Code? Open in Web Editor NEWMinimalistic C function for saving RGB/RGBA image as uncompressed PNG.
License: BSD 3-Clause "New" or "Revised" License
Minimalistic C function for saving RGB/RGBA image as uncompressed PNG.
License: BSD 3-Clause "New" or "Revised" License
叶老师可不可以讲解一下实现原理啊!看不懂啊,官方文档翻了半天,完全无法理解 打击!!_| ̄|○
C 标准只保证 unsigned
的宽度不小于 16 位。而在 CRC32 Table 中的数据是 32 位。此处应该使用 unsigned long
或者 uint32_t
。
In svpng.inc:72 it is said, that width is <16383
. I believe it should be <=16383
for RGBA and <=21844
for RGB.
使用者可能使用不同的方式构建 img
。比如:
#define ENA 0 /* Enable Alpha channel or not */
#define NX 256 /* Number of X points */
#define NY 256 /* Number of Y points */
#define NCH (3+ENA) /* Number of Channels */
enum Channel { R, G, B, A };
typedef uint8_t Pixel[NCH];
void fun(FILE *fp)
{
Pixel img[NX][NY];
unsigned x, y;
for (x = 0; x < NX; ++x) {
for (y = 0; y < NY; ++y) {
img[x][y][R] = x;
img[x][y][G] = y;
img[x][y][B] = 128;
}
}
svpng(fp, NX, NY, (unsigned char *) img, ENA);
}
为了避免在 img
前的强制转换,也许可以将其参数类型定为 void *
。
Milo您好,我在本地编译试验了下您的代码,想要生成一个高分辨率的图片,但似乎无法正确保存,经过测试 256 x 128 是可以保存到本地的,但 2560 x 1280 却生成不了,不知道为啥, 头文件的代码暂时没太看懂。
void test(void)
{
unsigned char rgb[2560 * 1280 * 3], *p = rgb;
unsigned x, y;
FILE *fp = fopen("wallpaper.png", "wb");
for (y = 0; y < 256; ++y)
{
for (x = 0; x < 128; ++x)
{
*p++ = 128;
*p++ = 128;
*p++ = 128;
*p++ = 128;
}
}
svpng(fp, 2560, 1280, rgb, 1);
fclose(fp);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.