Hello,
Images are currently generated as fast as possible, but in some
situations CPU time is cheaper than bandwidth. This patch implements a
new --compression-level option for rrdgraph to adjust the compression
level (sic) of the graphs. It takes a nonnegative integer as its argument.
This setting has currently only a meaning for PNG images, where it is
used as the zlib compression level (i.e. 0 for no compression to 9 for
best compression). We can also imagine to use greater values to switch
between PNG compression methods (e.g 27 for the method 2 and compression
7). The default value has been kept to 1, like the current behaviour.
Specifying this setting has no incidence on all the other formats (it is
not rejected).
Regards,
Vincent Pit.
--- doc/rrdgraph.pod 2007-05-02 20:06:13.000000000 +0200
+++ doc/rrdgraph.pod 2007-07-07 16:41:23.000000000 +0200
@@ -332,6 +332,11 @@
Helvetica-BoldOblique, Helvetica-Oblique, Helvetica, Symbol,
Times-Bold, Times-BoldItalic, Times-Italic, Times-Roman, and ZapfDingbats.
+[B<-C>|B<--compression-level> I<level>]
+
+Currently used only with PNG images. Set the compression level from 0
+(no compression, fastest) to 9 (best compression, slowest). Default is 1.
+
[B<-i>|B<--interlaced>]
If images are interlaced they become visible on browsers more quickly.
--- src/rrd_gfx.c 2007-05-02 20:06:10.000000000 +0200
+++ src/rrd_gfx.c 2007-07-07 16:36:39.000000000 +0200
@@ -99,6 +99,7 @@
canvas->zoom = 1.0;
canvas->font_aa_threshold = -1.0;
canvas->aa_type = AA_NORMAL;
+ canvas->compression = 1;
return canvas;
}
@@ -526,7 +527,7 @@
static int gfx_save_png (art_u8 *buffer, FILE *fp,
- long width, long height, long bytes_per_pixel);
+ long width, long height, long bytes_per_pixel, long
compression);
/* render grafics into png image */
int gfx_render_png (gfx_canvas_t *canvas,
@@ -764,7 +765,7 @@
}
node = node->next;
}
- gfx_save_png(buffer,fp , pys_width,pys_height,bytes_per_pixel);
+ gfx_save_png(buffer,fp , pys_width,pys_height,bytes_per_pixel,
canvas->compression);
art_free(buffer);
FT_Done_FreeType( library );
return 0;
@@ -787,7 +788,7 @@
return 0;
}
-static int gfx_save_png (art_u8 *buffer, FILE *fp, long width, long height,
long bytes_per_pixel){
+static int gfx_save_png (art_u8 *buffer, FILE *fp, long width, long height,
long bytes_per_pixel, long compression){
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
int i;
@@ -837,7 +838,7 @@
/* lets make this fast while ending up with some increass in image size */
png_set_filter(png_ptr,0,PNG_FILTER_NONE);
/* png_set_filter(png_ptr,0,PNG_FILTER_SUB); */
- png_set_compression_level(png_ptr,1);
+ png_set_compression_level(png_ptr, compression % 10);
/* png_set_compression_strategy(png_ptr,Z_HUFFMAN_ONLY); */
/*
png_set_filter(png_ptr,PNG_FILTER_TYPE_BASE,PNG_FILTER_SUB);
--- src/rrd_gfx.h 2007-05-02 20:06:10.000000000 +0200
+++ src/rrd_gfx.h 2007-07-07 16:34:18.000000000 +0200
@@ -55,6 +55,7 @@
double zoom; /* zoom for graph */
double font_aa_threshold; /* no anti-aliasing for sizes <= */
enum gfx_aa_type_en aa_type; /* anti-aliasing type (normal/light/none) */
+ long compression; /* compression level */
} gfx_canvas_t;
gfx_canvas_t *gfx_new_canvas (void);
--- src/rrd_graph.c 2007-05-02 20:06:10.000000000 +0200
+++ src/rrd_graph.c 2007-07-07 16:34:08.000000000 +0200
@@ -3245,6 +3245,7 @@
{"font-smoothing-threshold", required_argument, 0, 'B'},
{"watermark", required_argument, 0, 'W'},
{"alt-y-mrtg", no_argument, 0, 1000}, /* this has no effect
it is just here to save old apps from crashing when they use it */
+ {"compression-level", required_argument, 0, 'C'},
{0,0,0,0}};
int option_index = 0;
int opt;
@@ -3428,6 +3429,14 @@
return;
}
break;
+ case 'C':
+ long_tmp = atol(optarg);
+ if (long_tmp < 0) {
+ rrd_set_error("negative compression level");
+ return;
+ }
+ im->canvas->compression = long_tmp;
+ break;
case 'z':
im->lazy = 1;
break;
--- src/rrd_tool.c 2007-05-02 20:06:10.000000000 +0200
+++ src/rrd_tool.c 2007-07-07 16:38:41.000000000 +0200
@@ -119,6 +119,7 @@
"\t\t[-S|--step seconds]\n"
"\t\t[-f|--imginfo printfstr]\n"
"\t\t[-a|--imgformat PNG]\n"
+ "\t\t[-C|--compression-level level]\n"
"\t\t[-c|--color COLORTAG#rrggbb[aa]] [-t|--title string]\n"
"\t\t[-W|--watermark string]\n"
"\t\t[DEF:vname=rrd:ds-name:CF]\n";
_______________________________________________
rrd-developers mailing list
[email protected]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers