How to make a font using a png image?

How to parallelize PNG file creation with C++, libpng and OpenMP?

  • I am currently trying to implement a PNG encoder in C++ based on libpng that uses OpenMP to speed up the compression process. The tool is already able to generate PNG files from various image formats. I uploaded the complete source code to http://pastebin.com so you can see what I have done so far: http://pastebin.com/8wiFzcgV So far, so good! Now, my problem is to find a way how to parallelize the generation of the IDAT chunks containing the compressed image data. Usually, the libpng function png_write_row gets called in a for-loop with a pointer to the struct that contains all the information about the PNG file and a row pointer with the pixel data of a single image row. (Line 114-117 in the Pastebin file) //Loop through image for (i = 0, rp = info_ptr->row_pointers; i < png_ptr->height; i++, rp++) { png_write_row(png_ptr, *rp); } Libpng then compresses one row after another and fills an internal buffer with the compressed data. As soon as the buffer is full, the compressed data gets flushed in a IDAT chunk to the image file. My approach was to split the image into multiple parts and let one thread compress row 1 to 10 and another thread 11 to 20 and so on. But as libpng is using an internal buffer it is not as easy as I thought first :) I somehow have to make libpng write the compressed data to a separate buffer for every thread. Afterwards I need a way to concatenate the buffers in the right order so I can write them all together to the output image file. So, does someone have an idea how I can do this with OpenMP and some tweaking to libpng? Thank you very much!

  • Answer:

    This loop seems parallelizable in a straightforward way. I would try just putting   #pragma omp for   before the for loop and compile with -fopenmp or -openmp option depending on your compiler. If this code is in a library then you should modify its compile script to support openmp.

Nazım Dugan at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.