Skip to content
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

ERROR - internal GetPalette \nERROR - imgkap ((null)) return 2 #4

Open
spithost opened this issue Aug 22, 2016 · 15 comments
Open

ERROR - internal GetPalette \nERROR - imgkap ((null)) return 2 #4

spithost opened this issue Aug 22, 2016 · 15 comments

Comments

@spithost
Copy link

I generated tiles with a tileserver to 10240x10240 (16 million colordepth) pixel png's and want to convert the resulting png to .kap-files for usage in OpenCPN.
Of the 224 large png's, that cover the Netherlands, two of them make imgkap crash with the above ERROR-message.

I tried "fixing" the png's by converting them to bmp and back but the resulting files still crash so I guess it must be something in imgkap that overflowes because of the large number of colors in the png (28794 in one of the png's).

I can deliver the png for testing if you want?! You can mail me at [email protected]

@nohal
Copy link
Owner

nohal commented Aug 22, 2016

Klaus...
Yes please, post some testing file. Just from a quick look at your problem - 24bit PNG seems quite suboptimal and I would definitely preprocess the images with ImageMagick before trying to convert them into KAP.

Pavel

@spithost
Copy link
Author

Hi Pavel,

Thanks for the quick response!

I'll send it to you by Wetransfer (you'll get a message with a link to the file).
What do you suggest in preprocessing? Bring the number of colors or the filesize down?
Doesn't imgkap do that for some extent when converting the png to kap?

Klaus

@nohal
Copy link
Owner

nohal commented Aug 22, 2016

Yes, of course it does - the KAP contains a TIFF with palette so we must shrink it. But exactly for this reason it is much wiser to do it before depending on the input image. I did a small test with your file:

$ gm convert joined.png joined.jpg
$ gm convert joined.png png8:joined8.png
$ gm convert joined.png -colors 32 png8:joined8_reduced.png

-rw-r--r--@ 1 nohal  staff   7032418 Aug 22 10:22 joined.jpg
-rw-r--r--@ 1 nohal  staff  29415846 Aug 22 10:21 joined.png
-rw-r--r--@ 1 nohal  staff  18276274 Aug 22 10:24 joined8.png
-rw-r--r--@ 1 nohal  staff  11304021 Aug 22 10:25 joined8_reduced.png

Every single one of them is much smaller than your file and perfectly usable with imgkap...

If you ask me what to do, looking at the sample picture, I would definitely make the tileserver generate it with much reduced palette (Seems that 32 colors should be more than enough) to get the best possible resulting KAP.

@spithost
Copy link
Author

The conversions do make them smaller but..... will they still use the same colors for the same "object-types"? Otherwise you will get (slight) transitions in color between two aligning maps.
As you mentioned, iIt will propably be better to render with less colors to begin with, so I'll look into that. The problem with imgkap, having an overflow of some sorts I guess, remains though :-)

@nohal
Copy link
Owner

nohal commented Aug 22, 2016

You can use a fixed palette in your conversions. But note that you would have the same problem even now if it was to worry about - during the KAP creation your 24bit palette is shrunk to less than 8bit inside imgkap even though you don't directly see it, so still better to have the process under control and do it yourself, IMHO...
And yes, there is some problem with handling very big images with very big palettes, obviously.

@spithost
Copy link
Author

grin... I will bring down the number of used colors in the tileserver-stylesheet and re-render. Hopefully it will solve the problem.

@spithost
Copy link
Author

Hi Pavel,
I reduced the palette down to 8 bits with pngquant but some png's still crash imgkap allthough less then before ;-)
If I do a "normal" convert xxxx.png png:8 xxxx8.png instead of doing it with pngquant imgkap still crashes.
If I do a reduction to 32 colors (convert xxxx.png -colors 32 png8:xxxx8_reduced.png) the resulting png is "kap'able" by imgkap even if the resulting png is LARGER then with the normal reduction of the pallette to 8 bits with pngquant or convert.
I included the "troubling" file with this message. Maybe you can figure out what strange things happen with imgkap even when the pallette is reduced to 8 bits the "normal" way.

Regards,
Klaus

orig1506

@stevo01
Copy link

stevo01 commented Aug 29, 2018

Hi,
I got same error during usage of imagekap and found this reported issue with your discussion. A short look into the sources shows that imgkap is using a function calls of GetHistogram(), HistReduce() und HistGetPalette() inside function writeimgkap(). This looks like a image processing procedure which is resposible to reduce the number of used colors for the kap file to 127 colors. A closer look into the implementation shows a lot of undocumented code with recursive function calls. I think I need additional documentation or background infos, or a lot of time to understand the function and the error with is returned from function HistGetPalette() .

I added a call of library function FreeImage_ColorQuantizeEx() before the call of function writeimgkap() to reduce the number of colors to 127 with the library function. This workaround solved my conversion problem without additional call of the imagemagick "convert" application.

Best Regards

Steffen

@nohal
Copy link
Owner

nohal commented Aug 29, 2018

Steffen...
Thanks for the information. Can you please send a PR with your modifications?

@nohal
Copy link
Owner

nohal commented Aug 29, 2018

Looked at the PR, I get the point. I have checked with the above attached image and FreeImage_ColorQuantizeEx returns NULL from it. The (awful)FreeImage_ColorQuantizeEx(FreeImage_ConvertTo24Bits(tmp_bitmap), FIQ_NNQUANT, 127, 0, NULL); hack seems to resolve it. Can you please check if it would be usable also with your problematic bitmaps?

@spithost
Copy link
Author

spithost commented Aug 29, 2018 via email

@spithost
Copy link
Author

spithost commented Sep 3, 2018

Hi Pavel,

I'm no C-wonder I'm afraid....
What should I change in the imgkap.c-code to realize the correction?

I'm building a new "tile to .kap-server" at the moment and it would be nice to implement the right changes in imgkap and put them to use :-)

Regards,
Klaus

@nohal
Copy link
Owner

nohal commented Sep 3, 2018

I will push a slightly changed logic outlined by #6 in a couple of days, just being way too busy right now.

@stevo01
Copy link

stevo01 commented May 8, 2019

Hi Pavel,
could you spend some time and review my pull request ?
I think it should solve this issue ..

Best Regards

Steffen

@nohal
Copy link
Owner

nohal commented May 8, 2019

I did. Unfortunately it has other issues. I did not have time to fix those yet.

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

No branches or pull requests

3 participants