home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / IMGPROC.ZIP / C9.ZIP / PTTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-06  |  7.1 KB  |  224 lines

  1. /*  
  2. Copyright 1990 by John Wiley & Sons, Inc.
  3.           All Rights Reserved.
  4. */
  5. /****************************************/
  6. /*       Image Processing Code          */
  7. /*      Point Process Functions         */
  8. /*       written in Turbo C 2.0         */
  9. /*                by                    */
  10. /*         Craig A. Lindley             */
  11. /*                                      */
  12. /*   Vers: 1.0  Last Update: 12/26/89   */
  13. /****************************************/
  14.  
  15. #include <stdio.h>
  16. #include <alloc.h>
  17. #include <process.h>
  18. #include <graphics.h>
  19. #include "misc.h"
  20. #include "pcx.h"
  21. #include "vga.h"
  22. #include "imagesup.h"
  23. #include "ptprocess.h"
  24.  
  25. /* main point process program */
  26.  
  27. void main(void)
  28. {
  29.    char *InFileName1  = "p2ch9i1a";
  30.    char *InFileName2  = "p2ch9i2a";
  31.    char *InFileName3  = "p2ch9i3a";
  32.    char *InFileName4a = "p2ch9i4a";
  33.    char *InFileName4b = "p2ch9i4c";
  34.    char *InFileName4c = "p2ch9i4e";
  35.    char *InFileName5  = "p2ch9i5a";
  36.    char *InFileName6  = "p2ch9i6a";
  37.  
  38.    BYTE huge *TheImage;
  39.    unsigned GenPCXFiles = FALSE;  /* controls generation of output files */
  40.    BYTE PseudoColorLUT[MAXQUANTLEVELS];
  41.  
  42.    InitGraphics();
  43.  
  44.    printf("Point Transform Example Program\n\n");
  45.    printf("Reading the Image PCX File into memory\n");
  46.  
  47.    /* generate image sequence p2ch9i1 - Image brightening */
  48.    /* load the PCX file into memory */
  49.    if (ReadPCXFileToBuf (InFileName1,&TheImage) != NoError)
  50.       exit(1);
  51.  
  52.    /* display the image pointed at by TheImage */
  53.    DisplayImageInBuf(TheImage,INITVGALOADPALETTE,WAITFORKEY);
  54.    DisplayHist(TheImage,MINCOLNUM,MINROWNUM,130,MAXROWS);
  55.    if (GenPCXFiles)
  56.       WritePCXFile("p2ch9i1b",8,320,200,1,320);
  57.    AdjImageBrightness(TheImage,+17,MINCOLNUM,MINROWNUM,130,MAXROWS);
  58.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  59.    if (GenPCXFiles)
  60.       WritePCXFile("p2ch9i1c",8,320,200,1,320);
  61.    DisplayHist(TheImage,MINCOLNUM,MINROWNUM,130,MAXROWS);
  62.    if (GenPCXFiles)
  63.       WritePCXFile("p2ch9i1d",8,320,200,1,320);
  64.  
  65.    farfree((BYTE far *)TheImage);
  66.  
  67.  
  68.    /* generate image sequence p2ch9i2 - Image negation */
  69.    /* load the PCX file into memory */
  70.    if (ReadPCXFileToBuf (InFileName2,&TheImage) != NoError)
  71.       exit(1);
  72.  
  73.    /* display the image pointed at by TheImage */
  74.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  75.    NegateImage(TheImage,0,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
  76.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  77.    if (GenPCXFiles)
  78.       WritePCXFile("p2ch9i2b",8,320,200,1,320);
  79.  
  80.    farfree((BYTE far *)TheImage);
  81.  
  82.    /* reload the PCX file into memory */
  83.    if (ReadPCXFileToBuf (InFileName2,&TheImage) != NoError)
  84.       exit(1);
  85.  
  86.    /* display the image pointed at by TheImage */
  87.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  88.    NegateImage(TheImage,50,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
  89.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  90.    if (GenPCXFiles)
  91.       WritePCXFile("p2ch9i2c",8,320,200,1,320);
  92.  
  93.    farfree((BYTE far *)TheImage);
  94.  
  95.  
  96.    /* generate image sequence p2ch9i3 - Image thresholding */
  97.    /* load the PCX file into memory */
  98.    if (ReadPCXFileToBuf (InFileName3,&TheImage) != NoError)
  99.       exit(1);
  100.  
  101.    /* display the image pointed at by TheImage */
  102.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  103.    ThresholdImage(TheImage,35,110,50,105,105);
  104.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  105.    if (GenPCXFiles)
  106.       WritePCXFile("p2ch9i3b",8,320,200,1,320);
  107.  
  108.    farfree((BYTE far *)TheImage);
  109.  
  110.    /* generate image sequence p2ch9i4 - A Study of Contrasts */
  111.    /* load the PCX file into memory */
  112.    if (ReadPCXFileToBuf (InFileName4a,&TheImage) != NoError)
  113.       exit(1);
  114.  
  115.    /* display the image pointed at by TheImage */
  116.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  117.    DisplayHist(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
  118.    if (GenPCXFiles)
  119.       WritePCXFile("p2ch9i4b",8,320,200,1,320);
  120.  
  121.    farfree((BYTE far *)TheImage);
  122.  
  123.    /* load the PCX file into memory */
  124.    if (ReadPCXFileToBuf (InFileName4b,&TheImage) != NoError)
  125.       exit(1);
  126.  
  127.    /* display the image pointed at by TheImage */
  128.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  129.    DisplayHist(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
  130.    if (GenPCXFiles)
  131.       WritePCXFile("p2ch9i4d",8,320,200,1,320);
  132.  
  133.    farfree((BYTE far *)TheImage);
  134.  
  135.    /* load the PCX file into memory */
  136.    if (ReadPCXFileToBuf (InFileName4c,&TheImage) != NoError)
  137.       exit(1);
  138.  
  139.    /* display the image pointed at by TheImage */
  140.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  141.    DisplayHist(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
  142.    if (GenPCXFiles)
  143.       WritePCXFile("p2ch9i4f",8,320,200,1,320);
  144.  
  145.    farfree((BYTE far *)TheImage);
  146.  
  147.    /* generate image sequence p2ch9i5 - Contrast Stretching */
  148.    /* load the PCX file into memory */
  149.    if (ReadPCXFileToBuf (InFileName5,&TheImage) != NoError)
  150.       exit(1);
  151.  
  152.    /* display the image pointed at by TheImage */
  153.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  154.    DisplayHist(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
  155.    if (GenPCXFiles)
  156.       WritePCXFile("p2ch9i5b",8,320,200,1,320);
  157.    StretchImageContrast(TheImage,Histogram,475,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
  158.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  159.    if (GenPCXFiles)
  160.       WritePCXFile("p2ch9i5c",8,320,200,1,320);
  161.    DisplayHist(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
  162.    if (GenPCXFiles)
  163.       WritePCXFile("p2ch9i5d",8,320,200,1,320);
  164.    farfree((BYTE far *)TheImage);
  165.  
  166.    /* generate image sequence p2ch9i6 - Pseudo Coloring */
  167.    /* load the PCX file into memory */
  168.    if (ReadPCXFileToBuf (InFileName6,&TheImage) != NoError)
  169.       exit(1);
  170.  
  171.    /* display the image pointed at by TheImage */
  172.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  173.  
  174.    /* Set color reg 64 to red, 65 to green and 66 to blue */
  175.    SetAColorReg(64,63,0,0);
  176.    SetAColorReg(65,0,63,0);
  177.    SetAColorReg(66,0,0,63);
  178.  
  179.    /*
  180.    Calling InitializeLUT establishes straight through
  181.    mapping for the LUT. Only the values that need to
  182.    be changed from their default will be changed.
  183.    */
  184.    InitializeLUT(PseudoColorLUT);
  185.    /*
  186.    Assign color register 64 to pixel values
  187.    60 - 63
  188.    */
  189.    PseudoColorLUT[63] = 64;
  190.    PseudoColorLUT[62] = 64;
  191.    PseudoColorLUT[61] = 64;
  192.    PseudoColorLUT[60] = 64;
  193.    /*
  194.    Assign color register 65 to pixel values
  195.    56 - 59
  196.    */
  197.    PseudoColorLUT[59] = 65;
  198.    PseudoColorLUT[58] = 65;
  199.    PseudoColorLUT[57] = 65;
  200.    PseudoColorLUT[56] = 65;
  201.    /*
  202.    Assign color register 66 to pixel values
  203.    52 - 55
  204.    */
  205.    PseudoColorLUT[55] = 66;
  206.    PseudoColorLUT[54] = 66;
  207.    PseudoColorLUT[53] = 66;
  208.    PseudoColorLUT[52] = 66;
  209.    /*
  210.    At this point the LUT is initialized
  211.    completely. Next, apply the transform to
  212.    the image data.
  213.    */
  214.    PtTransform(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,PseudoColorLUT);
  215.  
  216.    /* display the pseudo colored image */
  217.    DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
  218.    if (GenPCXFiles)
  219.       WritePCXFile("p2ch9i6b",8,320,200,1,320);
  220.    farfree((BYTE far *)TheImage);
  221.  
  222.    restorecrtmode();
  223.    closegraph();
  224. }
  225.