Skip to content

Conversation

@Chuan1937
Copy link
Contributor

Add a GMT_IS_IMAGE branch to the gmtinit_get_region_from_data() function, read the image header information using the correct image type and GMT_CONTAINER_ONLY mode, extract the boundary coordinates, and then release the data structure.

Fixes #8878

@Chuan1937
Copy link
Contributor Author

Chuan1937 commented Jan 28, 2026

@joa-quim
I add a new case for this problem, and add a test for it.
I don't know if it can solve this problem in julia.

@joa-quim
Copy link
Member

@Chuan1937 Thanks a lot for looking into this. However, I don't think it solves it.

Adding a GMT_IS_IMAGE branch doesn't help because in gmtinit_set_missing_R_from_grid() the call to gmtinit_get_region_from_data is always done with GMT_IS_GRID

if ((err = gmtinit_get_region_from_data (API, GMT_IS_GRID, exact, options, wesn, &API->GMT->common.R.aspect)))

and in fact this doesn't seem to be a problem because at the end the code flow ends up in the function that read an image. I have debugged this a bit further but still think there is something fundamentally broken in gmtinit_set_missing_R_from_grid. I think I can now force it to follow a path that should work but can't still base it in a robust logic.

And your test script. Yes, I guess it will work but it is not testing this case. Reading a file works fine, but reading one that is already loaded in memory (and you would need GMT.jl to test this) is where this keep failing.

@Chuan1937 Chuan1937 marked this pull request as draft January 29, 2026 03:02
@Chuan1937
Copy link
Contributor Author

Can you give me the failed Julia Code?
I've installed Julia.@joa-quim

- Modified gmtinit_set_missing_R_from_grid to detect image files by extension
  and use GMT_IS_IMAGE instead of hardcoded GMT_IS_GRID
- Modified gmtapi_import_image to skip padding checks when GMT_CONTAINER_ONLY
  is set, allowing pre-loaded images to be imported for header reading
- This fixes the failure when using multiple pre-loaded images in Julia subplots
@joa-quim
Copy link
Member

I smell the scent of a challenge 😃

When I have a easy to use Julia function I'll post instructions here (later today).

But your attempts are way off. A pre-loaded image is one that was already read and data is present in memory. That is what the wrappers do when they want to send in data already available. It has nothing to do files and extensions. Have a look at my attempt that almost worked
https://github.com/GenericMappingTools/gmt/pull/8883/changes

@joa-quim
Copy link
Member

joa-quim commented Jan 31, 2026

OK, you need to install the GMT.jl master version. You do that with:

] add GMT#master

than pick two images (whatever) and do

montage(["A.png", "A.png"], grid=(1,2))     # This works because it tells GMT to read the files
montage([gmtread("A.png"), gmtread("A.png")], grid=(1,2))     # This works because the montage function passes a -R under the hood in all commands
montage([gmtread("A.png"), gmtread("A.png")], grid=(1,2), noR=true)     # This fails due to issue of this issue  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

subplot with two pre-loaded images in Julia fails due to failure in region detection of second image.

2 participants