Custom formats are particularly useful if reading medical images from an X-ray scanner, which vary from one manufacturer to the other. Images can be compressed by a number of available methods.
Of course, with this much flexibility it is impossible to test every possible combination of parameters on every destination platform, so it is advisable to make a test image before proceeding, to make sure the file is readable on the target system.
Note: It is necessary have write permission in the directory where the file formats is stored in order for this to work. The location of this file can be changed by changing the format_list line in tnimage.ini (default location is $HOME/.tnimage/formats ).
Defining a custom format is a very flexible and convenient way of storing images, since someone else wishing to view the image only needs the corresponding image descriptor file.
When reading a custom image file, tnimage first looks for the file descriptor in the directory
$HOME/.tnimage/formats .
This file descriptor is an ordinary text file, which can be created manually or by using the ``Create file format'' menu option. The filename of the file descriptor must be the same as the ``Identifier'' described below.
Here is the procedure for creating a new custom format:
If mode=GIF
Assumes bits are packed in the following format (example for n=9 bits pixel, where a,b,c... are pixels) :
7 6 5 4 3 2 1 0
----------------------------
Byte 1 a7 a6 a5 a4 a3 a2 a1 a0
Byte 2 b6 b5 b4 b3 b2 b1 b0 a8
Byte 3 c5 c4 c3 c2 c1 c0 b8 b7
Byte 4 d4 c3 d2 d1 d0 c8 c7 c6
...
If mode=TIF Assumes bits are packed in the following format (example for n=9) :
7 6 5 4 3 2 1 0
----------------------------
Byte 1 a8 a7 a6 a5 a4 a3 a2 a1
Byte 2 a0 b8 b7 b6 b5 b4 b3 b2
Byte 3 b1 b0 c8 c7 c6 c5 c4 c3
Byte 4 c2 c1 c0 d8 d7 d6 d5 d4
In most cases, the bit packing should be left at ``none''.
Note: Compressed formats can only be identified by extension.
Y size (2) 8
means the image contains two bytes starting at a position 8 bytes from the start of the file that indicate the image height (Y size) in pixels. If an offset is set to 65535, it will be ignored.
It is very important that none of the offsets overlap with each other, and that no offsets are included in the file descriptor that do not actually exist in the image file. For example, if an offset for a palette (color LUT) is specified at offset 76, no other parameters can have offsets between 76 and 844, because the palette uses 768 bytes. tnimage does not check for this.
The parameters in the table below can be recognized from the image file. Note that, when creating the format descriptor, it is necessary to enter the position in the file where the parameter resides, not the actual value. At run time, tnimage will fill in the value automatically. The ``number of bytes'' in the table below refers to the maximum size in bytes that the parameter can attain. Thus, for X size, with only 2 bytes, the maximum width of an image is only 65535. This was done to provide the ability to read certain other (older) image formats as custom format images.
| Parameter | Bytes | Meaning |
| Identifier | 64 | Format identifier or file extension |
| X size | 2 | Width of image in pixels |
| Y size | 2 | Height of image in pixels |
| Bits/pixel | 2 | Bits per pixel in image |
| Color type | 2 | 0=Grayscale, 1=Indexed color, 2=true color |
| Compression | 2 | 0=no compression, 1=compressed |
| Red bpp | 2 | Bits/pixel for red |
| Green bpp | 2 | Bits/pixel for green |
| Blue bpp | 2 | Bits/pixel for blue |
| Black bpp | 2 | Bits/pixel for black |
| X position | 2 | Position of left edge of image in pixels |
| Y position | 4 | Position of top of image in pixels |
| Frames | 4 | No. of frames in image |
| Frames/sec | 2 | Speed of ``movie'' for multi-frame images |
| Chromakey | 2 | -1=inverse, 0=none, 1=normal chromakey |
| Chr.gray min | 4 | Min. pixel value for chromakey if image is grayscale |
| Chr.gray max | 4 | Max. pixel value for chromakey if image is grayscale |
| Chr. RGB min | 4 | Min. RGB value for chromakey if image is color |
| Chr. RGB max | 4 | Max. RGB value for chromakey if image is color |
| Palette | 768 | Colormap for image, if image is Indexed color |
| Image offset | 2 | Starting offset for image data. |
When creating a new image format, it is advantageous to separate the parameters by at least 4 bytes for future compatibility. Also, there is no harm in specifying an offset for a parameter (such as frames/sec) even if it will never be used.
The image data are stored in pixel order, starting at the upper left of the image, as RGBRGB... for color images or IIIIIIII.. for indexed or grayscale images. Successive frames are stored without any intervening spaces, except that, if bit packing is used, unused bits at the end of a line or frame are set to 0 and each line and frame starts on a new byte.
Unless the images are always the same size, the image offset should be the highest offset. If the format descriptor file is edited manually, the entries do not need to be in any particular order.
NOTE: If a nonzero value is specified for ``Bytes to skip'', this value will override any value in the file at position image offset for the start of image data.
No. of colors =
.
Thus, if there are only 2 colors (black and white), there is 1 bit per pixel.
Warning: Incorrect settings in the format file can crash tnimage.