home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / magic.lha / MAGIC / src / mtest.c < prev   
C/C++ Source or Header  |  1993-01-24  |  3KB  |  108 lines

  1. /*
  2.  * MAGIC Image Tester - does a negative effect on default public image.
  3.  *
  4.  * Written by Thomas Krehbiel
  5.  *
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10. #include <libraries/dos.h>
  11. #include <clib/exec_protos.h>
  12. #include <clib/alib_protos.h>
  13. #include <clib/dos_protos.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <stdio.h>
  17.  
  18. #include <magic/magic.h>
  19. #include <magic/magic_protos.h>
  20. #include <magic/magic_pragmas.h>
  21.  
  22.  
  23. struct MagicBase *MagicBase;
  24.  
  25.  
  26. void __regargs negative (UBYTE *s, int n)
  27. {
  28.    while (n--) {
  29.       *s = 255 - *s;
  30.       s++;
  31.    }
  32. }
  33.  
  34. void main (void)
  35. {
  36.    struct MagicHandle *mh;
  37.    UBYTE *data;
  38.    int w, h, d;
  39.    int j;
  40.  
  41.    /*
  42.     * Open the magic.library.
  43.     */
  44.    if (MagicBase = (struct MagicBase *)OpenLibrary(MAGIC_NAME, 34)) {
  45.  
  46.       /*
  47.        * Open the default MAGIC image.  We don't need to provide a
  48.        * message port since we won't be around long enough to worry
  49.        * about it, and most of the messages are for applications with
  50.        * interfaces.
  51.        */
  52.       if (mh = OpenMagicImage(NULL, NULL, TAG_END)) {
  53.          w = mh->Object->Width;
  54.          h = mh->Object->Height;
  55.          d = mh->Object->Depth;
  56.          if (data = AllocMem(w, MEMF_CLEAR)) {
  57.             /*
  58.              * Obtain a write lock on the image before starting
  59.              */
  60.             if (AttemptLockMagicImage(mh, LMI_Write)) {
  61.                /*
  62.                 * Save a copy as an undo buffer in case the user changes
  63.                 * his mind.
  64.                 */
  65.                SaveMagicImage(mh, 0, 0, w, h);
  66.                /*
  67.                 * Convert the image, a line at a time.
  68.                 */
  69.                for (j = 0; j < h; j++) {
  70.                   if (GetMagicImageData(mh, j, 1, GMI_Red, data, TAG_END)) {
  71.                      negative(data, w);
  72.                      PutMagicImageData(mh, j, 1, GMI_Red, data, TAG_END);
  73.                   }
  74.                   if (d > 1) {
  75.                      if (GetMagicImageData(mh, j, 1, GMI_Green, data, TAG_END)) {
  76.                         negative(data, w);
  77.                         PutMagicImageData(mh, j, 1, GMI_Green, data, TAG_END);
  78.                      }
  79.                      if (GetMagicImageData(mh, j, 1, GMI_Blue, data, TAG_END)) {
  80.                         negative(data, w);
  81.                         PutMagicImageData(mh, j, 1, GMI_Blue, data, TAG_END);
  82.                      }
  83.                   }
  84.                }
  85.                /*
  86.                 * Redraw so the user can see what happened.
  87.                 */
  88.                RedrawMagicImage(mh, 0, 0, w, h);
  89.                /*
  90.                 * Release our lock.
  91.                 */
  92.                UnlockMagicImage(mh);
  93.             }
  94.             else {
  95.                printf("Default Image is locked.\n");
  96.             }
  97.             FreeMem(data, w);
  98.          }
  99.          CloseMagicImage(mh);
  100.       }
  101.  
  102.       CloseLibrary((struct Library *)MagicBase);
  103.    }
  104.    else {
  105.       printf("Magic server not running.\n");
  106.    }
  107. }
  108.