c++raspberry-pijpegppm

How to convert image.jpg to image.ppm in c++


I now hope to convert image.jpg to image.ppm via c++ code implementation. What library can I implement in C++? By the way: my work platform is Raspberry Pi 3B+. I look forward to any help and reply from you.


Solution

  • I would recommend CImg library for this. It is modern, lightweight and very, very simple to use because it is "header only" - just a single include file.

    #define cimg_display 0  // if you dont have x11.and you can delete-Dcimg_display=0. https://github.com/GreycLab/CImg/issues/187
    #include "CImg.h"
    
    using namespace cimg_library;
    
    int main() {
       // Load JPEG image
       CImg<unsigned char> im("image.jpg");
    
       // Save as PPM
       im.save("result.ppm");
       // show ppm: ffplay -i a.ppm / ffmpeg -i a.ppm a.bmp
    }
    

    Compile like this:

    g++ -std=c++11 -O3 -march=native -Dcimg_jpeg=1 -Dcimg_display=0  main.cpp -o main