Handling Latin1 and UTF8 Encoding in Image Attribute Parameters

83 Views Asked by At

I am working with the stable diffusion webUI library and trying to use oiio to read the attribute parameters of images that the library generates. The encoding conventions of this library seem to be a mix of Latin1 and UTF8.

oiio code:

ImageBuf inp;
...
const ImageSpec& spec = inp.spec();

OIIO::ustring parameters;
spec.getattribute("Parameters", TypeString, &parameters);

For example, I have noticed that one of space character encoded as %C2%A0 in UTF8 is encoded as %A0 in Latin1. When I pass a Latin1 encoded string containing this space character to the JSON module for processing, it crashes.

I would like to know how I can handle this situation. Is there a way to convert the Latin1 encoded strings to UTF8 before passing them to JSON? Or is there any way I can find out what its code is?

I am relatively new to Python and appreciate any guidance on this matter. Thank you.

0

There are 0 best solutions below