xmag_multivis.c revision 1233
0N/A * xmag - simple magnifying glass application 0N/A * $XConsortium: xmag.c,v 1.29 89/12/10 17:23:58 rws Exp $ 0N/A * Copyright 1988 Massachusetts Institute of Technology 0N/A * Permission to use, copy, modify, and distribute this software and its 0N/A * documentation for any purpose and without fee is hereby granted, provided 0N/A * that the above copyright notice appear in all copies and that both that 0N/A * copyright notice and this permission notice appear in supporting 0N/A * documentation, and that the name of M.I.T. not be used in advertising or 0N/A * publicity pertaining to distribution of the software without specific, 0N/A * written prior permission. M.I.T. makes no representations about the 0N/A * suitability of this software for any purpose. It is provided "as is" 0N/A * without express or implied warranty. 0N/A * Author: Jim Fulton, MIT X Consortium 0N/A * 11-15-90 MultiVis changes made by: Milind M. Pansare 0N/A * milind@Eng.Sun.COM 0N/A * Copyright (c) 1990, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * Permission is hereby granted, free of charge, to any person obtaining a 0N/A * copy of this software and associated documentation files (the "Software"), 0N/A * to deal in the Software without restriction, including without limitation 0N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense, 156N/A * and/or sell copies of the Software, and to permit persons to whom the 0N/A * Software is furnished to do so, subject to the following conditions: 156N/A * The above copyright notice and this permission notice (including the next 156N/A * paragraph) shall be included in all copies or substantial portions of the 156N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 156N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 156N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 156N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 0N/A * DEALINGS IN THE SOFTWARE. 156N/A/* prevent "Function has no return statement" error for shhh() */ 0N/A /* w1 is TrueColor 24 bit */ 0N/A /* mw is the window that is finally 0N/A/* start MultiVisual Fix */ 0N/Aint wd,
ht;
/* request width & height */ 0N/A We'll use this for output */ 0N/Aint allplanes;
/* Is the SUN_ASLLPLANES extension present ? */ 0N/A#
endif /* ALLPLANES */ 156N/A/* end MultiVisual Fix */ 0N/A"where options include:",
156N/A" -display displaystring X server to contact",
0N/A" -geometry geomstring size and location of enlargement",
156N/A" -source geomstring size and location of area to be enlarged",
156N/A" -mag magfactor integral amount by which area is enlarged",
0N/A" -bw pixels border width in pixels",
0N/A" -bd color border color",
0N/A" -bg colororpixelvalue background color or %pixel number",
0N/A" -fn fontname name of font for examining enlarged pixels",
0N/A" -z grab server during dynamics and XGetImage",
0N/A"Options may be abbreviated to the shortest unambiguous prefix.",
int i;
/* iterator variable */ for (i =
1; i <
argc; i++) {
if (
arg[0] ==
'-') {
/* process command line switches */ case 'd':
/* -display displaystring */ case 'g':
/* -geometry geomstring */ case 's':
/* -source geomstring */ case 'm':
/* -mag magnification */ case 'w':
/* -bw pixels */ case 'd':
/* -bd color */ case 'g':
/* -bg colororpixel*/ case 'f':
/* -font fontname */ }
else {
/* any command line parameters */ * set the fatal error handler to be an innocuous wimp that XSetIOErrorHandler(shhh); * get defaults (would be nice to use the resource manager instead) /* start MultiVisual fix */ /* The default visual is TrueColor, 24 bit... */ /* end MultiVisual fix */ /* start MultiVisual Fix */ /* end MultiVisual Fix */ * Do the setup for the magnification. Use the geometry, source_geometry, * and magnification to figure out how big of an area to magnify, and by * how much it should be enlarged according to the following relations: * magnification = window.geometry.width / source_geometry.width * Thus, only two of the three values may be specified by the user. The * following values are used to indicate that the default should be taken: * Variable blank value default value * window NULL "320x320-0-0" * If a location is not specified for the source, a square centered on the * pointer will be displayed that can be dragged around the screen. int params;
/* for which arguments present */ int tmp;
/* work variable */ unsigned long valuemask;
/* for window attributes */ unsigned long back_pixel;
/* background of enlargement */ * Check to make sure that user didn't give -geometry, -source, and -mag fprintf (
stderr,
"%s: magnifier size over specified, ignoring -mag\n",
* Verify the input and compute the appropriate sizes * At this point, both hints structures contain the appropriate width * and height fields. Now we need to do the placement calculations. * Set the flags entries so that we know what we have if (*s ==
'x' || *s ==
'X') {
* Make the enlargment window, but don't map it /* start MultiVisual Fix */ * If the worst has happened, and we have a mix of Visuals to * work from, then we insist on a TrueColor 24 bit Visual. *This makes life (a bit) simpler. /* The default visual is not 24 bit True Color, Create a colormap for this visual */ /* We assume that there's going to be a 24 bit TrueColor Visual to display the Image we create. Also, that each of R,G,B masks will be 8 bits. We now need to calculate the R, G, B offsets & order in the pixel. CAUTION: We also assume that the upper 8 bits of each of RGB in the XColor are the significant 8 bits, and discard the lower /* This visual is no good for us */ /* At this moment, create both windows.. later decide which one to map */ /* end MultiVisual Fix */ /* start MultiVisual Fix */ /* end MultiVisual Fix */ /* repaint_image fills in foreground */ /* start MultiVisual Fix */ /* end MultiVisual Fix */ * Do the work. If the user specified the location of the source, * then just that one spot, otherwise do some dynamics. static GC invGC = (
GC)
NULL;
/* for drawing source region outline */ if (!
invGC) {
/* make it the first time */ * Do the loop looking for a button press, drawing the image each time; * since other clients may be running, make sure that the xor segments all * get drawn at the same time. /* fill in the outline box */ box[i].x = x;
box[i].y = y;
/* u.l. */ box[i+
3].x = x;
box[i+
3].y =
box[i+
2].y;
/* l.l. */ * Don't get bits that are off the edges of the screen /* start MultiVisual Fix */ if (
num_vis >
1) {
/* Fire, Walk with me */ /* Initialise the MultiVisual Routines */ /* Get a list of intersecting windows, with their visual details */ /* Check if we have a multiVis on our hands */ /* Creat an Image where mvDoWindows.. will operate */ printf(
"mvCreatImg failed\n");
/* Convert the map into an XImage */ if (
multiVis ==
2)
/* Warn the user .... */ "%s: Warning -- source windows differ in VisualClass or ColorMap\n",
printf(
"Where are all the visuals ? \n");
/* end MultiVisual Fix */ if (!
image) {
/* clean up */ /* start MultiVisual fix */ /* Nothing to do, as we assume that the program will exit when we return */ /* end MultiVisual fix */ * Map the window and do the work. Space means do another; * Button1 press displays pixel value. /* start MultiVisual Fix */ if (!
w1) {
/* But we *insisted* on a TrueColor Window ! */ printf(
"Couldn't get a TrueColor 24 bit window...\n");
/* end MultiVisual Fix */ while (
1) {
/* loop until button released */ /* start MultiVisual Fix */ "Pixel at (%d,%d): %3lx (%04x, %04x, %04x)",
/* end MultiVisual Fix */ "Pixel at (%d,%d): %3lx (%04x, %04x, %04x)",
* free the image and return /* start MultiVisual Fix */ /* end MultiVisual Fix */ unsigned long pixel;
/* image pixel values */ unsigned long prev_pixel;
/* last pixel set with XChangeGC */ * figure out where in the image we have to start and end * Repaint the image; be somewhat clever by only drawing when the pixel * changes or when we run out of lines. * iterate over scanlines (rows) r_width = 0;
/* have done nothing so far */ * iterate over pixels in scanline (columns) * If the current pixel is different from the previous pixel, * then we need to set the drawing color and do the previous * rectangle. We can also avoid extra calls to XChangeGC by * keeping track of the last value we set (note that this may * be different from gcv.foreground if the latter is the same * as back_pixel). This is most useful when magnifying the * background stipple pattern on monochrome displays. * We only need to draw the rectangle if it isn't background. * draw final rectangle on line /* creates a small window inside of 'wind', at the top or bottom, suitable for displaying one line of text. Also loads in a font if necessary; John Bradley, University of Pennsylvania */ /* start MultiVisual fix */ /**** don't use CreateSimpleWindow when there is the possibility of Multiple visuals ...... pixwind = XCreateSimpleWindow (dpy, wind, 0, y, w, thigh, 0, None, BlackPixel (dpy, screen)); * Note that all these fileds need to be set, as the * default CopyFromParent values may cause BadMatch * errors, if the depth of the parent is different. /* We don't care for the border pixel, but must set it * anyways, to any value at all, for the above reasons. /* End MultiVisual Fix */ /* start MultiVisual Fix */ /* end MultiVisual Fix */ /* start MultiVisual Fix */ * Create an XImage from the Img we have. * Note that this routine has nothing to * do with the MultiVisual Mechanism. * It is a matter of policy that XMag chooses to * do all output to a 24 bit true color visual. * Selecting the best visual to display Img * is a totally distinct problem. XMag * solves it simplistically, by insisting on 24bit TrueColor. * The TrueColor visual is assumed to provide a * linear ramp in each primary. for (y = 0; y <
ht; y++) {
* Based on what mvLib returns, determine the best thing to do ... case 0:
/* No multiVis problems, do it the simple way */ case 1:
/* Definitely a multidepth problem */ case 2:
/* no depth problem , but colormap or visual class mismatch */ /* do a best effort... if 24bit window exists, use the mvLib else do a simple GetImage, and warn user that displayed image may not show true colors. */ if (
w1)
/* have TrueColor capability */ "%s: Warning - source window has different colormap or visual than root\n Image displayed using colormap and visual of root\n",
/* end MultiVisual Fix */