5t4cktr4c3
5t4cktr4c3

Reputation: 161

Parsing UIColor from NSKeyedArchiver: negative values

I'm trying to read a database, created by an iOS/macOS app, in Python. In one table is a column with binary data, which have been apparently archived with NSKeyedArchiver. My rows look like this:

{'$version': 100000, '$archiver': 'NSKeyedArchiver', '$top': {'root': UID(1)}, '$objects': ['$null', {'UIColorComponentCount': 4, 'UIGreen': 0.866697371006012, 'UIBlue': -0.2701350450515747, 'UIAlpha': 1.0, 'NSRGB': b'0.975 0.867 -0.27', '$class': UID(2), 'UIRed': 0.9749125838279724, 'NSColorSpace': 2}, {'$classname': 'UIColor', '$classes': ['UIColor', 'NSObject'], '$classhints': ['NSColor']}]}
{'$version': 100000, '$archiver': 'NSKeyedArchiver', '$top': {'root': UID(1)}, '$objects': ['$null', {'NSComponents': b'0.8875159454 0 0.06146364689 1', 'NSRGB': b'0.8483365774 0 0.05997940153\x00', 'NSColorSpace': 1, 'NSCustomColorSpace': UID(2), '$class': UID(5)}, {'NSID': 7, 'NSICC': UID(3), '$class': UID(4)}, '(replaced raw bytes)', {'$classname': 'NSColorSpace', '$classes': ['NSColorSpace', 'NSObject']}, {'$classname': 'NSColor', '$classes': ['NSColor', 'NSObject']}]}
{'$version': 100000, '$archiver': 'NSKeyedArchiver', '$top': {'root': UID(1)}, '$objects': ['$null', {'UIColorComponentCount': 4, 'UIGreen': 0.6479833126068115, 'UIBlue': -0.15340086817741394, 'UIAlpha': 1.0, 'NSRGB': b'0.163 0.648 -0.153', '$class': UID(2), 'UIRed': 0.16299211978912354, 'NSColorSpace': 2}, {'$classname': 'UIColor', '$classes': ['UIColor', 'NSObject'], '$classhints': ['NSColor']}]}
{'$version': 100000, '$archiver': 'NSKeyedArchiver', '$top': {'root': UID(1)}, '$objects': ['$null', {'NSRGB': b'0 0 0\x00', 'NSColorSpace': 2, '$class': UID(2)}, {'$classname': 'NSColor', '$classes': ['NSColor', 'NSObject']}]}

Unarchiving with bpylist allowed my to define custom classes for UIColor and NSRGB. Working with the 4 types of possible structures (see above) seems easy.

However, what me irritates is that there are negative RGB values in some rows. Apparently, this only happens with UIColor classes, possibly because the app uses UIColorPicker?

{'UIColorComponentCount': 4, 'UIGreen': -0.09628119319677353, 'UIBlue': -0.023068491369485855, 'UIAlpha': 1.0, 'NSRGB': b'0.746 -0.0963 -0.0231', '$class': UID(2), 'UIRed': 0.7462500929832458, 'NSColorSpace': 2}
{'UIColorComponentCount': 4, 'UIGreen': 0.6940679550170898, 'UIBlue': 0.7472937703132629, 'UIAlpha': 1.0, 'NSRGB': b'-0.252 0.694 0.747', '$class': UID(2), 'UIRed': -0.25186771154403687, 'NSColorSpace': 2}
{'UIColorComponentCount': 4, 'UIGreen': -0.13570761680603027, 'UIBlue': -0.06656593829393387, 'UIAlpha': 1.0, 'NSRGB': b'0.972 -0.136 -0.0666', '$class': UID(2), 'UIRed': 0.9720380902290344, 'NSColorSpace': 2}

How can RGB values be negative? Is something wrong with the parsing or am I missing something else here?

Upvotes: 0

Views: 33

Answers (0)

Related Questions