Clip mask on all screen


 
Thread Tools Search this Thread
Top Forums Programming Clip mask on all screen
# 1  
Old 01-18-2013
Clip mask on all screen

Hello everyone.
I'm programming in C with xlib (standart libs).
I need set GC with transparent pixmap (in some pixels).
I have colored pixmap, that set tile for GC via XSetTile. This pixmap is painted on all screen.
And I have mask, created by this pixmap. This mask is set by XSetClipMask.
But mask is set only for one pixmap, that stay in (0, 0).
How I can multiple this mask on all screen?
# 2  
Old 01-24-2013
Function create bitmaps from mulricolor pixmap (xpm), set context by each bitmap
and draw polygons with each context:

Code:
void XFillPolygonByPixmap(Display *disp, Drawable d, GC gc,
                          XPoint *polygon, int len,
                          Pixmap pixmap, Pixmap mask)
{
    const unsigned short MAX_PIXMAP_WHC = 50;

    char data[MAX_PIXMAP_WHC*MAX_PIXMAP_WHC];
    unsigned short indData = 0;
    unsigned short currColor = 0;
    char colorHex[6];
    unsigned short ind;
    static signed short noneColor = -1;
    XpmImage xpmImage;       // xpm color of line
    unsigned short indBuf = 0;
    unsigned char buf = 0;
    static Pixmap currBitmap[MAX_PIXMAP_WHC];
    static Pixmap prevPixmap = NULL;
    static unsigned short indBitmap = 0;
    static unsigned long colorLong[MAX_PIXMAP_WHC];
    static unsigned int ncolor = 0;

    // Using tile if no mask in *.xpm
    if (!mask)
    {
        XSetFillStyle(disp, gc, FillTiled);
        XSetTile(disp, gc, pixmap);
        XFillPolygon(disp, d, gc, polygon, len, Complex, CoordModeOrigin);
        return;
    }

    // Generate new data. Else - use previous
    if (pixmap != prevPixmap)
    {
        prevPixmap = pixmap;
        noneColor = -1;
        XpmCreateXpmImageFromPixmap(disp, pixmap, mask, &xpmImage, NULL);
        ncolor = xpmImage.ncolors;

        // Take all colors
        for (ind = 0; ind < ncolor; ind++)
        {
            // for look and understand format of c_color use:
            // printf("%s\n", xpmImage.colorTable[ind].c_color);
            colorHex[0] = xpmImage.colorTable[ind].c_color[1];
            colorHex[1] = xpmImage.colorTable[ind].c_color[2];
            colorHex[2] = xpmImage.colorTable[ind].c_color[5];
            colorHex[3] = xpmImage.colorTable[ind].c_color[6];
            colorHex[4] = xpmImage.colorTable[ind].c_color[9];
            colorHex[5] = xpmImage.colorTable[ind].c_color[10];

            // Get index of None color in colorTable
            if (xpmImage.colorTable[ind].c_color[0] == 'N'
                    && xpmImage.colorTable[ind].c_color[1] == 'o'
                    && xpmImage.colorTable[ind].c_color[2] == 'n'
                    && xpmImage.colorTable[ind].c_color[3] == 'e')
                noneColor = ind;

            // Save all colors
            colorLong[ind] = strtol(colorHex, NULL, 16);
        }

        for (ind = 0; ind < indBitmap; ind++)
            XFreePixmap(disp, currBitmap[ind]);

        // Create bitmaps for each color
        for (currColor = 0, indBitmap = 0;
             currColor < ncolor; currColor++)
        {
            if (currColor == noneColor)
                continue;

            // Filter all array on current color
            for (ind = 0, buf = 0, indBuf = 0, indData = 0;
                 ind < xpmImage.width*xpmImage.height; ind++)
            {
                // If current pixel is equal current color - set high bit
                // else - bit is zero
                if (xpmImage.data[ind] == currColor)
                    buf |= 0x80;

                // if index is equal width - shift right on width-indBuf bits
                bool flagWidth = ((ind+1)%xpmImage.width == 0);

                // If num of bits is 8 or flag is set, save data
                if (indBuf == 7 || flagWidth)
                {
                    if (flagWidth)
                    {
                        while(indBuf < 7)
                        {
                            buf = buf >> 1;
                            indBuf++;
                        }
                    }
                    data[indData++] = buf;
                    indBuf = 0;
                    buf = 0;
                }
                else
                {
                    indBuf++;
                    buf = buf >> 1;
                }
            }

            // Create bitmaps for each color
            currBitmap[indBitmap++] = XCreateBitmapFromData(disp, d, data,
                                               xpmImage.width, xpmImage.height);
        }
    }

    // For each color set stipple by bitmap  and fill polygon
    for (currColor = 0, ind = 0;
         currColor < ncolor, ind < indBitmap; currColor++)
    {
        if (currColor == noneColor)
            continue;

        XSetFillStyle(disp, gc, FillStippled);
        XSetForeground(disp, gc, colorLong[currColor]);
        XSetStipple(disp, gc, currBitmap[ind++]);
        XFillPolygon(disp, d, gc, polygon, len, Complex, CoordModeOrigin);
    }
    return;
}

Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What is mask and effective right mask in setfacl?

Hi Guys, can someone explain what is mask and effective right mask in setfacl and getfacl command with example, unable to get it. (3 Replies)
Discussion started by: Jcpratap
3 Replies

2. Red Hat

Samba create mask and dir mask on RHEL 4.8

Hi Experts, I'm using samba -3.6.1 on Red Hat Enterprise Linux ES release 4 (Nahant Update 8) ,all seems ok. The issue im facing is as follows. When ever a user creates a file via windows explorer the permissions assgined to the file are as follows -rw-rwxr--+ 1 tom group2 0 Mar 9... (1 Reply)
Discussion started by: maverick_here
1 Replies

3. UNIX for Advanced & Expert Users

trim 165 MB video clip with ffmpeg (only last 3 minutes)

Hi original video clip > ls -alh reallynotpr0n.flv -rw-r--r-- 1 jonny staff 165M Nov 18 19:57 reallynotpr0n.flvtrying to cut only last 3 minutes of the clip out. > ffmpeg -i reallynotpr0n.flv -vcodec copy -acodec copy -ss 00:52:00 -t 00:03:48 trimmed_video.avi ffmpeg version 0.7.7,... (3 Replies)
Discussion started by: slashdotweenie
3 Replies

4. Shell Programming and Scripting

clip selective text and minus

After doing some scripting in a log file, I am left with some lines like this. 10:00:00 Received Message Message ID 1 10:05:00 Published Message Message ID 1 10:10:00 Received Message Message ID 2 10:15:00 Published Message Message ID 2 10:20:00 Received Message Message ID 3 10:26:00... (1 Reply)
Discussion started by: srini123
1 Replies

5. UNIX for Advanced & Expert Users

Clearing paste/clip board

Hello..... Is there anyway that I can clear the clipboard/paste/buffer in UNIX, Xterm, telnet? I have a number of scripts that require values being inputted correctly by the user. I have nothing to validate the values so I have to put trust in their ability to cut/paste correctly. :rolleyes: ... (4 Replies)
Discussion started by: nhatch
4 Replies
Login or Register to Ask a Question