misc0110 / libattopng Goto Github PK
View Code? Open in Web Editor NEWA minimal C library to write uncompressed PNG images
License: MIT License
A minimal C library to write uncompressed PNG images
License: MIT License
Hi, thanks for this library! Currently, information can only be encoded up to a bit depth per pixel of 8. Would it be possible to also support 16-bit pixel values?
valgrind tells that saving a png file can in some cases lead to "Use of uninitialised value".
Proposing to use calloc() instead of malloc() in libattopng_new():
Line 79 in b427234
Test program
#include <libattopng.h>
int main(int argc, char *argv[]) {
libattopng_t *png = libattopng_new(10, 10, PNG_RGBA);
libattopng_save(png, "/tmp/test.png");
libattopng_destroy(png);
return 0;
}
// valgrind -v ...
Hey! I'm using this library to generate huge images (128000 x 96000 for example), and I'm encountering the problem of max 65k pixels.
After some search, it seems to be due to chunk limit which is of this size, but I also found that PNG do not have width or height limit...
Do you think there is any way this could be implemented, or maybe you have done more research than I have and you've got a reason why there's a limit?
Thanks in advance :)
In 7d8441a the license of the project (LICENSE) was changed from LGPLv3 to MIT, however both libattopng.c and libattopng.h still start with a LGPLv3 header.
Is the library available under MIT as the main license file and the commit seem to suggest? Or is it available only under LPGLv3 as the source code would suggest?
I am using ffmpeg libs to extract frames from video.
I want to save frames to png and i found libattopng for this purpose.
Аfter getting the RGB information about the frame, I use the following procedure:
void save_frame_as_png(AVFrame *pFrame, int width, int height, size_t frameNum)
#define RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16) | (0xff << 24))
#define R(x, y) 3*(x + y*width) + 0
#define G(x, y) 3*(x + y*width) + 1
#define B(x, y) 3*(x + y*width) + 2
{
char szFilename[32];
int y;
sprintf(szFilename, "frames/frame%d.png", (int)frameNum);
libattopng_t* png = libattopng_new(width, height, PNG_RGB);
char *pColorChannel = pFrame->data[0];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
libattopng_set_pixel(png, x, y,
RGB(pColorChannel[R(x, y)],
pColorChannel[G(x, y)],
pColorChannel[B(x, y)])
);
}
}
libattopng_save(png, szFilename);
libattopng_destroy(png);
}
But after saving the file, there are blue spots on the image (what is more, where colors are close to white).
I have the procedure that saving frame to .ppm (from http://dranger.com/ffmpeg/tutorial01.html):
void save_frame_as_ppm(AVFrame *pFrame, int width, int height, size_t frameNum) {
FILE *pFile;
char szFilename[32];
int y;
sprintf(szFilename, "frames/frame%d.ppm", (int)frameNum);
pFile = fopen(szFilename, "wb");
if (pFile == NULL)
return;
// Write header of ppm file
fprintf(pFile, "P6\n%d %d\n255\n", width, height);
// Write pixel data
for (y = 0; y < height; y++)
fwrite(pFrame->data[0] + y * pFrame->linesize[0], 1, width * 3, pFile);
fclose(pFile);
}
Example of frame, that saved as .png and .ppm: frame10.zip
All code: https://pastebin.com/eL7AizFU
So, my question is: do I use the library libattopng correctly? Is there a solution to the blue areas in my context?
I have the following chunk of code:
libattopng_t* png = libattopng_new( xsize, ysize, PNG_RGBA );
for( int y = 0; y < ysize; y++ )
{
for( int x = 0; x < xsize; x++ )
{
libattopng_set_pixel(png, x, ysize - y, image[x][y]);
}
//printf( "%d\n", y );
}
libattopng_save( png, output_file_name );
libattopng_destroy( png );
When I set xsize = 4,320
and ysize = 2,160
then everything works fine.
However when I set xsize = 21,600
and ysize = 10,800
( 233,280,000 pixels ) then I get a core dump. The png file has about 900 Mbytes written to it before the crash but is corrupted somehow.
From a quick investigation the crash seems to be caused by the free(png->data);
line in libattopng_destroy
. However if I comment out the call to libattopng_destroy
the program terminates normally without a crash but the resulting PNG file is still corrupt.
Before I investigate any further would you expect the library to handle these large file sizes?
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.