Skip to content

Let -Fx write hex CPT tables#7019

Merged
PaulWessel merged 4 commits intomasterfrom
hex-colors-out
Sep 7, 2022
Merged

Let -Fx write hex CPT tables#7019
PaulWessel merged 4 commits intomasterfrom
hex-colors-out

Conversation

@PaulWessel
Copy link
Member

This PR adds new directive -Fx to tell makecpt and grd2cpt to write their r/g/b triplets in hex format #rrggbb. Closes #7018.
@anbj, please give it a test or two.

This PR adds new directive x to tell makecpt and grd2cpt to write their r/g/b triplets in hex format #rrggbb.  Closes #7018.
@PaulWessel PaulWessel added the enhancement Improving an existing feature label Sep 7, 2022
@PaulWessel PaulWessel added this to the 6.5.0 milestone Sep 7, 2022
@PaulWessel PaulWessel self-assigned this Sep 7, 2022
@anbj
Copy link
Contributor

anbj commented Sep 7, 2022

makecpt seems to work fine.
grd2cpt doesn't care about the Fx yet, apparently:

$ gmt grd2cpt @earth_relief_30m -Fx
-9454.5	61.75/55.25/143.5	-5292.09617579	61.75/55.25/143.5	L
-5292.09617579	70.75/123.5/242.5	-4125.37616927	70.75/123.5/242.5	L
-4125.37616927	40.5/187.25/235.75	-3284.08895941	40.5/187.25/235.75	L
-3284.08895941	32.5/234.25/171.5	-2565.24005812	32.5/234.25/171.5	L
-2565.24005812	120/254/89.75	-1893.34927828	120/254/89.75	L
-1893.34927828	195.75/240.75/52	-1221.45849844	195.75/240.75/52	L
-1221.45849844	245.75/195.5/58	-502.609597148	245.75/195.5/58	L
-502.609597148	251/128.25/33.75	338.67761271	251/128.25/33.75	L
338.67761271	221.5/61.5/8	1505.39761923	221.5/61.5/8	L
1505.39761923	163.25/18.75/1	5887.5	163.25/18.75/1	B
B	black
F	white
N	128

@joa-quim
Copy link
Member

joa-quim commented Sep 7, 2022

On a side note, sorry, why wasting loops converting some colors to color names? IMO it doesn't even increase readability as I don't know, for example, what a dimgray is.

makecpt -T0/255/256+n -G0.4/0.94 -Cgray
0       gray40  1       gray40  L
1       102.81  2       102.81  L
2       103.35  3       103.35  L
3       103.89  4       103.89  L
4       104.43  5       104.43  L
5       dimgray 6       dimgray L
6       105.51  7       105.51  L
7       106.05  8       106.05  L
8       gray42  9       gray42  L
9       gray42  10      gray42  L
10      107.67  11      107.67  L

@PaulWessel
Copy link
Member Author

PaulWessel commented Sep 7, 2022

I think there is -Fr for that situation (no names) but for gray it gives

253 238.89/238.89/238.89 254 238.89/238.89/238.89 L

So we need to let that mean just shade if CPT is gray shades only.

@anbj
Copy link
Contributor

anbj commented Sep 7, 2022

Not relevant, but I just discovered that the gmt color names are the same as those in /usr/share/X11/rgb.txt. Not a coincidence I presume?

@PaulWessel
Copy link
Member Author

Hi @anbj, thanks for the check. I found an unrelated bug in grd2cpt that would have affected any -F? argument. Now it works I think.

@PaulWessel
Copy link
Member Author

@joa-quim, do we know if hex is used for gray shades with just two chars? E.g., #ee or are they always repeated #eeeeee.

@PaulWessel
Copy link
Member Author

yes, they are based on the X11 table.

@anbj
Copy link
Contributor

anbj commented Sep 7, 2022

grd2cpt looks good now!

$ gmt grd2cpt @earth_relief_30m -Fx
-9454.5	#3e3790	-5292.09617579	#3e3790	L
-5292.09617579	#477bf2	-4125.37616927	#477bf2	L
-4125.37616927	#28bbec	-3284.08895941	#28bbec	L
-3284.08895941	#20eaac	-2565.24005812	#20eaac	L
-2565.24005812	#78fe5a	-1893.34927828	#78fe5a	L
-1893.34927828	#c4f134	-1221.45849844	#c4f134	L
-1221.45849844	#f6c33a	-502.609597148	#f6c33a	L
-502.609597148	#fb8022	338.67761271	#fb8022	L
338.67761271	#dd3d08	1505.39761923	#dd3d08	L
1505.39761923	#a31301	5887.5	#a31301	B
B	#000000
F	#ffffff
N	#808080

@joa-quim
Copy link
Member

joa-quim commented Sep 7, 2022

@joa-quim, do we know if hex is used for gray shades with just two chars? E.g., #ee or are they always repeated #eeeeee.

Don't know but in that site I pointed (https://hexwords.netlify.app/) many colors have only 3 chars, so if less than 6 something is assumed.

@PaulWessel
Copy link
Member Author

OK, I dont think we will go there but I am guessing 2-chars would be a gray shade and 3 would be r/g/b with the high text char. So undefined.

@PaulWessel
Copy link
Member Author

Need approval on this one.

@anbj
Copy link
Contributor

anbj commented Sep 7, 2022

Thanks Paul!

@PaulWessel
Copy link
Member Author

Ping @joa-quim in case he needs to know that gmt_enum_dict.h changed?

@joa-quim
Copy link
Member

joa-quim commented Sep 7, 2022

Changing enums should not matter for the Julia FFI

@PaulWessel PaulWessel merged commit 9abb818 into master Sep 7, 2022
@PaulWessel PaulWessel deleted the hex-colors-out branch September 7, 2022 22:45
@maxrjones maxrjones added the add-changelog Add PR to the changelog label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-changelog Add PR to the changelog enhancement Improving an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

makecpt and grd2cpt: allow hex output

4 participants