# LazyFix tool

LazyFix tool

GUI shell in the editor

Platforms: Linux, Windows, Mac OS X
Coded in: C++
State: Actual
Source code: GitHub
Official site:

The LazyFix Tool is a tool that fixes masks considered invalid or improper by PGE (such as 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.

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.

## How it works

Due to an improper (considered an invalid) mask being a copy of a source image, it's necessary to compare all pixels between the mask and the original source image.

Note: Previous to the introduction of a newer algorithm in version 2.0, pixels were filled with color black if they were equal.

The newer algorithm can be best described in the following manner.

• An empty image 'Destination' is created with the same resolution as the original image and is filled with the gray color (RGB 128,128,128).
• Each pixel of the 'ForegroundImage' is fetched and the same is used on the pixel indexes belonging to the 'Mask' and 'Destination' images. It's now applied in per-pixel operations:
• It's applied bitwise, between the R, G and B pixel values of the 'Mask' and 'Destination' and written to the destination.
• The alpha-channel value is calculated with the following formula:
newAlpha = 255 - (Destination.Red + Destination.Green + Destination.Blue) / 3);

• The alpha channel value for a pixel is equal to 'newAlpha'
• It's either applied bitwise OR between the R, G and B pixel values of 'ForegroundImage' and 'Target' and written to the target without modification of the alpha-channel value.
• The new alpha-channel value is now calculated with the formula:
newAlpha += newAlpha + ((ForegroundImage.Red +
ForegroundImage.Green +
ForegroundImage.Blue) / 3);

• If 'newAlpha' is going to have values above 255, they're now set to 255.
• All pixels belonging to the 'newAlpha' are copied.

These operations would result in a mask considered valid by PGE in comparison to an improper or broken 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


More detailed usage guide you can take by --help argument.

### 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.

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