XGetImage to SDL

Hi All,

Ok , I did some progress and use this code , I can get ScreenShoot of my
desktop when I use depth 32, but When I change it into depth 24, it dosn’t
work , any idea?

I just change this line:
SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_HWSURFACE, at.width, at.height,
24, img->red_mask, img->green_mask, img->blue_mask, 0);

#include <assert.h>
#include <SDL/SDL.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

void screenshot(const char *filename)
{
Display *disp = XOpenDisplay(NULL);
Window win = XDefaultRootWindow(disp);
XWindowAttributes at;
XGetWindowAttributes(disp, win, &at);
XImage *img = XGetImage(disp, win, at.x, at.y, at.width, at.height,
XAllPlanes(), ZPixmap);

SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_HWSURFACE, at.width,

at.height, 32, img->red_mask, img->green_mask, img->blue_mask, 0);
int x, y;
SDL_LockSurface(tmp);
for (y = 0; y < at.height; y++) {
for (x = 0; x < at.width; x++) {
((unsigned *)tmp->pixels)[x + y * at.width] = XGetPixel(img, x,
y);
}
}
SDL_UnlockSurface(tmp);
SDL_SaveBMP(tmp, filename);
SDL_FreeSurface(tmp);
XCloseDisplay(disp);
}

int main(int argc, char *argv[])
{
assert(argc > 1);
SDL_Init(SDL_INIT_VIDEO);
screenshot(argv[1]);
return 0;
}

Best Regards,
Gadi

It doesn’t work as in how? In any case you seem to be treating a
24-bit surface like it’s 32-bit, which doesn’t seem to be very helpful
(also I’d rather use the uint*_t types over the standard ones for
fixed-size integers, but that’s another issue).

2013/1/30, Gadi Dor :> Hi All,

Ok , I did some progress and use this code , I can get ScreenShoot of my
desktop when I use depth 32, but When I change it into depth 24, it dosn’t
work , any idea?

I just change this line:
SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_HWSURFACE, at.width, at.height,
24, img->red_mask, img->green_mask, img->blue_mask, 0);

#include <assert.h>
#include <SDL/SDL.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

void screenshot(const char *filename)
{
Display *disp = XOpenDisplay(NULL);
Window win = XDefaultRootWindow(disp);
XWindowAttributes at;
XGetWindowAttributes(disp, win, &at);
XImage *img = XGetImage(disp, win, at.x, at.y, at.width, at.height,
XAllPlanes(), ZPixmap);

SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_HWSURFACE, at.width,

at.height, 32, img->red_mask, img->green_mask, img->blue_mask, 0);
int x, y;
SDL_LockSurface(tmp);
for (y = 0; y < at.height; y++) {
for (x = 0; x < at.width; x++) {
((unsigned *)tmp->pixels)[x + y * at.width] = XGetPixel(img, x,
y);
}
}
SDL_UnlockSurface(tmp);
SDL_SaveBMP(tmp, filename);
SDL_FreeSurface(tmp);
XCloseDisplay(disp);
}

int main(int argc, char *argv[])
{
assert(argc > 1);
SDL_Init(SDL_INIT_VIDEO);
screenshot(argv[1]);
return 0;
}

Best Regards,
Gadi

Dude, is there any information/media regarding this project you are working
on? I am starting to get curious about what you are creating.On Wed, Jan 30, 2013 at 1:48 PM, Sik the hedgehog < sik.the.hedgehog at gmail.com> wrote:

It doesn’t work as in how? In any case you seem to be treating a
24-bit surface like it’s 32-bit, which doesn’t seem to be very helpful
(also I’d rather use the uint*_t types over the standard ones for
fixed-size integers, but that’s another issue).

2013/1/30, Gadi Dor :

Hi All,

Ok , I did some progress and use this code , I can get ScreenShoot of my
desktop when I use depth 32, but When I change it into depth 24, it
dosn’t
work , any idea?

I just change this line:
SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_HWSURFACE, at.width,
at.height,
24, img->red_mask, img->green_mask, img->blue_mask, 0);

#include <assert.h>
#include <SDL/SDL.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

void screenshot(const char *filename)
{
Display *disp = XOpenDisplay(NULL);
Window win = XDefaultRootWindow(disp);
XWindowAttributes at;
XGetWindowAttributes(disp, win, &at);
XImage *img = XGetImage(disp, win, at.x, at.y, at.width, at.height,
XAllPlanes(), ZPixmap);

SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_HWSURFACE, at.width,

at.height, 32, img->red_mask, img->green_mask, img->blue_mask, 0);
int x, y;
SDL_LockSurface(tmp);
for (y = 0; y < at.height; y++) {
for (x = 0; x < at.width; x++) {
((unsigned *)tmp->pixels)[x + y * at.width] = XGetPixel(img,
x,
y);
}
}
SDL_UnlockSurface(tmp);
SDL_SaveBMP(tmp, filename);
SDL_FreeSurface(tmp);
XCloseDisplay(disp);
}

int main(int argc, char *argv[])
{
assert(argc > 1);
SDL_Init(SDL_INIT_VIDEO);
screenshot(argv[1]);
return 0;
}

Best Regards,
Gadi


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Bust0ut, Surgemcgee: Systems/Web/Software Engineer