home *** CD-ROM | disk | FTP | other *** search
- /**╟─────────────────────────────────────────────────────╢
- **║ ║
- **║ Copyright MCMXCI, Jeffrey Chasen ║
- **║ ║
- **║ ║
- **╟─────────────────────────────────────────────────────╢
- */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <sys\stat.h>
- #include <dos.h>
- #include <conio.h>
- #include <alloc.h>
- #include <graphics.h>
-
- /* ------------------------------------------------------------------- */
- /* The file created by BGISNap contains a header telling how many image */
- /* segments the image was split in to. Borland BGI has a max size of */
- /* 64K for any given image. */
- /* */
- /* Format of the file created by BGISnap is as follows: */
- /* Header -- (contains 2 bytes which is the number of segments) */
- /* Byte 1 -- (int) containing the number of image segments */
- /* Byte 2 -- contained in this file (a segment can be up to 64k) */
- /* */
- /* Segment 1 (all byte positions are now relative to this segment) */
- /* Byte 1 -- (unsigned int) containing the byte size of this segment*/
- /* Byte 2 */
- /* */
- /* Byte 3 -- (int) containg the X position of the image */
- /* Byte 4 */
- /* */
- /* Byte 5 -- (int) containg the Y position of the segment */
- /* Byte 6 */
- /* */
- /* Byte 7 -- Beginning of image data (a normal putimage() can be */
- /* done on his data) */
- /* ............. */
- /* Segment 2 .etc */
- /* ------------------------------------------------------------------- */
-
- /* ------------------------------------------------------------------- */
- /* This function will display an image snapped by BGISnap into file */
- /* The graphics system must have been previously been initialized */
- /* to the proper mode. */
- /* ------------------------------------------------------------------- */
- void displayBGIImage(char *file)
- {
- int i, x1, y1, numSegments;
- static char far *buf = NULL;
- unsigned int gSeg, size;
- FILE *fp;
-
- fp = fopen(file,"rb");
- if (fp == NULL)
- return;
-
- // allocate memory first time from DOS
- // can be changed to allocate each time the function is called
- // or even for each segment
- if (buf == NULL)
- {
- unsigned int size = 64*(1024/16); // allocate 64K which is
- allocmem(size,&gSeg); // the largest a segment can be
- buf = MK_FP(gSeg,0);
- }
-
-
- fread(&numSegments,1,sizeof(int),fp); // read each segment and
- for (i = 0; i < numSegments; i++) // display it at the proper position
- {
- fread(&size,1,sizeof(int),fp);
- fread(&x1,1,sizeof(int),fp);
- fread(&y1,1,sizeof(int),fp);
- fread(buf,1,size,fp);
- putimage(x1,y1,buf,COPY_PUT);
- }
-
- /* freemem(gSeg); can be used to free memory each time if it is needed */
-
- fclose(fp);
- }
-