1

I want to manipulate JPEG images with C++ using the decoder Mini Jpeg Decoder.

The problem is: I want to read pixel per pixel, but the decoder only returns an imageData-array, similar as libjpeg does.

I can't make a method like this:

char getPixel(char x, char y, unsigned char* imageData) 
{
    //...???
}

The return (the char variable) should contain the luminance of the pixel.

(I work with grayscale images...)

How can I solve this problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
cafaxo
  • 187
  • 8

1 Answers1

0

As far as I can tell, the Decoder class delivers a byte array of color values with the GetImage() method. So you could write a function that looks like this:

char getLuminance(Decoder* dec, int x, int y) {
    if(x < 0 || y < 0 || x >= dec->GetWidth() || y >= dec->GetHeight()) {
        throw "out of bounds";
    }

    return dec->GetImage()[x + y * dec->GetWidth()];
}

I'm uncertain of the pixel layout, so maybe the array access is not right. Also this only works for grey-scale images, or else you would get the luminance of the Red color value at the position only. HTH

Constantinius
  • 34,183
  • 8
  • 77
  • 85