home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
universal_plane_file_format
/
NewXShowPlane
/
Xshpl.c
< prev
Wrap
C/C++ Source or Header
|
1993-12-06
|
10KB
|
313 lines
/*
* ------------------------------------------------------------------
* Xshpl.c - show plane guts
* Created by Robert Heller on Fri Dec 3 10:24:55 1993
* ------------------------------------------------------------------
* Modification History:
* ------------------------------------------------------------------
* Contents:
* ------------------------------------------------------------------
*
*
* Copyright 1993 University of Massachusetts.
* All rights reserved.
*
* Permission to copy and modify this software and its documen-
* tation only for internal use in your organization is hereby
* granted, provided that this notice is retained thereon and
* on all copies. UMASS makes no representations as to the sui-
* tability and operability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
* UMASS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
* NESS. IN NO EVENT SHALL UMASS BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY OTHER DAMAGES WHAT-
* SOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER-
* FORMANCE OF THIS SOFTWARE.
*
* No other rights, including, for example, the right to redis-
* tribute this software and its documentation or the right to
* prepare derivative works, are granted unless specifically
* provided in a separate license agreement.
*
* Copyright 1993, University of Massachusetts. All rights
* reserved.
*
*
*/
#include <stdio.h>
#include <math.h>
#include <X11/Intrinsic.h>
#include "llvs_per_plane.h"
#define autoscale ((minval == 0.0) && (maxval == 0.0))
static plane_min_max(plane,plane_info,limits,minval,maxval)
PLANE *plane;
PLANE_INFO *plane_info;
LIMITS *limits;
double *minval, *maxval;
{
int runlevel;
int deltapllevel;
int roff,coff;
int crow,ccol;
int flag;
double pixel,fback;
runlevel = limits->level;
if (plane_info->datatype == FLOAT) fback = plane_info->background.flonum;
else fback = plane_info->background.fixnum;
deltapllevel = runlevel - plane_info->level;
flag = TRUE;
for (crow = limits->startrow;
crow <= limits->endrow;
crow += limits->deltarow)
{
TRANSLEVEL(roff,crow,deltapllevel,plane_info->row_location);
for (ccol = limits->startcol;
ccol <= limits->endcol;
ccol += limits->deltacol)
{
TRANSLEVEL(coff,ccol,deltapllevel,plane_info->column_location);
GET_PIXEL(pixel,fback,plane,roff,coff,
(*plane_info));
if (flag)
{
*minval = pixel;
*maxval = pixel;
flag = FALSE;
} else if (pixel > *maxval) *maxval = pixel;
else if (pixel < *minval) *minval = pixel;
}
}
}
XShpl_grey(PLANE *plane,PLANE_INFO *plane_info,LIMITS *limits,
double minval,double maxval,int pixelsize,
int absolute,int negative,XImage *ximage,
Pixel *pixel_mapping,int number_grey)
{
int i, ipixel;
int runlevel;
int deltapllevel;
int roff,coff;
int xim_y_coord, xim_x_coord;
int crow,ccol;
int byte, ipixrow, ipixcol;
double intensity_scale,value_range,pixel,scaled_pixel,fback;
if (autoscale) plane_min_max(plane,plane_info,limits,&minval,&maxval);
runlevel = limits->level;
if (plane_info->datatype == FLOAT) fback = plane_info->background.flonum;
else fback = plane_info->background.fixnum;
deltapllevel = runlevel - plane_info->level;
value_range = maxval - minval;
intensity_scale = ((double) (number_grey - 1)) / value_range;
for (crow = limits->startrow;
crow <= limits->endrow;
crow += limits->deltarow) {
TRANSLEVEL(roff,crow,deltapllevel,plane_info->row_location);
xim_y_coord = (crow - limits->startrow) * pixelsize;
for (ccol = limits->startcol;
ccol <= limits->endcol;
ccol += limits->deltacol) {
TRANSLEVEL(coff,ccol,deltapllevel,plane_info->column_location);
xim_x_coord = (ccol - limits->startcol) * pixelsize;
GET_PIXEL(pixel,fback,plane,roff,coff,
(*plane_info));
if (absolute) pixel = fabs(pixel);
/* scale pixel. out of range values get black or white.
otherwise linear mapping */
if (intensity_scale > 0.0) {
/* positive slope case */
if (pixel < minval)
scaled_pixel = 0.0;
else
if (pixel > maxval)
scaled_pixel = number_grey-1;
else
scaled_pixel =(pixel - minval) *
intensity_scale;
} else { /* negative slope case */
if (pixel < maxval)
scaled_pixel = number_grey-1;
else
if (pixel > minval)
scaled_pixel = 0.0;
else
scaled_pixel =(pixel - minval) *
intensity_scale;
}
byte = scaled_pixel + 0.5;
if (negative) byte = (number_grey-1) - byte;
for (ipixrow = 0; ipixrow < pixelsize; ipixrow++) {
for (ipixcol = 0; ipixcol < pixelsize; ipixcol++) {
XPutPixel(ximage,xim_x_coord+ipixcol,
xim_y_coord+ipixrow,pixel_mapping[byte]);
}
}
}
}
}
/* maximum device intensity. these values are typical for 8 bits/color
devices */
#define ZERO 0
#define MAXINT_F 255.0
#define MAXINT_I 255
/* dithering matrix */
const static short int matrix[16][16] = {
{1, 235, 59, 219, 15, 231, 55, 215, 4, 234, 58, 218, 14, 230, 54, 214},
{129, 65, 187, 123, 143, 79, 183, 119, 132, 68, 186, 122, 142, 78, 182,
118},
{33, 193, 17, 251, 47, 207, 31, 247, 36, 196, 20, 250, 46, 206, 30, 246},
{161, 97, 145, 81, 175, 111, 159, 95, 164, 100, 148, 84, 174, 110, 158,
94},
{9, 225, 49, 209, 5, 239, 63, 223, 12, 228, 52, 212, 8, 238, 62, 222},
{137, 73, 177, 113, 133, 69, 191, 127, 140, 76, 180, 116, 136, 72, 190,
126},
{41, 201, 25, 241, 37, 197, 21, 255, 44, 204, 28, 244, 40, 200, 24, 254},
{169, 105, 153, 89, 165, 101, 149, 85, 172, 108, 156, 92, 168, 104, 152,
88},
{3, 233, 57, 217, 13, 229, 53, 213, 2, 236, 60, 220, 16, 232, 56, 216},
{131, 67, 185, 121, 141, 77, 181, 117, 130, 66, 188, 124, 144, 80, 184,
120},
{35, 195, 19, 249, 45, 205, 29, 245, 34, 194, 18, 252, 48, 208, 32, 248},
{163, 99, 147, 83, 173, 109, 157, 93, 162, 98, 146, 82, 176, 112, 160,
96},
{11, 227, 51, 211, 7, 237, 61, 221, 10, 226, 50, 210, 6, 240, 64, 224},
{139, 75, 179, 115, 135, 71, 189, 125, 138, 74, 178, 114, 134, 70, 192,
128},
{43, 203, 27, 243, 39, 199, 23, 253, 42, 202, 26, 242, 38, 198, 22, 256},
{171, 107, 155, 91, 167, 103, 151, 87, 170, 106, 154, 90, 166, 102, 150,
86}
};
XShpl_dither(PLANE *plane,PLANE_INFO *plane_info,LIMITS *limits,
double minval,double maxval,int pixsize,
int absolute,int negative,XImage *ximage)
{
int runlevel;
int deltapllevel;
int roff,coff;
int xim_y_coord, xim_x_coord, rbitoff, bitoff, byteoff, bitbyte;
register int maskrow, maskcol, saved_maskcol, saved_maskrow;
register int ipixrow, ipixcol;
int crow,ccol;
int byte;
double intensity_scale,value_range,pixel,scaled_pixel,fback;
register short int *maskrow_ptr;
if (autoscale) plane_min_max(plane,plane_info,limits,&minval,&maxval);
saved_maskrow = maskrow = 0;
runlevel = limits->level;
if (plane_info->datatype == FLOAT) fback = plane_info->background.flonum;
else fback = plane_info->background.fixnum;
deltapllevel = runlevel - plane_info->level;
value_range = maxval - minval;
intensity_scale = MAXINT_F / value_range;
for (crow = limits->startrow;
crow <= limits->endrow;
crow += limits->deltarow) {
saved_maskrow = (maskrow % 16);
maskcol = 0;
TRANSLEVEL(roff,crow,deltapllevel,plane_info->row_location);
xim_y_coord = (crow - limits->startrow) * pixsize;
for (ccol = limits->startcol;
ccol <= limits->endcol;
ccol += limits->deltacol) {
TRANSLEVEL(coff,ccol,deltapllevel,plane_info->column_location);
xim_x_coord = (ccol - limits->startcol) * pixsize;
maskrow = saved_maskrow;
GET_PIXEL(pixel,fback,plane,roff,coff,
(*plane_info));
if (absolute) pixel = fabs(pixel);
/* scale pixel. out of range values get black or white.
otherwise linear mapping */
if (intensity_scale > 0.0) {
/* positive slope case */
if (pixel < minval)
scaled_pixel = 0.0;
else
if (pixel > maxval)
scaled_pixel = MAXINT_F;
else
scaled_pixel =(pixel - minval) *
intensity_scale;
}
else { /* negative slope case */
if (pixel < maxval)
scaled_pixel = MAXINT_F;
else
if (pixel > minval)
scaled_pixel = 0.0;
else
scaled_pixel =(pixel - minval) *
intensity_scale;
}
byte = scaled_pixel + 0.5;
if (negative) byte = MAXINT_I - byte;
saved_maskcol = (maskcol % 16);
for (ipixrow=0;ipixrow<pixsize;ipixrow++) {
bitbyte = 1 << (bitoff & 0x07);
if (maskrow > 15) maskrow = 0;
maskrow_ptr = (&matrix[maskrow][0]);
maskcol = saved_maskcol;
for (ipixcol=0;ipixcol<pixsize;ipixcol++) {
if (maskcol > 15) maskcol = 0;
if (maskrow_ptr[maskcol] < byte) {
XPutPixel(ximage,xim_x_coord+ipixcol,xim_y_coord+ipixrow,1);
}
bitbyte = bitbyte << 1;
if (bitbyte > 0x0080) {
bitbyte = 1;
}
maskcol++;
}
maskrow++;
}
}
}
}