home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / gifmachine_405.lzh / GIFMachine / Sources / xcomp.c < prev   
C/C++ Source or Header  |  1990-11-17  |  2KB  |  84 lines

  1. /* Copyright 1990 by Christopher A. Wichura.
  2.    See file GIFMachine.doc for full description of rights.
  3. */
  4.  
  5. /* This function will take the gif screen we have read in and scale it to
  6.    one half of its previous X size.
  7.  
  8.    What we do here is just a step above skipping every other pixel (like
  9.    most routines I have seen do).  While we still put emphasis on the
  10.    even pixels, we at least take account of the odds next to them by
  11.    using a weighted average.
  12.  
  13.    This method is by no means the best way to do this.  If anyone wants
  14.    to build a smarter one I would be very interested in seeing it.
  15. */
  16.  
  17. #include "GIFMachine.h"
  18.  
  19. extern struct GIFdescriptor gdesc;
  20. EXTERNBITPLANE;
  21.  
  22. extern char *AbortMsg;
  23.  
  24. void DoXComp(void)
  25. {
  26.     register UWORD x1;
  27.     register UWORD x2;
  28.     register UWORD y;
  29.     register UWORD num;
  30.     UWORD ColBuf[3];
  31.     UWORD NewWidth;
  32.  
  33.     NewWidth = gdesc.gd_Width >> 1;
  34.     if (NewWidth & 1)
  35.         NewWidth++;
  36.  
  37.     MyPrintf("...Compressing width to %ld.\n......Line ", NewWidth);
  38.  
  39.         for (y = 0; y < gdesc.gd_Height; y++) {
  40.         MyPrintf("%5ld", y);
  41.  
  42.         for (x1 = x2 = 0; x2 < gdesc.gd_Width; x1++, x2 += 2) {
  43.             num = 4;
  44.  
  45.             ColBuf[0] = BitPlane[y][x2].rgb_Red * 4;
  46.             ColBuf[1] = BitPlane[y][x2].rgb_Green * 4;
  47.             ColBuf[2] = BitPlane[y][x2].rgb_Blue * 4;
  48.  
  49.             if (x2 > 1) {
  50.                 num += 2;
  51.  
  52.                 ColBuf[0] += BitPlane[y][x2 - 1].rgb_Red * 2;
  53.                 ColBuf[1] += BitPlane[y][x2 - 1].rgb_Green * 2;
  54.                 ColBuf[2] += BitPlane[y][x2 - 1].rgb_Blue * 2;
  55.             }
  56.  
  57.             if (x2 + 1 < gdesc.gd_Width) {
  58.                 num += 2;
  59.  
  60.                 ColBuf[0] += BitPlane[y][x2 + 1].rgb_Red * 2;
  61.                 ColBuf[1] += BitPlane[y][x2 + 1].rgb_Green * 2;
  62.                 ColBuf[2] += BitPlane[y][x2 + 1].rgb_Blue * 2;
  63.             }
  64.  
  65.             BitPlane[y][x1].rgb_Red   = ((ColBuf[0] + num / 2) / num);
  66.             BitPlane[y][x1].rgb_Green = ((ColBuf[1] + num / 2) / num);
  67.             BitPlane[y][x1].rgb_Blue  = ((ColBuf[2] + num / 2) / num);
  68.         }
  69.  
  70.         BitPlane[y][x1].rgb_Red = BitPlane[y][x1].rgb_Green = BitPlane[y][x1].rgb_Blue = 0;
  71.  
  72.         if (SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
  73.             MyPrintf("\n%s", AbortMsg);
  74.             MyExit(ABORTEXITVAL);
  75.         }
  76.  
  77.         PutStr("\x9B" "5D");
  78.     }
  79.  
  80.     PutStr("\x9B" "5DCompressed.\n");
  81.  
  82.     gdesc.gd_Width = NewWidth;
  83. }
  84.