2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include "mag_image.h"
26 static int get_num(char* msg);
27 static void get_coord(char* msg,point *p);
28 static void get_rect(char* msg, point *p1, point *p2);
29 static void compute_center_coord(point p1, point p2, point *center);
30 static xlib_colormap * xlib_get_colormap (Colormap id, Visual *visual, MagnifierData *data);
31 static guint32 mask_table[] = {
32 0x00000000, 0x00000001, 0x00000003, 0x00000007,
33 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
34 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
35 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
36 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
37 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
38 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
39 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
43 void parse_message(char *msg, MagnifierData *data){
46 point roi_pos, roi_size;
47 point mag_pos, mag_size;
51 fprintf(stderr,"corrupted message, discarding\n");
54 type = atoi((char*)&msg[1]);
57 old_factor_x = data->factor_x;
58 data->factor_x = get_num(msg);
59 old_factor_y = data->factor_y;
60 data->factor_y = get_num(msg);
61 printf("FACTOR = %d\n",data->factor_x);
64 data->contrast = get_num(msg);
65 printf("CONTRAST = %d\n",data->contrast);
68 data->follow_mouse = get_num(msg);
69 printf("FOLLOW_MOUSE = %d\n",data->follow_mouse);
72 data->color_inverted = get_num(msg);
73 printf("COLOR_INVERTED = %d\n",data->color_inverted);
76 get_coord(msg, &data->center);
77 printf("GOTO = (%d,%d)\n", data->center.x, data->center.y);
80 get_rect (msg, &roi_pos, &roi_size);
81 printf("ROI = (%d,%d; %d,%d)\n", roi_pos.x, roi_pos.y, roi_size.x, roi_size.y);
82 compute_center_coord (roi_pos, roi_size, &data->center);
85 get_rect (msg, &mag_pos, &mag_size);
86 printf("EXTENTS = (%d,%d; %d,%d)\n", mag_pos.x, mag_pos.y, mag_size.x, mag_size.y);
87 data->mag_width = mag_size.x;
88 data->mag_height = mag_size.y;
89 gdk_window_move_resize (data->output_window->window, mag_pos.x,
91 data->mag_width, data->mag_height);
103 static int get_num(char* msg){
105 sscanf(msg,"~%d:%d:",&type,&num);
109 static void get_coord(char* msg,point *p){
111 sscanf(msg,"~%d:%d,%d:",&type,&p->x,&p->y);
114 static void get_rect(char* msg, point *p1, point *p2){
116 sscanf(msg,"~%d:%d,%d;%d,%d:",&type, &p1->x, &p1->y, &p2->x, &p2->y);
119 static void compute_center_coord (point pos, point size, point *center) {
120 center->x = pos.x + (size.x/2);
121 center->y = pos.y + (size.y/2);
124 int display_image(gpointer data)
126 MagnifierData *mag_data = (MagnifierData *)data;
127 update_image(mag_data);
128 gdk_pixbuf_scale(image,
132 DisplayWidth (mag_data->target_display,screen_num),
133 DisplayHeight(mag_data->target_display,screen_num),
140 gdk_pixbuf_render_to_drawable (scaled_image,
141 drawing_area->window,
142 drawing_area->style->fg_gc[GTK_STATE_NORMAL],
143 0,0,0,0,DisplayWidth (mag_data->target_display,screen_num),
144 DisplayHeight(mag_data->target_display,screen_num),
145 GDK_RGB_DITHER_NORMAL,0,0);
147 gdk_window_raise (drawing_area->window);
151 void update_image(MagnifierData *mag_data)
153 int x, y, total_width, total_height;
155 if(mag_data->follow_mouse){
156 Window root_return, child_return;
157 int win_x_return,win_y_return;
158 unsigned int mask_return;
159 XQueryPointer(mag_data->source_display,spi_image_root_window,
160 &root_return,&child_return,
161 &mag_data->center.x,&mag_data->center.y,
162 &win_x_return,&win_y_return,&mask_return);
165 total_width = DisplayWidth (mag_data->source_display,screen_num);
166 total_height = DisplayHeight(mag_data->source_display,screen_num);
168 x = mag_data->center.x - mag_data->mag_width/mag_data->factor_x/2;
169 y = mag_data->center.y - mag_data->mag_height/mag_data->factor_y/2;
171 if(mag_data->center.x < mag_data->mag_width/mag_data->factor_x/2)
173 if(mag_data->center.x > (total_width - mag_data->mag_width/mag_data->factor_x/2))
174 x = total_width - mag_data->mag_width/mag_data->factor_x;
175 if(mag_data->center.y < mag_data->mag_height/mag_data->factor_y/2)
177 if(mag_data->center.y > (total_height - mag_data->mag_height/mag_data->factor_y/2))
178 y = total_height - mag_data->mag_height/mag_data->factor_y;
184 printf("p = (%d,%d), x,y = (%d,%d), h,w = (%d,%d), ht,wt = (%d,%d)\n",
188 mag_data->mag_height,mag_data->mag_width,
192 if(mag_data->factor_x != old_factor_x || mag_data->factor_y != old_factor_y){
193 g_object_unref((GObject *)image);
194 image = gdk_pixbuf_new (GDK_COLORSPACE_RGB,FALSE, 8,
195 DisplayWidth (mag_data->target_display,screen_num)/mag_data->factor_x,
196 DisplayHeight(mag_data->target_display,screen_num)/mag_data->factor_y);
197 /* yes, use target display above, since the size of the area grabbed depends on the target */
198 old_factor_x = mag_data->factor_x;
199 old_factor_y = mag_data->factor_y;
201 get_root_image(spi_image_root_window,
207 void expose_event(GtkWidget * w, GdkEventExpose *event, gpointer data){
214 /* SpiImage grabbing and convertion routines from gdk-pixbuf-xlib */
216 convert 1 bits-pixel data
220 rgb1 (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
226 register guint8 data;
228 guint8 *srow = image->data, *orow = pixels;
230 /* convert upto 8 pixels/time */
231 /* its probably not worth trying to make this run very fast, who uses
232 1 bit displays anymore? */
233 width = image->width;
234 height = image->height;
235 bpl = image->bytes_per_line;
237 for (yy = 0; yy < height; yy++) {
241 for (xx = 0; xx < width; xx ++) {
242 data = srow[xx >> 3] >> (7 - (xx & 7)) & 1;
243 *o++ = colormap->colors[data].red;
244 *o++ = colormap->colors[data].green;
245 *o++ = colormap->colors[data].blue;
253 convert 1 bits/pixel data
257 rgb1a (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
263 register guint8 data;
265 guint8 *srow = image->data, *orow = pixels;
268 /* convert upto 8 pixels/time */
269 /* its probably not worth trying to make this run very fast, who uses
270 1 bit displays anymore? */
271 width = image->width;
272 height = image->height;
273 bpl = image->bytes_per_line;
275 for (xx = 0; xx < 2; xx++) {
277 remap[xx] = 0xff000000
278 | colormap->colors[xx].blue << 16
279 | colormap->colors[xx].green << 8
280 | colormap->colors[xx].red;
283 | colormap->colors[xx].red << 24
284 | colormap->colors[xx].green << 16
285 | colormap->colors[xx].blue << 8;
289 for (yy = 0; yy < height; yy++) {
293 for (xx = 0; xx < width; xx ++) {
294 data = srow[xx >> 3] >> (7 - (xx & 7)) & 1;
303 convert 8 bits/pixel data
307 rgb8 (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
313 register guint32 data;
314 guint8 *srow = image->data, *orow = pixels;
318 width = image->width;
319 height = image->height;
320 bpl = image->bytes_per_line;
322 mask = mask_table[image->depth];
324 for (yy = 0; yy < height; yy++) {
327 for (xx = 0; xx < width; xx++) {
329 *o++ = colormap->colors[data].red;
330 *o++ = colormap->colors[data].green;
331 *o++ = colormap->colors[data].blue;
339 convert 8 bits/pixel data
343 rgb8a (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
349 register guint32 data;
351 register guint8 *s; /* read 2 pixels at once */
353 guint8 *srow = image->data, *orow = pixels;
355 width = image->width;
356 height = image->height;
357 bpl = image->bytes_per_line;
359 mask = mask_table[image->depth];
361 for (xx = 0; xx < colormap->size; xx++) {
363 remap[xx] = 0xff000000
364 | colormap->colors[xx].blue << 16
365 | colormap->colors[xx].green << 8
366 | colormap->colors[xx].red;
369 | colormap->colors[xx].red << 24
370 | colormap->colors[xx].green << 16
371 | colormap->colors[xx].blue << 8;
375 for (yy = 0; yy < height; yy++) {
377 o = (guint32 *) orow;
378 for (xx = 0; xx < width; xx ++) {
388 convert 16 bits/pixel data
393 rgb565lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
400 register guint32 *s; /* read 2 pixels at once */
402 register guint8 *s; /* read 2 pixels at once */
405 guint8 *srow = image->data, *orow = pixels;
407 width = image->width;
408 height = image->height;
409 bpl = image->bytes_per_line;
411 for (yy = 0; yy < height; yy++) {
413 s = (guint32 *) srow;
417 o = (guint16 *) orow;
418 for (xx = 1; xx < width; xx += 2) {
419 register guint32 data;
422 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
423 | (data & 0x7e0) << 5 | (data & 0x600) >> 1;
424 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
425 | (data & 0xf8000000) >> 16 | (data & 0xe0000000) >> 21;
426 *o++ = (data & 0x7e00000) >> 19 | (data & 0x6000000) >> 25
427 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
429 /* swap endianness first */
430 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
432 *o++ = (data & 0xf800) | (data & 0xe000) >> 5
433 | (data & 0x7e0) >> 3 | (data & 0x600) >> 9;
434 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
435 | (data & 0xf8000000) >> 24 | (data & 0xe0000000) >> 29;
436 *o++ = (data & 0x7e00000) >> 11 | (data & 0x6000000) >> 17
437 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
440 /* check for last remaining pixel */
442 register guint16 data;
444 data = *((short *) s);
446 data = *((short *) s);
447 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
449 ((char *) o)[0] = ((data >> 8) & 0xf8) | ((data >> 13) & 0x7);
450 ((char *) o)[1] = ((data >> 3) & 0xfc) | ((data >> 9) & 0x3);
451 ((char *) o)[2] = ((data << 3) & 0xf8) | ((data >> 2) & 0x7);
459 convert 16 bits/pixel data
464 rgb565msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
471 register guint8 *s; /* need to swap data order */
473 register guint32 *s; /* read 2 pixels at once */
476 guint8 *srow = image->data, *orow = pixels;
478 width = image->width;
479 height = image->height;
480 bpl = image->bytes_per_line;
482 for (yy = 0; yy < height; yy++) {
486 s = (guint32 *) srow;
488 o = (guint16 *) orow;
489 for (xx = 1; xx < width; xx += 2) {
490 register guint32 data;
492 /* swap endianness first */
493 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
495 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
496 | (data & 0x7e0) << 5 | (data & 0x600) >> 1;
497 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
498 | (data & 0xf8000000) >> 16 | (data & 0xe0000000) >> 21;
499 *o++ = (data & 0x7e00000) >> 19 | (data & 0x6000000) >> 25
500 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
503 *o++ = (data & 0xf800) | (data & 0xe000) >> 5
504 | (data & 0x7e0) >> 3 | (data & 0x600) >> 9;
505 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
506 | (data & 0xf8000000) >> 24 | (data & 0xe0000000) >> 29;
507 *o++ = (data & 0x7e00000) >> 11 | (data & 0x6000000) >> 17
508 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
511 /* check for last remaining pixel */
513 register guint16 data;
515 data = *((short *) s);
516 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
518 data = *((short *) s);
520 ((char *) o)[0] = ((data >> 8) & 0xf8) | ((data >> 13) & 0x7);
521 ((char *) o)[1] = ((data >> 3) & 0xfc) | ((data >> 9) & 0x3);
522 ((char *) o)[2] = ((data << 3) & 0xf8) | ((data >> 2) & 0x7);
530 convert 16 bits/pixel data
535 rgb565alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
542 register guint16 *s; /* read 1 pixels at once */
548 guint8 *srow = image->data, *orow = pixels;
550 width = image->width;
551 height = image->height;
552 bpl = image->bytes_per_line;
554 for (yy = 0; yy < height; yy++) {
556 s = (guint16 *) srow;
560 o = (guint32 *) orow;
561 for (xx = 0; xx < width; xx ++) {
562 register guint32 data;
563 /* rrrrrggg gggbbbbb -> rrrrrRRR ggggggGG bbbbbBBB aaaaaaaa */
564 /* little endian: aaaaaaaa bbbbbBBB ggggggGG rrrrrRRR */
567 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
568 | (data & 0x7e0) << 5 | (data & 0x600) >> 1
569 | (data & 0x1f) << 19 | (data & 0x1c) << 14
572 /* swap endianness first */
573 data = s[0] | s[1] << 8;
575 *o++ = (data & 0xf800) << 16 | (data & 0xe000) << 11
576 | (data & 0x7e0) << 13 | (data & 0x600) << 7
577 | (data & 0x1f) << 11 | (data & 0x1c) << 6
587 convert 16 bits/pixel data
592 rgb565amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
601 register guint16 *s; /* read 1 pixels at once */
605 guint8 *srow = image->data, *orow = pixels;
607 width = image->width;
608 height = image->height;
609 bpl = image->bytes_per_line;
611 for (yy = 0; yy < height; yy++) {
613 o = (guint32 *) orow;
614 for (xx = 0; xx < width; xx ++) {
615 register guint32 data;
616 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggg00 bbbbbBBB aaaaaaaa */
617 /* little endian: aaaaaaaa bbbbbBBB gggggg00 rrrrrRRR */
619 /* swap endianness first */
620 data = s[0] | s[1] << 8;
622 *o++ = (data & 0xf800) >> 8 | (data & 0xe000) >> 13
623 | (data & 0x7e0) << 5 | (data & 0x600) >> 1
624 | (data & 0x1f) << 19 | (data & 0x1c) << 14
628 *o++ = (data & 0xf800) << 16 | (data & 0xe000) << 11
629 | (data & 0x7e0) << 13 | (data & 0x600) << 7
630 | (data & 0x1f) << 11 | (data & 0x1c) << 6
640 convert 15 bits/pixel data
645 rgb555lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
652 register guint32 *s; /* read 2 pixels at once */
654 register guint8 *s; /* read 2 pixels at once */
657 guint8 *srow = image->data, *orow = pixels;
659 width = image->width;
660 height = image->height;
661 bpl = image->bytes_per_line;
663 for (yy = 0; yy < height; yy++) {
665 s = (guint32 *) srow;
669 o = (guint16 *) orow;
670 for (xx = 1; xx < width; xx += 2) {
671 register guint32 data;
674 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
675 | (data & 0x3e0) << 6 | (data & 0x380) << 1;
676 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
677 | (data & 0x7c000000) >> 15 | (data & 0x70000000) >> 20;
678 *o++ = (data & 0x3e00000) >> 18 | (data & 0x3800000) >> 23
679 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
681 /* swap endianness first */
682 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
684 *o++ = (data & 0x7c00) << 1 | (data & 0x7000) >> 4
685 | (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
686 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
687 | (data & 0x7c000000) >> 23 | (data & 0x70000000) >> 28;
688 *o++ = (data & 0x3e00000) >> 10 | (data & 0x3800000) >> 15
689 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
692 /* check for last remaining pixel */
694 register guint16 data;
696 data = *((short *) s);
698 data = *((short *) s);
699 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
701 ((char *) o)[0] = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12;
702 ((char *) o)[1] = (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
703 ((char *) o)[2] = (data & 0x1f) << 3 | (data & 0x1c) >> 2;
711 convert 15 bits/pixel data
716 rgb555msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
723 register guint8 *s; /* read 2 pixels at once */
725 register guint32 *s; /* read 2 pixels at once */
728 guint8 *srow = image->data, *orow = pixels;
730 width = image->width;
731 height = image->height;
732 bpl = image->bytes_per_line;
734 for (yy = 0; yy < height; yy++) {
736 o = (guint16 *) orow;
737 for (xx = 1; xx < width; xx += 2) {
738 register guint32 data;
740 /* swap endianness first */
741 data = s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
743 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
744 | (data & 0x3e0) << 6 | (data & 0x380) << 1;
745 *o++ = (data & 0x1f) << 3 | (data & 0x1c) >> 2
746 | (data & 0x7c000000) >> 15 | (data & 0x70000000) >> 20;
747 *o++ = (data & 0x3e00000) >> 18 | (data & 0x3800000) >> 23
748 | (data & 0x1f0000) >> 5 | (data & 0x1c0000) >> 10;
751 *o++ = (data & 0x7c00) << 1 | (data & 0x7000) >> 4
752 | (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
753 *o++ = (data & 0x1f) << 11 | (data & 0x1c) << 6
754 | (data & 0x7c000000) >> 23 | (data & 0x70000000) >> 28;
755 *o++ = (data & 0x3e00000) >> 10 | (data & 0x3800000) >> 15
756 | (data & 0x1f0000) >> 13 | (data & 0x1c0000) >> 18;
759 /* check for last remaining pixel */
761 register guint16 data;
763 data = *((short *) s);
764 data = ((data >> 8) & 0xff) | ((data & 0xff) << 8);
766 data = *((short *) s);
768 ((char *) o)[0] = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12;
769 ((char *) o)[1] = (data & 0x3e0) >> 2 | (data & 0x380) >> 7;
770 ((char *) o)[2] = (data & 0x1f) << 3 | (data & 0x1c) >> 2;
778 convert 15 bits/pixel data
783 rgb555alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
790 register guint16 *s; /* read 1 pixels at once */
796 guint8 *srow = image->data, *orow = pixels;
798 width = image->width;
799 height = image->height;
800 bpl = image->bytes_per_line;
802 for (yy = 0; yy < height; yy++) {
804 s = (guint16 *) srow;
808 o = (guint32 *) orow;
809 for (xx = 0; xx < width; xx++) {
810 register guint32 data;
811 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggGGG bbbbbBBB aaaaaaaa */
812 /* little endian: aaaaaaaa bbbbbBBB gggggGGG rrrrrRRR */
815 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
816 | (data & 0x3e0) << 6 | (data & 0x380) << 1
817 | (data & 0x1f) << 19 | (data & 0x1c) << 14
820 /* swap endianness first */
821 data = s[0] | s[1] << 8;
823 *o++ = (data & 0x7c00) << 17 | (data & 0x7000) << 12
824 | (data & 0x3e0) << 14 | (data & 0x380) << 9
825 | (data & 0x1f) << 11 | (data & 0x1c) << 6
835 convert 15 bits/pixel data
840 rgb555amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
847 register guint16 *s; /* read 1 pixels at once */
853 guint8 *srow = image->data, *orow = pixels;
855 width = image->width;
856 height = image->height;
857 bpl = image->bytes_per_line;
859 for (yy = 0; yy < height; yy++) {
861 s = (guint16 *) srow;
865 o = (guint32 *) orow;
866 for (xx = 0; xx < width; xx++) {
867 register guint32 data;
868 /* rrrrrggg gggbbbbb -> rrrrrRRR gggggGGG bbbbbBBB aaaaaaaa */
869 /* little endian: aaaaaaaa bbbbbBBB gggggGGG rrrrrRRR */
871 /* swap endianness first */
872 data = s[0] | s[1] << 8;
874 *o++ = (data & 0x7c00) >> 7 | (data & 0x7000) >> 12
875 | (data & 0x3e0) << 6 | (data & 0x380) << 1
876 | (data & 0x1f) << 19 | (data & 0x1c) << 14
880 *o++ = (data & 0x7c00) << 17 | (data & 0x7000) << 12
881 | (data & 0x3e0) << 14 | (data & 0x380) << 9
882 | (data & 0x1f) << 11 | (data & 0x1c) << 6
893 rgb888alsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
899 guint8 *s; /* for byte order swapping */
901 guint8 *srow = image->data, *orow = pixels;
903 width = image->width;
904 height = image->height;
905 bpl = image->bytes_per_line;
908 for (yy = 0; yy < height; yy++) {
911 for (xx = 0; xx < width; xx++) {
924 rgb888lsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
930 guint8 *srow = image->data, *orow = pixels;
933 width = image->width;
934 height = image->height;
935 bpl = image->bytes_per_line;
938 for (yy = 0; yy < height; yy++) {
941 for (xx = 0; xx < width; xx++) {
953 rgb888amsb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
959 guint8 *srow = image->data, *orow = pixels;
964 guint8 *s; /* for byte order swapping */
969 width = image->width;
970 height = image->height;
971 bpl = image->bytes_per_line;
974 for (yy = 0; yy < height; yy++) {
976 s = (guint32 *) srow;
977 o = (guint32 *) orow;
982 for (xx = 0; xx < width; xx++) {
990 *o++ = (*s << 8) | 0xff; /* untested */
1000 rgb888msb (XImage *image, guchar *pixels, int rowstride, xlib_colormap *colormap)
1006 guint8 *srow = image->data, *orow = pixels;
1011 width = image->width;
1012 height = image->height;
1013 bpl = image->bytes_per_line;
1015 for (yy = 0; yy < height; yy++) {
1018 for (xx = 0; xx < width; xx++) {
1029 visual_decompose_mask (gulong mask,
1036 while (!(mask & 0x1)) {
1041 while (mask & 0x1) {
1049 This should work correctly with any display/any endianness, but will probably
1053 convert_real_slow (XImage *image, guchar *pixels, int rowstride, xlib_colormap *cmap, int alpha)
1058 guint8 *srow = image->data, *orow = pixels;
1065 int red_shift, red_prec, green_shift, green_prec, blue_shift, blue_prec;
1067 width = image->width;
1068 height = image->height;
1069 bpl = image->bytes_per_line;
1072 visual_decompose_mask (v->red_mask, &red_shift, &red_prec);
1073 visual_decompose_mask (v->green_mask, &green_shift, &green_prec);
1074 visual_decompose_mask (v->blue_mask, &blue_shift, &blue_prec);
1076 for (yy = 0; yy < height; yy++) {
1079 for (xx = 0; xx < width; xx++) {
1080 pixel = XGetPixel (image, xx, yy);
1082 /* I assume this is right for static & greyscale's too? */
1087 *o++ = cmap->colors[pixel].red;
1088 *o++ = cmap->colors[pixel].green;
1089 *o++ = cmap->colors[pixel].blue;
1092 /* This is odd because it must sometimes shift left (otherwise
1093 I'd just shift >> (*_shift - 8 + *_prec + <0-7>). This logic
1094 should work for all bit sizes/shifts/etc. */
1096 for (i = 24; i < 32; i += red_prec)
1097 component |= ((pixel & v->red_mask) << (32 - red_shift - red_prec)) >> i;
1100 for (i = 24; i < 32; i += green_prec)
1101 component |= ((pixel & v->green_mask) << (32 - green_shift - green_prec)) >> i;
1104 for (i = 24; i < 32; i += blue_prec)
1105 component |= ((pixel & v->blue_mask) << (32 - blue_shift - blue_prec)) >> i;
1109 *o++ = cmap->colors[((pixel & v->red_mask) << (32 - red_shift - red_prec)) >> 24].red;
1110 *o++ = cmap->colors[((pixel & v->green_mask) << (32 - green_shift - green_prec)) >> 24].green;
1111 *o++ = cmap->colors[((pixel & v->blue_mask) << (32 - blue_shift - blue_prec)) >> 24].blue;
1122 static xlib_colormap *
1123 xlib_get_colormap (Colormap id, Visual *visual, MagnifierData *mag_data)
1126 xlib_colormap *xc = g_new (xlib_colormap, 1);
1128 xc->size = visual->map_entries;
1129 xc->colors = g_new (XColor, xc->size);
1130 xc->visual = visual;
1133 for (i = 0; i < xc->size; i++) {
1134 xc->colors[i].pixel = i;
1135 xc->colors[i].flags = DoRed | DoGreen | DoBlue;
1138 XQueryColors (mag_data->source_display, xc->colormap, xc->colors, xc->size);
1143 typedef void (* cfunc) (XImage *image, guchar *pixels, int rowstride, xlib_colormap *cmap);
1144 static cfunc convert_map[] = {
1145 rgb1,rgb1,rgb1a,rgb1a,
1146 rgb8,rgb8,rgb8a,rgb8a,
1147 rgb555lsb,rgb555msb,rgb555alsb,rgb555amsb,
1148 rgb565lsb,rgb565msb,rgb565alsb,rgb565amsb,
1149 rgb888lsb,rgb888msb,rgb888alsb,rgb888amsb
1153 rgbconvert (XImage *image, guchar *pixels, int rowstride, int alpha, xlib_colormap *cmap,
1154 MagnifierData *mag_data)
1156 int index = (image->byte_order == MSBFirst) | (alpha != 0) << 1;
1157 int bank=5; /* default fallback converter */
1158 Visual *v = cmap->visual;
1159 if (mag_data->fast_rgb_convert)
1162 /* I assume this is right for static & greyscale's too? */
1167 switch (image->bits_per_pixel) {
1177 switch (image->depth) {
1179 if (v->red_mask == 0x7c00 && v->green_mask == 0x3e0 && v->blue_mask == 0x1f
1180 && image->bits_per_pixel == 16)
1184 if (v->red_mask == 0xf800 && v->green_mask == 0x7e0 && v->blue_mask == 0x1f
1185 && image->bits_per_pixel == 16)
1190 if (v->red_mask == 0xff0000 && v->green_mask == 0xff00 && v->blue_mask == 0xff
1191 && image->bits_per_pixel == 32)
1197 /* always use the slow version */
1203 convert_real_slow(image, pixels, rowstride, cmap, alpha);
1206 (* convert_map[index]) (image, pixels, rowstride, cmap);
1210 void get_root_image(Window src, GdkPixbuf *dest, int src_x, int src_y, MagnifierData *mag_data) {
1212 int width = mag_data->mag_width/mag_data->factor_x;
1213 int height = mag_data->mag_height/mag_data->factor_y;
1215 /* Get SpiImage in ZPixmap format (packed bits). */
1216 image = XGetImage (mag_data->source_display, src, src_x, src_y,
1217 width, height, AllPlanes, ZPixmap);
1218 g_assert(image != NULL);
1221 XWindowAttributes wa;
1222 XGetWindowAttributes (mag_data->source_display, src, &wa);
1223 x_cmap = xlib_get_colormap (wa.colormap, wa.visual, mag_data);
1225 /* we offset into the image data based on the position we are retrieving from */
1226 rgbconvert (image, gdk_pixbuf_get_pixels(dest),
1227 gdk_pixbuf_get_rowstride(dest),
1228 gdk_pixbuf_get_has_alpha(dest),
1232 /* would like to use GDK routine, but since we don't have multi-head
1233 yet, we have to use X */
1235 XDestroyImage (image);