4 static int get_num(char* msg);
5 static void get_coord(char* msg,point *p);
6 static void get_rect(char* msg, point *p1, point *p2);
7 static void compute_center_coord(point p1, point p2, point *center);
8 static xlib_colormap * xlib_get_colormap (Colormap id, Visual *visual, MagnifierData *data);
9 static guint32 mask_table[] = {
10 0x00000000, 0x00000001, 0x00000003, 0x00000007,
11 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
12 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
13 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
14 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
15 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
16 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
17 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
21 void parse_message(char *msg, MagnifierData *data){
24 point roi_pos, roi_size;
25 point mag_pos, mag_size;
29 fprintf(stderr,"corrupted message, discarding\n");
32 type = atoi((char*)&msg[1]);
35 old_factor_x = data->factor_x;
36 data->factor_x = get_num(msg);
37 old_factor_y = data->factor_y;
38 data->factor_y = get_num(msg);
39 printf("FACTOR = %d\n",data->factor_x);
42 data->contrast = get_num(msg);
43 printf("CONTRAST = %d\n",data->contrast);
46 data->follow_mouse = get_num(msg);
47 printf("FOLLOW_MOUSE = %d\n",data->follow_mouse);
50 data->color_inverted = get_num(msg);
51 printf("COLOR_INVERTED = %d\n",data->color_inverted);
54 get_coord(msg, &data->center);
55 printf("GOTO = (%d,%d)\n", data->center.x, data->center.y);
58 get_rect (msg, &roi_pos, &roi_size);
59 printf("ROI = (%d,%d; %d,%d)\n", roi_pos.x, roi_pos.y, roi_size.x, roi_size.y);
60 compute_center_coord (roi_pos, roi_size, &data->center);
63 get_rect (msg, &mag_pos, &mag_size);
64 printf("EXTENTS = (%d,%d; %d,%d)\n", mag_pos.x, mag_pos.y, mag_size.x, mag_size.y);
65 data->mag_width = mag_size.x;
66 data->mag_height = mag_size.y;
67 gdk_window_move_resize (data->output_window->window, mag_pos.x,
69 data->mag_width, data->mag_height);
81 static int get_num(char* msg){
83 sscanf(msg,"~%d:%d:",&type,&num);
87 static void get_coord(char* msg,point *p){
89 sscanf(msg,"~%d:%d,%d:",&type,&p->x,&p->y);
92 static void get_rect(char* msg, point *p1, point *p2){
94 sscanf(msg,"~%d:%d,%d;%d,%d:",&type, &p1->x, &p1->y, &p2->x, &p2->y);
97 static void compute_center_coord (point pos, point size, point *center) {
98 center->x = pos.x + (size.x/2);
99 center->y = pos.y + (size.y/2);
102 int display_image(gpointer data)
104 MagnifierData *mag_data = (MagnifierData *)data;
105 update_image(mag_data);
106 gdk_pixbuf_scale(image,
110 DisplayWidth (mag_data->target_display,screen_num),
111 DisplayHeight(mag_data->target_display,screen_num),
118 gdk_pixbuf_render_to_drawable (scaled_image,
119 drawing_area->window,
120 drawing_area->style->fg_gc[GTK_STATE_NORMAL],
121 0,0,0,0,DisplayWidth (mag_data->target_display,screen_num),
122 DisplayHeight(mag_data->target_display,screen_num),
123 GDK_RGB_DITHER_NORMAL,0,0);
127 void update_image(MagnifierData *mag_data)
129 int x, y, total_width, total_height;
131 if(mag_data->follow_mouse){
132 Window root_return, child_return;
133 int win_x_return,win_y_return;
134 unsigned int mask_return;
135 XQueryPointer(mag_data->source_display,spi_image_root_window,
136 &root_return,&child_return,
137 &mag_data->center.x,&mag_data->center.y,
138 &win_x_return,&win_y_return,&mask_return);
141 total_width = DisplayWidth (mag_data->source_display,screen_num);
142 total_height = DisplayHeight(mag_data->source_display,screen_num);
144 x = mag_data->center.x - mag_data->mag_width/mag_data->factor_x/2;
145 y = mag_data->center.y - mag_data->mag_height/mag_data->factor_y/2;
147 if(mag_data->center.x < mag_data->mag_width/mag_data->factor_x/2)
149 if(mag_data->center.x > (total_width - mag_data->mag_width/mag_data->factor_x/2))
150 x = total_width - mag_data->mag_width/mag_data->factor_x;
151 if(mag_data->center.y < mag_data->mag_height/mag_data->factor_y/2)
153 if(mag_data->center.y > (total_height - mag_data->mag_height/mag_data->factor_y/2))
154 y = total_height - mag_data->mag_height/mag_data->factor_y;
160 printf("p = (%d,%d), x,y = (%d,%d), h,w = (%d,%d), ht,wt = (%d,%d)\n",
164 mag_data->mag_height,mag_data->mag_width,
168 if(mag_data->factor_x != old_factor_x || mag_data->factor_y != old_factor_y){
169 g_object_unref((GObject *)image);
170 image = gdk_pixbuf_new (GDK_COLORSPACE_RGB,FALSE, 8,
171 DisplayWidth (mag_data->target_display,screen_num)/mag_data->factor_x,
172 DisplayHeight(mag_data->target_display,screen_num)/mag_data->factor_y);
173 /* yes, use target display above, since the size of the area grabbed depends on the target */
174 old_factor_x = mag_data->factor_x;
175 old_factor_y = mag_data->factor_y;
177 get_root_image(spi_image_root_window,
183 void expose_event(GtkWidget * w, GdkEventExpose *event, gpointer data){
190 /* SpiImage grabbing and convertion routines from gdk-pixbuf-xlib */
192 convert 1 bits-pixel data
196 rgb1 (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
202 register guint8 data;
204 guint8 *srow = image->data, *orow = pixels;
206 /* convert upto 8 pixels/time */
207 /* its probably not worth trying to make this run very fast, who uses
208 1 bit displays anymore? */
209 width = image->width;
210 height = image->height;
211 bpl = image->bytes_per_line;
213 for (yy = 0; yy < height; yy++) {
217 for (xx = 0; xx < width; xx ++) {
218 data = srow[xx >> 3] >> (7 - (xx & 7)) & 1;
219 *o++ = colormap->colors[data].red;
220 *o++ = colormap->colors[data].green;
221 *o++ = colormap->colors[data].blue;
229 convert 1 bits/pixel data
233 rgb1a (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
239 register guint8 data;
241 guint8 *srow = image->data, *orow = pixels;
244 /* convert upto 8 pixels/time */
245 /* its probably not worth trying to make this run very fast, who uses
246 1 bit displays anymore? */
247 width = image->width;
248 height = image->height;
249 bpl = image->bytes_per_line;
251 for (xx = 0; xx < 2; xx++) {
253 remap[xx] = 0xff000000
254 | colormap->colors[xx].blue << 16
255 | colormap->colors[xx].green << 8
256 | colormap->colors[xx].red;
259 | colormap->colors[xx].red << 24
260 | colormap->colors[xx].green << 16
261 | colormap->colors[xx].blue << 8;
265 for (yy = 0; yy < height; yy++) {
269 for (xx = 0; xx < width; xx ++) {
270 data = srow[xx >> 3] >> (7 - (xx & 7)) & 1;
279 convert 8 bits/pixel data
283 rgb8 (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
289 register guint32 data;
290 guint8 *srow = image->data, *orow = pixels;
294 width = image->width;
295 height = image->height;
296 bpl = image->bytes_per_line;
298 mask = mask_table[image->depth];
300 for (yy = 0; yy < height; yy++) {
303 for (xx = 0; xx < width; xx++) {
305 *o++ = colormap->colors[data].red;
306 *o++ = colormap->colors[data].green;
307 *o++ = colormap->colors[data].blue;
315 convert 8 bits/pixel data
319 rgb8a (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
325 register guint32 data;
327 register guint8 *s; /* read 2 pixels at once */
329 guint8 *srow = image->data, *orow = pixels;
331 width = image->width;
332 height = image->height;
333 bpl = image->bytes_per_line;
335 mask = mask_table[image->depth];
337 for (xx = 0; xx < colormap->size; xx++) {
339 remap[xx] = 0xff000000
340 | colormap->colors[xx].blue << 16
341 | colormap->colors[xx].green << 8
342 | colormap->colors[xx].red;
345 | colormap->colors[xx].red << 24
346 | colormap->colors[xx].green << 16
347 | colormap->colors[xx].blue << 8;
351 for (yy = 0; yy < height; yy++) {
353 o = (guint32 *) orow;
354 for (xx = 0; xx < width; xx ++) {
364 convert 16 bits/pixel data
369 rgb565lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
376 register guint32 *s; /* read 2 pixels at once */
378 register guint8 *s; /* read 2 pixels at once */
381 guint8 *srow = image->data, *orow = pixels;
383 width = image->width;
384 height = image->height;
385 bpl = image->bytes_per_line;
387 for (yy = 0; yy < height; yy++) {
389 s = (guint32 *) srow;
393 o = (guint16 *) orow;
394 for (xx = 1; xx < width; xx += 2) {
395 register guint32 data;
398 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
399 | (data & 0x7e0) << 5 | (data & 0x600) >> 1;
400 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
401 | (data & 0xf8000000) >> 16 | (data & 0xe0000000) >> 21;
402 *o++ = (data & 0x7e00000) >> 19 | (data & 0x6000000) >> 25
403 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
405 /* swap endianness first */
406 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
408 *o++ = (data & 0xf800) | (data & 0xe000) >> 5
409 | (data & 0x7e0) >> 3 | (data & 0x600) >> 9;
410 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
411 | (data & 0xf8000000) >> 24 | (data & 0xe0000000) >> 29;
412 *o++ = (data & 0x7e00000) >> 11 | (data & 0x6000000) >> 17
413 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
416 /* check for last remaining pixel */
418 register guint16 data;
420 data = *((short *) s);
422 data = *((short *) s);
423 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
425 ((char *) o)[0] = ((data >> 8) & 0xf8) | ((data >> 13) & 0x7);
426 ((char *) o)[1] = ((data >> 3) & 0xfc) | ((data >> 9) & 0x3);
427 ((char *) o)[2] = ((data << 3) & 0xf8) | ((data >> 2) & 0x7);
435 convert 16 bits/pixel data
440 rgb565msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
447 register guint8 *s; /* need to swap data order */
449 register guint32 *s; /* read 2 pixels at once */
452 guint8 *srow = image->data, *orow = pixels;
454 width = image->width;
455 height = image->height;
456 bpl = image->bytes_per_line;
458 for (yy = 0; yy < height; yy++) {
462 s = (guint32 *) srow;
464 o = (guint16 *) orow;
465 for (xx = 1; xx < width; xx += 2) {
466 register guint32 data;
468 /* swap endianness first */
469 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
471 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
472 | (data & 0x7e0) << 5 | (data & 0x600) >> 1;
473 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
474 | (data & 0xf8000000) >> 16 | (data & 0xe0000000) >> 21;
475 *o++ = (data & 0x7e00000) >> 19 | (data & 0x6000000) >> 25
476 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
479 *o++ = (data & 0xf800) | (data & 0xe000) >> 5
480 | (data & 0x7e0) >> 3 | (data & 0x600) >> 9;
481 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
482 | (data & 0xf8000000) >> 24 | (data & 0xe0000000) >> 29;
483 *o++ = (data & 0x7e00000) >> 11 | (data & 0x6000000) >> 17
484 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
487 /* check for last remaining pixel */
489 register guint16 data;
491 data = *((short *) s);
492 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
494 data = *((short *) s);
496 ((char *) o)[0] = ((data >> 8) & 0xf8) | ((data >> 13) & 0x7);
497 ((char *) o)[1] = ((data >> 3) & 0xfc) | ((data >> 9) & 0x3);
498 ((char *) o)[2] = ((data << 3) & 0xf8) | ((data >> 2) & 0x7);
506 convert 16 bits/pixel data
511 rgb565alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
518 register guint16 *s; /* read 1 pixels at once */
524 guint8 *srow = image->data, *orow = pixels;
526 width = image->width;
527 height = image->height;
528 bpl = image->bytes_per_line;
530 for (yy = 0; yy < height; yy++) {
532 s = (guint16 *) srow;
536 o = (guint32 *) orow;
537 for (xx = 0; xx < width; xx ++) {
538 register guint32 data;
539 /* rrrrrggg gggbbbbb -> rrrrrRRR ggggggGG bbbbbBBB aaaaaaaa */
540 /* little endian: aaaaaaaa bbbbbBBB ggggggGG rrrrrRRR */
543 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
544 | (data & 0x7e0) << 5 | (data & 0x600) >> 1
545 | (data & 0x1f) << 19 | (data & 0x1c) << 14
548 /* swap endianness first */
549 data = s[0] | s[1] << 8;
551 *o++ = (data & 0xf800) << 16 | (data & 0xe000) << 11
552 | (data & 0x7e0) << 13 | (data & 0x600) << 7
553 | (data & 0x1f) << 11 | (data & 0x1c) << 6
563 convert 16 bits/pixel data
568 rgb565amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
577 register guint16 *s; /* read 1 pixels at once */
581 guint8 *srow = image->data, *orow = pixels;
583 width = image->width;
584 height = image->height;
585 bpl = image->bytes_per_line;
587 for (yy = 0; yy < height; yy++) {
589 o = (guint32 *) orow;
590 for (xx = 0; xx < width; xx ++) {
591 register guint32 data;
592 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggg00 bbbbbBBB aaaaaaaa */
593 /* little endian: aaaaaaaa bbbbbBBB gggggg00 rrrrrRRR */
595 /* swap endianness first */
596 data = s[0] | s[1] << 8;
598 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
599 | (data & 0x7e0) << 5 | (data & 0x600) >> 1
600 | (data & 0x1f) << 19 | (data & 0x1c) << 14
604 *o++ = (data & 0xf800) << 16 | (data & 0xe000) << 11
605 | (data & 0x7e0) << 13 | (data & 0x600) << 7
606 | (data & 0x1f) << 11 | (data & 0x1c) << 6
616 convert 15 bits/pixel data
621 rgb555lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
628 register guint32 *s; /* read 2 pixels at once */
630 register guint8 *s; /* read 2 pixels at once */
633 guint8 *srow = image->data, *orow = pixels;
635 width = image->width;
636 height = image->height;
637 bpl = image->bytes_per_line;
639 for (yy = 0; yy < height; yy++) {
641 s = (guint32 *) srow;
645 o = (guint16 *) orow;
646 for (xx = 1; xx < width; xx += 2) {
647 register guint32 data;
650 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
651 | (data & 0x3e0) << 6 | (data & 0x380) << 1;
652 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
653 | (data & 0x7c000000) >> 15 | (data & 0x70000000) >> 20;
654 *o++ = (data & 0x3e00000) >> 18 | (data & 0x3800000) >> 23
655 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
657 /* swap endianness first */
658 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
660 *o++ = (data & 0x7c00) << 1 | (data & 0x7000) >> 4
661 | (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
662 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
663 | (data & 0x7c000000) >> 23 | (data & 0x70000000) >> 28;
664 *o++ = (data & 0x3e00000) >> 10 | (data & 0x3800000) >> 15
665 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
668 /* check for last remaining pixel */
670 register guint16 data;
672 data = *((short *) s);
674 data = *((short *) s);
675 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
677 ((char *) o)[0] = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12;
678 ((char *) o)[1] = (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
679 ((char *) o)[2] = (data & 0x1f) << 3 | (data & 0x1c) >> 2;
687 convert 15 bits/pixel data
692 rgb555msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
699 register guint8 *s; /* read 2 pixels at once */
701 register guint32 *s; /* read 2 pixels at once */
704 guint8 *srow = image->data, *orow = pixels;
706 width = image->width;
707 height = image->height;
708 bpl = image->bytes_per_line;
710 for (yy = 0; yy < height; yy++) {
712 o = (guint16 *) orow;
713 for (xx = 1; xx < width; xx += 2) {
714 register guint32 data;
716 /* swap endianness first */
717 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
719 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
720 | (data & 0x3e0) << 6 | (data & 0x380) << 1;
721 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
722 | (data & 0x7c000000) >> 15 | (data & 0x70000000) >> 20;
723 *o++ = (data & 0x3e00000) >> 18 | (data & 0x3800000) >> 23
724 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
727 *o++ = (data & 0x7c00) << 1 | (data & 0x7000) >> 4
728 | (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
729 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
730 | (data & 0x7c000000) >> 23 | (data & 0x70000000) >> 28;
731 *o++ = (data & 0x3e00000) >> 10 | (data & 0x3800000) >> 15
732 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
735 /* check for last remaining pixel */
737 register guint16 data;
739 data = *((short *) s);
740 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
742 data = *((short *) s);
744 ((char *) o)[0] = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12;
745 ((char *) o)[1] = (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
746 ((char *) o)[2] = (data & 0x1f) << 3 | (data & 0x1c) >> 2;
754 convert 15 bits/pixel data
759 rgb555alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
766 register guint16 *s; /* read 1 pixels at once */
772 guint8 *srow = image->data, *orow = pixels;
774 width = image->width;
775 height = image->height;
776 bpl = image->bytes_per_line;
778 for (yy = 0; yy < height; yy++) {
780 s = (guint16 *) srow;
784 o = (guint32 *) orow;
785 for (xx = 0; xx < width; xx++) {
786 register guint32 data;
787 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggGGG bbbbbBBB aaaaaaaa */
788 /* little endian: aaaaaaaa bbbbbBBB gggggGGG rrrrrRRR */
791 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
792 | (data & 0x3e0) << 6 | (data & 0x380) << 1
793 | (data & 0x1f) << 19 | (data & 0x1c) << 14
796 /* swap endianness first */
797 data = s[0] | s[1] << 8;
799 *o++ = (data & 0x7c00) << 17 | (data & 0x7000) << 12
800 | (data & 0x3e0) << 14 | (data & 0x380) << 9
801 | (data & 0x1f) << 11 | (data & 0x1c) << 6
811 convert 15 bits/pixel data
816 rgb555amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
823 register guint16 *s; /* read 1 pixels at once */
829 guint8 *srow = image->data, *orow = pixels;
831 width = image->width;
832 height = image->height;
833 bpl = image->bytes_per_line;
835 for (yy = 0; yy < height; yy++) {
837 s = (guint16 *) srow;
841 o = (guint32 *) orow;
842 for (xx = 0; xx < width; xx++) {
843 register guint32 data;
844 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggGGG bbbbbBBB aaaaaaaa */
845 /* little endian: aaaaaaaa bbbbbBBB gggggGGG rrrrrRRR */
847 /* swap endianness first */
848 data = s[0] | s[1] << 8;
850 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
851 | (data & 0x3e0) << 6 | (data & 0x380) << 1
852 | (data & 0x1f) << 19 | (data & 0x1c) << 14
856 *o++ = (data & 0x7c00) << 17 | (data & 0x7000) << 12
857 | (data & 0x3e0) << 14 | (data & 0x380) << 9
858 | (data & 0x1f) << 11 | (data & 0x1c) << 6
869 rgb888alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
875 guint8 *s; /* for byte order swapping */
877 guint8 *srow = image->data, *orow = pixels;
879 width = image->width;
880 height = image->height;
881 bpl = image->bytes_per_line;
884 for (yy = 0; yy < height; yy++) {
887 for (xx = 0; xx < width; xx++) {
900 rgb888lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
906 guint8 *srow = image->data, *orow = pixels;
909 width = image->width;
910 height = image->height;
911 bpl = image->bytes_per_line;
914 for (yy = 0; yy < height; yy++) {
917 for (xx = 0; xx < width; xx++) {
929 rgb888amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
935 guint8 *srow = image->data, *orow = pixels;
940 guint8 *s; /* for byte order swapping */
945 width = image->width;
946 height = image->height;
947 bpl = image->bytes_per_line;
950 for (yy = 0; yy < height; yy++) {
952 s = (guint32 *) srow;
953 o = (guint32 *) orow;
958 for (xx = 0; xx < width; xx++) {
966 *o++ = (*s << 8) | 0xff; /* untested */
976 rgb888msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
982 guint8 *srow = image->data, *orow = pixels;
987 width = image->width;
988 height = image->height;
989 bpl = image->bytes_per_line;
991 for (yy = 0; yy < height; yy++) {
994 for (xx = 0; xx < width; xx++) {
1005 visual_decompose_mask (gulong mask,
1012 while (!(mask & 0x1)) {
1017 while (mask & 0x1) {
1025 This should work correctly with any display/any endianness, but will probably
1029 convert_real_slow (XImage *image, guchar *pixels, int rowstride, xlib_colormap *cmap, int alpha)
1034 guint8 *srow = image->data, *orow = pixels;
1041 int red_shift, red_prec, green_shift, green_prec, blue_shift, blue_prec;
1043 width = image->width;
1044 height = image->height;
1045 bpl = image->bytes_per_line;
1048 visual_decompose_mask (v->red_mask, &red_shift, &red_prec);
1049 visual_decompose_mask (v->green_mask, &green_shift, &green_prec);
1050 visual_decompose_mask (v->blue_mask, &blue_shift, &blue_prec);
1052 for (yy = 0; yy < height; yy++) {
1055 for (xx = 0; xx < width; xx++) {
1056 pixel = XGetPixel (image, xx, yy);
1058 /* I assume this is right for static & greyscale's too? */
1063 *o++ = cmap->colors[pixel].red;
1064 *o++ = cmap->colors[pixel].green;
1065 *o++ = cmap->colors[pixel].blue;
1068 /* This is odd because it must sometimes shift left (otherwise
1069 I'd just shift >> (*_shift - 8 + *_prec + <0-7>). This logic
1070 should work for all bit sizes/shifts/etc. */
1072 for (i = 24; i < 32; i += red_prec)
1073 component |= ((pixel & v->red_mask) << (32 - red_shift - red_prec)) >> i;
1076 for (i = 24; i < 32; i += green_prec)
1077 component |= ((pixel & v->green_mask) << (32 - green_shift - green_prec)) >> i;
1080 for (i = 24; i < 32; i += blue_prec)
1081 component |= ((pixel & v->blue_mask) << (32 - blue_shift - blue_prec)) >> i;
1085 *o++ = cmap->colors[((pixel & v->red_mask) << (32 - red_shift - red_prec)) >> 24].red;
1086 *o++ = cmap->colors[((pixel & v->green_mask) << (32 - green_shift - green_prec)) >> 24].green;
1087 *o++ = cmap->colors[((pixel & v->blue_mask) << (32 - blue_shift - blue_prec)) >> 24].blue;
1098 static xlib_colormap *
1099 xlib_get_colormap (Colormap id, Visual *visual, MagnifierData *mag_data)
1102 xlib_colormap *xc = g_new (xlib_colormap, 1);
1104 xc->size = visual->map_entries;
1105 xc->colors = g_new (XColor, xc->size);
1106 xc->visual = visual;
1109 for (i = 0; i < xc->size; i++) {
1110 xc->colors[i].pixel = i;
1111 xc->colors[i].flags = DoRed | DoGreen | DoBlue;
1114 XQueryColors (mag_data->source_display, xc->colormap, xc->colors, xc->size);
1119 typedef void (* cfunc) (XImage *image, guchar *pixels, int rowstride, xlib_colormap *cmap);
1120 static cfunc convert_map[] = {
1121 rgb1,rgb1,rgb1a,rgb1a,
1122 rgb8,rgb8,rgb8a,rgb8a,
1123 rgb555lsb,rgb555msb,rgb555alsb,rgb555amsb,
1124 rgb565lsb,rgb565msb,rgb565alsb,rgb565amsb,
1125 rgb888lsb,rgb888msb,rgb888alsb,rgb888amsb
1129 rgbconvert (XImage *image, guchar *pixels, int rowstride, int alpha, xlib_colormap *cmap,
1130 MagnifierData *mag_data)
1132 int index = (image->byte_order == MSBFirst) | (alpha != 0) << 1;
1133 int bank=5; /* default fallback converter */
1134 Visual *v = cmap->visual;
1135 if (mag_data->fast_rgb_convert)
1138 /* I assume this is right for static & greyscale's too? */
1143 switch (image->bits_per_pixel) {
1153 switch (image->depth) {
1155 if (v->red_mask == 0x7c00 && v->green_mask == 0x3e0 && v->blue_mask == 0x1f
1156 && image->bits_per_pixel == 16)
1160 if (v->red_mask == 0xf800 && v->green_mask == 0x7e0 && v->blue_mask == 0x1f
1161 && image->bits_per_pixel == 16)
1166 if (v->red_mask == 0xff0000 && v->green_mask == 0xff00 && v->blue_mask == 0xff
1167 && image->bits_per_pixel == 32)
1173 /* always use the slow version */
1179 convert_real_slow(image, pixels, rowstride, cmap, alpha);
1182 (* convert_map[index]) (image, pixels, rowstride, cmap);
1186 void get_root_image(Window src, GdkPixbuf *dest, int src_x, int src_y, MagnifierData *mag_data) {
1188 int width = mag_data->mag_width/mag_data->factor_x;
1189 int height = mag_data->mag_height/mag_data->factor_y;
1191 /* Get SpiImage in ZPixmap format (packed bits). */
1192 image = XGetImage (mag_data->source_display, src, src_x, src_y,
1193 width, height, AllPlanes, ZPixmap);
1194 g_assert(image != NULL);
1197 XWindowAttributes wa;
1198 XGetWindowAttributes (mag_data->source_display, src, &wa);
1199 x_cmap = xlib_get_colormap (wa.colormap, wa.visual, mag_data);
1201 /* we offset into the image data based on the position we are retrieving from */
1202 rgbconvert (image, gdk_pixbuf_get_pixels(dest),
1203 gdk_pixbuf_get_rowstride(dest),
1204 gdk_pixbuf_get_has_alpha(dest),
1208 /* would like to use GDK routine, but since we don't have multi-head
1209 yet, we have to use X */
1211 XDestroyImage (image);