CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-bytedeco--leptonica-platform

JavaCPP bindings for Leptonica image processing library with cross-platform support

Pending
Overview
Eval results
Files

core-images.mddocs/

Core Image Structures

Primary image containers supporting multiple bit depths, color models, and automatic memory management for comprehensive image processing operations.

Capabilities

PIX - Primary Image Structure

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 needed

AbstractPIX - Memory Management Base

Abstract 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();
}

FPIX - Float Pixel Image

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();

DPIX - Double Pixel Image

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();
}

Global Image Functions

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);

Memory Management Details

The JavaCPP binding provides sophisticated memory management:

  1. Automatic Cleanup: Abstract factory methods register deallocators automatically
  2. Reference Counting: Native reference counting prevents premature deallocation
  3. Manual Control: destroy() methods available for explicit cleanup
  4. Java Integration: ByteBuffer and Indexer provide safe data access
// 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();

Supported Image Types

  • 1 bpp: Binary images, with and without colormap
  • 2 bpp: 4-color images, with and without colormap
  • 4 bpp: 16-color images, with and without colormap
  • 8 bpp: 256-color or grayscale images, with and without colormap
  • 16 bpp: High-depth grayscale images (1 sample per pixel)
  • 32 bpp RGB: Color images (3 samples per pixel)
  • 32 bpp RGBA: Color images with alpha channel (4 samples per pixel)
  • 32-bit float: High-precision grayscale (FPIX)
  • 64-bit double: Maximum precision grayscale (DPIX)

Install with Tessl CLI

npx tessl i tessl/maven-org-bytedeco--leptonica-platform

docs

collections.md

connected-components.md

core-images.md

geometry.md

image-io.md

image-processing.md

index.md

morphology.md

text-recognition.md

utilities.md

tile.json