[xlib] Image has just 1/4 size


 
Thread Tools Search this Thread
Top Forums Programming [xlib] Image has just 1/4 size
# 1  
Old 08-06-2013
[xlib] Image has just 1/4 size

Hello,

i'm trying to show the Image of an monochrome webcam in an xlib-Window.

initializing of the window:
Code:
if (NULL == ((*XWindow)->display = XOpenDisplay(NULL))) APPLICATION_Set_Error(V4LCamera->Application, XWINDOW, "failed to open display", 123, -1, APPLICATION_ERROR_MESSAGE); 
    (*XWindow)->screen = XDefaultScreen((*XWindow)->display); 
    (*XWindow)->gc = XDefaultGC((*XWindow)->display, 0); 
    (*XWindow)->root = RootWindow((*XWindow)->display, (*XWindow)->screen); 
    (*XWindow)->white_pixel = WhitePixel((*XWindow)->display, (*XWindow)->screen); 
    (*XWindow)->black_pixel = BlackPixel((*XWindow)->display, (*XWindow)->screen); 
    (*XWindow)->nplanes = DisplayPlanes((*XWindow)->display, (*XWindow)->screen); 
    (*XWindow)->visual = XDefaultVisual((*XWindow)->display, (*XWindow)->screen); 
    (*XWindow)->window = XCreateSimpleWindow(   (*XWindow)->display, 
                                                (*XWindow)->root, 
                                                (*XWindow)->X, 
                                                (*XWindow)->Y, 
                                                (*XWindow)->Width, 
                                                (*XWindow)->Height, 
                                                1, 
                                                (*XWindow)->black_pixel, 
                                                (*XWindow)->white_pixel); 
    XSelectInput((*XWindow)->display, (*XWindow)->window, ButtonPressMask); 
    (*XWindow)->wmDeleteMessage = XInternAtom((*XWindow)->display, "WM_DELETE_WINDOW", True); 
    if ((*XWindow)->wmDeleteMessage) XSetWMProtocols((*XWindow)->display, (*XWindow)->window, &(*XWindow)->wmDeleteMessage, 1); 
    XMapWindow((*XWindow)->display, (*XWindow)->window);

width = 744
height = 480

The xlib-window opens with the correct size.

The window loop looks like:
Code:
 while (APPLICATION_Get_Status(XWindow->Object->Application) < 3) 
    { 
        unsigned char* MonoChromImage = V4LCAMERA_Get_Image(XWindow->V4LCamera); 
        if (MonoChromImage != NULL) 
        { 
            //XClearWindow(XWindow->display, XWindow->window); 
            unsigned char* RGBImage = XWINDOW_Convert_MonoChrom2RGB(XWindow, MonoChromImage); 
            free(MonoChromImage); 
            XImage* xImage = XCreateImage(  XWindow->display, 
                                            XWindow->visual, 
                                            XWindow->nplanes, 
                                            ZPixmap, 
                                            0, 
                                            (char*)RGBImage, 
                                            XWindow->V4LCamera->fmt.fmt.pix.width, 
                                            XWindow->V4LCamera->fmt.fmt.pix.height, 
                                            8, 
                                            XWindow->V4LCamera->fmt.fmt.pix.bytesperline * 4); 
            if (xImage != NULL) 
            { 
                XPutImage(XWindow->display, XWindow->window, XWindow->gc, xImage, 0, 0, 0, 0, XWindow->V4LCamera->fmt.fmt.pix.width, XWindow->V4LCamera->fmt.fmt.pix.height); 
                XDestroyImage(xImage); 
            } 
            //free(RGBImage); 
            XSync(XWindow->display, 0); 
        } 
        //XFlush(XWindow->display); 
        if (XCheckIfEvent(XWindow->display, &XWindow->event, XWINDOW_PredictateXCheckIfEvent, (char*)XWindow)) 
        { 
            printf("Passendes Event gefunden\n"); 
            switch(XWindow->event.type) 
            { 
                case ButtonPress: 
                    printf("Mouse button pressed!\n"); 
                    break; 
                case ClientMessage: 
                    if (XWindow->event.xclient.data.l[0] == XWindow->wmDeleteMessage)APPLICATION_Set_Status(XWindow->Object->Application, APPLICATION_STATUS_PREPARECLOSE); 
                    break; 
                default: 
                    // nothing 
                    break; 
            } 
        } 
        usleep(10000); 
    }

The MonoChromImage is an 8 bit with width 744 and height 480 grayscale image. I'm converting it with this function to an RGB-Image:
Code:
unsigned char*  XWINDOW_Convert_MonoChrom2RGB(pClassXWindow XWindow, unsigned char* MonoChromImage) 
{ 
    int x, y; 
    int position; 
    unsigned char PixelValue; 
    unsigned char* RGBImage = mem_malloc(sizeof(char) * (XWindow->V4LCamera->fmt.fmt.pix.width * XWindow->V4LCamera->fmt.fmt.pix.height * 4 + 1), XWINDOW, "failed to allocate memory for image buffer", 131); 
    
    position = 0; 
    for (y = 0; y < XWindow->V4LCamera->fmt.fmt.pix.width - 1; y++) 
    { 
        for (x = 0; x < XWindow->V4LCamera->fmt.fmt.pix.height - 1; x++) 
        { 
            PixelValue = MonoChromImage[y * XWindow->V4LCamera->fmt.fmt.pix.height + x]; 
            RGBImage[y * XWindow->V4LCamera->fmt.fmt.pix.height + x] = PixelValue; 
            RGBImage[y * XWindow->V4LCamera->fmt.fmt.pix.height + x + 1] = PixelValue; 
            RGBImage[y * XWindow->V4LCamera->fmt.fmt.pix.height + x + 2] = PixelValue; 
            RGBImage[y * XWindow->V4LCamera->fmt.fmt.pix.height + x + 3] = 0; 
        } 
    } 
            RGBImage[XWindow->V4LCamera->fmt.fmt.pix.width * XWindow->V4LCamera->fmt.fmt.pix.height * 4] = '\0'; 
    return RGBImage; 
}

Saving the MonoChromImage as BMP results in an correct Image. The RGBImage shown in the xlib-window results in 8 small Images with 4 colums and 2 raws. Each of this images has an size of 1/4 of the original size.

I don't know where i'm making a failure and have looked a lot of times over my source code.
Maybe someone of you can see my failure.

thanks
mirrowwinger
# 2  
Old 08-06-2013
Just and fyi: the portable bit map utilities and the source code may help...
Code:
http://old.tifster.com/tif/graphics/pbmintro.html

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Xlib registering

hey, Im new to the linux world. Lately, I have tried to create a glx window with xlib, making it a popup window(fullscreen) so I set override_redirect to true. Im happy with the removed borders, but apparantly, the application doesnt show up in the left bar in ubuntu, neither when I press alt... (4 Replies)
Discussion started by: thedardanius
4 Replies

2. Programming

Xlib help - Array of Structs

Hey guys! First of all english is not my main language so sorry for any english mistakes. Second im a total beginner in programming, still i have a school work to do and i found a problem. Probably something easy to solve but it's driving me crazy. So i created a struct, that holds 4 ints: ... (1 Reply)
Discussion started by: Spiritvs
1 Replies

3. Shell Programming and Scripting

matching image files to create one image

Hi, I have two sets of image files. Both sets have names A to Z but set 1 ends with .cdt.png and set 2 ends with .matrix.png. I want set 1 to match with set 2 if the names match (i.e. A.cdt.png will match with A.matrix.png) and with the convert image tool (program for images), it will merge the... (6 Replies)
Discussion started by: kylle345
6 Replies

4. Shell Programming and Scripting

perl Image::size function

Hi, How to use Image::size function ? because I want to list all image thatare less than size pixels in horizontal resolution. so here is my code : #!/usr/bin/perl -w use Image::Size; use constant GIVEN_WIDTH = '100'; my @filtered_images = grep { my @d = imgsize( $_ ); $d < GIVEN_WIDTH }... (8 Replies)
Discussion started by: guidely
8 Replies

5. UNIX for Dummies Questions & Answers

Xlib Errors

Hi, I am handling user issues in my team. Users have their Unix session running on Citrix MFU. Recently, I was suppose to address a user issue which is as below: Gets the below error when tries to open nedit: Xlib: connection to ":165.0" refused by server Xlib: Client is not... (1 Reply)
Discussion started by: mspatil0037
1 Replies

6. UNIX for Advanced & Expert Users

xlib error

Hello! Im running tight VNC on Red Hat Enterprise Linux 4.0. How can I increase the number of X clients that I can run in a VNC session?I need to run aproximately 500 programs in one VNC session, but at this time I can only 236 -> i've tryed to launch 250 xclock's in background and when it... (3 Replies)
Discussion started by: karpoand
3 Replies

7. UNIX for Advanced & Expert Users

Create an Ignite image on tape from Online IgniteUX image

Hi, (HP-UX 11.11) I need to create a tape image of an igniteUX image created on our igniteUX server. That is to say. I have a "Online" image of the igniteUX of the targeted system but I now need to copy it to a useable TAPE (igniteUX) image so i can build an other server from it that is not... (3 Replies)
Discussion started by: Andrek
3 Replies

8. UNIX for Dummies Questions & Answers

Add Image Size (W-H) to a UNIX statement

I am using a counter on Comcast and I have it working OK. What I need to do is to add the width and height of 'counter.gif'. Below is the statement I am using: &richportal is the counter name on the Comcast Server. EX: w=10px h=10px <img src="/cgi-bin/counter.gif?&richportal"> Thanks: Barry (0 Replies)
Discussion started by: barrie
0 Replies

9. Solaris

database image size

hi , we are using Veritas netbackup 5 to backup all databases at our site. i noticed lately that a specific filesystem on the netbackup servers in running critically out of space , after some investigations i found that there are images that are increasing in size everytime a backup is taken .... (6 Replies)
Discussion started by: ppass
6 Replies
Login or Register to Ask a Question