Menu

#833 Full dashtype support for libgd terminals and improved antialiasing quality

Version 6
open
nobody
5
2026-01-26
2026-01-22
Sethur
No

This patch enhances the libgd-based terminals (e.g. png, and other gd variants) by adding full dashtype support and improving antialiasing quality.

For dashed lines, it introduces a PNG_dashtype() implementation that maps gnuplot’s built-in dashtypes (dash, dot, dash-dot, dash-dot-dot) and user-defined custom dash patterns into a gdImageSetStyle() array (color/transparent run lengths), scaled by both linewidth and the terminal’s dashlength factor. The code tracks dash phase across connected vectors so dashes remain continuous across polyline segments.

For TrueColor output with butt caps, dashed lines are rendered through a new custom antialiased dashed-line path because libgd’s gdStyled rendering does not antialias. A small AA rasterizer for thick segments is added, including buffering/flush logic to reduce visible “seam striping” when curves are approximated by many short segments. Axis/grid dotted rendering remains a special case as before.

I did not benchmark the performance impact directly, but solid "lw 1" lines should render as fast as before. I developed this patch because I needed to generate a large amount of PNG plots including dashed lines and the pngcairo terminal was orders of magnitude slower then the old png terminal, at least on my system.

Full disclosure: I used recent LLMs (Claude Opus 4.5 and OpenAI GPT 5.2) to help with the code generation.

1 Attachments

Discussion

  • Sethur

    Sethur - 2026-01-22

    As an example of what is possible with the new dashtype support, I have attached the output of the follwing example script:

    set samples 500
    set xrange [0:4*pi]
    set yrange [-1.5:7.5]
    
    set xlabel "x"
    set ylabel "y"
    set title "Antialiased Dashed Lines Test" font ",14"
    
    set key right top box opaque
    set grid
    
    # Define line styles with different dash types and colors
    set style line 1 lc rgb "#E41A1C" lw 1 dt solid    # Red - solid
    set style line 2 lc rgb "#377EB8" lw 2 dt 2        # Blue - dashed
    set style line 3 lc rgb "#4DAF4A" lw 3 dt 3        # Green - dotted
    set style line 4 lc rgb "#984EA3" lw 4 dt 4        # Purple - dash-dot
    set style line 5 lc rgb "#FF7F00" lw 5 dt 5        # Orange - dash-dot-dot
    set style line 6 lc rgb "#A65628" lw 6 dt 1        # Brown - another solid
    
    # Also test thicker lines
    set style line 7 lc rgb "#F781BF" lw 7 dt 2        # Pink - thick dashed
    set style line 8 lc rgb "#999999" lw 8 dt 3        # Gray - thick dotted
    
    # Define the plot command as a macro for reuse
    plot_cmd = "plot sin(x)       ls 1 title 'solid (dt solid)', \
         sin(x) + 1   ls 2 title 'dt 2 (dashed)', \
         sin(x) + 2   ls 3 title 'dt 3 (dotted)', \
         sin(x) + 3   ls 4 title 'dt 4 (dash-dot)', \
         sin(x) + 4   ls 5 title 'dt 5 (dash-dot-dot)', \
         sin(x) + 5   ls 6 title 'dt 1 (solid)', \
         sin(x) + 6   ls 7 title 'dt 2 lw 4 (thick dashed)', \
         sin(x) + 7   ls 8 title 'dt 3 lw 4 (thick dotted)'"
    
    set terminal png size 1600,1200 enhanced font "Arial,10" truecolor
    set output "test_dashes.png"
    set title "Dashed Lines - PNG (libgd)" font ",14"
    eval plot_cmd
    
     
  • Sethur

    Sethur - 2026-01-26

    Are patches still considered? Should I have posted this somewhere else?

     
  • Ethan Merritt

    Ethan Merritt - 2026-01-26

    I'm traveling and will have alook ar your patch when I return next week. In the meantime, just a question. IsYour code something that could be added to the libgd library itself? If so that would benefit not just gnuplot but all other users of the library. I have contributed fixes to libgd before so I know they are receptive.
    Thanks for your contribution.

     
  • Sethur

    Sethur - 2026-01-26

    It would have been possible to add large parts of this patch directly to libgd, which indeed would have been the better solution, but gnuplot would still have to be patched to utilize the new capabilities. Additionally, the changes in how antialiasing with this patch works in general are significant and I found it quite unlikely that such a long-established library would adopt them.

    Also, I do not have a lot of experience with these kind of libraries and although I have tested this patch quite a bit and think that I have solved most issues, the code is probably still not as clean as it should be for something like libgd.

     

Log in to post a comment.