Skip to content

An Image to PlayStation TIM File Converter

License

Notifications You must be signed in to change notification settings

ArthCarvalho/img2tim

 
 

Repository files navigation

IMG2TIM-EX

An Image to PlayStation TIM File Converter

Converts image files supported by FreeImage into a PlayStation TIM for PlayStation homebrew development. Uses the FreeImage library. This fork add automatic conversion of 8-bit images into 4-bit if the conversor detects that only the first 16 colors are used.

Features

  • Properly preserves the original palette as is when converting 4-bit or 8-bit images.
  • Automatically detects and converts an image to 4-bit when the palette only contains only 16 colors.
  • Uses the same arguments used in bmp2tim with special additional arguments.
  • Supports alpha channel (if available) with threshold control as transparency mask.
  • Color-key and index-key transparency masking.
  • Basic RGB to color-index image conversion.
  • Automatic alpha to STP for semi-transparency effects.

Download

https://github.com/ArthCarvalho/img2tim/releases

Changelog

Version 1.0

  • Added automatic alpha to semi-transparent conversion.
  • Fixed a few bugs
  • Removed leftover debug printfs

Version 0.8

  • Forked from the original.
  • Added functions to convert 8-bit images into 4-bit automatically.

Version 0.75

  • Fixed a bug where a false error message is thrown when converting 4-bit images with -bpp 4.
  • Fixed a pixel order bug when converting images from either RGB or 4-bit depth to 4-bit color depth.

Version 0.60

  • Initial release.

Usage / Tutorials

Basic Usage - Drag and Drop

To convert, just drag and drop an image file on the executable.

Basic Usage - Command Line

img2tim [options] [-o <output filename>] <input filename>

Converting indexed textures to 4-bit with multiple palettes

It is possible to convert a palleted image (8bit, 256 colors max) into 4bit textures (16 colors) containing multiple palettes using the -collapse option. For this to work properly, a sprite editing software that can manipulate palettes is required.

This tutorial will use Aseprite, but other editors should have similar functions.

Setting up the palette

In order to convert properly into 4bit (16 colors) textures while using multiple palettes it is required that each palette be aligned into 16 entries. As in, the first 16 colors are going to become the first palette in the texture, while the second will be another and so on. Tutorial Each texture can contain up to 16 entries each.

Converting

Once the texture is exported as .png (indexed) the option -collapse must be passed to img2tim-ex as such: img2tim -collapse my_texture.png

Once the image is converted successfully, in order to use the different palettes on the PlayStation hardware it is just a matter of changing the clut offset in the y axis:

Assuming the clut was loaded to the location 0,480 in VRAM (the default value for img2tim): setClut(prim, 0, 480); Accessing the second color is a matter of adding an offset to the Y value: setClut(prim, 0, 480+offset);

Semi-transparency / Anti-aliasing

It is possible to convert textures with semi-transparency enabled on certain colors/pixels.

By default img2tim will read the alpha values and based on the threshold values will automatically apply the STP bit or black out transparent colors.

In order to set the threshold values, use the -alptrcommand: img2tim -alptr 100 180 my_texture.png Values below the first value will be blacked out, while below the second value will have the STP bit applied to them. This also applies to indexed textures. Note that the PlayStation only supports the following:

  • Completely transparent (RGB 0,0,0)
  • Semi-transparent (colors with the STP bit set to 1)
  • Solid (colors that are not completely black with the STP bit set to 0)

The default mode on the PlayStation is 50% transparency.

Black bumping

By default img2tim-ex will raise the color values of completely black pixels/entries that contains alpha values larger than 0 to the minimum color value the PlayStation will render as non-transparent. If this behavior is not desired, use the -nobumpblack to disable it.