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);
124 /* TODO: raise this window to top on refresh */
128 void update_image(MagnifierData *mag_data)
130 int x, y, total_width, total_height;
132 if(mag_data->follow_mouse){
133 Window root_return, child_return;
134 int win_x_return,win_y_return;
135 unsigned int mask_return;
136 XQueryPointer(mag_data->source_display,spi_image_root_window,
137 &root_return,&child_return,
138 &mag_data->center.x,&mag_data->center.y,
139 &win_x_return,&win_y_return,&mask_return);
142 total_width = DisplayWidth (mag_data->source_display,screen_num);
143 total_height = DisplayHeight(mag_data->source_display,screen_num);
145 x = mag_data->center.x - mag_data->mag_width/mag_data->factor_x/2;
146 y = mag_data->center.y - mag_data->mag_height/mag_data->factor_y/2;
148 if(mag_data->center.x < mag_data->mag_width/mag_data->factor_x/2)
150 if(mag_data->center.x > (total_width - mag_data->mag_width/mag_data->factor_x/2))
151 x = total_width - mag_data->mag_width/mag_data->factor_x;
152 if(mag_data->center.y < mag_data->mag_height/mag_data->factor_y/2)
154 if(mag_data->center.y > (total_height - mag_data->mag_height/mag_data->factor_y/2))
155 y = total_height - mag_data->mag_height/mag_data->factor_y;
161 printf("p = (%d,%d), x,y = (%d,%d), h,w = (%d,%d), ht,wt = (%d,%d)\n",
165 mag_data->mag_height,mag_data->mag_width,
169 if(mag_data->factor_x != old_factor_x || mag_data->factor_y != old_factor_y){
170 g_object_unref((GObject *)image);
171 image = gdk_pixbuf_new (GDK_COLORSPACE_RGB,FALSE, 8,
172 DisplayWidth (mag_data->target_display,screen_num)/mag_data->factor_x,
173 DisplayHeight(mag_data->target_display,screen_num)/mag_data->factor_y);
174 /* yes, use target display above, since the size of the area grabbed depends on the target */
175 old_factor_x = mag_data->factor_x;
176 old_factor_y = mag_data->factor_y;
178 get_root_image(spi_image_root_window,
184 void expose_event(GtkWidget * w, GdkEventExpose *event, gpointer data){
191 /* SpiImage grabbing and convertion routines from gdk-pixbuf-xlib */
193 convert 1 bits-pixel data
197 rgb1 (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
203 register guint8 data;
205 guint8 *srow = image->data, *orow = pixels;
207 /* convert upto 8 pixels/time */
208 /* its probably not worth trying to make this run very fast, who uses
209 1 bit displays anymore? */
210 width = image->width;
211 height = image->height;
212 bpl = image->bytes_per_line;
214 for (yy = 0; yy < height; yy++) {
218 for (xx = 0; xx < width; xx ++) {
219 data = srow[xx >> 3] >> (7 - (xx & 7)) & 1;
220 *o++ = colormap->colors[data].red;
221 *o++ = colormap->colors[data].green;
222 *o++ = colormap->colors[data].blue;
230 convert 1 bits/pixel data
234 rgb1a (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
240 register guint8 data;
242 guint8 *srow = image->data, *orow = pixels;
245 /* convert upto 8 pixels/time */
246 /* its probably not worth trying to make this run very fast, who uses
247 1 bit displays anymore? */
248 width = image->width;
249 height = image->height;
250 bpl = image->bytes_per_line;
252 for (xx = 0; xx < 2; xx++) {
254 remap[xx] = 0xff000000
255 | colormap->colors[xx].blue << 16
256 | colormap->colors[xx].green << 8
257 | colormap->colors[xx].red;
260 | colormap->colors[xx].red << 24
261 | colormap->colors[xx].green << 16
262 | colormap->colors[xx].blue << 8;
266 for (yy = 0; yy < height; yy++) {
270 for (xx = 0; xx < width; xx ++) {
271 data = srow[xx >> 3] >> (7 - (xx & 7)) & 1;
280 convert 8 bits/pixel data
284 rgb8 (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
290 register guint32 data;
291 guint8 *srow = image->data, *orow = pixels;
295 width = image->width;
296 height = image->height;
297 bpl = image->bytes_per_line;
299 mask = mask_table[image->depth];
301 for (yy = 0; yy < height; yy++) {
304 for (xx = 0; xx < width; xx++) {
306 *o++ = colormap->colors[data].red;
307 *o++ = colormap->colors[data].green;
308 *o++ = colormap->colors[data].blue;
316 convert 8 bits/pixel data
320 rgb8a (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
326 register guint32 data;
328 register guint8 *s; /* read 2 pixels at once */
330 guint8 *srow = image->data, *orow = pixels;
332 width = image->width;
333 height = image->height;
334 bpl = image->bytes_per_line;
336 mask = mask_table[image->depth];
338 for (xx = 0; xx < colormap->size; xx++) {
340 remap[xx] = 0xff000000
341 | colormap->colors[xx].blue << 16
342 | colormap->colors[xx].green << 8
343 | colormap->colors[xx].red;
346 | colormap->colors[xx].red << 24
347 | colormap->colors[xx].green << 16
348 | colormap->colors[xx].blue << 8;
352 for (yy = 0; yy < height; yy++) {
354 o = (guint32 *) orow;
355 for (xx = 0; xx < width; xx ++) {
365 convert 16 bits/pixel data
370 rgb565lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
377 register guint32 *s; /* read 2 pixels at once */
379 register guint8 *s; /* read 2 pixels at once */
382 guint8 *srow = image->data, *orow = pixels;
384 width = image->width;
385 height = image->height;
386 bpl = image->bytes_per_line;
388 for (yy = 0; yy < height; yy++) {
390 s = (guint32 *) srow;
394 o = (guint16 *) orow;
395 for (xx = 1; xx < width; xx += 2) {
396 register guint32 data;
399 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
400 | (data & 0x7e0) << 5 | (data & 0x600) >> 1;
401 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
402 | (data & 0xf8000000) >> 16 | (data & 0xe0000000) >> 21;
403 *o++ = (data & 0x7e00000) >> 19 | (data & 0x6000000) >> 25
404 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
406 /* swap endianness first */
407 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
409 *o++ = (data & 0xf800) | (data & 0xe000) >> 5
410 | (data & 0x7e0) >> 3 | (data & 0x600) >> 9;
411 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
412 | (data & 0xf8000000) >> 24 | (data & 0xe0000000) >> 29;
413 *o++ = (data & 0x7e00000) >> 11 | (data & 0x6000000) >> 17
414 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
417 /* check for last remaining pixel */
419 register guint16 data;
421 data = *((short *) s);
423 data = *((short *) s);
424 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
426 ((char *) o)[0] = ((data >> 8) & 0xf8) | ((data >> 13) & 0x7);
427 ((char *) o)[1] = ((data >> 3) & 0xfc) | ((data >> 9) & 0x3);
428 ((char *) o)[2] = ((data << 3) & 0xf8) | ((data >> 2) & 0x7);
436 convert 16 bits/pixel data
441 rgb565msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
448 register guint8 *s; /* need to swap data order */
450 register guint32 *s; /* read 2 pixels at once */
453 guint8 *srow = image->data, *orow = pixels;
455 width = image->width;
456 height = image->height;
457 bpl = image->bytes_per_line;
459 for (yy = 0; yy < height; yy++) {
463 s = (guint32 *) srow;
465 o = (guint16 *) orow;
466 for (xx = 1; xx < width; xx += 2) {
467 register guint32 data;
469 /* swap endianness first */
470 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
472 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
473 | (data & 0x7e0) << 5 | (data & 0x600) >> 1;
474 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
475 | (data & 0xf8000000) >> 16 | (data & 0xe0000000) >> 21;
476 *o++ = (data & 0x7e00000) >> 19 | (data & 0x6000000) >> 25
477 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
480 *o++ = (data & 0xf800) | (data & 0xe000) >> 5
481 | (data & 0x7e0) >> 3 | (data & 0x600) >> 9;
482 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
483 | (data & 0xf8000000) >> 24 | (data & 0xe0000000) >> 29;
484 *o++ = (data & 0x7e00000) >> 11 | (data & 0x6000000) >> 17
485 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
488 /* check for last remaining pixel */
490 register guint16 data;
492 data = *((short *) s);
493 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
495 data = *((short *) s);
497 ((char *) o)[0] = ((data >> 8) & 0xf8) | ((data >> 13) & 0x7);
498 ((char *) o)[1] = ((data >> 3) & 0xfc) | ((data >> 9) & 0x3);
499 ((char *) o)[2] = ((data << 3) & 0xf8) | ((data >> 2) & 0x7);
507 convert 16 bits/pixel data
512 rgb565alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
519 register guint16 *s; /* read 1 pixels at once */
525 guint8 *srow = image->data, *orow = pixels;
527 width = image->width;
528 height = image->height;
529 bpl = image->bytes_per_line;
531 for (yy = 0; yy < height; yy++) {
533 s = (guint16 *) srow;
537 o = (guint32 *) orow;
538 for (xx = 0; xx < width; xx ++) {
539 register guint32 data;
540 /* rrrrrggg gggbbbbb -> rrrrrRRR ggggggGG bbbbbBBB aaaaaaaa */
541 /* little endian: aaaaaaaa bbbbbBBB ggggggGG rrrrrRRR */
544 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
545 | (data & 0x7e0) << 5 | (data & 0x600) >> 1
546 | (data & 0x1f) << 19 | (data & 0x1c) << 14
549 /* swap endianness first */
550 data = s[0] | s[1] << 8;
552 *o++ = (data & 0xf800) << 16 | (data & 0xe000) << 11
553 | (data & 0x7e0) << 13 | (data & 0x600) << 7
554 | (data & 0x1f) << 11 | (data & 0x1c) << 6
564 convert 16 bits/pixel data
569 rgb565amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
578 register guint16 *s; /* read 1 pixels at once */
582 guint8 *srow = image->data, *orow = pixels;
584 width = image->width;
585 height = image->height;
586 bpl = image->bytes_per_line;
588 for (yy = 0; yy < height; yy++) {
590 o = (guint32 *) orow;
591 for (xx = 0; xx < width; xx ++) {
592 register guint32 data;
593 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggg00 bbbbbBBB aaaaaaaa */
594 /* little endian: aaaaaaaa bbbbbBBB gggggg00 rrrrrRRR */
596 /* swap endianness first */
597 data = s[0] | s[1] << 8;
599 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
600 | (data & 0x7e0) << 5 | (data & 0x600) >> 1
601 | (data & 0x1f) << 19 | (data & 0x1c) << 14
605 *o++ = (data & 0xf800) << 16 | (data & 0xe000) << 11
606 | (data & 0x7e0) << 13 | (data & 0x600) << 7
607 | (data & 0x1f) << 11 | (data & 0x1c) << 6
617 convert 15 bits/pixel data
622 rgb555lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
629 register guint32 *s; /* read 2 pixels at once */
631 register guint8 *s; /* read 2 pixels at once */
634 guint8 *srow = image->data, *orow = pixels;
636 width = image->width;
637 height = image->height;
638 bpl = image->bytes_per_line;
640 for (yy = 0; yy < height; yy++) {
642 s = (guint32 *) srow;
646 o = (guint16 *) orow;
647 for (xx = 1; xx < width; xx += 2) {
648 register guint32 data;
651 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
652 | (data & 0x3e0) << 6 | (data & 0x380) << 1;
653 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
654 | (data & 0x7c000000) >> 15 | (data & 0x70000000) >> 20;
655 *o++ = (data & 0x3e00000) >> 18 | (data & 0x3800000) >> 23
656 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
658 /* swap endianness first */
659 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
661 *o++ = (data & 0x7c00) << 1 | (data & 0x7000) >> 4
662 | (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
663 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
664 | (data & 0x7c000000) >> 23 | (data & 0x70000000) >> 28;
665 *o++ = (data & 0x3e00000) >> 10 | (data & 0x3800000) >> 15
666 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
669 /* check for last remaining pixel */
671 register guint16 data;
673 data = *((short *) s);
675 data = *((short *) s);
676 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
678 ((char *) o)[0] = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12;
679 ((char *) o)[1] = (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
680 ((char *) o)[2] = (data & 0x1f) << 3 | (data & 0x1c) >> 2;
688 convert 15 bits/pixel data
693 rgb555msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
700 register guint8 *s; /* read 2 pixels at once */
702 register guint32 *s; /* read 2 pixels at once */
705 guint8 *srow = image->data, *orow = pixels;
707 width = image->width;
708 height = image->height;
709 bpl = image->bytes_per_line;
711 for (yy = 0; yy < height; yy++) {
713 o = (guint16 *) orow;
714 for (xx = 1; xx < width; xx += 2) {
715 register guint32 data;
717 /* swap endianness first */
718 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
720 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
721 | (data & 0x3e0) << 6 | (data & 0x380) << 1;
722 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
723 | (data & 0x7c000000) >> 15 | (data & 0x70000000) >> 20;
724 *o++ = (data & 0x3e00000) >> 18 | (data & 0x3800000) >> 23
725 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
728 *o++ = (data & 0x7c00) << 1 | (data & 0x7000) >> 4
729 | (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
730 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
731 | (data & 0x7c000000) >> 23 | (data & 0x70000000) >> 28;
732 *o++ = (data & 0x3e00000) >> 10 | (data & 0x3800000) >> 15
733 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
736 /* check for last remaining pixel */
738 register guint16 data;
740 data = *((short *) s);
741 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
743 data = *((short *) s);
745 ((char *) o)[0] = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12;
746 ((char *) o)[1] = (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
747 ((char *) o)[2] = (data & 0x1f) << 3 | (data & 0x1c) >> 2;
755 convert 15 bits/pixel data
760 rgb555alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
767 register guint16 *s; /* read 1 pixels at once */
773 guint8 *srow = image->data, *orow = pixels;
775 width = image->width;
776 height = image->height;
777 bpl = image->bytes_per_line;
779 for (yy = 0; yy < height; yy++) {
781 s = (guint16 *) srow;
785 o = (guint32 *) orow;
786 for (xx = 0; xx < width; xx++) {
787 register guint32 data;
788 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggGGG bbbbbBBB aaaaaaaa */
789 /* little endian: aaaaaaaa bbbbbBBB gggggGGG rrrrrRRR */
792 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
793 | (data & 0x3e0) << 6 | (data & 0x380) << 1
794 | (data & 0x1f) << 19 | (data & 0x1c) << 14
797 /* swap endianness first */
798 data = s[0] | s[1] << 8;
800 *o++ = (data & 0x7c00) << 17 | (data & 0x7000) << 12
801 | (data & 0x3e0) << 14 | (data & 0x380) << 9
802 | (data & 0x1f) << 11 | (data & 0x1c) << 6
812 convert 15 bits/pixel data
817 rgb555amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
824 register guint16 *s; /* read 1 pixels at once */
830 guint8 *srow = image->data, *orow = pixels;
832 width = image->width;
833 height = image->height;
834 bpl = image->bytes_per_line;
836 for (yy = 0; yy < height; yy++) {
838 s = (guint16 *) srow;
842 o = (guint32 *) orow;
843 for (xx = 0; xx < width; xx++) {
844 register guint32 data;
845 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggGGG bbbbbBBB aaaaaaaa */
846 /* little endian: aaaaaaaa bbbbbBBB gggggGGG rrrrrRRR */
848 /* swap endianness first */
849 data = s[0] | s[1] << 8;
851 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
852 | (data & 0x3e0) << 6 | (data & 0x380) << 1
853 | (data & 0x1f) << 19 | (data & 0x1c) << 14
857 *o++ = (data & 0x7c00) << 17 | (data & 0x7000) << 12
858 | (data & 0x3e0) << 14 | (data & 0x380) << 9
859 | (data & 0x1f) << 11 | (data & 0x1c) << 6
870 rgb888alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
876 guint8 *s; /* for byte order swapping */
878 guint8 *srow = image->data, *orow = pixels;
880 width = image->width;
881 height = image->height;
882 bpl = image->bytes_per_line;
885 for (yy = 0; yy < height; yy++) {
888 for (xx = 0; xx < width; xx++) {
901 rgb888lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
907 guint8 *srow = image->data, *orow = pixels;
910 width = image->width;
911 height = image->height;
912 bpl = image->bytes_per_line;
915 for (yy = 0; yy < height; yy++) {
918 for (xx = 0; xx < width; xx++) {
930 rgb888amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
936 guint8 *srow = image->data, *orow = pixels;
941 guint8 *s; /* for byte order swapping */
946 width = image->width;
947 height = image->height;
948 bpl = image->bytes_per_line;
951 for (yy = 0; yy < height; yy++) {
953 s = (guint32 *) srow;
954 o = (guint32 *) orow;
959 for (xx = 0; xx < width; xx++) {
967 *o++ = (*s << 8) | 0xff; /* untested */
977 rgb888msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
983 guint8 *srow = image->data, *orow = pixels;
988 width = image->width;
989 height = image->height;
990 bpl = image->bytes_per_line;
992 for (yy = 0; yy < height; yy++) {
995 for (xx = 0; xx < width; xx++) {
1006 visual_decompose_mask (gulong mask,
1013 while (!(mask & 0x1)) {
1018 while (mask & 0x1) {
1026 This should work correctly with any display/any endianness, but will probably
1030 convert_real_slow (XImage *image, guchar *pixels, int rowstride, xlib_colormap *cmap, int alpha)
1035 guint8 *srow = image->data, *orow = pixels;
1042 int red_shift, red_prec, green_shift, green_prec, blue_shift, blue_prec;
1044 width = image->width;
1045 height = image->height;
1046 bpl = image->bytes_per_line;
1049 visual_decompose_mask (v->red_mask, &red_shift, &red_prec);
1050 visual_decompose_mask (v->green_mask, &green_shift, &green_prec);
1051 visual_decompose_mask (v->blue_mask, &blue_shift, &blue_prec);
1053 for (yy = 0; yy < height; yy++) {
1056 for (xx = 0; xx < width; xx++) {
1057 pixel = XGetPixel (image, xx, yy);
1059 /* I assume this is right for static & greyscale's too? */
1064 *o++ = cmap->colors[pixel].red;
1065 *o++ = cmap->colors[pixel].green;
1066 *o++ = cmap->colors[pixel].blue;
1069 /* This is odd because it must sometimes shift left (otherwise
1070 I'd just shift >> (*_shift - 8 + *_prec + <0-7>). This logic
1071 should work for all bit sizes/shifts/etc. */
1073 for (i = 24; i < 32; i += red_prec)
1074 component |= ((pixel & v->red_mask) << (32 - red_shift - red_prec)) >> i;
1077 for (i = 24; i < 32; i += green_prec)
1078 component |= ((pixel & v->green_mask) << (32 - green_shift - green_prec)) >> i;
1081 for (i = 24; i < 32; i += blue_prec)
1082 component |= ((pixel & v->blue_mask) << (32 - blue_shift - blue_prec)) >> i;
1086 *o++ = cmap->colors[((pixel & v->red_mask) << (32 - red_shift - red_prec)) >> 24].red;
1087 *o++ = cmap->colors[((pixel & v->green_mask) << (32 - green_shift - green_prec)) >> 24].green;
1088 *o++ = cmap->colors[((pixel & v->blue_mask) << (32 - blue_shift - blue_prec)) >> 24].blue;
1099 static xlib_colormap *
1100 xlib_get_colormap (Colormap id, Visual *visual, MagnifierData *mag_data)
1103 xlib_colormap *xc = g_new (xlib_colormap, 1);
1105 xc->size = visual->map_entries;
1106 xc->colors = g_new (XColor, xc->size);
1107 xc->visual = visual;
1110 for (i = 0; i < xc->size; i++) {
1111 xc->colors[i].pixel = i;
1112 xc->colors[i].flags = DoRed | DoGreen | DoBlue;
1115 XQueryColors (mag_data->source_display, xc->colormap, xc->colors, xc->size);
1120 typedef void (* cfunc) (XImage *image, guchar *pixels, int rowstride, xlib_colormap *cmap);
1121 static cfunc convert_map[] = {
1122 rgb1,rgb1,rgb1a,rgb1a,
1123 rgb8,rgb8,rgb8a,rgb8a,
1124 rgb555lsb,rgb555msb,rgb555alsb,rgb555amsb,
1125 rgb565lsb,rgb565msb,rgb565alsb,rgb565amsb,
1126 rgb888lsb,rgb888msb,rgb888alsb,rgb888amsb
1130 rgbconvert (XImage *image, guchar *pixels, int rowstride, int alpha, xlib_colormap *cmap,
1131 MagnifierData *mag_data)
1133 int index = (image->byte_order == MSBFirst) | (alpha != 0) << 1;
1134 int bank=5; /* default fallback converter */
1135 Visual *v = cmap->visual;
1136 if (mag_data->fast_rgb_convert)
1139 /* I assume this is right for static & greyscale's too? */
1144 switch (image->bits_per_pixel) {
1154 switch (image->depth) {
1156 if (v->red_mask == 0x7c00 && v->green_mask == 0x3e0 && v->blue_mask == 0x1f
1157 && image->bits_per_pixel == 16)
1161 if (v->red_mask == 0xf800 && v->green_mask == 0x7e0 && v->blue_mask == 0x1f
1162 && image->bits_per_pixel == 16)
1167 if (v->red_mask == 0xff0000 && v->green_mask == 0xff00 && v->blue_mask == 0xff
1168 && image->bits_per_pixel == 32)
1174 /* always use the slow version */
1180 convert_real_slow(image, pixels, rowstride, cmap, alpha);
1183 (* convert_map[index]) (image, pixels, rowstride, cmap);
1187 void get_root_image(Window src, GdkPixbuf *dest, int src_x, int src_y, MagnifierData *mag_data) {
1189 int width = mag_data->mag_width/mag_data->factor_x;
1190 int height = mag_data->mag_height/mag_data->factor_y;
1192 /* Get SpiImage in ZPixmap format (packed bits). */
1193 image = XGetImage (mag_data->source_display, src, src_x, src_y,
1194 width, height, AllPlanes, ZPixmap);
1195 g_assert(image != NULL);
1198 XWindowAttributes wa;
1199 XGetWindowAttributes (mag_data->source_display, src, &wa);
1200 x_cmap = xlib_get_colormap (wa.colormap, wa.visual, mag_data);
1202 /* we offset into the image data based on the position we are retrieving from */
1203 rgbconvert (image, gdk_pixbuf_get_pixels(dest),
1204 gdk_pixbuf_get_rowstride(dest),
1205 gdk_pixbuf_get_has_alpha(dest),
1209 /* would like to use GDK routine, but since we don't have multi-head
1210 yet, we have to use X */
1212 XDestroyImage (image);