user198729 user198729 - 1 month ago 20
C Question

How to process jpg images with c/c++ most easily?

I want to iterate over each pixel color in a

jpg
format image,

which library should I refer to to do this so that the code can be as short as possible?

NG. NG.
Answer

I can think of either ImageMagick or CImg. Here is a CImg tutorial for you. They abstract away a lot of the decompression details and just give you a grid to work with.

If you go with CImg, you only need to use the data call. You can probably do something like:

CImg<unsigned char> src("image.jpg");
int width = src.width();
int height = src.height();
unsigned char* ptr = src.data(10,10); // get pointer to pixel @ 10,10
unsigned char pixel = *ptr;