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