/** * react-native-pixel-data * * High-performance React Native SDK for extracting raw pixel data * from images and preparing it for machine learning inference. * * @remarks * This library provides native implementations in Swift (iOS) and Kotlin (Android) * for optimal performance when preprocessing images for ML models. * * Key features: * - Multiple image sources (URL, file, base64, asset, photo library) * - Flexible color formats (RGB, RGBA, BGR, BGRA, grayscale) * - ML-ready normalization presets (ImageNet, TensorFlow, custom) * - Smart resize strategies (cover, contain, stretch) * - Data layouts for all major ML frameworks (HWC, CHW, NHWC, NCHW) * - Region of Interest (ROI) extraction * - Efficient batch processing * * @example * ```typescript * import { getPixelData } from 'react-native-pixel-data'; * * // Basic usage * const result = await getPixelData({ * source: { type: 'url', value: 'https://example.com/image.jpg' }, * resize: { width: 224, height: 224 }, * }); * * // Use with PyTorch model * const pytorchResult = await getPixelData({ * source: { type: 'url', value: 'https://example.com/image.jpg' }, * resize: { width: 224, height: 224, strategy: 'cover' }, * normalization: { preset: 'imagenet' }, * dataLayout: 'CHW', * }); * ``` * * @packageDocumentation * @module react-native-pixel-data */ import type { GetPixelDataOptions, PixelDataResult, BatchOptions, BatchResult } from './types'; export { type ImageSource, type UrlImageSource, type FileImageSource, type Base64ImageSource, type AssetImageSource, type PhotoLibraryImageSource, type ColorFormat, getChannelCount, type Normalization, type NormalizationPreset, type ResizeOptions, type ResizeStrategy, type DataLayout, type Roi, type OutputFormat, type GetPixelDataOptions, type PixelDataResult, type BatchOptions, type BatchResult, type PixelDataError, isPixelDataError, PixelDataException, } from './types'; /** * Extract pixel data from an image source. * * This is the main function for extracting normalized pixel data from images. * It supports various image sources, color formats, normalization presets, * and data layouts to match the requirements of different ML frameworks. * * @param options - Configuration for pixel data extraction * @returns Promise resolving to the extracted pixel data and metadata * @throws {PixelDataException} If image loading or processing fails * * @remarks * Processing pipeline: * 1. Load image from source * 2. Apply ROI cropping (if specified) * 3. Resize to target dimensions (if specified) * 4. Convert to target color format * 5. Apply normalization * 6. Rearrange to target data layout * * @example * Basic usage - get RGB pixel data from a URL: * ```typescript * import { getPixelData } from 'react-native-pixel-data'; * * const result = await getPixelData({ * source: { type: 'url', value: 'https://example.com/image.jpg' }, * resize: { width: 224, height: 224 }, * }); * * console.log(`Processed ${result.width}x${result.height} image`); * console.log(`Data length: ${result.data.length}`); * ``` * * @example * PyTorch model preprocessing: * ```typescript * const result = await getPixelData({ * source: { type: 'url', value: 'https://example.com/image.jpg' }, * colorFormat: 'RGB', * resize: { width: 224, height: 224, strategy: 'cover' }, * normalization: { preset: 'imagenet' }, * dataLayout: 'CHW', // PyTorch expects CHW format * }); * * // result.data is now ready for PyTorch inference * // Shape: [3, 224, 224] (channels, height, width) * ``` * * @example * TensorFlow model preprocessing: * ```typescript * const result = await getPixelData({ * source: { type: 'url', value: 'https://example.com/image.jpg' }, * colorFormat: 'RGB', * resize: { width: 224, height: 224, strategy: 'cover' }, * normalization: { preset: 'tensorflow' }, * dataLayout: 'NHWC', // TensorFlow expects NHWC format * }); * * // result.data is now ready for TensorFlow inference * // Shape: [1, 224, 224, 3] (batch, height, width, channels) * ``` * * @example * Extract region of interest: * ```typescript * const result = await getPixelData({ * source: { type: 'file', value: '/path/to/large-image.jpg' }, * roi: { x: 100, y: 100, width: 200, height: 200 }, * resize: { width: 224, height: 224 }, * }); * ``` * * @example * Error handling: * ```typescript * import { getPixelData, PixelDataException } from 'react-native-pixel-data'; * * try { * const result = await getPixelData(options); * } catch (error) { * if (error instanceof PixelDataException) { * console.error(`[${error.code}] ${error.message}`); * } * } * ``` */ export declare function getPixelData(options: GetPixelDataOptions): Promise; /** * Process multiple images in batch with concurrency control. * * This function efficiently processes multiple images in parallel, * with configurable concurrency to balance speed and memory usage. * * @param optionsArray - Array of options for each image to process * @param batchOptions - Batch processing configuration (optional) * @returns Promise resolving to batch results * @throws {PixelDataException} If validation fails for any image * * @remarks * - Results maintain the same order as the input array * - Failed images return PixelDataError instead of throwing * - Use `isPixelDataError()` to check for individual failures * - Higher concurrency uses more memory but processes faster * * @example * Basic batch processing: * ```typescript * import { batchGetPixelData, isPixelDataError } from 'react-native-pixel-data'; * * const images = [ * 'https://example.com/image1.jpg', * 'https://example.com/image2.jpg', * 'https://example.com/image3.jpg', * ]; * * const result = await batchGetPixelData( * images.map(url => ({ * source: { type: 'url', value: url }, * resize: { width: 224, height: 224 }, * normalization: { preset: 'imagenet' }, * })), * { concurrency: 4 } * ); * * console.log(`Processed ${result.results.length} images in ${result.totalTimeMs}ms`); * ``` * * @example * Handle individual failures: * ```typescript * const result = await batchGetPixelData(optionsArray); * * result.results.forEach((item, index) => { * if (isPixelDataError(item)) { * console.error(`Image ${index} failed: [${item.code}] ${item.message}`); * } else { * console.log(`Image ${index}: ${item.width}x${item.height}`); * // Use item.data for ML inference * } * }); * * // Count successes and failures * const successes = result.results.filter(r => !isPixelDataError(r)); * const failures = result.results.filter(isPixelDataError); * console.log(`Success: ${successes.length}, Failed: ${failures.length}`); * ``` * * @example * Prepare batch for ML model: * ```typescript * const result = await batchGetPixelData( * imageUrls.map(url => ({ * source: { type: 'url', value: url }, * resize: { width: 224, height: 224 }, * normalization: { preset: 'imagenet' }, * dataLayout: 'CHW', * })), * { concurrency: 2 } // Lower concurrency for memory-constrained devices * ); * * // Extract successful results only * const pixelDataBatch = result.results * .filter((r): r is PixelDataResult => !isPixelDataError(r)) * .map(r => r.data); * * // pixelDataBatch is now ready for batch ML inference * ``` */ export declare function batchGetPixelData(optionsArray: GetPixelDataOptions[], batchOptions?: BatchOptions): Promise; //# sourceMappingURL=index.d.ts.map