Re: pdfcairo terminal; seams between bars in the colorbox
Dima Kogan <[email protected]> Sun, 11 Jun 2023 16:22:01 -0700
| Newsgroups | gmane.comp.graphics.gnuplot.devel |
|---|---|
| Message-ID | <[email protected]> |
Ethan A Merritt <[email protected]> writes: > I may not understand what you are suggesting. Hi. I guess I wasn't clear. The suggestion was that instead of creating 128 discrete bars with different colors we create a 128x1 bitmap and draw it as an image. The thought was that this would work because images look correct in pdfcairo, without the ugly border lines. I implemented this in the attached patch, and it works and looks good. I tried several gnuplot terminals (x11, qt, wxt, pdfcairo, png, svg), and it looks like it works there too. I haven't found anything that this breaks. The script I used to test: plot 'demo/blutux.rgb' binary array=(128,128) flipy format='%uchar' with rgbimage, 5 with points palette I don't understand the gnuplot codebase deeply, so I might have missed things. Some questions: - I patched draw_inside_colorbox_bitmap_smooth() only. There are other flavors of this function (look where it is called), and I don't know if the others should be updated in this way as well - I have an extra "gray = 1 - gray;" that I don't understand. It makes things correct, though - The patch uses rgb unconditionally. I that going to break something in some terminal? - I copied most of the logic from the old function without an understanding of what it does. Am I handling these properly? - sm_palette.use_maxcolors - sm_palette.gradient_num - sm_palette.positive - If I "set colorbox horizontal" then the colorbox stays in the same spot with the same shape, but I change the color sequence to move horizontally. This happens even before my patch. I'm here: ae7dfa3f3..: Ethan A Merritt 2023-06-09 qt: qt4 was apparently weak at int->double promotion Shouldn't the colorbox move below or above the plot, and reorient itself? Or is it the user's job to set the geometry? This makes my PDFs look nice. It'd be good if some version of this patch was merged. Thanks _______________________________________________ gnuplot-beta mailing list [email protected] Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
color-bar-image.patch
(text/x-diff, 3.1 KB)
diff --git a/src/color.c b/src/color.c
index f1c09451d..3c22115d3 100644
--- a/src/color.c
+++ b/src/color.c
@@ -492,63 +492,53 @@ draw_inside_colorbox_bitmap_discrete ()
static void
draw_inside_colorbox_bitmap_smooth()
{
- int steps;
- int i, xy, xy2, xy_from, xy_to;
- double xy_step, gray;
- gpiPoint corners[4];
-
- /* Determins the steps for rectangles boxes from palette's color number specification. */
-
- steps = 128; /* I think that nobody can distinguish more colours drawn in the palette */
+ gpiPoint corners[4] = {
+ {.x = color_box.bounds.xleft, .y = color_box.bounds.ytop},
+ {.x = color_box.bounds.xright, .y = color_box.bounds.ybot},
+ {.x = color_box.bounds.xleft, .y = color_box.bounds.ytop},
+ {.x = color_box.bounds.xright, .y = color_box.bounds.ybot}
+ };
+ int steps = 128;
if ( sm_palette.use_maxcolors != 0 ) {
steps = sm_palette.use_maxcolors;
} else if ( sm_palette.gradient_num > 128 ) {
- steps = sm_palette.gradient_num;
+ steps = sm_palette.gradient_num;
}
- if (color_box.rotation == 'v') {
- corners[0].x = corners[3].x = color_box.bounds.xleft;
- corners[1].x = corners[2].x = color_box.bounds.xright;
- xy_from = color_box.bounds.ybot;
- xy_to = color_box.bounds.ytop;
- xy_step = (color_box.bounds.ytop - color_box.bounds.ybot) / (double)steps;
- } else {
- corners[0].y = corners[1].y = color_box.bounds.ybot;
- corners[2].y = corners[3].y = color_box.bounds.ytop;
- xy_from = color_box.bounds.xleft;
- xy_to = color_box.bounds.xright;
- xy_step = (color_box.bounds.xright - color_box.bounds.xleft) / (double)steps;
- }
-
- for (i = 0, xy2 = xy_from; i < steps; i++) {
+ coordval image[3*steps];
- xy = xy2;
- xy2 = xy_from + (int) (xy_step * (i + 1));
+ for (int i = 0; i < steps; i++) {
- gray = i / (double)steps;
+ double gray = (double)i / (double)(steps-1);
if ( sm_palette.use_maxcolors != 0 ) {
gray = quantize_gray(gray);
}
if (sm_palette.positive == SMPAL_NEGATIVE)
gray = 1 - gray;
- set_color(gray);
- if (color_box.rotation == 'v') {
- corners[0].y = corners[1].y = xy;
- corners[2].y = corners[3].y = GPMIN(xy_to,xy2+1);
- } else {
- corners[0].x = corners[3].x = xy;
- corners[1].x = corners[2].x = GPMIN(xy_to,xy2+1);
- }
- /* print the rectangle with the given colour */
- if (default_fillstyle.fillstyle == FS_EMPTY)
- corners->style = FS_OPAQUE;
- else
- corners->style = style_from_fill(&default_fillstyle);
- term->filled_polygon(4, corners);
+ // Need to unconditionally invert this for some reason
+ gray = 1 - gray;
+
+ rgb_color rgb1;
+ rgb1maxcolors_from_gray( gray, &rgb1 );
+ image[3*i + 0] = rgb1.r;
+ image[3*i + 1] = rgb1.g;
+ image[3*i + 2] = rgb1.b;
}
+
+
+ if (color_box.rotation == 'v')
+ term->image(1, steps,
+ image,
+ corners,
+ IC_RGB);
+ else
+ term->image(steps, 1,
+ image,
+ corners,
+ IC_RGB);
}
static void