home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright 1990 by John Wiley & Sons, Inc.
- All Rights Reserved.
- */
- /****************************************/
- /*All Resolution Video Digitizer Program*/
- /* Digitizes, Displays and Saves Images */
- /* in all supported digitizer modes */
- /* written in Turbo C 2.0 */
- /* by */
- /* Craig A. Lindley */
- /* */
- /* Vers: 1.0 Last Update: 09/28/89 */
- /****************************************/
-
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- #include <process.h>
- #include <string.h>
- #include <graphics.h>
- #include <alloc.h>
- #include "misc.h"
- #include "pcx.h"
- #include "vga.h"
- #include "digitizer.h"
-
-
- #define MaxFileNameLen 13 /* filename str length including null */
-
- /*
- The two defines offset the focus window so it
- is displayed in the center on the VGA screen.
- */
-
- #define ColCenterOffsetAmount 110
- #define RowCenterOffsetAmount 50
-
- /* Global Variables */
-
- struct ImageReq Req;
- char huge *PictureData;
- unsigned ColCenterOffset, RowCenterOffset;
-
-
- /* display the digitized image in VGA mode 13h with 64 levels of gray */
- void DisplayPictData1 (char huge *PictData)
- {
- register unsigned Col, Row, Color;
- unsigned ColSpan, RowSpan;
- unsigned long PixelBufOffset;
-
- ColSpan = Req.LastPixel - Req.FirstPixel;
- RowSpan = Req.LastLine - Req.FirstLine;
- for (Col=0; Col < ColSpan; Col++)
- {
- PixelBufOffset = (long) RowSpan * Col;
- for (Row=0; Row < RowSpan; Row++)
- {
- Color = PictData[PixelBufOffset + Row];
- PutPixel256(Col+ColCenterOffset,
- Row+RowCenterOffset,Color);
- }
- }
- }
-
- /* display the digitized image in normal 16 color VGA modes */
- void DisplayPictData2 (char huge *PictData)
- {
- register unsigned Col, Row, Color;
- unsigned ColSpan, RowSpan;
- unsigned long PixelBufOffset;
-
- ColSpan = Req.LastPixel - Req.FirstPixel;
- RowSpan = Req.LastLine - Req.FirstLine;
- for (Col=0; Col < ColSpan; Col++)
- {
- PixelBufOffset = (long) RowSpan * Col;
- for (Row=0; Row < RowSpan; Row++)
- {
- Color = PictData[PixelBufOffset + Row];
- Color >>= 2; /* scale data to 0 ..15 */
- putpixel(Col,Row,Color);
- }
- }
- }
-
- /*
- This function provides help in the advent of operator error. Program
- terminates after help is given
- */
-
- void ShowHelp( void )
- {
- printf("\nThis program digitizes, displays and optionally\n");
- printf("saves in PCX format a single digitized image in\n");
- printf("three different resolutions. Its usage is as follows:\n\n");
- printf("allvideo [-o] filename <cr>\n");
- printf(" -o creates output PCX files\n");
- printf(" filename is name given to the PCX file(s). Do not\n");
- printf(" specify a file extension, it will be provided.\n\n");
- exit(1);
- }
-
- /* main digitizer program */
-
- void main(short argc, char *argv[])
- {
- unsigned long RasterSize;
- unsigned GenPCXFile;
- unsigned FileNameCounter, ArgIndex, StrLength;
- char *ImageFileName;
- char ProcessedFileName[MaxFileNameLen];
- char LRName[MaxFileNameLen];
- char MRName[MaxFileNameLen];
- char HRName[MaxFileNameLen];
-
-
- InitGraphics();
-
- clrscr();
- printf("Digitize and Display Gray Scale Images in Many Resolutions\n\n");
-
- /* install default options */
- GenPCXFile = FALSE; /* don't generate a. PCX file */
-
- /* parse command line arguments */
-
- FileNameCounter = 0; /* count of user specified filenames */
- for (ArgIndex=1; ArgIndex < argc; ArgIndex++)
- {
- if (*argv[ArgIndex] != '-') /* if not a cmd line switch */
- { /* must be a filename */
- if (*argv[ArgIndex] == '?') /* help requested ? */
- ShowHelp();
- if (FileNameCounter > 1) /* only one filename allowed */
- ShowHelp(); /* if more then error exit */
- ImageFileName = argv[ArgIndex]; /* save image filename */
- FileNameCounter++; /* inc count for error check */
- }
- else /* its a cmd line switch */
- {
- switch (*(argv[ArgIndex]+1)) /* parse the cmd line */
- {
- case 'o': /* o or O = output files */
- case 'O':
- GenPCXFile = TRUE;
- break;
- default:
- printf("Error - invalid cmd line switch encountered\n");
- ShowHelp();
- }
- }
- }
- if (GenPCXFile && (FileNameCounter != 1))
- {
- printf("Error - single filename required for PCX files\n");
- ShowHelp();
- }
-
- /*
- Preprocess any filename input from the cmd line. Strip
- off any specified extension and limit the filename
- length to six characters max. This will allow the
- designations LR.PCX, MR.PCX and HR.PCX to be appended.
- */
-
- if (GenPCXFile) /* only process if necessary */
- {
-
- strcpy(ProcessedFileName,""); /* empty string */
-
- /* find filename length minus the extension */
- StrLength = strcspn(ImageFileName,".");
-
- if (StrLength > 6) /* exceeds max length ? */
- strncat(ProcessedFileName,ImageFileName,6); /* cat only 6 chars */
- else
- strncat(ProcessedFileName,ImageFileName,StrLength);
- /*
- Copy the processed file name to each of the PCX
- filename storage areas and append the appropriate string.
- */
- strcpy(LRName,ProcessedFileName);
- strcat(LRName,"LR.PCX");
- strupr(LRName);
-
- strcpy(MRName,ProcessedFileName);
- strcat(MRName,"MR.PCX");
- strupr(MRName);
-
- strcpy(HRName,ProcessedFileName);
- strcat(HRName,"HR.PCX");
- strupr(HRName);
- }
-
- printf("Use focus window to focus camera. Then press\n");
- printf("any key to start the digitization process.\n");
- printf("Image resolutions are: 320x200, 640x200 and 640x480\n\n");
-
- if (GenPCXFile)
- {
- printf("Image filenames will be:\n\n");
- printf(" %s for the low resolution 320x200 image\n",LRName);
- printf(" %s for the mid resolution 640x200 image\n",MRName);
- printf(" %s for the high resolution 640x480 image\n",HRName);
- }
- else
- printf("PCX files will not be generated\n");
-
- printf("\nPress any key after third image to terminate program.\n\n");
- delay(4000);
-
- /* pick largest size image buffer required */
-
- RasterSize = 307200L; /* big enough for 640x480 image */
-
- /* allocate picture buffer and set it to zeros */
-
- if ((PictureData = (char huge *) farcalloc(RasterSize,
- (unsigned long) sizeof(char))) == NULL)
- {
- printf("Digitize - Not enough memory\n");
- exit(ENoMemory);
- }
-
- /*
- Build a structure that defines what the digitizer should acquire. this
- will be passed to the digitizer by a call to InitializeDigitizer
- function. The following portion of the ImageReq structure does
- not change as the image resolution changes.
- */
-
- Req.ComputerType = PS220;
- Req.PrtBase = 0x3BC;
- Req.NumberOfPasses = 1;
- Req.Flags = 0L;
- Req.PictBuf = PictureData; /* put buffer addr into ImageReq */
-
- /*
- This portion of the structure changes with image resolution
- */
-
- Req.HMode = LowRes;
- Req.VMode = NonInterlace;
- Req.FirstLine = 50; /* focus window dimensions */
- Req.FirstPixel = 110;
- Req.LastLine = 150;
- Req.LastPixel = 210;
-
- InitializeDigitizer(&Req);/* initialize digitizer */
-
- Set256ColorMode(); /* 320x200 256 color VGA mode */
- LoadGray64Palette(); /* load the gray scale palette */
-
- /* offset focus window to the center of the screen */
- ColCenterOffset = ColCenterOffsetAmount;
- RowCenterOffset = RowCenterOffsetAmount;
-
- while (!kbhit()) /* acquire a picture continually */
- { /* until operator hits key */
- GetPicture();
- DisplayPictData1(PictureData);
- }
- getch(); /* empty key buffer */
-
- /* now digitize a full 320x200 image */
-
- Req.HMode = LowRes;
- Req.VMode = NonInterlace;
- Req.FirstLine = 0;
- Req.FirstPixel = 0;
- Req.LastLine = 200; /* do a 320x200 image */
- Req.LastPixel = 320;
-
- InitializeDigitizer(&Req); /* initialize digitizer */
-
- GetPicture(); /* acquire the picture */
-
- /* remove display offset as required for full image display */
- ColCenterOffset = 0;
- RowCenterOffset = 0;
-
- DisplayPictData1(PictureData); /* display the picture */
-
- if (GenPCXFile) /* write out the PCX file */
- WritePCXFile(LRName,8,320,200,1,320);
-
- /* now digitize a full 640x200 image */
-
- Req.HMode = HighRes;
- Req.VMode = NonInterlace;
- Req.LastLine = 200; /* do a 640x200 image */
- Req.LastPixel = 640;
-
- InitializeDigitizer(&Req); /* initialize digitizer */
-
- GetPicture(); /* acquire the picture */
- setgraphmode(VGALO);
- LoadGray16Palette(); /* load the gray scale palette */
- DisplayPictData2(PictureData); /* display the picture */
-
- if (GenPCXFile) /* write out the PCX file */
- WritePCXFile(MRName,1,640,200,4,80);
-
- /* now digitize a full 640x480 image */
-
- Req.HMode = HighRes;
- Req.VMode = Interlace;
- Req.LastLine = 480; /* do a 640x480 image */
- Req.LastPixel = 640;
-
- InitializeDigitizer(&Req); /* initialize digitizer */
-
- GetPicture(); /* acquire the picture */
- setgraphmode(VGAHI);
- LoadGray16Palette(); /* load the gray scale palette */
- DisplayPictData2(PictureData); /* display the picture */
-
- if (GenPCXFile) /* write out the PCX file */
- WritePCXFile(HRName,1,640,480,4,80);
-
- getch(); /* wait for operator */
- restorecrtmode(); /* clean up and quit */
- farfree((char far *)PictureData);
- closegraph();
- }
-