Search code examples
c++image-processinglibjpeg

libjpeg jpeg_write_coefficients


I have created my own DCT calculation.

How do I use jpeg_write_coefficients to write my 64 DCT values into JPEG file using jpeg_write_coefficients (it needs jvirt_barray_ptr * coef_arrays)?

How do I create this?


Solution

  • Look around for the request_virt_barray function (in jmemmgr.c).

    Also have a look at this question. It's reading DCT coefficients as opposed to writing them, but it should give you an idea of how coefficient arrays are stored like. Aside from the coefficients, you also need to pass in the quantization table (through the j_compress_ptr cinfo struct). This is because inside the libjpeg library, forward DCT and quantization is performed in one step. If you want to do the forward DCT by yourself, you have to do the quantization yourself too.

    It's also worth reading through the libjpeg documentation. It's long, but actually quite readable, and will greatly improve your understanding of the library. The most helpful file is structure.txt. It has sections on memory management and the encoder structure that are likely to help you.