Antialiasing

SRC SRC src_s at rocketmail.com
Mon Jan 30 06:34:08 UTC 2017


Hi,

I was able to successfully create a translucent window using xlib and then set the transparency using the XRender extension, and make the window have rounded corners with the Xshape extension and the following code:

void rectAttributes(XRectangle *rect ,int width, int height, int x, int y) {
  rect->height = height;
  rect->width = width;
  rect->x=x;
  rect->y=y;
}

void createRoundedEdges(int radius, Display *display, Window window) {
  XWindowAttributes attr;
  XGetWindowAttributes(display,window, &attr);
  int windowHeight = attr.height,
      windowWidth = attr.width,
      cornerCoordinates[radius],
      x_bar = windowWidth - radius;
  XRectangle rect[(radius*4)]; //*4 because of 4 corners
  /* Populate the firstCorner array */
  for (int i=radius; i!=0; i--) {
    int y = i,
        x = sqrt((radius*radius)-(y*y));
    cornerCoordinates[radius-i] = x;
  }
  for (int i=0,j=radius,k=2*j,l=3*j;i<radius;i++,j++,k++,l++) {
    rectAttributes(&rect[i],windowWidth,1,x_bar+cornerCoordinates[i],i); //top-right
    rectAttributes(&rect[j],windowWidth,1,x_bar+cornerCoordinates[(2*radius)-1-j] //bottom-right
                    ,windowHeight-(2*radius)+j);
    rectAttributes(&rect[k],windowWidth,1,radius-windowWidth-cornerCoordinates[i],i); //top-left
    rectAttributes(&rect[l],windowWidth,1,rect[k].x,windowHeight-1-i); //bottom-left
  }
  int sizeOfArray = sizeof(rect)/sizeof(rect[0]);
  XShapeCombineRectangles(display,window,0,0,0,rect,sizeOfArray,ShapeSubtract,0);
}

This is what the above code generates:



If you look closely at the rounded corners, they seem to be not smooth but rather jagged, and to make those corners smooth I’d have to do ant-aliasing on the window. I could do that in two ways, one is by writing the anti-aliasing algorithm and placing pixels with differing alpha values along the edges using Xrender, or by finding an extension that does the anti-aliasing on the window. So, I was wondering if you could point me to an anti-aliasing extension that I can use to make the corners smooth mostly because I really don’t want to spend the time writing an antialiasing algorithm from scratch if an extension already exists that does just that.

Thanks!
Sajeeb Roy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.x.org/archives/xorg-devel/attachments/20170129/b28c6573/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2017-01-29 at 11.11.48 PM.png
Type: image/png
Size: 260211 bytes
Desc: not available
URL: <https://lists.x.org/archives/xorg-devel/attachments/20170129/b28c6573/attachment-0001.png>


More information about the xorg-devel mailing list