我有一个要用jpeg压缩的ximage。
但是在此之前,我需要获取图像的RGB值。
我目前使用下面的代码来执行此操作,效果很好,但我想对其进行优化以提高速度。
void XimageToRgb(XImage* image , unsigned char* data , const int W , const int H )
{
unsigned long red_mask = image->red_mask;
unsigned long green_mask = image->green_mask;
unsigned long blue_mask = image->blue_mask;
int x, y;
int ii = 0;
for (y = 0; y < H; y++) {
for (x = 0; x < W; x++) {
unsigned long pixel = XGetPixel(image,x,y);
unsigned char blue = (pixel & blue_mask);
unsigned char green = (pixel & green_mask) >> 8;
unsigned char red = (pixel & red_mask) >> 16;
data[ii + 2] = blue;
data[ii + 1] = green;
data[ii + 0] = red;
ii += 3;
}
}
}