home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d541 / gifmachine.lha / GIFMachine / Sources / xcomp.c < prev   
C/C++ Source or Header  |  1991-09-17  |  2KB  |  93 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. extern BOOL DisplayCounts;
  25.  
  26. void DoXComp(void)
  27. {
  28.     register UWORD x1;
  29.     register UWORD x2;
  30.     register UWORD y;
  31.     register UWORD num;
  32.     UWORD ColBuf[3];
  33.     UWORD NewWidth;
  34.  
  35.     NewWidth = gdesc.gd_Width >> 1;
  36.     if (NewWidth & 1)
  37.         NewWidth++;
  38.  
  39.     MyPrintf("...Compressing width to %ld.\n......", NewWidth);
  40.     if (DisplayCounts)
  41.         PutStr("Line ");
  42.     else
  43.         PutStr("Working");
  44.     Flush(Output());
  45.  
  46.         for (y = 0; y < gdesc.gd_Height; y++) {
  47.         if (DisplayCounts)
  48.             MyPrintf("%5ld", y);
  49.  
  50.         for (x1 = x2 = 0; x2 < gdesc.gd_Width; x1++, x2 += 2) {
  51.             num = 4;
  52.  
  53.             ColBuf[0] = BitPlane[y][x2].rgb_Red * 4;
  54.             ColBuf[1] = BitPlane[y][x2].rgb_Green * 4;
  55.             ColBuf[2] = BitPlane[y][x2].rgb_Blue * 4;
  56.  
  57.             if (x2 > 1) {
  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.             if (x2 + 1 < gdesc.gd_Width) {
  66.                 num += 2;
  67.  
  68.                 ColBuf[0] += BitPlane[y][x2 + 1].rgb_Red * 2;
  69.                 ColBuf[1] += BitPlane[y][x2 + 1].rgb_Green * 2;
  70.                 ColBuf[2] += BitPlane[y][x2 + 1].rgb_Blue * 2;
  71.             }
  72.  
  73.             BitPlane[y][x1].rgb_Red   = ((ColBuf[0] + num / 2) / num);
  74.             BitPlane[y][x1].rgb_Green = ((ColBuf[1] + num / 2) / num);
  75.             BitPlane[y][x1].rgb_Blue  = ((ColBuf[2] + num / 2) / num);
  76.         }
  77.  
  78.         BitPlane[y][x1].rgb_Red = BitPlane[y][x1].rgb_Green = BitPlane[y][x1].rgb_Blue = 0;
  79.  
  80.         if (SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
  81.             MyPrintf("\n%s", AbortMsg);
  82.             MyExit(ABORTEXITVAL);
  83.         }
  84.  
  85.         if (DisplayCounts)
  86.             PutStr("\x1B[5D");
  87.     }
  88.  
  89.     MyPrintf("\x1B[%ldDCompressed.      \n", (DisplayCounts ? 5 : 7));
  90.  
  91.     gdesc.gd_Width = NewWidth;
  92. }
  93.