JavaCPP bindings for Leptonica image processing library with cross-platform support
—
Primary image containers supporting multiple bit depths, color models, and automatic memory management for comprehensive image processing operations.
The main image container supporting 1, 2, 4, 8, 16, and 32 bits per pixel with automatic memory management.
/**
* Primary image structure supporting multiple bit depths and color models
*/
class PIX extends AbstractPIX {
// Factory methods with automatic memory management
static PIX create(int width, int height, int depth);
static PIX createNoInit(int width, int height, int depth);
static PIX createTemplate(PIX pixs);
static PIX createTemplateNoInit(PIX pixs);
static PIX createHeader(int width, int height, int depth);
// Cloning with memory management
PIX clone();
// Image dimensions and properties
int w(); // width in pixels
int h(); // height in pixels
int d(); // depth in bits per pixel (1, 2, 4, 8, 16, 32)
int spp(); // samples per pixel
int wpl(); // 32-bit words per line
int refcount(); // reference count
// Resolution information
int xres(); // horizontal resolution in pixels per inch
int yres(); // vertical resolution in pixels per inch
// Format and metadata
int informat(); // input file format (IFF_* constants)
int special(); // special processing instructions
BytePointer text(); // associated text string
// Image data access
IntPointer data(); // raw image data
PIXCMAP colormap(); // color palette (may be null)
// Java integration methods
ByteBuffer createBuffer(); // ByteBuffer view of image data
UByteIndexer createIndexer(); // Indexer for pixel access
void destroy(); // manual cleanup
}Usage Examples:
import org.bytedeco.leptonica.*;
import static org.bytedeco.leptonica.global.leptonica.*;
// Create a new 8-bit grayscale image
PIX pix = PIX.create(640, 480, 8);
// Create from template (copies dimensions)
PIX template = PIX.createTemplate(sourcePix);
// Access image properties
int width = pix.w();
int height = pix.h();
int depth = pix.d();
System.out.println("Image: " + width + "x" + height + "x" + depth + " bpp");
// Get raw data access for custom processing
IntPointer data = pix.data();
ByteBuffer buffer = pix.createBuffer();
// Memory is automatically managed - no manual cleanup neededAbstract base class providing automatic memory management and Java integration for PIX objects.
/**
* Abstract base providing automatic memory management for PIX objects
*/
abstract class AbstractPIX extends Pointer implements Indexable {
// Factory methods register automatic cleanup
static PIX create(int width, int height, int depth);
static PIX createNoInit(int width, int height, int depth);
static PIX createTemplate(PIX pixs);
static PIX createTemplateNoInit(PIX pixs);
static PIX createHeader(int width, int height, int depth);
static PIX create(int width, int height, int depth, Pointer data);
// Clone with automatic memory management
PIX clone();
// Java integration
ByteBuffer createBuffer();
ByteBuffer createBuffer(int index);
UByteIndexer createIndexer();
UByteIndexer createIndexer(boolean direct);
// Manual cleanup (optional)
void destroy();
}32-bit floating point image container for high-precision processing operations.
/**
* 32-bit floating point image container
*/
class FPIX extends AbstractFPIX {
// Similar structure to PIX but for float data
int w(); // width in pixels
int h(); // height in pixels
int wpl(); // words per line
int refcount(); // reference count
int xres(); // horizontal resolution
int yres(); // vertical resolution
FloatPointer data(); // float image data
}
/**
* Abstract base for FPIX with automatic memory management
*/
abstract class AbstractFPIX extends Pointer {
// Factory methods with cleanup registration
static FPIX create(int width, int height);
static FPIX createTemplate(FPIX fpixs);
FPIX clone();
void destroy();
}Usage Examples:
// Create float image for high-precision processing
FPIX fpix = AbstractFPIX.create(640, 480);
// Convert from PIX to FPIX for floating point operations
FPIX floatImage = pixConvertToFPix(sourcePix, 1);
// Access float data
FloatPointer floatData = fpix.data();64-bit double precision image container for maximum precision in mathematical operations.
/**
* 64-bit double precision image container
*/
class DPIX extends AbstractDPIX {
int w(); // width in pixels
int h(); // height in pixels
int wpl(); // words per line
int refcount(); // reference count
int xres(); // horizontal resolution
int yres(); // vertical resolution
DoublePointer data(); // double image data
}
/**
* Abstract base for DPIX with automatic memory management
*/
abstract class AbstractDPIX extends Pointer {
static DPIX create(int width, int height);
static DPIX createTemplate(DPIX dpixs);
DPIX clone();
void destroy();
}Core functions for creating, manipulating, and analyzing images across all types.
// PIX creation and destruction (use Abstract factory methods instead)
PIX pixCreate(int width, int height, int depth);
PIX pixCreateNoInit(int width, int height, int depth);
PIX pixCreateTemplate(PIX pixs);
void pixDestroy(PIX pix);
// Property access
int pixGetWidth(PIX pix);
int pixGetHeight(PIX pix);
int pixGetDepth(PIX pix);
int pixGetSpp(PIX pix);
int pixGetWpl(PIX pix);
int pixGetRefcount(PIX pix);
int pixGetXRes(PIX pix);
int pixGetYRes(PIX pix);
IntPointer pixGetData(PIX pix);
PIXCMAP pixGetColormap(PIX pix);
BytePointer pixGetText(PIX pix);
// Property modification
int pixSetSpp(PIX pix, int spp);
int pixSetText(PIX pix, String textstring);
int pixSetResolution(PIX pix, int xres, int yres);
int pixSetColormap(PIX pix, PIXCMAP colormap);
// Image copying and cloning
PIX pixCopy(PIX pixd, PIX pixs);
PIX pixClone(PIX pixs);
PIX pixClipRectangle(PIX pixs, BOX box, IntPointer pboxc);
// FPIX functions
FPIX fpixCreate(int width, int height);
void fpixDestroy(FPIX fpix);
int fpixGetWidth(FPIX fpix);
int fpixGetHeight(FPIX fpix);
FloatPointer fpixGetData(FPIX fpix);
// DPIX functions
DPIX dpixCreate(int width, int height);
void dpixDestroy(DPIX dpix);
DoublePointer dpixGetData(DPIX dpix);
// Type conversions
FPIX pixConvertToFPix(PIX pixs, int ncomps);
DPIX pixConvertToDPix(PIX pixs, int ncomps);
PIX fpixConvertToPix(FPIX fpix, int outdepth, int negvals, int errorflag);
PIX dpixConvertToPix(DPIX dpix, int outdepth, int negvals, int errorflag);Usage Examples:
// Get image dimensions using global functions
int width = pixGetWidth(pix);
int height = pixGetHeight(pix);
int depth = pixGetDepth(pix);
// Access raw data
IntPointer data = pixGetData(pix);
// Set image text metadata
pixSetText(pix, "Processed image");
// Set resolution
pixSetResolution(pix, 300, 300); // 300 DPI
// Clone image (increases reference count)
PIX cloned = pixClone(pix);
// Extract rectangular region
BOX region = boxCreate(100, 100, 200, 150);
PIX clipped = pixClipRectangle(pix, region, null);The JavaCPP binding provides sophisticated memory management:
destroy() methods available for explicit cleanup// Recommended: Use Abstract factory methods
PIX pix = PIX.create(640, 480, 8); // Automatic cleanup registered
// Access data safely through Java interfaces
ByteBuffer buffer = pix.createBuffer();
UByteIndexer indexer = pix.createIndexer();
// Memory automatically freed when Java object is garbage collected
// Manual cleanup optional: pix.destroy();Install with Tessl CLI
npx tessl i tessl/maven-org-bytedeco--leptonica-platform