我正在尝试缩小我捕获的 X 显示器的大小,以便在新窗口中显示它。我尝试平均单个 RGB 分量,但图像看起来不太好。这是我的算法:
img = XGetImage(d_remote,RootWindow(d_remote,0),0,0,attr.width,attr.height,XAllPlanes(),ZPixmap);
int i;
int j;
for(i=0;i<attr.height;i=i+2){
for(j=0;j<attr.width;j=j+2) {
unsigned long p1 = XGetPixel(img, j, i);
unsigned long p1R = p1 & 0x00ff0000;
unsigned long p1G = p1 & 0x0000ff00;
unsigned long p1B = p1 & 0x000000ff;
unsigned long p2 = XGetPixel(img, j+1, i);
unsigned long p2R = p2 & 0x00ff0000;
unsigned long p2G = p2 & 0x0000ff00;
unsigned long p2B = p2 & 0x000000ff;
unsigned long p3 = XGetPixel(img, j, i+1);
unsigned long p3R = p3 & 0x00ff0000;
unsigned long p3G = p3 & 0x0000ff00;
unsigned long p3B = p3 & 0x000000ff;
unsigned long p4 = XGetPixel(img, j+1, i+1);
unsigned long p4R = p4 & 0x00ff0000;
unsigned long p4G = p4 & 0x0000ff00;
unsigned long p4B = p4 & 0x000000ff;
unsigned long averageR = (p1R+p2R+p3R+p4R)/4;
unsigned long averageG = (p1G+p2G+p3G+p4G)/4;
unsigned long averageB = (p1B+p2B+p3B+p4B)/4;
int average = averageR | averageG | averageB | 0x00000000;
XPutPixel(newImg, j/2, i/2, average);
}
}
平均像素是一种不好的方法吗?我基本上是在尝试将 img 缩放 50%。我的假设是我在像素图上移动一个 2x2 正方形。