Diff for /parser3/src/classes/gd/Attic/gif.C between versions 1.5.8.1 and 1.13

version 1.5.8.1, 2001/09/15 15:42:08 version 1.13, 2001/10/08 16:06:49
Line 1 Line 1
 /** @file  /** @file
         Parser: image manipulations impl1.          Parser: image manipulations impl1.
   
           Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)          Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
   
         $Id$          $Id$
   
           based on: gd
   
           Written by Tom Boutell, 5/94.
           Copyright 1994, Cold Spring Harbor Labs.
           Permission granted to use this code in any fashion provided
           that this notice is retained and any alterations are
           labeled as such. It is requested, but not required, that
           you share extensions to this module with us so that we
           can incorporate them into new versions. 
 */  */
   
 #include "gif.h"  #include "gif.h"
   
   #include "mtables.h"
   
 //static void BrushApply(int x, int y);  //static void BrushApply(int x, int y);
 //static void TileApply(int x, int y);  //static void TileApply(int x, int y);
   
Line 19  void gdImage::Create(int asx, int asy) { Line 32  void gdImage::Create(int asx, int asy) {
         pixels = (unsigned char **) malloc(sizeof(unsigned char *) * sx);          pixels = (unsigned char **) malloc(sizeof(unsigned char *) * sx);
         polyInts = 0;          polyInts = 0;
         polyAllocated = 0;          polyAllocated = 0;
         lineWidth = 1;          lineWidth = 1;  lineStyle=0;
         for (i=0; (i<asx); i++)          for (i=0; (i<asx); i++)
                 pixels[i] = (unsigned char *) calloc(asy);                  pixels[i] = (unsigned char *) calloc(asy);
         colorsTotal = 0;          colorsTotal = 0;
Line 146  int gdImage::GetPixel(int x, int y) Line 159  int gdImage::GetPixel(int x, int y)
   
 /* Bresenham as presented in Foley & Van Dam */  /* Bresenham as presented in Foley & Van Dam */
   
 void gdImage::Line(int x1, int y1, int x2, int y2, int color)  
 {  
         int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;  
         dx = abs(x2-x1);  
         dy = abs(y2-y1);  
         if (dy <= dx) {  
                 d = 2*dy - dx;  
                 incr1 = 2*dy;  
                 incr2 = 2 * (dy - dx);  
                 if (x1 > x2) {  
                         x = x2;  
                         y = y2;  
                         ydirflag = (-1);  
                         xend = x1;  
                 } else {  
                         x = x1;  
                         y = y1;  
                         ydirflag = 1;  
                         xend = x2;  
                 }  
                 SetPixel(x, y, color);  
                 if (((y2 - y1) * ydirflag) > 0) {  
                         while (x < xend) {  
                                 x++;  
                                 if (d <0) {  
                                         d+=incr1;  
                                 } else {  
                                         y++;  
                                         d+=incr2;  
                                 }  
                                 SetPixel(x, y, color);  
                         }  
                 } else {  
                         while (x < xend) {  
                                 x++;  
                                 if (d <0) {  
                                         d+=incr1;  
                                 } else {  
                                         y--;  
                                         d+=incr2;  
                                 }  
                                 SetPixel(x, y, color);  
                         }  
                 }                 
         } else {  
                 d = 2*dx - dy;  
                 incr1 = 2*dx;  
                 incr2 = 2 * (dx - dy);  
                 if (y1 > y2) {  
                         y = y2;  
                         x = x2;  
                         yend = y1;  
                         xdirflag = (-1);  
                 } else {  
                         y = y1;  
                         x = x1;  
                         yend = y2;  
                         xdirflag = 1;  
                 }  
                 SetPixel(x, y, color);  
                 if (((x2 - x1) * xdirflag) > 0) {  
                         while (y < yend) {  
                                 y++;  
                                 if (d <0) {  
                                         d+=incr1;  
                                 } else {  
                                         x++;  
                                         d+=incr2;  
                                 }  
                                 SetPixel(x, y, color);  
                         }  
                 } else {  
                         while (y < yend) {  
                                 y++;  
                                 if (d <0) {  
                                         d+=incr1;  
                                 } else {  
                                         x--;  
                                         d+=incr2;  
                                 }  
                                 SetPixel(x, y, color);  
                         }  
                 }  
         }  
 }  
   
 /* As above, plus dashing */  /* As above, plus dashing */
   
 #define styledSet \  #define styledSet \
Line 246  void gdImage::Line(int x1, int y1, int x Line 173  void gdImage::Line(int x1, int y1, int x
                 } \                  } \
         }          }
   
 void gdImage::StyledLine(int x1, int y1, int x2, int y2, int color, const char *lineStyle)  void gdImage::Line(int x1, int y1, int x2, int y2, int color)
 {  {
         int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;          int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;
         int styleStep = 0;          int styleStep = 0;
Line 344  void gdImage::StyledLine(int x1, int y1, Line 271  void gdImage::StyledLine(int x1, int y1,
   at least for me) and there are other inefficiencies (small circles    at least for me) and there are other inefficiencies (small circles
   do far too much work). */    do far too much work). */
   
   void gdImage::Arc(int cx, int cy, int w, int h, int s, int e, int color)
   {
           if(w!=h) {
                   int i;
                   int lx = 0, ly = 0;
                   int w2, h2;
                   w2 = w/2;
                   h2 = h/2;
                   while (e < s) {
                           e += 360;
                   }
                   for (i=s; (i <= e); i++) {
                           int x, y;
                           x = ((long)cost[i % 360] * (long)w2 / costScale) + cx; 
                           y = ((long)sint[i % 360] * (long)h2 / sintScale) + cy;
                           if (i != s) {
                                   Line(lx, ly, x, y, color);      
                           }
                           lx = x;
                           ly = y;
                   }
           } else {
                   /* Bresenham octant code, which I should use eventually */
                   int x, y, d;
                   x = 0;
                   y = w/2;
                   d = 3-w;
                   while (x <= y) {
                           SetPixel(cx+x, cy+y, color);
                           SetPixel(cx+x, cy-y, color);
                           SetPixel(cx-x, cy+y, color);
                           SetPixel(cx-x, cy-y, color);
                           SetPixel(cx+y, cy+x, color);
                           SetPixel(cx+y, cy-x, color);
                           SetPixel(cx-y, cy+x, color);
                           SetPixel(cx-y, cy-x, color);
                           if (d < 0) {
                                   d += 4 * x + 6;
                           } else {
                                   d += 4 * (x - y) + 10;
                                   y--;
                           }
                           x++;
                   }
           }
   }
   
   
   void gdImage::Sector(int cx, int cy, int w, int h, int s, int e, int color)
   {
           int i;
           int lx = 0, ly = 0;
           int w2, h2;
           w2 = w/2;
           h2 = h/2;
           while (e < s) {
                   e += 360;
           }
           for (i=s; (i <= e); i++) {
                   int x, y;
                   x = ((long)cost[i % 360] * (long)w2 / costScale) + cx; 
                   y = ((long)sint[i % 360] * (long)h2 / sintScale) + cy;
                   if(i==s || i==e)
                           Line(cx, cy, x, y, color);
                   if (i != s) {
                           Line(lx, ly, x, y, color);      
                   }
                   lx = x;
                   ly = y;
           }
   }
   
   
   
 void gdImage::FillToBorder(int x, int y, int border, int color)  void gdImage::FillToBorder(int x, int y, int border, int color)
 {  {
         if(!BoundsSafe(x, y)) //PAF          if(!BoundsSafe(x, y)) //PAF
Line 494  void gdImage::Rectangle(int x1, int y1, Line 495  void gdImage::Rectangle(int x1, int y1,
   
 void gdImage::FilledRectangle(int x1, int y1, int x2, int y2, int color)  void gdImage::FilledRectangle(int x1, int y1, int x2, int y2, int color)
 {  {
           if(x1>x2) {
                   int t=x1;
                   x1=x2;
                   x2=t;
           }
           if(y1>y2) {
                   int t=y1;
                   y1=y2;
                   y2=t;
           }
         int x, y;          int x, y;
   
         for (y=y1; (y<=y2); y++)          for (y=y1; (y<=y2); y++)
                 for (x=x1; (x<=x2); x++)                  for (x=x1; (x<=x2); x++)
                         SetPixel(x, y, color);                          SetPixel(x, y, color);
Line 587  static int gdGetByte(int *result, FILE * Line 599  static int gdGetByte(int *result, FILE *
         return 1;          return 1;
 }  }
   
 void gdImage::Polygon(Point *p, int n, int c)  void gdImage::Polygon(Point *p, int n, int c, bool closed)
 {  {
         int i;          int i;
         int lx, ly;          int lx, ly;
Line 596  void gdImage::Polygon(Point *p, int n, i Line 608  void gdImage::Polygon(Point *p, int n, i
         }          }
         lx = p->x;          lx = p->x;
         ly = p->y;          ly = p->y;
         Line(lx, ly, p[n-1].x, p[n-1].y, c);          if(closed)
                   Line(lx, ly, p[n-1].x, p[n-1].y, c);
         for (i=1; (i < n); i++) {          for (i=1; (i < n); i++) {
                 p++;                  p++;
                 Line(lx, ly, p->x, p->y, c);                  Line(lx, ly, p->x, p->y, c);
Line 861  void gdImage::SetLineWidth(int width) Line 874  void gdImage::SetLineWidth(int width)
 {  {
         lineWidth=width;          lineWidth=width;
 }  }
   
   void gdImage::SetLineStyle(const char *alineStyle)
   {
           lineStyle=alineStyle;
   }
   

Removed from v.1.5.8.1  
changed lines
  Added in v.1.13


E-mail: