Annotation of mstools/samples/rpc/mandel/calc.c, revision 1.1.1.2

1.1       root        1: /****************************************************************************
                      2: 
                      3:     CALC.C --
                      4: 
                      5:     Code to do the calculations for the Windows Mandelbrot Set distributed
                      6:     drawing program.
                      7: 
                      8:     Copyright (C) 1990 Microsoft Corporation.
                      9: 
                     10:     This code sample is provided for demonstration purposes only.
                     11:     Microsoft makes no warranty, either express or implied,
                     12:     as to its usability in any given situation.
                     13: 
                     14: ****************************************************************************/
                     15: 
                     16: #include <windows.h>
                     17: #include <malloc.h>   // malloc, free
                     18: #include <stdio.h>
                     19: 
                     20: #ifdef RPC
                     21: #include <rpc.h>
                     22: #include "mdlrpc.h"
                     23: #endif
                     24: 
                     25: #include "mandel.h"
                     26: 
                     27: void  MandelCalc(PCPOINT pcptLL,
                     28:                 PLONGRECT  prcDraw,
                     29:                 double  precision,
                     30:                  DWORD   ulThreshold,
                     31:                  PLINEBUF pbBuf)
                     32: {
                     33:     DWORD   h, height;
                     34:     DWORD   width;
                     35:     PWORD   pbPtr;
                     36:     double  dreal, dimag, dimag2;
                     37:     short maxit = 0;
                     38: 
                     39:     pbPtr = (PWORD) pbBuf;  // PLINEBUF points to the struct LINEBUF;
                     40:                              // LINEBUF is an array of WORDS
                     41: 
                     42:     dreal = pcptLL->real + ((double)prcDraw->xLeft * precision);
                     43:     dimag = pcptLL->imag + ((double)prcDraw->yBottom * precision);
                     44: 
                     45:     maxit = (short) ulThreshold;
                     46: 
                     47:     height = (prcDraw->yTop - prcDraw->yBottom) + 1;
                     48:     width = (prcDraw->xRight - prcDraw->xLeft) + 1;
                     49: 
                     50:     for ( ; width > 0; --width, dreal += precision) {
                     51:         for (dimag2 = dimag, h = height; h > 0; --h, dimag2 += precision)
                     52:         {
                     53:               if ((dreal > 4.0) || (dreal < -4.0) ||
                     54:                   (dimag2 > 4.0) || (dimag2 < -4.0))
                     55:                 *(pbPtr++) = 0L;
                     56:               else
                     57:                *(pbPtr++) = (WORD) (calcmand(dreal, dimag2, maxit));
                     58:        }
                     59:     }
                     60:     return;
                     61: }
                     62: 
                     63: 
                     64: // midl requires these functions
                     65: // ====================================================================
                     66: //                MIDL allocate and free
                     67: // ====================================================================
                     68: 
                     69: 
                     70: /* C version of the assembly language program */
                     71: 
                     72: short calcmand(double dreal, double dimag, short maxit)
                     73: {
                     74: double x, y, xsq, ysq;
                     75: short k;
                     76: 
                     77:     k = (short) maxit;
                     78:     x = dreal;
                     79:     y = dimag;
                     80: 
                     81:     while (1) {
                     82:         xsq = x * x;
                     83:         ysq = y * y;
                     84:         y = 2.0 * x * y + dimag;
                     85:         x = (xsq - ysq) + dreal;
                     86:         if (--k == 0)
                     87:             return((short) (maxit - k));
                     88:         if ((xsq + ysq) > 4.0)
                     89:             return((short) (maxit - k));
                     90:     }
                     91: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.