Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What C library allows scaling of ginormous images?

Consider the following file:

-rw-r--r-- 1 user user 470886479 2009-12-15 08:26 the_known_universe.png

How would you scale the image down to a reasonable resolution, using no more than 4GB of RAM?

For example:

$ convert -scale 7666x3833 the_known_universe.png

What C library would handle it?

Thank you!

like image 371
Dave Jarvis Avatar asked Jul 20 '10 00:07

Dave Jarvis


2 Answers

I believe libpng has a stream interface. I think this can be used to read parts of the image at a time; depending on the image file you might be able to get the lines in order. You could then shrink each line (e.g. for 50% shrinking, shrink the line horizontally and discard every second line) and write to an output file.

Using libpng in C can take a fair amount of code, but the documentation guides you through it pretty well.

http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-3.8

like image 67
Edmund Avatar answered Oct 05 '22 19:10

Edmund


You could try making a 64 bit build of ImageMagick or seeing if there is one. My colleague wrote a blog with a super-simple png decoder (assumes you have zlib or equivalent) so you can kind of see the code you'd need to roll your own.

http://www.atalasoft.com/cs/blogs/stevehawley/archive/2010/02/23/libpng-you-re-doing-it-wrong.aspx

You would need to do the resample as you're reading it in.

like image 21
Lou Franco Avatar answered Oct 05 '22 19:10

Lou Franco