} else {
txarc = (int)(360 * (txp / (float)100));
}
+ }
+
+ // background filled circle
+ gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 0, 360, ic->cbgoffset, 0);
- /* fix possible graphical glitch */
- if (!rxarc) {
- rxarc = 1;
+ if (txarc) {
+ gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
+ if (txarc >= 5) {
+ gdImageFill(ic->im, x+1, y-(DOUTRAD/2-3), ic->ctx);
}
+ gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
+ }
- if (!txarc) {
- txarc = 1;
+ if (rxarc) {
+ gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
+ if (rxarc >= 5) {
+ gdImageFill(ic->im, x+(DOUTRAD/2-3)*cos(((270*2+2*txarc+rxarc)/2)*M_PI/180), y+(DOUTRAD/2-3)*sin(((270*2+2*txarc+rxarc)/2)*M_PI/180), ic->crx);
}
+ gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
}
- gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 0, 360, ic->cbgoffset, 0);
+ // remove center from background filled circle, making it a donut
+ gdImageFilledArc(ic->im, x, y, DINRAD-2, DINRAD-2, 0, 360, ic->cbackground, 0);
+}
+
+void drawdonut_libgd_native(IMAGECONTENT *ic, const int x, const int y, const float rxp, const float txp)
+{
+ int rxarc = 0, txarc = 0;
if ( (int)(rxp + txp) > 0 ) {
+ rxarc = (int)(360 * (rxp / (float)100));
+ if ( (int)(rxp + txp) == 100 ) {
+ txarc = 360 - rxarc;
+ } else {
+ txarc = (int)(360 * (txp / (float)100));
+ }
+ }
+
+ // background filled circle
+ gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 0, 360, ic->cbgoffset, 0);
+
+ if (txarc) {
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctx, 0);
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
+ gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
+ }
+
+ if (rxarc) {
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crx, 0);
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
-
- gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
}
+ // remove center from background filled circle, making it a donut
gdImageFilledArc(ic->im, x, y, DINRAD-2, DINRAD-2, 0, 360, ic->cbackground, 0);
}
}
END_TEST
+START_TEST(output_check)
+{
+ int ret, x, y;
+ IMAGECONTENT ic;
+ FILE *pngout;
+
+ x = 1060;
+ y = 420;
+
+ defaultcfg();
+ initimagecontent(&ic);
+ ic.im = gdImageCreate(x, y);
+ colorinit(&ic);
+ ic.interface.updated = get_timestamp(2001, 2, 3, 4, 5);
+ layoutinit(&ic, "vnstati output reference test", x, y);
+
+ pngout = fopen("vnstati_check.png", "w");
+ ck_assert_ptr_ne(pngout, NULL);
+
+ drawlegend(&ic, 40, 30);
+
+ /* line 1 */
+ x = 40;
+ y = 80;
+ gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+105, (unsigned char*)"libgd bug workaround", ic.ctext);
+ drawdonut(&ic, x, y, 0, 0);
+ drawdonut(&ic, x+55, y, 50.0, 50.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 50/50", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 100.0, 0);
+ drawdonut(&ic, x+55, y, 0, 100.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"100/0 - 0/100", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 60.0, 40.0);
+ drawdonut(&ic, x+55, y, 40.0, 60.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"60/40 - 40/60", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 75.0, 25.0);
+ drawdonut(&ic, x+55, y, 25.0, 75.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"75/25 - 25/75", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 90.0, 10.0);
+ drawdonut(&ic, x+55, y, 10.0, 90.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"90/10 - 10/90", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 95.0, 5.0);
+ drawdonut(&ic, x+55, y, 5.0, 95.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"95/5 - 5/95", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 99.0, 1.0);
+ drawdonut(&ic, x+55, y, 1.0, 99.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99/1 - 1/99", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 99.9, 0.1);
+ drawdonut(&ic, x+55, y, 0.1, 99.9);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99.9/0.1 - 0.1/99.9", ic.ctext);
+
+ /* line 2 */
+ x = 40;
+ y = 160;
+ drawdonut(&ic, x, y, 0, 0);
+ drawdonut(&ic, x+55, y, 25.0, 25.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 25/25", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 50.0, 0);
+ drawdonut(&ic, x+55, y, 0, 50.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"50/0 - 0/50", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 40.0, 30.0);
+ drawdonut(&ic, x+55, y, 30.0, 40.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"40/30 - 30/40", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 30.0, 20.0);
+ drawdonut(&ic, x+55, y, 20.0, 30.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"30/20 - 20/30", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 20.0, 10.0);
+ drawdonut(&ic, x+55, y, 10.0, 20.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"20/10 - 10/20", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 15.0, 5.0);
+ drawdonut(&ic, x+55, y, 5.0, 15.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"15/5 - 5/15", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 10.0, 1.0);
+ drawdonut(&ic, x+55, y, 1.0, 10.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"10/1 - 1/10", ic.ctext);
+
+ x += 130;
+ drawdonut(&ic, x, y, 1.0, 0.1);
+ drawdonut(&ic, x+55, y, 0.1, 1.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"1.0/0.1 - 0.1/1.0", ic.ctext);
+
+ /* line 3 */
+ x = 40;
+ y = 270;
+ gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+105, (unsigned char*)"libgd native", ic.ctext);
+ drawdonut_libgd_native(&ic, x, y, 0, 0);
+ drawdonut_libgd_native(&ic, x+55, y, 50.0, 50.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 50/50", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 100.0, 0);
+ drawdonut_libgd_native(&ic, x+55, y, 0, 100.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"100/0 - 0/100", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 60.0, 40.0);
+ drawdonut_libgd_native(&ic, x+55, y, 40.0, 60.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"60/40 - 40/60", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 75.0, 25.0);
+ drawdonut_libgd_native(&ic, x+55, y, 25.0, 75.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"75/25 - 25/75", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 90.0, 10.0);
+ drawdonut_libgd_native(&ic, x+55, y, 10.0, 90.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"90/10 - 10/90", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 95.0, 5.0);
+ drawdonut_libgd_native(&ic, x+55, y, 5.0, 95.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"95/5 - 5/95", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 99.0, 1.0);
+ drawdonut_libgd_native(&ic, x+55, y, 1.0, 99.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99/1 - 1/99", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 99.9, 0.1);
+ drawdonut_libgd_native(&ic, x+55, y, 0.1, 99.9);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99.9/0.1 - 0.1/99.9", ic.ctext);
+
+ /* line 4 */
+ x = 40;
+ y = 350;
+ drawdonut_libgd_native(&ic, x, y, 0, 0);
+ drawdonut_libgd_native(&ic, x+55, y, 25.0, 25.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 25/25", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 50.0, 0);
+ drawdonut_libgd_native(&ic, x+55, y, 0, 50.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"50/0 - 0/50", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 40.0, 30.0);
+ drawdonut_libgd_native(&ic, x+55, y, 30.0, 40.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"40/30 - 30/40", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 30.0, 20.0);
+ drawdonut_libgd_native(&ic, x+55, y, 20.0, 30.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"30/20 - 20/30", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 20.0, 10.0);
+ drawdonut_libgd_native(&ic, x+55, y, 10.0, 20.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"20/10 - 10/20", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 15.0, 5.0);
+ drawdonut_libgd_native(&ic, x+55, y, 5.0, 15.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"15/5 - 5/15", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 10.0, 1.0);
+ drawdonut_libgd_native(&ic, x+55, y, 1.0, 10.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"10/1 - 1/10", ic.ctext);
+
+ x += 130;
+ drawdonut_libgd_native(&ic, x, y, 1.0, 0.1);
+ drawdonut_libgd_native(&ic, x+55, y, 0.1, 1.0);
+ gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"1.0/0.1 - 0.1/1.0", ic.ctext);
+
+
+
+ gdImagePng(ic.im, pngout);
+ ret = fclose(pngout);
+ ck_assert_int_eq(ret, 0);
+ gdImageDestroy(ic.im);
+}
+END_TEST
+
void add_image_tests(Suite *s)
{
TCase *tc_image = tcase_create("Image");
tcase_add_test(tc_image, hourly_imagescaling_normal);
tcase_add_test(tc_image, hourly_imagescaling_rate_1024);
tcase_add_test(tc_image, hourly_imagescaling_rate_1000);
+ tcase_add_test(tc_image, output_check);
suite_add_tcase(s, tc_image);
}