home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright 1990 by John Wiley & Sons, Inc.
- All Rights Reserved.
- */
- /****************************************/
- /* Image Processing Code */
- /* Frame Process Functions */
- /* written in Turbo C 2.0 */
- /* by */
- /* Craig A. Lindley */
- /* */
- /* Vers: 1.0 Last Update: 11/14/89 */
- /****************************************/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <dos.h>
- #include <alloc.h>
- #include <process.h>
- #include <graphics.h>
- #include "misc.h"
- #include "pcx.h"
- #include "vga.h"
- #include "imagesup.h"
- #include "frprocess.h"
-
-
- /* Single function performs all image combinations */
-
- void CombineImages(BYTE huge *SImage,
- unsigned SCol, unsigned SRow,
- unsigned SWidth, unsigned SHeight,
- BYTE huge *DImage,
- unsigned DCol, unsigned DRow,
- enum BitFunction CombineType,
- short Scale)
- {
- register unsigned SImageCol, SImageRow, DestCol;
- short SData, DData;
- unsigned SColExtent, SRowExtent;
-
- if (ParameterCheckOK(SCol,SRow,SCol+SWidth,SRow+SHeight,"CombineImages") &&
- ParameterCheckOK(DCol,DRow,DCol+SWidth,DRow+SHeight,"CombineImages"))
- {
- SColExtent = SCol+SWidth;
- SRowExtent = SRow+SHeight;
-
- for (SImageRow = SRow; SImageRow < SRowExtent; SImageRow++)
- {
- /* Reset the destination Column count every row */
- DestCol = DCol;
- for (SImageCol = SCol; SImageCol < SColExtent; SImageCol++)
- {
- /* Get a byte of the source and dest image data */
- SData = GetPixelFromImage(SImage,SImageCol,SImageRow);
- DData = GetPixelFromImage(DImage,DestCol,DRow);
-
- /* Combine source and dest data according to parameter */
- switch(CombineType)
- {
- case And:
- DData &= SData;
- break;
- case Or:
- DData |= SData;
- break;
- case Xor:
- DData ^= SData;
- break;
- case Add:
- DData += SData;
- break;
- case Sub:
- DData -= SData;
- break;
- case Mult:
- DData *= SData;
- break;
- case Div:
- if (SData != 0)
- DData /= SData;
- break;
- case Min:
- DData = MIN(SData,DData);
- break;
- case Max:
- DData = MAX(SData,DData);
- break;
- case Ave:
- DData = (SData+DData)/2;
- break;
- case Overlay:
- DData = SData;
- break;
- }
- /*
- Scale the resultant data if requested to. A positive
- Scale value shifts the destination data to the right
- thereby dividing it by a power of two. A zero Scale
- value leaves the data untouched. A negative Scale
- value shifts the data left thereby multiplying it by
- a power of two.
- */
-
- if (Scale < 0)
- DData <<= abs(Scale);
- else if (Scale > 0)
- DData >>= Scale;
-
- /* Don't let the pixel data get out of range */
- DData = (DData < MINSAMPLEVAL) ? MINSAMPLEVAL:DData;
- DData = (DData > MAXSAMPLEVAL) ? MAXSAMPLEVAL:DData;
- PutPixelInImage(DImage,DestCol++,DRow,DData);
- }
- /* Bump to next row in the destination image */
- DRow++;
- }
- }
- }
-