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);
125 gdk_window_raise (drawing_area->window);
129 void update_image(MagnifierData *mag_data)
131 int x, y, total_width, total_height;
133 if(mag_data->follow_mouse){
134 Window root_return, child_return;
135 int win_x_return,win_y_return;
136 unsigned int mask_return;
137 XQueryPointer(mag_data->source_display,spi_image_root_window,
138 &root_return,&child_return,
139 &mag_data->center.x,&mag_data->center.y,
140 &win_x_return,&win_y_return,&mask_return);
143 total_width = DisplayWidth (mag_data->source_display,screen_num);
144 total_height = DisplayHeight(mag_data->source_display,screen_num);
146 x = mag_data->center.x - mag_data->mag_width/mag_data->factor_x/2;
147 y = mag_data->center.y - mag_data->mag_height/mag_data->factor_y/2;
149 if(mag_data->center.x < mag_data->mag_width/mag_data->factor_x/2)
151 if(mag_data->center.x > (total_width - mag_data->mag_width/mag_data->factor_x/2))
152 x = total_width - mag_data->mag_width/mag_data->factor_x;
153 if(mag_data->center.y < mag_data->mag_height/mag_data->factor_y/2)
155 if(mag_data->center.y > (total_height - mag_data->mag_height/mag_data->factor_y/2))
156 y = total_height - mag_data->mag_height/mag_data->factor_y;
162 printf("p = (%d,%d), x,y = (%d,%d), h,w = (%d,%d), ht,wt = (%d,%d)\n",
166 mag_data->mag_height,mag_data->mag_width,
170 if(mag_data->factor_x != old_factor_x || mag_data->factor_y != old_factor_y){
171 g_object_unref((GObject *)image);
172 image = gdk_pixbuf_new (GDK_COLORSPACE_RGB,FALSE, 8,
173 DisplayWidth (mag_data->target_display,screen_num)/mag_data->factor_x,
174 DisplayHeight(mag_data->target_display,screen_num)/mag_data->factor_y);
175 /* yes, use target display above, since the size of the area grabbed depends on the target */
176 old_factor_x = mag_data->factor_x;
177 old_factor_y = mag_data->factor_y;
179 get_root_image(spi_image_root_window,
185 void expose_event(GtkWidget * w, GdkEventExpose *event, gpointer data){
192 /* SpiImage grabbing and convertion routines from gdk-pixbuf-xlib */
194 convert 1 bits-pixel data
198 rgb1 (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
204 register guint8 data;
206 guint8 *srow = image->data, *orow = pixels;
208 /* convert upto 8 pixels/time */
209 /* its probably not worth trying to make this run very fast, who uses
210 1 bit displays anymore? */
211 width = image->width;
212 height = image->height;
213 bpl = image->bytes_per_line;
215 for (yy = 0; yy < height; yy++) {
219 for (xx = 0; xx < width; xx ++) {
220 data = srow[xx >> 3] >> (7 - (xx & 7)) & 1;
221 *o++ = colormap->colors[data].red;
222 *o++ = colormap->colors[data].green;
223 *o++ = colormap->colors[data].blue;
231 convert 1 bits/pixel data
235 rgb1a (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
241 register guint8 data;
243 guint8 *srow = image->data, *orow = pixels;
246 /* convert upto 8 pixels/time */
247 /* its probably not worth trying to make this run very fast, who uses
248 1 bit displays anymore? */
249 width = image->width;
250 height = image->height;
251 bpl = image->bytes_per_line;
253 for (xx = 0; xx < 2; xx++) {
255 remap[xx] = 0xff000000
256 | colormap->colors[xx].blue << 16
257 | colormap->colors[xx].green << 8
258 | colormap->colors[xx].red;
261 | colormap->colors[xx].red << 24
262 | colormap->colors[xx].green << 16
263 | colormap->colors[xx].blue << 8;
267 for (yy = 0; yy < height; yy++) {
271 for (xx = 0; xx < width; xx ++) {
272 data = srow[xx >> 3] >> (7 - (xx & 7)) & 1;
281 convert 8 bits/pixel data
285 rgb8 (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
291 register guint32 data;
292 guint8 *srow = image->data, *orow = pixels;
296 width = image->width;
297 height = image->height;
298 bpl = image->bytes_per_line;
300 mask = mask_table[image->depth];
302 for (yy = 0; yy < height; yy++) {
305 for (xx = 0; xx < width; xx++) {
307 *o++ = colormap->colors[data].red;
308 *o++ = colormap->colors[data].green;
309 *o++ = colormap->colors[data].blue;
317 convert 8 bits/pixel data
321 rgb8a (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
327 register guint32 data;
329 register guint8 *s; /* read 2 pixels at once */
331 guint8 *srow = image->data, *orow = pixels;
333 width = image->width;
334 height = image->height;
335 bpl = image->bytes_per_line;
337 mask = mask_table[image->depth];
339 for (xx = 0; xx < colormap->size; xx++) {
341 remap[xx] = 0xff000000
342 | colormap->colors[xx].blue << 16
343 | colormap->colors[xx].green << 8
344 | colormap->colors[xx].red;
347 | colormap->colors[xx].red << 24
348 | colormap->colors[xx].green << 16
349 | colormap->colors[xx].blue << 8;
353 for (yy = 0; yy < height; yy++) {
355 o = (guint32 *) orow;
356 for (xx = 0; xx < width; xx ++) {
366 convert 16 bits/pixel data
371 rgb565lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
378 register guint32 *s; /* read 2 pixels at once */
380 register guint8 *s; /* read 2 pixels at once */
383 guint8 *srow = image->data, *orow = pixels;
385 width = image->width;
386 height = image->height;
387 bpl = image->bytes_per_line;
389 for (yy = 0; yy < height; yy++) {
391 s = (guint32 *) srow;
395 o = (guint16 *) orow;
396 for (xx = 1; xx < width; xx += 2) {
397 register guint32 data;
400 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
401 | (data & 0x7e0) << 5 | (data & 0x600) >> 1;
402 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
403 | (data & 0xf8000000) >> 16 | (data & 0xe0000000) >> 21;
404 *o++ = (data & 0x7e00000) >> 19 | (data & 0x6000000) >> 25
405 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
407 /* swap endianness first */
408 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
410 *o++ = (data & 0xf800) | (data & 0xe000) >> 5
411 | (data & 0x7e0) >> 3 | (data & 0x600) >> 9;
412 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
413 | (data & 0xf8000000) >> 24 | (data & 0xe0000000) >> 29;
414 *o++ = (data & 0x7e00000) >> 11 | (data & 0x6000000) >> 17
415 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
418 /* check for last remaining pixel */
420 register guint16 data;
422 data = *((short *) s);
424 data = *((short *) s);
425 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
427 ((char *) o)[0] = ((data >> 8) & 0xf8) | ((data >> 13) & 0x7);
428 ((char *) o)[1] = ((data >> 3) & 0xfc) | ((data >> 9) & 0x3);
429 ((char *) o)[2] = ((data << 3) & 0xf8) | ((data >> 2) & 0x7);
437 convert 16 bits/pixel data
442 rgb565msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
449 register guint8 *s; /* need to swap data order */
451 register guint32 *s; /* read 2 pixels at once */
454 guint8 *srow = image->data, *orow = pixels;
456 width = image->width;
457 height = image->height;
458 bpl = image->bytes_per_line;
460 for (yy = 0; yy < height; yy++) {
464 s = (guint32 *) srow;
466 o = (guint16 *) orow;
467 for (xx = 1; xx < width; xx += 2) {
468 register guint32 data;
470 /* swap endianness first */
471 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
473 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
474 | (data & 0x7e0) << 5 | (data & 0x600) >> 1;
475 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
476 | (data & 0xf8000000) >> 16 | (data & 0xe0000000) >> 21;
477 *o++ = (data & 0x7e00000) >> 19 | (data & 0x6000000) >> 25
478 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
481 *o++ = (data & 0xf800) | (data & 0xe000) >> 5
482 | (data & 0x7e0) >> 3 | (data & 0x600) >> 9;
483 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
484 | (data & 0xf8000000) >> 24 | (data & 0xe0000000) >> 29;
485 *o++ = (data & 0x7e00000) >> 11 | (data & 0x6000000) >> 17
486 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
489 /* check for last remaining pixel */
491 register guint16 data;
493 data = *((short *) s);
494 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
496 data = *((short *) s);
498 ((char *) o)[0] = ((data >> 8) & 0xf8) | ((data >> 13) & 0x7);
499 ((char *) o)[1] = ((data >> 3) & 0xfc) | ((data >> 9) & 0x3);
500 ((char *) o)[2] = ((data << 3) & 0xf8) | ((data >> 2) & 0x7);
508 convert 16 bits/pixel data
513 rgb565alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
520 register guint16 *s; /* read 1 pixels at once */
526 guint8 *srow = image->data, *orow = pixels;
528 width = image->width;
529 height = image->height;
530 bpl = image->bytes_per_line;
532 for (yy = 0; yy < height; yy++) {
534 s = (guint16 *) srow;
538 o = (guint32 *) orow;
539 for (xx = 0; xx < width; xx ++) {
540 register guint32 data;
541 /* rrrrrggg gggbbbbb -> rrrrrRRR ggggggGG bbbbbBBB aaaaaaaa */
542 /* little endian: aaaaaaaa bbbbbBBB ggggggGG rrrrrRRR */
545 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
546 | (data & 0x7e0) << 5 | (data & 0x600) >> 1
547 | (data & 0x1f) << 19 | (data & 0x1c) << 14
550 /* swap endianness first */
551 data = s[0] | s[1] << 8;
553 *o++ = (data & 0xf800) << 16 | (data & 0xe000) << 11
554 | (data & 0x7e0) << 13 | (data & 0x600) << 7
555 | (data & 0x1f) << 11 | (data & 0x1c) << 6
565 convert 16 bits/pixel data
570 rgb565amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
579 register guint16 *s; /* read 1 pixels at once */
583 guint8 *srow = image->data, *orow = pixels;
585 width = image->width;
586 height = image->height;
587 bpl = image->bytes_per_line;
589 for (yy = 0; yy < height; yy++) {
591 o = (guint32 *) orow;
592 for (xx = 0; xx < width; xx ++) {
593 register guint32 data;
594 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggg00 bbbbbBBB aaaaaaaa */
595 /* little endian: aaaaaaaa bbbbbBBB gggggg00 rrrrrRRR */
597 /* swap endianness first */
598 data = s[0] | s[1] << 8;
600 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
601 | (data & 0x7e0) << 5 | (data & 0x600) >> 1
602 | (data & 0x1f) << 19 | (data & 0x1c) << 14
606 *o++ = (data & 0xf800) << 16 | (data & 0xe000) << 11
607 | (data & 0x7e0) << 13 | (data & 0x600) << 7
608 | (data & 0x1f) << 11 | (data & 0x1c) << 6
618 convert 15 bits/pixel data
623 rgb555lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
630 register guint32 *s; /* read 2 pixels at once */
632 register guint8 *s; /* read 2 pixels at once */
635 guint8 *srow = image->data, *orow = pixels;
637 width = image->width;
638 height = image->height;
639 bpl = image->bytes_per_line;
641 for (yy = 0; yy < height; yy++) {
643 s = (guint32 *) srow;
647 o = (guint16 *) orow;
648 for (xx = 1; xx < width; xx += 2) {
649 register guint32 data;
652 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
653 | (data & 0x3e0) << 6 | (data & 0x380) << 1;
654 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
655 | (data & 0x7c000000) >> 15 | (data & 0x70000000) >> 20;
656 *o++ = (data & 0x3e00000) >> 18 | (data & 0x3800000) >> 23
657 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
659 /* swap endianness first */
660 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
662 *o++ = (data & 0x7c00) << 1 | (data & 0x7000) >> 4
663 | (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
664 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
665 | (data & 0x7c000000) >> 23 | (data & 0x70000000) >> 28;
666 *o++ = (data & 0x3e00000) >> 10 | (data & 0x3800000) >> 15
667 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
670 /* check for last remaining pixel */
672 register guint16 data;
674 data = *((short *) s);
676 data = *((short *) s);
677 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
679 ((char *) o)[0] = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12;
680 ((char *) o)[1] = (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
681 ((char *) o)[2] = (data & 0x1f) << 3 | (data & 0x1c) >> 2;
689 convert 15 bits/pixel data
694 rgb555msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
701 register guint8 *s; /* read 2 pixels at once */
703 register guint32 *s; /* read 2 pixels at once */
706 guint8 *srow = image->data, *orow = pixels;
708 width = image->width;
709 height = image->height;
710 bpl = image->bytes_per_line;
712 for (yy = 0; yy < height; yy++) {
714 o = (guint16 *) orow;
715 for (xx = 1; xx < width; xx += 2) {
716 register guint32 data;
718 /* swap endianness first */
719 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
721 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
722 | (data & 0x3e0) << 6 | (data & 0x380) << 1;
723 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
724 | (data & 0x7c000000) >> 15 | (data & 0x70000000) >> 20;
725 *o++ = (data & 0x3e00000) >> 18 | (data & 0x3800000) >> 23
726 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
729 *o++ = (data & 0x7c00) << 1 | (data & 0x7000) >> 4
730 | (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
731 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
732 | (data & 0x7c000000) >> 23 | (data & 0x70000000) >> 28;
733 *o++ = (data & 0x3e00000) >> 10 | (data & 0x3800000) >> 15
734 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
737 /* check for last remaining pixel */
739 register guint16 data;
741 data = *((short *) s);
742 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
744 data = *((short *) s);
746 ((char *) o)[0] = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12;
747 ((char *) o)[1] = (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
748 ((char *) o)[2] = (data & 0x1f) << 3 | (data & 0x1c) >> 2;
756 convert 15 bits/pixel data
761 rgb555alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
768 register guint16 *s; /* read 1 pixels at once */
774 guint8 *srow = image->data, *orow = pixels;
776 width = image->width;
777 height = image->height;
778 bpl = image->bytes_per_line;
780 for (yy = 0; yy < height; yy++) {
782 s = (guint16 *) srow;
786 o = (guint32 *) orow;
787 for (xx = 0; xx < width; xx++) {
788 register guint32 data;
789 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggGGG bbbbbBBB aaaaaaaa */
790 /* little endian: aaaaaaaa bbbbbBBB gggggGGG rrrrrRRR */
793 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
794 | (data & 0x3e0) << 6 | (data & 0x380) << 1
795 | (data & 0x1f) << 19 | (data & 0x1c) << 14
798 /* swap endianness first */
799 data = s[0] | s[1] << 8;
801 *o++ = (data & 0x7c00) << 17 | (data & 0x7000) << 12
802 | (data & 0x3e0) << 14 | (data & 0x380) << 9
803 | (data & 0x1f) << 11 | (data & 0x1c) << 6
813 convert 15 bits/pixel data
818 rgb555amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
825 register guint16 *s; /* read 1 pixels at once */
831 guint8 *srow = image->data, *orow = pixels;
833 width = image->width;
834 height = image->height;
835 bpl = image->bytes_per_line;
837 for (yy = 0; yy < height; yy++) {
839 s = (guint16 *) srow;
843 o = (guint32 *) orow;
844 for (xx = 0; xx < width; xx++) {
845 register guint32 data;
846 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggGGG bbbbbBBB aaaaaaaa */
847 /* little endian: aaaaaaaa bbbbbBBB gggggGGG rrrrrRRR */
849 /* swap endianness first */
850 data = s[0] | s[1] << 8;
852 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
853 | (data & 0x3e0) << 6 | (data & 0x380) << 1
854 | (data & 0x1f) << 19 | (data & 0x1c) << 14
858 *o++ = (data & 0x7c00) << 17 | (data & 0x7000) << 12
859 | (data & 0x3e0) << 14 | (data & 0x380) << 9
860 | (data & 0x1f) << 11 | (data & 0x1c) << 6
871 rgb888alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
877 guint8 *s; /* for byte order swapping */
879 guint8 *srow = image->data, *orow = pixels;
881 width = image->width;
882 height = image->height;
883 bpl = image->bytes_per_line;
886 for (yy = 0; yy < height; yy++) {
889 for (xx = 0; xx < width; xx++) {
902 rgb888lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
908 guint8 *srow = image->data, *orow = pixels;
911 width = image->width;
912 height = image->height;
913 bpl = image->bytes_per_line;
916 for (yy = 0; yy < height; yy++) {
919 for (xx = 0; xx < width; xx++) {
931 rgb888amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
937 guint8 *srow = image->data, *orow = pixels;
942 guint8 *s; /* for byte order swapping */
947 width = image->width;
948 height = image->height;
949 bpl = image->bytes_per_line;
952 for (yy = 0; yy < height; yy++) {
954 s = (guint32 *) srow;
955 o = (guint32 *) orow;
960 for (xx = 0; xx < width; xx++) {
968 *o++ = (*s << 8) | 0xff; /* untested */
978 rgb888msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
984 guint8 *srow = image->data, *orow = pixels;
989 width = image->width;
990 height = image->height;
991 bpl = image->bytes_per_line;
993 for (yy = 0; yy < height; yy++) {
996 for (xx = 0; xx < width; xx++) {
1007 visual_decompose_mask (gulong mask,
1014 while (!(mask & 0x1)) {
1019 while (mask & 0x1) {
1027 This should work correctly with any display/any endianness, but will probably
1031 convert_real_slow (XImage *image, guchar *pixels, int rowstride, xlib_colormap *cmap, int alpha)
1036 guint8 *srow = image->data, *orow = pixels;
1043 int red_shift, red_prec, green_shift, green_prec, blue_shift, blue_prec;
1045 width = image->width;
1046 height = image->height;
1047 bpl = image->bytes_per_line;
1050 visual_decompose_mask (v->red_mask, &red_shift, &red_prec);
1051 visual_decompose_mask (v->green_mask, &green_shift, &green_prec);
1052 visual_decompose_mask (v->blue_mask, &blue_shift, &blue_prec);
1054 for (yy = 0; yy < height; yy++) {
1057 for (xx = 0; xx < width; xx++) {
1058 pixel = XGetPixel (image, xx, yy);
1060 /* I assume this is right for static & greyscale's too? */
1065 *o++ = cmap->colors[pixel].red;
1066 *o++ = cmap->colors[pixel].green;
1067 *o++ = cmap->colors[pixel].blue;
1070 /* This is odd because it must sometimes shift left (otherwise
1071 I'd just shift >> (*_shift - 8 + *_prec + <0-7>). This logic
1072 should work for all bit sizes/shifts/etc. */
1074 for (i = 24; i < 32; i += red_prec)
1075 component |= ((pixel & v->red_mask) << (32 - red_shift - red_prec)) >> i;
1078 for (i = 24; i < 32; i += green_prec)
1079 component |= ((pixel & v->green_mask) << (32 - green_shift - green_prec)) >> i;
1082 for (i = 24; i < 32; i += blue_prec)
1083 component |= ((pixel & v->blue_mask) << (32 - blue_shift - blue_prec)) >> i;
1087 *o++ = cmap->colors[((pixel & v->red_mask) << (32 - red_shift - red_prec)) >> 24].red;
1088 *o++ = cmap->colors[((pixel & v->green_mask) << (32 - green_shift - green_prec)) >> 24].green;
1089 *o++ = cmap->colors[((pixel & v->blue_mask) << (32 - blue_shift - blue_prec)) >> 24].blue;
1100 static xlib_colormap *
1101 xlib_get_colormap (Colormap id, Visual *visual, MagnifierData *mag_data)
1104 xlib_colormap *xc = g_new (xlib_colormap, 1);
1106 xc->size = visual->map_entries;
1107 xc->colors = g_new (XColor, xc->size);
1108 xc->visual = visual;
1111 for (i = 0; i < xc->size; i++) {
1112 xc->colors[i].pixel = i;
1113 xc->colors[i].flags = DoRed | DoGreen | DoBlue;
1116 XQueryColors (mag_data->source_display, xc->colormap, xc->colors, xc->size);
1121 typedef void (* cfunc) (XImage *image, guchar *pixels, int rowstride, xlib_colormap *cmap);
1122 static cfunc convert_map[] = {
1123 rgb1,rgb1,rgb1a,rgb1a,
1124 rgb8,rgb8,rgb8a,rgb8a,
1125 rgb555lsb,rgb555msb,rgb555alsb,rgb555amsb,
1126 rgb565lsb,rgb565msb,rgb565alsb,rgb565amsb,
1127 rgb888lsb,rgb888msb,rgb888alsb,rgb888amsb
1131 rgbconvert (XImage *image, guchar *pixels, int rowstride, int alpha, xlib_colormap *cmap,
1132 MagnifierData *mag_data)
1134 int index = (image->byte_order == MSBFirst) | (alpha != 0) << 1;
1135 int bank=5; /* default fallback converter */
1136 Visual *v = cmap->visual;
1137 if (mag_data->fast_rgb_convert)
1140 /* I assume this is right for static & greyscale's too? */
1145 switch (image->bits_per_pixel) {
1155 switch (image->depth) {
1157 if (v->red_mask == 0x7c00 && v->green_mask == 0x3e0 && v->blue_mask == 0x1f
1158 && image->bits_per_pixel == 16)
1162 if (v->red_mask == 0xf800 && v->green_mask == 0x7e0 && v->blue_mask == 0x1f
1163 && image->bits_per_pixel == 16)
1168 if (v->red_mask == 0xff0000 && v->green_mask == 0xff00 && v->blue_mask == 0xff
1169 && image->bits_per_pixel == 32)
1175 /* always use the slow version */
1181 convert_real_slow(image, pixels, rowstride, cmap, alpha);
1184 (* convert_map[index]) (image, pixels, rowstride, cmap);
1188 void get_root_image(Window src, GdkPixbuf *dest, int src_x, int src_y, MagnifierData *mag_data) {
1190 int width = mag_data->mag_width/mag_data->factor_x;
1191 int height = mag_data->mag_height/mag_data->factor_y;
1193 /* Get SpiImage in ZPixmap format (packed bits). */
1194 image = XGetImage (mag_data->source_display, src, src_x, src_y,
1195 width, height, AllPlanes, ZPixmap);
1196 g_assert(image != NULL);
1199 XWindowAttributes wa;
1200 XGetWindowAttributes (mag_data->source_display, src, &wa);
1201 x_cmap = xlib_get_colormap (wa.colormap, wa.visual, mag_data);
1203 /* we offset into the image data based on the position we are retrieving from */
1204 rgbconvert (image, gdk_pixbuf_get_pixels(dest),
1205 gdk_pixbuf_get_rowstride(dest),
1206 gdk_pixbuf_get_has_alpha(dest),
1210 /* would like to use GDK routine, but since we don't have multi-head
1211 yet, we have to use X */
1213 XDestroyImage (image);