home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / IMGPROC.ZIP / C12.ZIP / GETEST.C < prev   
Encoding:
C/C++ Source or Header  |  1990-04-06  |  6.5 KB  |  207 lines

  1. /*  
  2. Copyright 1990 by John Wiley & Sons, Inc.
  3.           All Rights Reserved.
  4. */
  5. /****************************************/
  6. /*   Geometric Process Demo Program     */
  7. /*       written in Turbo C 2.0         */
  8. /*                by                    */
  9. /*         Craig A. Lindley             */
  10. /*                                      */
  11. /*   Vers: 1.0  Last Update: 12/26/89   */
  12. /****************************************/
  13.  
  14. #include <stdio.h>
  15. #include <conio.h>
  16. #include <dos.h>
  17. #include <alloc.h>
  18. #include <process.h>
  19. #include <graphics.h>
  20. #include "misc.h"
  21. #include "pcx.h"
  22. #include "vga.h"
  23. #include "imagesup.h"
  24. #include "geprocess.h"
  25.  
  26. /* main geometric process program */
  27.  
  28. void main(void)
  29. {
  30.    char *InFileName1 = "p2c12i1a";
  31.    char *InFileName2 = "p2c12i2a";
  32.    char *InFileName3 = "p2c12i3a";
  33.    char *InFileName4 = "p2c12i4a";
  34.    char *InFileName5 = "p2c12i5a";
  35.  
  36.    BYTE huge *InImage;
  37.    BYTE huge *Buffer;
  38.    unsigned GenPCXFiles = FALSE; /* controls output file generation */
  39.  
  40.  
  41.    InitGraphics();
  42.  
  43.    printf("Geometric Transform Example Program\n\n");
  44.    printf("Reading the Image PCX File into memory\n");
  45.  
  46.    /* allocate far memory buffer for images */
  47.    Buffer = (BYTE huge *)farcalloc(RASTERSIZE,(long)sizeof(BYTE));
  48.  
  49.    if (Buffer == NULL)
  50.    {
  51.       restorecrtmode();
  52.       printf("Error Not enough memory for geometric operation\n");
  53.       exit(ENoMemory);
  54.    }
  55.  
  56.    /*
  57.    Prepare image sequence p2ch12i1 - Image Magnification
  58.    */
  59.    if (ReadPCXFileToBuf (InFileName1,&InImage) != NoError)
  60.       exit(ENoMemory);
  61.  
  62.    DisplayImageInBuf(InImage,INITVGALOADPALETTE,WAITFORKEY);
  63.  
  64.    /* Clear the output buffer to black. */
  65.    ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,WHITE);
  66.  
  67.    ScaleImage(InImage,119,13,83,111,1.3,1.3,Buffer,100,25,FALSE);
  68.    DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
  69.    if (GenPCXFiles)
  70.       WritePCXFile("p2c12i1b",8,320,200,1,320);
  71.  
  72.    /* Clear the output buffer to black. */
  73.    ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,BLACK);
  74.  
  75.    ScaleImage(InImage,119,13,83,111,1.3,1.3,Buffer,100,25,TRUE);
  76.    DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
  77.    if (GenPCXFiles)
  78.       WritePCXFile("p2c12i1c",8,320,200,1,320);
  79.  
  80.    farfree((BYTE far *)InImage); /* free memory */
  81.  
  82.    /*
  83.    Prepare image sequence p2ch12i2 - Image Reduction
  84.    */
  85.    if (ReadPCXFileToBuf (InFileName2,&InImage) != NoError)
  86.       exit(ENoMemory);
  87.  
  88.    DisplayImageInBuf(InImage,NOVGAINIT,WAITFORKEY);
  89.  
  90.    /* Clear the output buffer to black. */
  91.    ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,WHITE);
  92.  
  93.    ScaleImage(InImage,9,76,291,105,0.5,0.5,Buffer,80,74,FALSE);
  94.    DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
  95.    if (GenPCXFiles)
  96.       WritePCXFile("p2c12i2b",8,320,200,1,320);
  97.  
  98.    /* Clear the output buffer to black. */
  99.    ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,WHITE);
  100.  
  101.    ScaleImage(InImage,9,76,291,105,0.5,0.5,Buffer,80,74,TRUE);
  102.    DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
  103.    if (GenPCXFiles)
  104.       WritePCXFile("p2c12i2c",8,320,200,1,320);
  105.  
  106.    farfree((BYTE far *)InImage); /* free memory */
  107.  
  108.    /* Prepare image sequence p2ch12i3 Various Sized Images */
  109.  
  110.    if (ReadPCXFileToBuf (InFileName3,&InImage) != NoError)
  111.       exit(ENoMemory);
  112.  
  113.    DisplayImageInBuf(InImage,NOVGAINIT,WAITFORKEY);
  114.  
  115.    /*
  116.    Clearing the output buffer to white will show the
  117.    boarder areas not touched by the scaling process. It also
  118.    provides a nice white frame for the output image.
  119.    */
  120.    ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,WHITE);
  121.  
  122.    /* Image 1 is scaled .5 x .5 and occupies lower right corner */
  123.    ScaleImage(InImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  124.           0.5,0.5,Buffer,155,95,TRUE);
  125.  
  126.    /* Image 2 is scaled .45 x .67 and occupies upper left corner */
  127.    ScaleImage(InImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  128.           0.45,0.67,Buffer,4,4,TRUE);
  129.  
  130.    /* Image 3 is scaled .5 x .42 and occupies upper right corner */
  131.    ScaleImage(InImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  132.           0.5,0.42,Buffer,155,4,TRUE);
  133.  
  134.    /* Image 4 is scaled .25 x .25 and occupies lower left corner */
  135.    ScaleImage(InImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  136.           0.25,0.25,Buffer,38,145,TRUE);
  137.  
  138.    DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
  139.    if (GenPCXFiles)
  140.       WritePCXFile("p2c12i3b",8,320,200,1,320);
  141.  
  142.    farfree((BYTE far *)InImage); /* free memory */
  143.  
  144.    /* Prepare image sequence p2ch12i4 - Rotated Images */
  145.  
  146.    if (ReadPCXFileToBuf (InFileName4,&InImage) != NoError)
  147.       exit(ENoMemory);
  148.  
  149.    DisplayImageInBuf(InImage,NOVGAINIT,WAITFORKEY);
  150.  
  151.    /*
  152.    Clearing the output buffer to black.
  153.    */
  154.    ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,BLACK);
  155.  
  156.    RotateImage(InImage,105,43,117,107,37.5,Buffer,FALSE);
  157.    DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
  158.    if (GenPCXFiles)
  159.       WritePCXFile("p2c12i4b",8,320,200,1,320);
  160.  
  161.    ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,BLACK);
  162.  
  163.    RotateImage(InImage,105,43,117,107,37.5,Buffer,TRUE);
  164.    DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
  165.    if (GenPCXFiles)
  166.       WritePCXFile("p2c12i4c",8,320,200,1,320);
  167.  
  168.    ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,BLACK);
  169.  
  170.    RotateImage(InImage,105,43,117,107,300.0,Buffer,FALSE);
  171.    DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
  172.    if (GenPCXFiles)
  173.       WritePCXFile("p2c12i4d",8,320,200,1,320);
  174.  
  175.    ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,BLACK);
  176.  
  177.    RotateImage(InImage,105,43,117,107,300.0,Buffer,TRUE);
  178.    DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
  179.    if (GenPCXFiles)
  180.       WritePCXFile("p2c12i4e",8,320,200,1,320);
  181.  
  182.    farfree((BYTE far *)InImage); /* free memory */
  183.  
  184.    /* Prepare image sequence p2ch12i5 - Mirrored Images */
  185.  
  186.    if (ReadPCXFileToBuf (InFileName5,&InImage) != NoError)
  187.       exit(ENoMemory);
  188.  
  189.    DisplayImageInBuf(InImage,NOVGAINIT,WAITFORKEY);
  190.  
  191.    /*
  192.    Clearing the output buffer to black.
  193.    */
  194.    ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,BLACK);
  195.    TranslateImage(InImage,82,76,166,48,Buffer,82,10,FALSE);
  196.    MirrorImage(InImage,82,76,166,48,HorizMirror,Buffer,82,76);
  197.    MirrorImage(InImage,82,76,166,48,VertMirror,Buffer,82,142);
  198.    DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
  199.    if (GenPCXFiles)
  200.       WritePCXFile("p2c12i5b",8,320,200,1,320);
  201.  
  202.    farfree((BYTE far *)InImage); /* free memory */
  203.    farfree((BYTE far *)Buffer);
  204.    restorecrtmode();
  205.    closegraph();
  206. }
  207.