LazyFix tool

From PGE Wiki
Jump to: navigation, search


LazyFix tool

LazyFixIcon.png

Lazyfix.png
GUI shell in the editor

Platforms: Linux, Windows, Mac OS X
Latest version: 3.0.0
Coded in: C++
License: GPLv3
State: Actual
Download: LazyFixTool
Source code: GitHub
Official site:


The LazyFix Tool is a tool that fixes masks considered invalid or improper by PGE (such as for example when the mask is the same as the front image). Improper masks cause issues due to the algorithm used in PGE not being able to properly render these types of masks.

Alpha-channel masks

A mask is an Alpha-channel coding image. Each pixel of the masks defines the level of opacity to be considered for the equivalent pixel on a source image:

Each pixel in a mask defines the value of opacity for the equivalent pixel in a source image.

Alpha-channel mask

How it works

Due to an invalid/improper mask being a copy of source image, we must compare all pixels between an image and its mask.

Note that before the 2.0 version's newer algorithm was implemented, pixels were filled with the color black if they were equal.

The new algorithm namely is:

  • Create an empty image 'Destination' with the same size as the original image and fill with the gray RGB (128,128,128) color.
  • Fetch each pixel of the 'ForegroundImage' and use the same pixel indexes on the 'Mask' and 'Destination' images and then apply per-pixel operations:
    • Apply bitwise AND between R, G and B pixel values of 'Mask' and 'Destination' and write into the destination.
    • Calculate the alpha-channel value with a formula:
      newAlpha = 255 - (Destination.Red + Destination.Green + Destination.Blue) / 3);
      
    • Set the alpha channel value for this pixel equal to 'newAlpha'
    • Apply bitwise OR between R, G and B pixel values of 'ForegroundImage' and 'Target' and write them into the target without modification of the alpha-channel value.
    • Calculate the new alpha-channel value with formula:
      newAlpha += newAlpha + ((ForegroundImage.Red + 
                               ForegroundImage.Green +
                               ForegroundImage.Blue) / 3);
      
    • If 'newAlpha' is going to have a value above 255 - set it to 255.
  • Copy all pixels of 'newAlpha' value.

These operations would create a mask considered valid by PGE in comparison to an improper or broken specified source mask.

How to use

The LazyFix tool is a console tool.

You will need to first of all open a terminal or command line and change directories to wherever its located on your machine.

This utility also fixes SMBX64 graphics (GIF with mask images) in a selected folder and (optionally) all graphics inside a selected folder's subfolders.

An improper source mask must be placed in the same directory alongside its source image, as the fixing process is based on calculating broken pixels by comparing between the pixels of both images.

For fixing graphics which are in one folder:
LazyFixTool C:\SMBX\worlds\episode1\level3
For fixing graphics of an entire episode, the "-d" switch may be used:
LazyFixTool -d C:\SMBX\worlds\episode1

Note: After its done running, the source masks that existed before the tool was run will be placed in a directory called "_backup". This way, if you encounter errors after running it, you can restore the original source mask images from the backup directory.


You can skip the creation of backup directories with the usage of the "-n" switch. However, you now won't be able to fix your old images, and will need to draw a mask manually:
LazyFixTool -n C:\SMBX\worlds\episode1\level5

Usage of the LazyFix tool for single images

It's possible to also drag image files into the LazyFix application such as you would into a folder in most desktop environments. This will automatically cause the tool to begin fixing those images.

Example for the Microsoft Windows
LazyFixTool D:\path\to\some\image.gif
Example for the Linux and Mac OS X
LazyFixTool /home/myhome/path/to/some/image.gif

The LazyFix tool with a GUI

The PGE Editor includes a GUI shell for setting properties related to the LazyFix tool.

In order to try this, navigate using the menu item: "Tools -> External tools -> Fix Lazily-made graphics (LazyFix tool)"

You can also configure properties for fixing a batch of images.

Lazyfix.png

Once "Start" is pressed, the "Development Console" window will now be launched and the tool's fixing process should now be visible.

See also

Links