使用Mini Jpeg Decoder处理JPEG图像像素每像素
问题描述:
我想用C++使用解码器处理JPEG图像Mini Jpeg Decoder。使用Mini Jpeg Decoder处理JPEG图像像素每像素
的问题是:我想读每个像素的像素,但解码器仅返回一个为imageData阵列,如libjpeg不相似。
我不能使一个方法是这样的:
char getPixel(char x, char y, unsigned char* imageData)
{
//...???
}
返回(在char
变量)应该包含像素的亮度。
(我使用灰度图像......)
我该如何解决这个问题?
答
据我所知,Decoder
类与GetImage()
方法提供了一个颜色值的字节数组。所以你可以写一个看起来像这样的函数:
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()];
}
我不确定像素布局,所以也许数组访问是不正确的。此外,这仅适用于灰度图像,否则您只能在该位置获得红色值的亮度。 HTH
非常感谢你,它完美的作品! – cafaxo 2011-06-04 20:44:10