home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GRIPS 2: Government Rast…rocessing Software & Data
/
GRIPS_2.cdr
/
dos
/
imdisp
/
source
/
display.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-11-20
|
8KB
|
260 lines
/*************************************************************/
/* Copyright (C) 1989, California Institute of Technology */
/* U. S. Government Sponsorship under NASA Contract */
/* NAS7-918 is acknowledged. */
/*************************************************************/
/*** IMDISP module DISPLAY.C
DISPLAY contains the routines to handle the actual display
screen.
***/
/* * * * INCLUDE files * * * */
#include <conio.h>
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "imdef.h"
#include "imdisp.h"
#include "dispio.h"
#include "disputil.h"
#include "imageio.h"
#include "labutil.h"
#include "refresh.h"
/* * * * External functions * * * */
/* * * * Function declarations * * * */
int DisplayImage (void);
/* * * * Global Variables * * * */
int DisplayImage(void)
/* DisplayImage performs the display command.
First it gets the values (or defaults) of all of the possible
parameters. Then it checks them for validity and processes
the parameters into useful form. It then loops through the
image, reading a line, formatting it, displaying it, and stuffing
it into the refresh buffer.
*/
{
int line, samp, i, j, k;
int bitshift, NoScale, flag;
int centsub, centerflag, flipflag;
int up, down, left, right, upflag, downflag, leftflag, rightflag;
unsigned int bytesneeded;
char status[128];
unsigned char *buffer,ch;
if (OpenFileFlag == 0)
{
StatusLine(0,"Use the \'FILE fname\' command to select image");
return;
}
if (IMCB[0].nl == 0)
{
StatusLine(0,"No lines in image");
return;
}
GetKeywordInteger (CommandString, "SL", 1, &sl, &flag);
GetKeywordInteger (CommandString, "SS", 1, &ss, &flag);
if (ss > ns)
ss = 1;
GetKeywordInteger (CommandString, "NL", nl-sl+1, &nld, &flag);
GetKeywordInteger (CommandString, "NS", ns-ss+1, &nsd, &flag);
GetKeywordInteger (CommandString, "DSL", 1, &sldd, &flag);
GetKeywordInteger (CommandString, "DSS", 1, &ssdd, &flag);
GetKeywordInteger (CommandString, "SUB", 1, &subsample, &flag);
GetKeywordInteger (CommandString, "ZOO", 1, &zoom, &flag);
GetKeywordSubcommand (CommandString, "CEN", ¢erflag);
GetKeywordInteger (CommandString, "LEF", dispns, &left, &leftflag);
GetKeywordInteger (CommandString, "RIG", dispns, &right, &rightflag);
GetKeywordInteger (CommandString, "UP", dispnl, &up, &upflag);
GetKeywordInteger (CommandString, "DOW", dispnl, &down, &downflag);
GetKeywordSubcommand (CommandString, "FLI", &flipflag);
if (subsample < 1)
subsample = 1;
if (zoom < 1)
zoom = 1;
if (subsample > 1)
zoom = 1;
if ( (leftflag > -1) || (rightflag > -1) ||
(upflag > -1) || (downflag > -1) )
{
sl = lastsl;
ss = lastss;
if (leftflag > -1)
ss -= left;
if (rightflag > -1)
ss += right;
if (upflag > -1)
sl -= up;
if (downflag > -1)
sl += down;
}
if (sl < 1)
sl = 1;
else if (sl > nl)
sl = nl;
if (ss < 1)
ss = 1;
else if (ss > ns)
ss = ns;
/* CENTer command stuff */
if ( (centerflag >= 0) && (centerline > 0) )
{
nldd = zoom*nld / subsample;
nsdd = zoom*nsd / subsample;
if (nldd+sldd-1 > dispnl)
nldd = dispnl-sldd+1;
if (nsdd+ssdd-1 > dispns)
nsdd = dispns-ssdd+1;
nld = subsample*nldd / zoom;
nsd = subsample*nsdd / zoom;
sl = centerline - (nld / 2);
if (sl < 1) sl = 1;
ss = centersamp - (nsd / 2);
if (ss < 1) ss = 1;
CursorLine = zoom*(centerline - sl) / subsample + sldd;
CursorSample = zoom*(centersamp - ss) / subsample + ssdd;
}
lastsl = sl;
lastss = ss;
if (nld+sl-1 > nl)
nld = nl-sl+1;
if (nsd+ss-1 > ns)
nsd = ns-ss+1;
nldd = zoom*nld / subsample;
nsdd = zoom*nsd / subsample;
if (nldd+sldd-1 > dispnl)
nldd = dispnl-sldd+1;
if (nsdd+ssdd-1 > dispns)
nsdd = dispns-ssdd+1;
nld = subsample*nldd / zoom;
nsd = subsample*nsdd / zoom;
nldd = zoom*nld / subsample;
nsdd = zoom*nsd / subsample;
if (bitsperpix <= 8)
bytesneeded = zoom*nsd;
else if (bitsperpix == 32)
bytesneeded = 4*zoom*nsd;
else
bytesneeded = 2*zoom*nsd;
while ((buffer = malloc(bytesneeded)) == NULL)
FreeRefresh("pixel buffer");
if (bitsperpix >= 8)
{
bitshift = Round(log(((double)DNhigh-DNlow+1)/numDN) /0.693147);
NoScale = (DNlow==0) && (DNhigh==(1 << bitsperpix)-1);
}
else
bitshift = bitsperpix - Round(log((double)numDN)/0.693147);
/* Loop through image line by line */
if (zoom == 1)
{
line = sl;
for (i = sldd; i < nldd+sldd; i++)
{
if (flipflag == 1)
j = nldd+sldd - i;
else
j = i;
ReadLine (0, buffer, line, ss, nsd, status);
if (BadStatus(status))
{
free (buffer);
break;
}
FormatLine (buffer, nsdd, nsd, bitshift, NoScale, status);
if (BadStatus(status))
{
free (buffer);
break;
}
DisplayLine (buffer, j, ssdd, nsdd);
PutRefresh (buffer, j, ssdd, nsdd);
line += subsample;
if (kbhit()) /* abort disp if keypressed mdm 2/19/88*/
{
if ((ch = getch()) == 0) ch = 0x80 | getch();
if (ch != 17) /* don't abort if cntl q */
{
i=nldd+sldd;
abort_disp = 1;
}
}
}
}
else
{
i = sldd;
for (line = sl; line < nld+sl; line++)
{
if (flipflag == 1)
j = nld*zoom - i;
else
j = i;
ReadLine (0, buffer, line, ss, nsd, status);
if (BadStatus(status))
free (buffer);
FormatLine (buffer, nsdd, nsd, bitshift, NoScale, status);
if (BadStatus(status))
free (buffer);
for (k = 1; k <= zoom; k++)
{
DisplayLine (buffer, j, ssdd, nsdd);
PutRefresh (buffer, j, ssdd, nsdd);
i++; j++;
if (kbhit()) /* abort disp if keypressed mdm 2/19/88*/
{
if ((ch = getch()) == 0) ch = 0x80 | getch();
if (ch != 17) /* don't abort if cntl q */
{
line = nld+sl;
k=zoom;
abort_disp = 1;
}
}
}
}
}
/* If SelectFlag is raised indicating the SELECT option has been
selected in the BROWSE command, then prompt user
Ron Baalke 11/04/90 */
if (SelectFlag)
{
StatusLine(1,"Select this image (Y=Yes N=No (default) Q=Quit) ?");
i = getch();
if ((i == 89) || (i == 121)) /* 'Y' or 'y' */
fprintf(SelectFile,"%s\n",ImageFileName);
else if ((i == 81) || (i == 113) || (i==27)) /* 'Q', 'q' or ESC */
abort_disp = 1;
}
}