-
Notifications
You must be signed in to change notification settings - Fork 346
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
gdal_read is not filling out the pixels correctly (?) #3294
Comments
Haven't dive into the code but when I read the
and it reports it to be |
Can you point me to a place where (GMT or elsewhere) where BRP, TRP etc are explained? It should not matter what the source image is, the I->data returned should be consistently the same, and then output can be set to whatever, but internally it makes no sense to have different layouts. That would mean every program needing to work on images must have all those cases there.
|
We invented that: 1st char T(op) or B(ott) to indicate if the array is topdown ot bottomup Depending on final usage (PS (pixel interleaving) is different from exporting to Matlab (band interleaving)) the image is read stored directly with the final memory layout. Having an internal fixed storage would mean doing intermediate copies and memory shuflings on potentially big images. |
Thanks, we should copy/paste that definition into the code somewhere. So what do you recommend? That grdmix or other tools that read 1-3 images must for each one have a case-laden switch to rearrange those images to a common layout, do the compositing, then rearrange to another layout that GDAL can write? Seems like a lot of work that has to be repeated everywhere. Just so I understand, when gmt_gdalread returns it has set the mem_layout string to reflect the actual layout of I->data? Judging from grdimage, I guess gmt_gdalread never strips off the alpha and places it in I->alpha on input since in grdimage we are dealing with possible RGBA quadruplets. |
What about the 4th character? Seems to be 'a' or ' '? Why lower case a and not A, or are the other options? |
It is but always hard to find. In gdalread we have this
It means by default the mem layout is Yes, I->alpha should contain the alpha band when it exists. the |
So grdmix calls this up front:
I then read a PNG. It returns and says layout is TRPa. But the I->data does not match that, given only the first 1/3 of the pixels are set. So what can I do? |
I would need to debug and to night I don't know when I'll have time but I think you want "TRBa". Band not Pixel interleaving. |
Change the initial call to
My dump shows that I->data has the separate bands and now all the data are there. Good. However, upon calling GMT_Write_Data I get these
This happens whether I try to reset API_IMAGE_LAYOUT to TRPa or not. Do I mess with the I->header->mem_layout string? |
Or do I have to shuffle I->data myself to TRPa, update the I->header->mem_layout to say that, and then write? |
Seems you are supporting TRB in input but not output? |
FYI, I am working on adding TRB to gmt_gdalwrite.c |
Sorry, had a long zoom. The idea is that you select the layout, do the processing and save, without any need to the shuffle the image. But it might happen that the writing layout is not implemented. But I think we have functions to convert some of the layouts. |
Dont the TRB out would seem simple. I follow your code but build TPR from TRB. First attempt not work of course. Try, try again. |
I remember that we have stuff to deal with images and that you wrote some of those cryptic codes with bitwise operations but don't remember more. |
Found the thread |
Hah. OK, yes, not used anywhere but it is there. So I guess I should call this before writing and request TRP (whatever mode that might be)? |
OK, so the required TRB to TRP is not one of the supported ones... So I guess I will add that and try this. |
It is used by |
OK, now I get it. I found the bit-stuff you mentioned and all. It is like a goldmine - long forgotten. IT is actually pretty nice (!) if we can add more cases. I will focus on the ability to go from TRB to TRP for now and then do it via this function. |
I got GMT_Change_Layout to work. I added a few more cases but have not tested them. I did a few of the TR? cases. I guess TC? are for Matlab. Not sure what does B??. |
This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions. |
In debugging new module grdmix in branch mix-imgs-module I read in a 50x50 all red PNG. GDAL correctly reports 50x50 with 3 bands, and we allocate 50x50x3 = 7500 bytes for it. However, the I->data array returned by GMT_Read_Data, if we loop over the 2500 pixels and print the R/G/B values, yields this result:
All pixels after 833 are 0/0/0. So instead of 2500 red pixels, we get 2500/3 ~ 834 red pixels and the rest are all zero. Somewhere in gmt_gdalread there is a division of 3 that causes problems. I note that if I plot the red.png in psimage it comes out correctly, but this may be because postscriptlight detects this as an indexed image with 1 color so it makes a 1-bit image. Hard to trace. However, clearly the 3*size array returned by GMT_Read_Data is flawed. Need @joa-quim to have a look. Attached is red.png.
The text was updated successfully, but these errors were encountered: