Skip to content

Allow image source from str or non-PIL file handle - #64

Merged
K0lb3 merged 1 commit into
K0lb3:masterfrom
UserUnknownFactor:master
Aug 3, 2021
Merged

K0lb3 merged 1 commit into
K0lb3:masterfrom
UserUnknownFactor:master

Conversation

@UserUnknownFactor

Copy link
Copy Markdown
Contributor

This allows assigning images by their path or opened file handle.
Also adds possibility to change the cab name from outside.

@UserUnknownFactor
UserUnknownFactor force-pushed the master branch 2 times, most recently from 36e2acd to 2de113c Compare July 21, 2021 11:15
@K0lb3

K0lb3 commented Jul 24, 2021

Copy link
Copy Markdown
Owner

Hi, great to see you again.
Looks good overall,
but we have to talk a bit about the image assignment.

The main idea behind forcing the user to pass PIL.Image was, that later on texture compression could be added to UnityPy, which would make handling other types a bit troublesome.
My idea was to add the compression to the Texture2DConverter,
so an Image opener would have to be kept within Texture2D.image instead of within the converter.
That's also the reason the converter returns bytes and not an image,
if compression would be used, it would happen within the converter, so it would have to return bytes and couldn't return a PIL image.

Regarding the importance of compression, it's required for DXT1,5 and some ECT textures that are used in shaders. I already created a lib for that and haven't come around to add it yet.

So overall, the only change that should be done regarding the texture2d for now is adding the PIL.open to the image setter.

The cab handling you added is fine and can be accepted as it is.

@UserUnknownFactor
UserUnknownFactor force-pushed the master branch 2 times, most recently from a3f4b36 to 4b3adf1 Compare July 25, 2021 16:02
(while minding possible texture compression)

Allow external cab name setting through File
@K0lb3

K0lb3 commented Aug 3, 2021

Copy link
Copy Markdown
Owner

Looks good now.

I just noticed that I forgot to mention something else last time,
and that is the value of m_CompleteImageSize.
It corresponds to the size of the decompressed texture, so using the length of the data isn't really correct.
In practice the image size should be calculated via the original texture format multiplied by the pixel count.

@K0lb3
K0lb3 merged commit 5b0a688 into K0lb3:master Aug 3, 2021
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

Successfully merging this pull request may close these issues.

2 participants