-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify transparency in grids and images #8191
Conversation
See forum post for some background and limitations. This PR does not implement code changes yet, but tries to describe via the documentation what we would like to have implemented before 6.5 is released:
4rth case is the more complex one. Current situation uses a blending mechanism that makes a weighted composition of the R,G,B,A and simulates transparency. That is, if plotting only the RGBA image, it looks transparent, but if we overlay it on another one we realize that it's actually opaque. This is what gave rise to the post in forum. Now, if we want that a variable RGBA is truly transparent and PS provides only a all or nothing solution, we have a problem as only one of the RGB colors can be transparent. Not completely sure but I think that is what you are proposing in the fourth case. Related: #3477 |
Add new function grdimage_transparencies which determines what type of scenario we have regarding the alpha channel.
Yes, 4th case is approximating transparency since PS cannot do that on a per-pixel basis. So we need to explain that - I will add a Transparency Limitation section to grdimage man page.
This info is now available via Conf->trans so we can take appropriate (and possibly new) action in the imaging functions doing transparency. Then my suggestion of -Q +o|t modifiers can be used to select the single true transparency color or do the blending as we do now (but allow to replace white as the blend color). Gotta go shopping now. Later. |
Fine, but there is more in the transparency land. Indexed images may also be set transparent by indicating which color in the CPT represents the transparency. There is code for that in the lib but likely that's information only to GDAL and since it was work previous to -Q it's probably ignored on the PS side. Needs digging. |
Found things. In
But this is only used by MEX & Julia, and is used to save indexed images with transparency.
So, at least for a single transparency value, we have that info available but don't know if we make any use of it for images. ... Continuing. In
but it doesn't seem to be used as a transparency info in |
Thanks, I will add the needed parsing of -Q to handle the new modifiers. We're having dinner guests today so may work for an hour and then later tonight. |
Tried this to get a variable transparency RGBA but it actually crashed
So will be working on fixing that bug (-C assumed we gave a grid, not an image for the -A operation. Need a test to test the above changes. |
@earth_days are indexed. |
Yes, not a problem, but no A. Fixing grdmix now and it adds alpha to write RGBA tiff just fine. |
gmtlib_bcr_get_img sames the r,g,b values at given point, but did not also do tramsparency (unless it was coded as 4th band). This commit checks if alpha is not NULLand bands is 1 or 3 then we also compute the sampled transparency
If image header has wesn so that e>w and n> s we use that for domain
Figured out the strangeness by slowly building another branch and moving over smaller commits until I found why it broke: I had changed gmt_get_raster to take true instead of false since that would better return what the file was (image vs grids). For ex52 we read an image but the working version return GMT_IS_GRID and then do other things in grdimage.c. I will delete this branch and upload a new branch that has new stuff but is still passing all tests. |
See forum post for some background and limitations. This PR does not implement code changes yet, but tries to describe via the documentation what we would like to have implemented in grdimage before 6.5 is released:
This would let us handle RGBA files with alpha channel containing either transparency or opacity, either as a two-value 0 + 255 alphas, or a variable alpha from 0-255 (in which case we blend image color and fixed transparent color [white]). @joa, is anything missing from this proposal (apart from there being four not three schemes above)?