home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright 1990 by John Wiley & Sons, Inc.
- All Rights Reserved.
- */
- /****************************************/
- /* Generic Video Digitizer Program */
- /* Digitizes 320x200 Images */
- /* Images displayed with both 16 and 64 */
- /* levels of gray */
- /* written in Turbo C 2.0 */
- /* by */
- /* Craig A. Lindley */
- /* */
- /* Vers: 1.0 Last Update: 09/14/89 */
- /****************************************/
-
- #include <stdio.h>
- #include <conio.h>
- #include <process.h>
- #include <graphics.h>
- #include <alloc.h>
- #include "misc.h"
- #include "pcx.h"
- #include "vga.h"
- #include "digitizer.h"
-
- /* Global Variables */
-
- static struct ImageReq Req;
- static char huge *PictureData;
-
-
- /*
- This function displays the digitized image with a 16
- level gray scale palette. Notice the video data in
- PictData is shifted to the right twice. This scales
- the 6 bit data to 4 bits as required for
- a 16 color display. Notice also that this function is
- driven by parameters in the ImageReq structure. That means
- DisplayPictData will automatically configure itself as
- the image parameters change.
- */
-
- void DisplayPictData16Gray (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;
- /* use special VGA mode 13h putpixel function */
- /* required for 320x200 images */
- PutPixel256(Col,Row,Color);
- }
- }
- }
-
- /*
- This function displays the digitized image with a 64
- level gray scale palette. Notice the video data in
- is not scaled in this case as all 6 bits are needed
- to index the correct color register.
- */
-
- void DisplayPictData64Gray (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];
- /* use special VGA mode 13h putpixel function */
- /* required for 320x200 images */
- PutPixel256(Col,Row,Color);
- }
- }
- }
-
- /* main digitizer program */
-
- void main(void)
- {
- unsigned Count;
- unsigned long RasterSize;
-
- InitGraphics(); /* initialize graphics subsystem */
-
- clrscr();
- printf("Generic Digitizer Test Program\n\n");
- printf("This program digitizes a 320x200 pixel image then\n");
- printf("displays it first with 16 and then with 64 levels\n");
- printf("of gray.\n\n");
-
- /*
- Build a structure that defines what the digitizer should acquire. this
- will be passed to the digitizer by a call to InitializeDigitizer
- function
- */
-
- Req.ComputerType = PS220;
- Req.PrtBase = 0x3BC;
- Req.HMode = LowRes;
- Req.VMode = NonInterlace;
- Req.NumberOfPasses = 1;
- Req.Flags = 0L;
- Req.FirstLine = 0;
- Req.FirstPixel = 0;
- Req.LastLine = 200; /* set up 320x200 image */
- Req.LastPixel = 320;
-
- RasterSize = (Req.LastLine - Req.FirstLine) *
- (Req.LastPixel - Req.FirstPixel);
-
- /* allocate picture buffer from the far heap and set it to zeros */
- printf("Allocating Image Buffer - RasterSize is %lu bytes\n\n",RasterSize);
-
- if ((PictureData = (char huge *) farcalloc(RasterSize,
- (unsigned long) sizeof(char))) == NULL)
- {
- printf("Digitize - Not enough memory\n");
- exit(ENoMemory);
- }
-
- /* place address of image buffer in the ImageReq structure */
- Req.PictBuf = PictureData;
-
- /* inform digitizer of image parameters */
- InitializeDigitizer(&Req);
-
- /* run a test of the digitizer */
- printf("SyncPerField Digitizer Synchronization Test\n\n");
- for (Count = 0; Count < 10; Count++)
- printf("SPF=%d\n",SyncsPerField());
-
- printf("\nPress any key to terminate image display\n\n");
- printf("Acquiring Image . . .\n");
-
- GetPicture(); /* acquire requested image */
-
- Set256ColorMode(); /* 320x200 256 color VGA mode */
-
- LoadGray16Palette(); /* load the gray scale palette */
-
- DisplayPictData16Gray(PictureData); /* display the image */
-
- getch(); /* operator terminates display */
-
- LoadGray64Palette(); /* load the new gray scale palette */
-
- DisplayPictData64Gray(PictureData); /* display the image */
-
- getch(); /* operator terminates display */
-
- restorecrtmode(); /* back to text mode */
- farfree((char far *)PictureData); /* give memory back */
- closegraph(); /* close up shop */
- }
-