From c9093664186cdf86c13b63b3f699d52e9783b3a0 Mon Sep 17 00:00:00 2001 From: Solar Smith Date: Thu, 29 Jan 2026 15:30:36 -0500 Subject: [PATCH 1/3] Adjust PSL_setcolor to guard stroke and fill transparencies when the other is set --- src/postscriptlight.c | 23 +++++++++++++++++++---- test/baseline/postscriptlight.dvc | 4 ---- 2 files changed, 19 insertions(+), 8 deletions(-) delete mode 100644 test/baseline/postscriptlight.dvc diff --git a/src/postscriptlight.c b/src/postscriptlight.c index a1df1ada0e0..0ad399699dc 100644 --- a/src/postscriptlight.c +++ b/src/postscriptlight.c @@ -5166,12 +5166,27 @@ int PSL_setcolor (struct PSL_CTRL *PSL, double rgb[], int mode) { if (PSL_eq (rgb[0], -2.0) || PSL_eq (rgb[0], -1.0)) return (PSL_NO_ERROR); /* Settings to be ignored */ if (PSL_same_rgb (rgb, PSL->current.rgb[mode])) return (PSL_NO_ERROR); /* Same color as already set */ - /* Because psl_putcolor does not set transparency if it is 0%, we reset it here when needed */ - if (PSL_eq (rgb[3], 0.0) && !PSL_eq (PSL->current.rgb[mode][3], 0.0)) + /* Guard: When setting stroke or fill with transparency, preserve the other channel's transparency */ + if (!PSL_eq (rgb[3], 0.0) && (mode == PSL_IS_STROKE || mode == PSL_IS_FILL)) { + double transp[2], rgb_copy[4]; + /* Preserve current transparencies and update only the relevant channel */ + transp[PSL_FILL_TRANSP] = (mode == PSL_IS_FILL) ? rgb[3] : PSL->current.rgb[PSL_IS_FILL][3]; + transp[PSL_PEN_TRANSP] = (mode == PSL_IS_STROKE) ? rgb[3] : PSL->current.rgb[PSL_IS_STROKE][3]; + /* Set transparency explicitly for both channels */ + PSL_command (PSL, "%.12g %.12g /%s PSL_transp\n", 1.0 - transp[PSL_FILL_TRANSP], 1.0 - transp[PSL_PEN_TRANSP], PSL->current.transparency_mode); + /* Make a copy with transparency zeroed out for psl_putcolor to avoid double-setting */ + PSL_rgb_copy (rgb_copy, rgb); + rgb_copy[3] = 0.0; + PSL_command (PSL, "%s\n", psl_putcolor (PSL, rgb_copy, 0)); + } + else { + /* Because psl_putcolor does not set transparency if it is 0%, we reset it here when needed */ + if (PSL_eq (rgb[3], 0.0) && !PSL_eq (PSL->current.rgb[mode][3], 0.0)) PSL_command (PSL, "%.12g %.12g /Normal PSL_transp ", PSL->init.transparencies[PSL_FILL_TRANSP], PSL->init.transparencies[PSL_PEN_TRANSP]); - /* Then, finally, set the color using psl_putcolor */ - PSL_command (PSL, "%s\n", psl_putcolor (PSL, rgb, 0)); + /* Then, finally, set the color using psl_putcolor */ + PSL_command (PSL, "%s\n", psl_putcolor (PSL, rgb, 0)); + } /* Update the current stroke/fill color information */ diff --git a/test/baseline/postscriptlight.dvc b/test/baseline/postscriptlight.dvc deleted file mode 100644 index b5251baa584..00000000000 --- a/test/baseline/postscriptlight.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: e5ec08fe1ffe6b7a29733983a3dc988b.dir - nfiles: 1 - path: postscriptlight From 383b5525b42935ed764212bc44cfc70a7206e13e Mon Sep 17 00:00:00 2001 From: Solar Smith Date: Thu, 29 Jan 2026 15:31:54 -0500 Subject: [PATCH 2/3] Add test of tansparency independence --- .gitignore | 3 +++ test/baseline/.gitignore | 1 - .../postscriptlight/fillTransparency.ps.dvc | 5 +++++ test/postscriptlight/fillTransparency.sh | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/baseline/postscriptlight/fillTransparency.ps.dvc create mode 100755 test/postscriptlight/fillTransparency.sh diff --git a/.gitignore b/.gitignore index 9579a3846a8..fcdb05ae2f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ build ?build ?build-mp +Testing .*~ cmake/ConfigUser.cmake cmake/ConfigUserAdvanced.cmake @@ -12,6 +13,8 @@ src/newsuppl* doc/examples/**/*.mp4 doc/examples/**/*.png doc/examples/**/*.gif +test/**/*.ps +!test/**/*.ps.dvc .vscode cmake/ConfigUser.cmake.orig cmake/ConfigUserAdvanced.cmake.orig diff --git a/test/baseline/.gitignore b/test/baseline/.gitignore index a30031e47ab..984083bd9da 100644 --- a/test/baseline/.gitignore +++ b/test/baseline/.gitignore @@ -55,7 +55,6 @@ /pscontour /psclip /project -/postscriptlight /ogr /nearneighbor /movie diff --git a/test/baseline/postscriptlight/fillTransparency.ps.dvc b/test/baseline/postscriptlight/fillTransparency.ps.dvc new file mode 100644 index 00000000000..ee01b5f435d --- /dev/null +++ b/test/baseline/postscriptlight/fillTransparency.ps.dvc @@ -0,0 +1,5 @@ +outs: +- md5: d1c50e48f2e2fe1d0dccfc43f3307f33 + size: 26097 + hash: md5 + path: fillTransparency.ps diff --git a/test/postscriptlight/fillTransparency.sh b/test/postscriptlight/fillTransparency.sh new file mode 100755 index 00000000000..43166ab8e76 --- /dev/null +++ b/test/postscriptlight/fillTransparency.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env -S bash -ex +# GMT modern mode bash template +# Date: 2026-01-21T12:44:22 +# User: solarsmith +# Purpose: Purpose of this script +set -e +export GMT_SESSION_NAME=$$ # Set a unique session name + +gmt begin fillTransparency ps + gmt basemap -R-2/2/-2/2 -JX10c/4c -B + echo -1 0 | gmt plot -Ss1c -W1p,blue@60 -Gbrown + echo 0 0 | gmt plot -Ss1c -W1p,blue -Gbrown@30 + echo 1 0 | gmt plot -Ss1c -W1p,blue@60 -Gbrown@30 +gmt end \ No newline at end of file From 79d86a0bfafbd973037c70488a34459c557aa546 Mon Sep 17 00:00:00 2001 From: Solar Smith Date: Thu, 29 Jan 2026 15:50:07 -0500 Subject: [PATCH 3/3] updated test and result image to test independence of -G and -W explicit and default transparencies --- test/baseline/postscriptlight/fillTransparency.ps.dvc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/baseline/postscriptlight/fillTransparency.ps.dvc b/test/baseline/postscriptlight/fillTransparency.ps.dvc index ee01b5f435d..ced6e64c5bb 100644 --- a/test/baseline/postscriptlight/fillTransparency.ps.dvc +++ b/test/baseline/postscriptlight/fillTransparency.ps.dvc @@ -1,5 +1,5 @@ outs: -- md5: d1c50e48f2e2fe1d0dccfc43f3307f33 - size: 26097 +- md5: cd022252f83b80a3c67e52094323d52d + size: 26087 hash: md5 path: fillTransparency.ps