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

  1. /* Copyright 1990 by Christopher A. Wichura.
  2.    See file GIFMachine.doc for full description of rights.
  3. */
  4.  
  5. #include "GIFMachine.h"
  6.  
  7. extern struct GIFdescriptor gdesc;
  8. EXTERNBITPLANE;
  9.  
  10. extern char *AbortMsg;
  11.  
  12. extern int NoBorderLineThresh;
  13.  
  14. #define BorderCheck(a, b) ((BitPlane[b][a].rgb_Red   != BorderCol.rgb_Red) || \
  15.                (BitPlane[b][a].rgb_Green != BorderCol.rgb_Green) || \
  16.                (BitPlane[b][a].rgb_Blue  != BorderCol.rgb_Blue))
  17.  
  18. void StripBorder(void)
  19. {
  20.     register UWORD x;
  21.     register UWORD y;
  22.     register int thresh;
  23.     register BOOL breakout;
  24.     LONG LeftEdge, TopEdge;
  25.     LONG Width, Height;
  26.     UWORD OrigWidth, OrigHeight;
  27.     int WidthThresh, HeightThresh;
  28.     int Corner;
  29.  
  30.     struct RGB BorderCol;
  31.  
  32.     PutStr("...Removing border.\n");
  33.  
  34.     OrigWidth = gdesc.gd_Width;
  35.     OrigHeight = gdesc.gd_Height;
  36.  
  37.     for (Corner = 0; Corner < 4; Corner++) {
  38.         x = (Corner & 1) ? (gdesc.gd_Width - 1) : 0;
  39.         y = (Corner & 2) ? (gdesc.gd_Height - 1) : 0;
  40.  
  41.         BorderCol = BitPlane[y][x];
  42.  
  43.         WidthThresh  = NoBorderLineThresh * gdesc.gd_Width  / 100;
  44.         HeightThresh = NoBorderLineThresh * gdesc.gd_Height / 100;
  45.  
  46.         for (breakout = y = 0; (y < gdesc.gd_Height) && !breakout; y++) {
  47.             for (thresh = x = 0; x < gdesc.gd_Width; x++)
  48.                 if (BorderCheck(x, y))
  49.                     if (++thresh > WidthThresh) {
  50.                         breakout = TRUE;
  51.                         break;
  52.                     }
  53.  
  54.             if (SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
  55.                 PutStr(AbortMsg);
  56.                 MyExit(ABORTEXITVAL);
  57.             }
  58.         }
  59.  
  60.         TopEdge = y - 1;
  61.  
  62.         for (breakout = 0, y = gdesc.gd_Height - 1; (y > 0) && !breakout; y--) {
  63.             for (thresh = x = 0; x < gdesc.gd_Width; x++)
  64.                 if (BorderCheck(x, y))
  65.                     if (++thresh > WidthThresh) {
  66.                         breakout = TRUE;
  67.                         break;
  68.                     }
  69.  
  70.             if (SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
  71.                 PutStr(AbortMsg);
  72.                 MyExit(ABORTEXITVAL);
  73.             }
  74.         }
  75.  
  76.         Height = y - TopEdge + 2;
  77.  
  78.         for (breakout = x = 0; (x < gdesc.gd_Width) && !breakout; x++) {
  79.             for (thresh = y = 0; y < gdesc.gd_Height; y++)
  80.                 if (BorderCheck(x, y))
  81.                     if (++thresh > HeightThresh) {
  82.                         breakout = TRUE;
  83.                         break;
  84.                     }
  85.  
  86.             if (SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
  87.                 PutStr(AbortMsg);
  88.                 MyExit(ABORTEXITVAL);
  89.             }
  90.         }
  91.  
  92.         LeftEdge = x - 1;
  93.  
  94.         for (breakout = 0, x = gdesc.gd_Width - 1; (x > 0) && !breakout; x--) {
  95.             for (thresh = y = 0; y < gdesc.gd_Height; y++)
  96.                 if (BorderCheck(x, y))
  97.                     if (++thresh > HeightThresh) {
  98.                         breakout = TRUE;
  99.                         break;
  100.                     }
  101.  
  102.             if (SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
  103.                 PutStr(AbortMsg);
  104.                 MyExit(ABORTEXITVAL);
  105.             }
  106.         }
  107.  
  108.         Width = x - LeftEdge + 2;
  109.  
  110.         if ((Width != gdesc.gd_Width) || (Height != gdesc.gd_Height)) {
  111.             if (Width < 5 || Height < 5) {
  112.                 PutStr("......Too much of picture would be removed.  Not modified.\n");
  113.                 return;
  114.             }
  115.  
  116.             for (y = 0; y < Height; y++) {
  117.                 for (x = 0; x < Width; x++)
  118.                     BitPlane[y][x] = BitPlane[TopEdge + y][LeftEdge + x];
  119.  
  120.                 BitPlane[y][x].rgb_Red   =
  121.                 BitPlane[y][x].rgb_Green =
  122.                 BitPlane[y][x].rgb_Blue  = 0;
  123.  
  124.                 if (SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
  125.                     PutStr(AbortMsg);
  126.                     MyExit(ABORTEXITVAL);
  127.                 }
  128.             }
  129.  
  130.             gdesc.gd_Width = Width;
  131.             gdesc.gd_Height = Height;
  132.         }
  133.     }
  134.  
  135.     if ((gdesc.gd_Width != OrigWidth) || (gdesc.gd_Height != OrigHeight)) {
  136.         if (gdesc.gd_Width & 1)
  137.             gdesc.gd_Width++;
  138.  
  139.         MyPrintf("......New width = %ld, New height = %ld\n",
  140.             gdesc.gd_Width, gdesc.gd_Height);
  141.     }
  142. }
  143.