"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/image_support.c" between
vnstat-2.7.tar.gz and vnstat-2.8.tar.gz

About: vnStat is a console-based network traffic monitor (using the /proc filesystem).

image_support.c  (vnstat-2.7):image_support.c  (vnstat-2.8)
skipping to change at line 93 skipping to change at line 93
void colorinitcheck(const char *color, const int value, const char *cfgtext, con st int *rgb) void colorinitcheck(const char *color, const int value, const char *cfgtext, con st int *rgb)
{ {
if (value == -1) { if (value == -1) {
printf("Error: ImageColorAllocate failed.\n"); printf("Error: ImageColorAllocate failed.\n");
printf(" C: \"%s\" T: \"%s\" RGB: %d/%d/%d\n", color, cfgte xt, rgb[0], rgb[1], rgb[2]); printf(" C: \"%s\" T: \"%s\" RGB: %d/%d/%d\n", color, cfgte xt, rgb[0], rgb[1], rgb[2]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
void layoutinit(IMAGECONTENT *ic, char *title, const int width, const int height ) void layoutinit(IMAGECONTENT *ic, const char *title, const int width, const int height)
{ {
struct tm *d; struct tm *d;
char datestring[64], buffer[512]; char datestring[64], buffer[512];
gdFontPtr datefont; gdFontPtr datefont;
if (ic->large) { if (ic->large) {
datefont = gdFontGetSmall(); datefont = gdFontGetSmall();
} else { } else {
datefont = gdFontGetTiny(); datefont = gdFontGetTiny();
} }
skipping to change at line 170 skipping to change at line 170
gdImageFilledRectangle(ic->im, x - 22 - (ic->large * 3), y + 4, x - 22 + ic->font->w - (ic->large * 3), y + 4 + ic->font->w, ic->crx); gdImageFilledRectangle(ic->im, x - 22 - (ic->large * 3), y + 4, x - 22 + ic->font->w - (ic->large * 3), y + 4 + ic->font->w, ic->crx);
gdImageRectangle(ic->im, x - 22 - (ic->large * 3), y + 4, x - 22 + ic->font->w - (ic->large * 3), y + 4 + ic->font->w, ic->ctext); gdImageRectangle(ic->im, x - 22 - (ic->large * 3), y + 4, x - 22 + ic->font->w - (ic->large * 3), y + 4 + ic->font->w, ic->ctext);
gdImageFilledRectangle(ic->im, x + 8 + (ic->large * 7), y + 4, x + 8 + ic->font->w + (ic->large * 7), y + 4 + ic->font->w, ic->ctx); gdImageFilledRectangle(ic->im, x + 8 + (ic->large * 7), y + 4, x + 8 + ic->font->w + (ic->large * 7), y + 4 + ic->font->w, ic->ctx);
gdImageRectangle(ic->im, x + 8 + (ic->large * 7), y + 4, x + 8 + ic->font->w + (ic->large * 7), y + 4 + ic->font->w, ic->ctext); gdImageRectangle(ic->im, x + 8 + (ic->large * 7), y + 4, x + 8 + ic->font->w + (ic->large * 7), y + 4 + ic->font->w, ic->ctext);
} }
} }
void drawbar(IMAGECONTENT *ic, const int x, const int y, const int len, const ui nt64_t rx, const uint64_t tx, const uint64_t max, const short isestimate) void drawbar(IMAGECONTENT *ic, const int x, const int y, const int len, const ui nt64_t rx, const uint64_t tx, const uint64_t max, const short isestimate)
{ {
int l, width = len; int rxl, txl, width = len, overlap = 0;
int crx = ic->crx, ctx = ic->ctx, crxd = ic->crxd, ctxd = ic->ctxd; int crx = ic->crx, ctx = ic->ctx, crxd = ic->crxd, ctxd = ic->ctxd;
int ybeginoffset = YBEGINOFFSET, yendoffset = YBEGINOFFSET + ic->font->h - 6 - ic->large; int ybeginoffset = YBEGINOFFSET, yendoffset = YBEGINOFFSET + ic->font->h - 6 - ic->large;
if (isestimate) { if (isestimate) {
switch (cfg.estimatestyle) { switch (cfg.estimatestyle) {
case 0: case 0:
return; return;
case 1: case 1:
crx = ic->cbgoffsetmore; crx = ic->cbgoffsetmore;
skipping to change at line 201 skipping to change at line 201
ctx = ic->cbgoffset; ctx = ic->cbgoffset;
break; break;
default: default:
return; return;
} }
} }
if ((rx + tx) < max) { if ((rx + tx) < max) {
width = (int)lrint(((double)(rx + tx) / (double)max) * len); width = (int)lrint(((double)(rx + tx) / (double)max) * len);
} else if ((rx + tx) > max || max == 0) { } else if ((rx + tx) > max || max == 0) {
if (debug && (rx + tx) > max) {
printf("Warning: Bar rx + tx sum exceeds given maximum, n
o bar shown\n");
}
return; return;
} }
if (width <= 0) { if (width <= 0) {
return; return;
} }
if (tx > rx) { if (tx > rx) {
l = (int)lrint(((double)rx / (double)(rx + tx) * width)); rxl = (int)lrint(((double)rx / (double)(rx + tx) * width));
txl = width - rxl;
if (l > 0) {
gdImageFilledRectangle(ic->im, x, y + ybeginoffset, x + l
, y + yendoffset, crx);
gdImageRectangle(ic->im, x, y + ybeginoffset, x + l, y +
yendoffset, crxd);
}
gdImageFilledRectangle(ic->im, x + l, y + ybeginoffset, x + width
, y + yendoffset, ctx);
gdImageRectangle(ic->im, x + l, y + ybeginoffset, x + width, y +
yendoffset, ctxd);
} else { } else {
l = (int)(lrint(((double)tx / (double)(rx + tx) * width))); txl = (int)lrint(((double)tx / (double)(rx + tx) * width));
rxl = width - txl;
gdImageFilledRectangle(ic->im, x, y + ybeginoffset, x + (width - }
l), y + yendoffset, crx);
gdImageRectangle(ic->im, x, y + ybeginoffset, x + (width - l), y
+ yendoffset, crxd);
if (l > 0) { if (rxl) {
gdImageFilledRectangle(ic->im, x + (width - l), y + ybegi if (txl > 0) {
noffset, x + width, y + yendoffset, ctx); overlap = 1;
gdImageRectangle(ic->im, x + (width - l), y + ybeginoffse
t, x + width, y + yendoffset, ctxd);
} }
gdImageFilledRectangle(ic->im, x, y + ybeginoffset, x + rxl - 1 +
overlap, y + yendoffset, crx);
gdImageRectangle(ic->im, x, y + ybeginoffset, x + rxl - 1 + overl
ap, y + yendoffset, crxd);
}
if (txl) {
gdImageFilledRectangle(ic->im, x + rxl, y + ybeginoffset, x + rxl
+ txl - 1, y + yendoffset, ctx);
gdImageRectangle(ic->im, x + rxl, y + ybeginoffset, x + rxl + txl
- 1, y + yendoffset, ctxd);
} }
} }
void drawpoles(IMAGECONTENT *ic, const int x, const int y, const int len, const uint64_t rx, const uint64_t tx, const uint64_t max) void drawpoles(IMAGECONTENT *ic, const int x, const int y, const int len, const uint64_t rx, const uint64_t tx, const uint64_t max)
{ {
int l; int l;
if (rx > 0) { if (rx > 0) {
l = (int)lrint(((double)rx / (double)max) * len); l = (int)lrint(((double)rx / (double)max) * len);
if (l > 0) { if (l > 0) {
skipping to change at line 253 skipping to change at line 254
if (tx > 0) { if (tx > 0) {
l = (int)lrint(((double)tx / (double)max) * len); l = (int)lrint(((double)tx / (double)max) * len);
if (l > 0) { if (l > 0) {
gdImageFilledRectangle(ic->im, x + 5 - (ic->large * 0), y + (len - l), x + 12 + (ic->large * 2), y + len, ic->ctx); gdImageFilledRectangle(ic->im, x + 5 - (ic->large * 0), y + (len - l), x + 12 + (ic->large * 2), y + len, ic->ctx);
} }
} }
} }
void drawdonut(IMAGECONTENT *ic, const int x, const int y, const float rxp, cons t float txp, const int size, const int holesize) void drawdonut(IMAGECONTENT *ic, const int x, const int y, const float rxp, cons t float txp, const int size, const int holesize)
{ {
// libgd versions 2.2.3 - 2.2.5 have bug in gdImageFilledArc() https://gi
thub.com/libgd/libgd/issues/351
// so workaround needs to be used, 2.2 version series ends with 2.2.5 and
the bug is fixed starting from 2.3.0
if (GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION
>= 3) {
drawdonut_libgd_bug_workaround(ic, x, y, rxp, txp, size, holesize
);
} else {
drawdonut_libgd_native(ic, x, y, rxp, txp, size, holesize);
}
}
void drawdonut_libgd_bug_workaround(IMAGECONTENT *ic, const int x, const int y,
const float rxp, const float txp, const int size, const int holesize)
{
int rxarc = 0, txarc = 0; int rxarc = 0, txarc = 0;
if ((int)(rxp + txp) > 0) { if ((int)(rxp + txp) > 0) {
rxarc = (int)lrintf(360 * (rxp / (float)100)); rxarc = (int)lrintf(360 * (rxp / (float)100));
if ((int)(rxp + txp) == 100) { if ((int)(rxp + txp) == 100) {
txarc = 360 - rxarc; txarc = 360 - rxarc;
} else { } else {
txarc = (int)lrintf(360 * (txp / (float)100)); txarc = (int)lrintf(360 * (txp / (float)100));
} }
} }
skipping to change at line 287 skipping to change at line 299
if (rxarc >= 5) { if (rxarc >= 5) {
gdImageFill(ic->im, (int)(x + (size / 2 - 3) * cos((int)( (270 * 2 + 2 * txarc + rxarc) / 2) * M_PI / 180)), (int)(y + (size / 2 - 3) * si n((int)((270 * 2 + 2 * txarc + rxarc) / 2) * M_PI / 180)), ic->crx); gdImageFill(ic->im, (int)(x + (size / 2 - 3) * cos((int)( (270 * 2 + 2 * txarc + rxarc) / 2) * M_PI / 180)), (int)(y + (size / 2 - 3) * si n((int)((270 * 2 + 2 * txarc + rxarc) / 2) * M_PI / 180)), ic->crx);
} }
gdImageFilledArc(ic->im, x, y, holesize, holesize, 270 + txarc, 2 70 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill); gdImageFilledArc(ic->im, x, y, holesize, holesize, 270 + txarc, 2 70 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill);
} }
// remove center from background filled circle, making it a donut // remove center from background filled circle, making it a donut
gdImageFilledArc(ic->im, x, y, holesize - 2, holesize - 2, 0, 360, ic->cb ackground, 0); gdImageFilledArc(ic->im, x, y, holesize - 2, holesize - 2, 0, 360, ic->cb ackground, 0);
} }
#ifdef CHECK_VNSTAT
void drawdonut_libgd_native(IMAGECONTENT *ic, const int x, const int y, const fl oat rxp, const float txp, const int size, const int holesize) void drawdonut_libgd_native(IMAGECONTENT *ic, const int x, const int y, const fl oat rxp, const float txp, const int size, const int holesize)
{ {
int rxarc = 0, txarc = 0; int rxarc = 0, txarc = 0;
if ((int)(rxp + txp) > 0) { if ((int)(rxp + txp) > 0) {
rxarc = (int)(360 * (rxp / (float)100)); rxarc = (int)(360 * (rxp / (float)100));
if ((int)(rxp + txp) == 100) { if ((int)(rxp + txp) == 100) {
txarc = 360 - rxarc; txarc = 360 - rxarc;
} else { } else {
txarc = (int)(360 * (txp / (float)100)); txarc = (int)(360 * (txp / (float)100));
skipping to change at line 319 skipping to change at line 330
if (rxarc) { if (rxarc) {
gdImageFilledArc(ic->im, x, y, size, size, 270 + txarc, 270 + txa rc + rxarc, ic->crx, 0); gdImageFilledArc(ic->im, x, y, size, size, 270 + txarc, 270 + txa rc + rxarc, ic->crx, 0);
gdImageFilledArc(ic->im, x, y, size, size, 270 + txarc, 270 + txa rc + rxarc, ic->crxd, gdEdged | gdNoFill); gdImageFilledArc(ic->im, x, y, size, size, 270 + txarc, 270 + txa rc + rxarc, ic->crxd, gdEdged | gdNoFill);
gdImageFilledArc(ic->im, x, y, holesize, holesize, 270 + txarc, 2 70 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill); gdImageFilledArc(ic->im, x, y, holesize, holesize, 270 + txarc, 2 70 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill);
} }
// remove center from background filled circle, making it a donut // remove center from background filled circle, making it a donut
gdImageFilledArc(ic->im, x, y, holesize - 2, holesize - 2, 0, 360, ic->cb ackground, 0); gdImageFilledArc(ic->im, x, y, holesize - 2, holesize - 2, 0, 360, ic->cb ackground, 0);
} }
#endif
void drawpole(IMAGECONTENT *ic, const int x, const int y, const int length, cons t int direction, const int color) void drawpole(IMAGECONTENT *ic, const int x, const int y, const int length, cons t int direction, const int color)
{ {
int len = length - 1; int len = length - 1;
if (length > 0) { if (length > 0) {
switch (direction) { switch (direction) {
case 1: case 1:
gdImageLine(ic->im, x, y, x, y - len, color); gdImageLine(ic->im, x, y, x, y - len, color);
break; break;
 End of changes. 10 change blocks. 
29 lines changed or deleted 41 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)