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
Convert images to webp format #6611
Conversation
@doofus-01 and @Lordbob FYI as well. |
Wait, you convert all images? What you convert story, portraits and other large file to wepb, ok, but small like units sprite, no. You must convert what heavy files for who reduce by change of format is useful, and never convert images in wesnoth\images folder. |
Why not? |
Maybe we should change the image-loading support so that UMC doesn't need to include the extension, or for 1.18 support automatically remapping .png and .jpg to .webp. |
Is there a central place that handles image loading, or is it more dispersed? |
I don't know. |
I'm not even sure whether it could be a good idea to have wmllint handle this.
Removing the extensions from WML will certainly cause issues to wmlscope (which uses a regex to catch all the references to image files). Also, what's going to happen if someone decides to have two files with different extensions (for example, |
Of those two options, do you have a preference one way or the other? |
Probably I'd go for a separate script and put the list of all the updated paths into a module. The script itself can be quite simple: use |
Alright. Lua files can contain image paths as well, so it would definitely would need to include lua. |
I get that converting everything vastly simplifies the task, but… does this actually work? If nothing else, I thought the terrain system hard-coded the png file extension…
I believe there is a central place, yes. So adding a fallback to try multiple extensions if the first one fails is likely possible.
I think this is also easily solved – try the file exactly as given first and only try appending a file extension if that file doesn't exist. |
I don't know, but if it doesn't, it should probably be made to work. |
@Elvish-Hunter Is there a preferred way to write the edited lines back to the file? Or should it just write back the entire file if any line changes? |
I am trying to clean the terrain macros up, it would be a good time to convert them. Is it just |
The usual way is this one:
It's also possible to open a file in read and write mode at the same time ( |
Using a read-write mode I assume would be essentially just the same as the steps you listed, just that the file wouldn't need to be opened twice? I'll see how long it takes single-threadedly before looking into multi-threading though. |
@doofus-01 it's just png -> webp. There are also definitely some places in C++ where the extension is hard-coded, I just don't know if it's done in the terrain code or not. I'm not really sure why it would do that (why do the extra work of stripping off the extension?), but I could also see it being done since it was probably assumed everything would always be png files. |
The reason for hard-coding an extension is, I think, because file paths are built up from components. Besides the terrain code (possibly), other examples might be damage icons or ellipses. |
@CelticMinstrel Hmm, alright. On the other hand though, just from a quick grep, I do see a lot of the terrain graphics macros do include the @Elvish-Hunter Does wmllint have some way of dealing with renames of files used in the new(er) animation syntax? ie: |
LIke .png extension specified in both .cfg files and cpp files, i continue to belive what convert all images is a bad idea, because the addons develloper who call core images in their proper files must modify extensions in cfg files for these images. For me, converting in webp is interesting for big files (portraits, story). I alrrady said that before but with all discussion what i see here, perhaps what you could think to this. |
don't convert in wesnoth\images folder without cganging extension in src files. |
No, it doesn't; then again, the only sprite paths that have been updated and added to the
Indeed, since portraits and story images don't have to deal with the animation syntax, they're easier to handle. |
I do pretty much agree with this, by the way. I'll hold off on the conversions in terrain-graphics - not that anyone was waiting on that, I anticipate merge conflicts with #6606. |
Well I guess,if the script can be updated to handle the animation syntax, what are people's thoughts about it? Very nearly every image in the repo gets smaller by being converted to webp, so the download size reduction will be much smaller if only portraits and story images are done. |
Is it easy to make a copy with a slightly modified script that skips all images 72x72 and smaller, just to determine what the reduction would be in that case? |
I'm also fairly confident that if terrain graphics don't support webp images in practice currently, we will be getting a feature request to have that be possible at some point. |
(That would still catch a few terrain and unit graphics, but it seems like a good starting point at least.)
Yes, I'd say we definitely need to figure something out on this front. |
It looks like it'd be fairly straight forward just from a quick google search, though it would require installing the Pillow library (if that matters). |
Or you can look at wmlscope's |
Yes, if they're just 683 it's better to place them inside wmllint. Actually, they'll be even less because paths referring to mainline campaigns aren't updated by wmllint, so I'll just have to add everything from the core directory. |
Alright, looks like that'd be closer to 200 images actually. So remaining work then being:
|
In af56f0d I've noticed an error. |
af56f0d
to
108498f
Compare
Whoops, fixed. |
@Pentarctagon you must change extension in doxyfen.cpp and manual html help files for fix ubuntu/CI |
I'm getting to it, it just takes a while to manually update all the image paths. |
@Elvish-Hunter Just to double check the python bits by the way, not the entire thing. |
Also the Dune Piercer no longer exists (replaced by Rider which is already mentioned).
6b80753
to
f81941b
Compare
The commits in order:
This was done in two separate commits like this so that git would be able to recognize the image files as being the same before and after, and so still be able to track their history through the conversion.
The list of file size changes for all images changed, sorted by change in size, is here. This conversion does result in 34 files that have their size increased by some amount, however given it's only 34 out of 15,532 images, for the sake of consistency I went ahead and had those converted as well. Additionally:
The end result of this conversion is a decrease in the total size of the images Wesnoth uses from 234,037,555 bytes to 160,955,590. This is a decrease of 73,081,965 bytes, or 31.23% (almost 1/3).
Remaining work: