Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Custom icon support #1129

Closed
wants to merge 6 commits into from
Closed

Custom icon support #1129

wants to merge 6 commits into from

Conversation

dg0yt
Copy link
Member

@dg0yt dg0yt commented Aug 23, 2018

No description provided.

@dg0yt dg0yt requested a review from lpechacek August 23, 2018 07:14
@dg0yt
Copy link
Member Author

dg0yt commented Aug 23, 2018

In the first place, this is an attempt to handle symbol icons from OCD files. However, I still don't know how to deal with OCD 8 compressed icons.

I could imagine that we simply add a GUI feature for custom icon import/export (PNG) to solve or at least mitigate the popular request for editable icons (#866). In OMAP files these icons could be embedded Base64-encoded.

@dg0yt
Copy link
Member Author

dg0yt commented Aug 23, 2018

OCD icons (22 pixels, 256 colors, scaled up) versus generated icons (optimal quality):
ocd-versus-generated

@lpechacek
Copy link
Member

First thoughts when looking at the patch set. Symbol: Add custom icon functions adds custom icon which replaces the generated icon. I have given a thought to the topic recently and came up with the idea of "overlay" icon, leveraging the image alpha channel. That way either the whole generated icon could be replaced, or just a part of it (my understanding of issue #866). However, any user edited bitmap image will fail to match the dynamically generated symbol icons. Icon overlaying/composition still may make sense. Thinking on...

@dg0yt
Copy link
Member Author

dg0yt commented Aug 24, 2018

I would rather not mix icons. Needing to understand alpha channel can be a little too much. Different icon resolutions may be source for surprises.

Instead, the mentioned export function could easily export the default (generated) icon.

I would probably add this to another settings tab.

Something like:

______| Icon |_______________________

Default icon:  [ 54 px +/- ]
                    ###
                    ###

Custom icon:     22 px                 (or: "not set")
                     **
                     **
                  22 x 22 px

Actions:        [Import...] [Export...] [Reset]
__________________________________________

Default buttons...   [OK]

And then, we are not far away from other customization options (rotation, path, even the existing text symbol icon text).

@dg0yt
Copy link
Member Author

dg0yt commented Aug 24, 2018

Well, you could add a "overlay" checkbox 😄

@dg0yt
Copy link
Member Author

dg0yt commented Aug 24, 2018

icon-settings

@lpechacek
Copy link
Member

The combination of custom icon for OCD and OMAP export is troublesome. ...bla bla bla deleted... Anyway, let's go with 22px true color icons and forget about overlaying. Although this is not "perfect", it will be understandable for end users.

BTW, I'll surely be one of the early adopters. I frequently have difficulty distinguishing between contour slope line vs form line slope line and shallow body of water border line vs minor water channel.

@dg0yt dg0yt mentioned this pull request Aug 25, 2018
@dg0yt
Copy link
Member Author

dg0yt commented Aug 25, 2018

Done.
(Should be a good starting point for adding the overlay behaviour.)

@dg0yt dg0yt changed the title Handle OCD icons as custom icons Custom icon support Aug 25, 2018
@dg0yt dg0yt added this to the v0.9.0 milestone Aug 25, 2018
Copy link
Member

@lpechacek lpechacek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the patch series looks good to me. There are a few suggestions to consider in review comments.

@dg0yt dg0yt self-assigned this Aug 30, 2018
@dg0yt dg0yt mentioned this pull request Sep 15, 2018
@dg0yt dg0yt changed the base branch from dev to ocd-icon September 15, 2018 08:34
@lpechacek
Copy link
Member

However, I still don't know how to deal with OCD 8 compressed icons.

I played a bit with the compressed icons and came to the conclusion that they are perhaps (TIFF style) LZW compressed. A half black, half white icon which has 242 zeros and 242 0x7c's encodes as follows:

Half black square, binary notation

000000000 << 0x00 for black
100000010 << 0x102, first dictionary entry
100000011
100000100
100000101
100000110
100000111
100001000
100001001
100001010
100001011
100001100
100001101
100001110
100001111
100010000
100010001
100010010
100010011
100010100
100010101
100001011
001111100 <<< 0x7c for white
100011000
100011001
100011010
100011011
100011100
100011101
100011110
100011111
100100000
100100001
100100010
100100011
100100100
100100101
100100110
100100111
100101000
100101001
100101010
100101011
100100001
100000001 << (likely) end of data marker
111111000 << trailing bits

Unix compress program gives very similar output with the exception of the first and last code. The first dictionary code from compress entry is 0x101, as opposed to 0x102 here, and there is no termination code. Searching around, I found out that TIFF uses 0x101 as End Of Input marker and its first dictionary code is 0x102, which is in line with what I see in the .ocd.

Will you look into implementation or shall I start coding (which may take long time)?

---- code scrap for later reuse
$ perl -e 'print "\0" x 242; print "|" x 242' | compress | xxd -g1
$ cat /dev/shm/binout.py 
#!/usr/bin/python3

import sys

for line in sys.stdin:
    print(line.strip(), format(int(line, 16), '08b'))

@dg0yt
Copy link
Member Author

dg0yt commented Sep 26, 2018

I played a bit with the compressed icons and came to the conclusion that they are perhaps (TIFF style) LZW compressed.

GIF/TIFF/LZW were my suspects too, but I always stopped at some point. Now I finally understood a) how to decode a LZW code stream when the original data was like aSaSa (such as a plain white line), and b) how GIF turns the code stream in a bit stream.

Will you look into implementation or shall I start coding (which may take long time)?

I look into implementation again now. I will drop a note if I should put this aside again.

@lpechacek
Copy link
Member

The initial 16 bytes have some meaning too. They are often 0xFF's but in some cases there are different values. Two examples from OCAD 8 symbol set:

In symbol symbol 527.0 'Settlement': Unsupported compressed icon
0000   2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b ff b2 b2 b2 b2 5a 
0010   04 0e 24 58 d0 e0 41 84 09 15 2e 64 d8 d0 e1 43 88 
0020   11 25 4e a4 58 d1 e2 45 8c 19 35 6e e4 d8 d1 e3 c4 
0030   80 2b 2b 2b 2b 2b 2b 2b ff b2 b2 b2 b2 b2 b2 b2 b2 
0040   b2 b2 b2 11 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b ff b2 
0050   b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 11 2b 2b 2b 2b 2b 2b 
0060   2b 2b 2b 2b 2b ff b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 
0070   11 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b ff b2 b2 b2 b2 
0080   b2 b2 b2 b2 b2 b2 b2 11 2b 2b 2b 2b 2b 2b 2b 2b 2b 
0090   2b 2b ff b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 11 2b 2b 
00a0   2b 2b 2b 2b 2b 2b 2b 2b 2b ff b2 b2 b2 b2 b2 b2 b2 
00b0   b2 b2 b2 b2 11 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b ff 
00c0   b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 11 2b 2b 2b 2b 2b 
00d0   2b 2b 2b 2b 2b 2b ff b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 
00e0   b2 11 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b ff b2 b2 b2 
00f0   b2 b2 b2 b2 b2 b2 b2 b2 11 

In symbol symbol 401.0 'Open land': Unsupported compressed icon
0000   b9 bb b9 bb b9 bb b9 bb b9 bb b9 bb bb bb bb bb 73 
0010   04 0e 24 58 d0 e0 41 84 09 15 2e 64 d8 d0 e1 43 88 
0020   11 25 4e a4 58 d1 e2 45 8c 19 35 6e e4 d8 d1 e3 c4 
0030   80 b9 bb b9 bb b9 bb b9 bb bb bb bb bb bb bb bb bb 
0040   bb bb bb bb bb b9 bb b9 bb b9 bb b9 bb b9 bb bb bb 
0050   bb bb bb bb bb bb bb bb bb bb b9 b9 bb b9 bb b9 bb 
0060   b9 bb b9 bb b9 bb bb bb bb bb bb bb bb bb bb bb bb 
0070   bb bb b9 bb b9 bb b9 bb b9 bb b9 bb bb bb bb bb bb 
0080   bb bb bb bb bb bb bb b9 b9 bb b9 bb b9 bb b9 bb b9 
0090   bb b9 bb bb bb bb bb bb bb bb bb bb bb bb bb bb b9 
00a0   bb b9 bb b9 bb b9 bb b9 bb bb bb bb bb bb bb bb bb 
00b0   bb bb bb bb b9 b9 bb b9 bb b9 bb b9 bb b9 bb b9 bb 
00c0   bb bb bb bb bb bb bb bb bb bb bb bb bb b9 bb b9 bb 
00d0   b9 bb b9 bb b9 bb bb bb bb bb bb bb bb bb bb bb bb 
00e0   bb b9 b9 bb b9 bb b9 bb b9 bb b9 bb b9 bb bb bb bb 
00f0   bb bb bb bb bb bb bb bb bb 

There are 7 icons of this kind in the whole set.

@dg0yt
Copy link
Member Author

dg0yt commented Sep 27, 2018

The initial 16 bytes have some meaning too.

To me, the unused data looks to me like left-over uncompressed garbage. But I have almost finished decompression, so you can test soon.

@lpechacek
Copy link
Member

To me, the unused data looks to me like left-over uncompressed garbage.

Indeed. All icons, including the above examples, load fine with changes from ocd-compressed-icons.

dg0yt added 4 commits October 1, 2018 06:04
Prior to this change, AreaSymbolSettings assumed that there was
just a single ("General") tab preceding the list of tabs managed
by AreaSymbolSettings. However, we need to have a variable number
of general tabs, e.g. for adding a symbol icon tab.
@dg0yt
Copy link
Member Author

dg0yt commented Oct 1, 2018

Now all comments should be resolved. This will be merged with the compression changes, once they are complete.

@dg0yt
Copy link
Member Author

dg0yt commented Oct 8, 2018

Merged.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants