home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / IMGPROC.ZIP / C11.ZIP / FRPROCES.C next >
Encoding:
C/C++ Source or Header  |  1990-04-06  |  3.3 KB  |  122 lines

  1. /*  
  2. Copyright 1990 by John Wiley & Sons, Inc.
  3.           All Rights Reserved.
  4. */
  5. /****************************************/
  6. /*        Image Processing Code         */
  7. /*       Frame Process Functions        */
  8. /*        written in Turbo C 2.0        */
  9. /*                 by                   */
  10. /*          Craig A. Lindley            */
  11. /*                                      */
  12. /*   Vers: 1.0  Last Update: 11/14/89   */
  13. /****************************************/
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <conio.h>
  18. #include <dos.h>
  19. #include <alloc.h>
  20. #include <process.h>
  21. #include <graphics.h>
  22. #include "misc.h"
  23. #include "pcx.h"
  24. #include "vga.h"
  25. #include "imagesup.h"
  26. #include "frprocess.h"
  27.  
  28.  
  29. /* Single function performs all image combinations */
  30.  
  31. void CombineImages(BYTE huge *SImage,
  32.            unsigned SCol, unsigned SRow,
  33.            unsigned SWidth, unsigned SHeight,
  34.            BYTE huge *DImage,
  35.            unsigned DCol, unsigned DRow,
  36.            enum BitFunction CombineType,
  37.            short Scale)
  38. {
  39.    register unsigned SImageCol, SImageRow, DestCol;
  40.    short SData, DData;
  41.    unsigned SColExtent, SRowExtent;
  42.  
  43.    if (ParameterCheckOK(SCol,SRow,SCol+SWidth,SRow+SHeight,"CombineImages") &&
  44.        ParameterCheckOK(DCol,DRow,DCol+SWidth,DRow+SHeight,"CombineImages"))
  45.    {
  46.       SColExtent = SCol+SWidth;
  47.       SRowExtent = SRow+SHeight;
  48.  
  49.       for (SImageRow = SRow; SImageRow < SRowExtent; SImageRow++)
  50.       {
  51.      /* Reset the destination Column count every row */
  52.      DestCol = DCol;
  53.      for (SImageCol = SCol; SImageCol < SColExtent; SImageCol++)
  54.      {
  55.         /* Get a byte of the source and dest image data */
  56.         SData = GetPixelFromImage(SImage,SImageCol,SImageRow);
  57.         DData = GetPixelFromImage(DImage,DestCol,DRow);
  58.  
  59.         /* Combine source and dest data according to parameter */
  60.         switch(CombineType)
  61.         {
  62.            case And:
  63.          DData &= SData;
  64.          break;
  65.            case Or:
  66.          DData |= SData;
  67.          break;
  68.            case Xor:
  69.          DData ^= SData;
  70.          break;
  71.            case Add:
  72.          DData += SData;
  73.          break;
  74.            case Sub:
  75.          DData -= SData;
  76.          break;
  77.            case Mult:
  78.          DData *= SData;
  79.          break;
  80.            case Div:
  81.          if (SData != 0)
  82.             DData /= SData;
  83.          break;
  84.            case Min:
  85.          DData = MIN(SData,DData);
  86.          break;
  87.            case Max:
  88.          DData = MAX(SData,DData);
  89.          break;
  90.            case Ave:
  91.          DData = (SData+DData)/2;
  92.          break;
  93.            case Overlay:
  94.          DData = SData;
  95.          break;
  96.         }
  97.         /*
  98.         Scale the resultant data if requested to. A positive
  99.         Scale value shifts the destination data to the right
  100.         thereby dividing it by a power of two. A zero Scale
  101.         value leaves the data untouched. A negative Scale
  102.         value shifts the data left thereby multiplying it by
  103.         a power of two.
  104.         */
  105.  
  106.         if (Scale < 0)
  107.            DData <<= abs(Scale);
  108.         else if (Scale > 0)
  109.            DData >>= Scale;
  110.  
  111.         /* Don't let the pixel data get out of range */
  112.         DData = (DData < MINSAMPLEVAL) ? MINSAMPLEVAL:DData;
  113.         DData = (DData > MAXSAMPLEVAL) ? MAXSAMPLEVAL:DData;
  114.         PutPixelInImage(DImage,DestCol++,DRow,DData);
  115.      }
  116.      /* Bump to next row in the destination image */
  117.      DRow++;
  118.       }
  119.    }
  120. }
  121.  
  122.