this SHOULD fix cross-endianness issues (serve and client not same endianess)

...


SVN revision: 15923
This commit is contained in:
Carsten Haitzler 2005-07-28 04:15:11 +00:00
parent 5e1351eeda
commit cf7ddecef8
3 changed files with 126 additions and 1 deletions

View File

@ -6,7 +6,7 @@ INCLUDES = \
@my_includes@
if BUILD_X11
X_BASED_PROGS = imlib2_show imlib2_test imlib2_bumpmap imlib2_poly imlib2_colorspace imlib2_view
X_BASED_PROGS = imlib2_show imlib2_test imlib2_bumpmap imlib2_poly imlib2_colorspace imlib2_view imlib2_grab
endif
bin_PROGRAMS = \
@ -33,3 +33,6 @@ imlib2_colorspace_LDADD = $(top_builddir)/src/lib/libImlib2.la
imlib2_view_SOURCES = imlib2_view.c
imlib2_view_LDADD = $(top_builddir)/src/lib/libImlib2.la
imlib2_grab_SOURCES = imlib2_grab.c
imlib2_grab_LDADD = $(top_builddir)/src/lib/libImlib2.la

65
src/bin/imlib2_grab.c Normal file
View File

@ -0,0 +1,65 @@
#include "config.h"
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "Imlib2.h"
Display *disp;
Visual *vis;
Colormap cm;
int depth;
int image_width = 0, image_height = 0;
int
main(int argc, char **argv)
{
Imlib_Image *im = NULL;
char *file = NULL;
int no = 1;
const char *display_name = getenv("DISPLAY");
if (argc < 2)
return 1;
file = argv[no];
if (display_name == NULL)
display_name = ":0";
disp = XOpenDisplay(display_name);
if (disp == NULL)
{
fprintf(stderr, "Can't open display %s\n", display_name);
return 1;
}
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
imlib_context_set_display(disp);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
imlib_context_set_drawable(DefaultRootWindow(disp));
im = imlib_create_image_from_drawable(0, 0, 0,
DisplayWidth(disp, DefaultScreen(disp)),
DisplayHeight(disp, DefaultScreen(disp)),
1);
if (!im)
{
fprintf(stderr, "Cannot grab image!\n");
exit(0);
}
if (argc > 1)
{
imlib_context_set_image(im);
imlib_save_image(argv[1]);
}
return 0;
}

View File

@ -55,6 +55,63 @@ __imlib_GrabXImageToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
/* go thru the XImage and convert */
if (xim->bits_per_pixel == 32)
depth = 32;
/* data needs swapping */
#define SWAP32(x) (x) = \
((((int)(x) & 0x000000ff ) << 24) |\
(((int)(x) & 0x0000ff00 ) << 8) |\
(((int)(x) & 0x00ff0000 ) >> 8) |\
(((int)(x) & 0xff000000 ) >> 24))
#define SWAP16(x) (x) = \
((((short)(x) & 0x00ff ) << 8) |\
(((short)(x) & 0xff00 ) >> 8))
#ifdef WORDS_BIGENDIAN
if (xim->bitmap_bit_order == LSBFirst)
#else
if (xim->bitmap_bit_order == MSBFirst)
#endif
{
switch (depth)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
break;
case 15:
case 16:
for (y = 0; y < h; y++)
{
unsigned short *tmp;
tmp = (unsigned short *)(xim->data + (xim->bytes_per_line * y));
for (x = 0; x < w; x++)
{
SWAP16(*tmp);
tmp++;
}
}
case 24:
case 32:
for (y = 0; y < h; y++)
{
unsigned int *tmp;
tmp = (unsigned int *)(xim->data + (xim->bytes_per_line * y));
for (x = 0; x < w; x++)
{
SWAP32(*tmp);
tmp++;
}
}
break;
default:
break;
}
}
switch (depth)
{
case 0: