TIFF image codec for PascalAI. Read and write TIFF files with LZW/ZIP/JPEG compression, multi-page documents, tiled access for large images, and GeoTIFF support. The standard format for scanned documents, scientific imaging, GIS, and archival photography.
uses libtiff;
var t := OpenRead('/data/scan.tif');
var info := GetInfo(t);
WriteLn('Size: ' + IntToStr(info.Width) + 'x' + IntToStr(info.Height));
WriteLn('Pages: ' + IntToStr(info.PagesCount));
WriteLn('Depth: ' + IntToStr(info.Depth) + ' bpp');
{ Read first page as RGBA }var pixels := ReadRGBA(t);
Close(t);
Write a multi-page TIFF
uses libtiff;
var t := OpenWrite('/output/report.tif');
var pages := [page1RGBA, page2RGBA, page3RGBA];
for var i := 0to2dobeginSetDimensions(t, 2480, 3508, 4, 8); { A4 at 300dpi, RGBA }SetCompression(t, tcLZW);
SetPhotometric(t, tpRGB);
SetResolution(t, 300.0, 300.0);
WriteRGBA(t, pages[i], 2480, 3508);
WriteDirectory(t); { advance to next page }end;
Close(t);
Open/Close API
Function
Signature
Description
OpenRead
OpenRead(path: string): TTIFF
Open a TIFF file for reading. Raises an error if the file does not exist or is not a valid TIFF.
OpenWrite
OpenWrite(path: string): TTIFF
Create or overwrite a TIFF file for writing.
OpenAppend
OpenAppend(path: string): TTIFF
Open an existing TIFF to append additional pages.
Close
Close(t: TTIFF)
Flush pending writes and release the file handle. Always call Close when done.
Info API
Function / Field
Type
Description
GetInfo
GetInfo(t: TTIFF): TTIFFInfo
Return image metadata for the currently selected page.
PageCount
PageCount(t: TTIFF): Integer
Return the total number of pages (directories) in the file.
SelectPage
SelectPage(t: TTIFF; page: Integer)
Make the given 0-based page index active for subsequent reads.
TTIFFInfo.Width
Integer
Image width in pixels.
TTIFFInfo.Height
Integer
Image height in pixels.
TTIFFInfo.PagesCount
Integer
Number of pages/directories in the file.
TTIFFInfo.Depth
Integer
Bits per sample (e.g. 8 or 16).
TTIFFInfo.Channels
Integer
Number of samples per pixel (1=gray, 3=RGB, 4=RGBA).
TTIFFInfo.Compression
TTIFFCompression
Compression scheme in use.
TTIFFInfo.IsTiled
Boolean
True if the image is stored in tiles rather than strips.
Read API
Function
Signature
Description
ReadRGBA
ReadRGBA(t: TTIFF): TBytes
Decode the current page to a flat RGBA byte array (width × height × 4 bytes). Handles any color type and bit depth automatically.
ReadRaw
ReadRaw(t: TTIFF): TBytes
Read raw, unprocessed image data as stored on disk.
ReadStrip
ReadStrip(t: TTIFF; stripIndex: Integer): TBytes
Read a single strip of scanlines. Use for memory-efficient sequential access of large files.
ReadTile
ReadTile(t: TTIFF; x, y: Integer): TBytes
Read a single tile at tile coordinates (x, y). Only valid for tiled images.