|
|
| version 1.5.8.1, 2001/09/15 15:42:08 | version 1.8, 2001/09/24 14:34:25 |
|---|---|
| Line 3 | Line 3 |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) |
| $Id$ | |
| */ | */ |
| static const char *RCSId="$Id$"; | |
| #include "gif.h" | #include "gif.h" |
| Line 19 void gdImage::Create(int asx, int asy) { | Line 19 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 146 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 160 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 587 static int gdGetByte(int *result, FILE * | Line 501 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 510 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 776 void gdImage::SetLineWidth(int width) |
| { | { |
| lineWidth=width; | lineWidth=width; |
| } | } |
| void gdImage::SetLineStyle(const char *alineStyle) | |
| { | |
| lineStyle=alineStyle; | |
| } | |