JavaCPP Presets for libdc1394 - Java bindings for controlling IEEE 1394 (FireWire) digital cameras following IIDC/DCAM specifications
—
Advanced scalable format support allowing custom image sizes, positions, and region of interest (ROI) configuration for libdc1394.
Discovers available Format7 modes and their capabilities.
/**
* Gets information about all Format7 modes
* @param camera Camera instance
* @param modeset Output structure containing all Format7 modes
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_modeset(dc1394camera_t camera, dc1394format7modeset_t modeset);
/**
* Gets information about a specific Format7 mode
* @param camera Camera instance
* @param mode Format7 mode number (0-7)
* @param mode_info Output structure for mode information
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_mode_info(dc1394camera_t camera, int mode, dc1394format7mode_t mode_info);
/**
* Gets supported color codings for a Format7 mode
* @param camera Camera instance
* @param mode Format7 mode number
* @param codings Output structure containing supported color codings
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_color_codings(dc1394camera_t camera, int mode, dc1394color_codings_t codings);Usage Example:
import org.bytedeco.libdc1394.*;
import static org.bytedeco.libdc1394.global.dc1394.*;
// Get all Format7 mode information
dc1394format7modeset_t modeset = new dc1394format7modeset_t();
int err = dc1394_format7_get_modeset(camera, modeset);
if (err != DC1394_SUCCESS) {
dc1394_log_error("Failed to get Format7 modeset: " + err);
return;
}
// Check each Format7 mode
for (int i = 0; i < 8; i++) {
dc1394format7mode_t mode = modeset.mode(i);
if (mode.present()) {
System.out.println("Format7 Mode " + i + ":");
System.out.println(" Max size: " + mode.max_size_x() + "x" + mode.max_size_y());
System.out.println(" Unit size: " + mode.unit_size_x() + "x" + mode.unit_size_y());
System.out.println(" Pixel unit: " + mode.unit_pos_x() + "x" + mode.unit_pos_y());
// Get supported color codings
dc1394color_codings_t codings = new dc1394color_codings_t();
dc1394_format7_get_color_codings(camera, i, codings);
System.out.println(" Color codings: " + codings.num());
}
}Controls the image size and position within the sensor area.
/**
* Gets the maximum image size for a Format7 mode
* @param camera Camera instance
* @param mode Format7 mode number
* @param h_size Output parameter for maximum width
* @param v_size Output parameter for maximum height
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_max_image_size(dc1394camera_t camera, int mode,
IntPointer h_size, IntPointer v_size);
/**
* Sets the image size for a Format7 mode
* @param camera Camera instance
* @param mode Format7 mode number
* @param width Image width in pixels
* @param height Image height in pixels
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_set_image_size(dc1394camera_t camera, int mode, int width, int height);
/**
* Gets the current image size
* @param camera Camera instance
* @param mode Format7 mode number
* @param width Output parameter for current width
* @param height Output parameter for current height
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_image_size(dc1394camera_t camera, int mode,
IntPointer width, IntPointer height);
/**
* Sets the image position (top-left corner) within the sensor
* @param camera Camera instance
* @param mode Format7 mode number
* @param left Left position in pixels
* @param top Top position in pixels
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_set_image_position(dc1394camera_t camera, int mode, int left, int top);
/**
* Gets the current image position
* @param camera Camera instance
* @param mode Format7 mode number
* @param left Output parameter for left position
* @param top Output parameter for top position
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_image_position(dc1394camera_t camera, int mode,
IntPointer left, IntPointer top);Usage Example:
// Set custom image size for Format7 Mode 0
int mode = 0;
// Get maximum size first
IntPointer maxWidth = new IntPointer(1);
IntPointer maxHeight = new IntPointer(1);
dc1394_format7_get_max_image_size(camera, mode, maxWidth, maxHeight);
System.out.println("Max size: " + maxWidth.get() + "x" + maxHeight.get());
// Set image size to half maximum
int width = maxWidth.get() / 2;
int height = maxHeight.get() / 2;
int err = dc1394_format7_set_image_size(camera, mode, width, height);
if (err != DC1394_SUCCESS) {
dc1394_log_error("Failed to set image size: " + err);
}
// Center the image on sensor
int left = (maxWidth.get() - width) / 2;
int top = (maxHeight.get() - height) / 2;
dc1394_format7_set_image_position(camera, mode, left, top);Controls the pixel format for Format7 modes.
/**
* Sets the color coding for a Format7 mode
* @param camera Camera instance
* @param mode Format7 mode number
* @param color_coding Color coding constant (DC1394_COLOR_CODING_*)
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_set_color_coding(dc1394camera_t camera, int mode, int color_coding);
/**
* Gets the current color coding
* @param camera Camera instance
* @param mode Format7 mode number
* @param color_coding Output parameter for current color coding
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_color_coding(dc1394camera_t camera, int mode, IntPointer color_coding);
/**
* Gets the color filter pattern for RAW color codings
* @param camera Camera instance
* @param mode Format7 mode number
* @param color_filter Output parameter for color filter pattern
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_color_filter(dc1394camera_t camera, int mode, IntPointer color_filter);Controls packet size for optimal bandwidth utilization.
/**
* Gets recommended packet size for current Format7 configuration
* @param camera Camera instance
* @param mode Format7 mode number
* @param packet_size Output parameter for recommended packet size
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_recommended_packet_size(dc1394camera_t camera, int mode,
IntPointer packet_size);
/**
* Gets packet size unit (minimum increment)
* @param camera Camera instance
* @param mode Format7 mode number
* @param unit_bytes Output parameter for packet size unit
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_unit_size_and_position(dc1394camera_t camera, int mode,
IntPointer unit_x, IntPointer unit_y,
IntPointer unit_pos_x, IntPointer unit_pos_y);
/**
* Sets the packet size for a Format7 mode
* @param camera Camera instance
* @param mode Format7 mode number
* @param packet_size Packet size in bytes (must be multiple of unit)
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_set_packet_size(dc1394camera_t camera, int mode, int packet_size);
/**
* Gets the current packet size
* @param camera Camera instance
* @param mode Format7 mode number
* @param packet_size Output parameter for current packet size
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_packet_size(dc1394camera_t camera, int mode, IntPointer packet_size);Usage Example:
// Set color coding to RGB8
int err = dc1394_format7_set_color_coding(camera, mode, DC1394_COLOR_CODING_RGB8);
if (err != DC1394_SUCCESS) {
dc1394_log_error("Failed to set color coding: " + err);
}
// Get and set recommended packet size
IntPointer packetSize = new IntPointer(1);
dc1394_format7_get_recommended_packet_size(camera, mode, packetSize);
System.out.println("Recommended packet size: " + packetSize.get());
dc1394_format7_set_packet_size(camera, mode, packetSize.get());Convenient function to set up complete ROI configuration.
/**
* Sets up complete Region of Interest configuration
* @param camera Camera instance
* @param mode Format7 mode number
* @param color_coding Color coding to use
* @param packet_size Packet size (use DC1394_USE_RECOMMENDED for automatic)
* @param left Left position of ROI
* @param top Top position of ROI
* @param width Width of ROI
* @param height Height of ROI
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_set_roi(dc1394camera_t camera, int mode, int color_coding, int packet_size,
int left, int top, int width, int height);
/**
* Gets the current ROI configuration
* @param camera Camera instance
* @param mode Format7 mode number
* @param color_coding Output parameter for color coding
* @param packet_size Output parameter for packet size
* @param left Output parameter for left position
* @param top Output parameter for top position
* @param width Output parameter for width
* @param height Output parameter for height
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_roi(dc1394camera_t camera, int mode, IntPointer color_coding,
IntPointer packet_size, IntPointer left, IntPointer top,
IntPointer width, IntPointer height);Usage Example:
// Set up ROI for center 800x600 region with RGB8 format
int mode = 0;
int err = dc1394_format7_set_roi(camera, mode,
DC1394_COLOR_CODING_RGB8, // Color format
DC1394_USE_RECOMMENDED, // Auto packet size
200, 150, // Position (left, top)
800, 600); // Size (width, height)
if (err != DC1394_SUCCESS) {
dc1394_log_error("Failed to set ROI: " + err);
} else {
System.out.println("ROI configured successfully");
}
// Switch to this Format7 mode
dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_0 + mode);Gets timing information for Format7 configurations.
/**
* Gets data rate for current Format7 configuration
* @param camera Camera instance
* @param mode Format7 mode number
* @param data_rate Output parameter for data rate in bytes/second
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_data_depth(dc1394camera_t camera, int mode, IntPointer data_depth);
/**
* Gets frame interval for Format7 mode
* @param camera Camera instance
* @param mode Format7 mode number
* @param interval Output parameter for frame interval in microseconds
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_format7_get_frame_interval(dc1394camera_t camera, int mode, FloatPointer interval);/**
* Comprehensive Format7 mode information structure (19 fields)
*/
class dc1394format7mode_t extends Pointer {
/**
* Mode availability
* @return true if mode is present/supported, false otherwise
*/
boolean present();
/**
* Maximum image width for this mode
* @return Maximum width in pixels
*/
int max_size_x();
/**
* Maximum image height for this mode
* @return Maximum height in pixels
*/
int max_size_y();
/**
* Width increment unit (image width must be multiple of this)
* @return Width unit in pixels
*/
int unit_size_x();
/**
* Height increment unit (image height must be multiple of this)
* @return Height unit in pixels
*/
int unit_size_y();
/**
* Horizontal position unit (left position must be multiple of this)
* @return Position unit in pixels
*/
int unit_pos_x();
/**
* Vertical position unit (top position must be multiple of this)
* @return Position unit in pixels
*/
int unit_pos_y();
/**
* Current image width
* @return Current width in pixels
*/
int size_x();
/**
* Current image height
* @return Current height in pixels
*/
int size_y();
/**
* Current horizontal position
* @return Current left position in pixels
*/
int pos_x();
/**
* Current vertical position
* @return Current top position in pixels
*/
int pos_y();
/**
* Current color coding
* @return Color coding constant
*/
int color_coding();
/**
* Color filter pattern for RAW formats
* @return Color filter constant
*/
int color_filter();
/**
* Current packet size
* @return Packet size in bytes
*/
int packet_size();
/**
* Packet size per unit
* @return Bytes per packet unit
*/
int packet_size_per_unit();
/**
* Recommended packet size
* @return Recommended packet size in bytes
*/
int packet_size_recommended();
/**
* Maximum packet size
* @return Maximum packet size in bytes
*/
int packet_size_max();
/**
* Data depth in bits per pixel
* @return Bits per pixel
*/
int data_depth();
/**
* Bytes per packet
* @return Bytes per packet
*/
int pixnum_per_packet();
}/**
* Container for all Format7 modes (0-7)
*/
class dc1394format7modeset_t extends Pointer {
/**
* Access individual Format7 mode information
* @param i Mode number (0-7)
* @return Format7 mode information structure
*/
dc1394format7mode_t mode(int i);
}// Special values for Format7 configuration
static final int DC1394_QUERY_FROM_CAMERA = Integer.MAX_VALUE; // Query value from camera
static final int DC1394_USE_MAX_AVAIL = 0; // Use maximum available
static final int DC1394_USE_RECOMMENDED = -1; // Use recommended value// Format7 mode identifiers (0-7)
static final int DC1394_FORMAT7_MODE_0 = 0;
static final int DC1394_FORMAT7_MODE_1 = 1;
static final int DC1394_FORMAT7_MODE_2 = 2;
static final int DC1394_FORMAT7_MODE_3 = 3;
static final int DC1394_FORMAT7_MODE_4 = 4;
static final int DC1394_FORMAT7_MODE_5 = 5;
static final int DC1394_FORMAT7_MODE_6 = 6;
static final int DC1394_FORMAT7_MODE_7 = 7;// Configure multiple ROIs for different applications
void configureMultiROI(dc1394camera_t camera) {
// High-speed small ROI for tracking
dc1394_format7_set_roi(camera, 0,
DC1394_COLOR_CODING_MONO8, // Fast monochrome
DC1394_USE_RECOMMENDED,
400, 300, 200, 200); // 200x200 center region
// High-quality large ROI for imaging
dc1394_format7_set_roi(camera, 1,
DC1394_COLOR_CODING_RGB8, // Full color
DC1394_USE_RECOMMENDED,
100, 100, 1000, 800); // Large region
// RAW capture for scientific imaging
dc1394_format7_set_roi(camera, 2,
DC1394_COLOR_CODING_RAW8, // Bayer pattern
DC1394_USE_MAX_AVAIL, // Maximum packet size
0, 0, 1600, 1200); // Full sensor
}// Adjust ROI during capture for tracking applications
void adjustROIForTracking(dc1394camera_t camera, int mode, int targetX, int targetY) {
// Get mode constraints
dc1394format7mode_t modeInfo = new dc1394format7mode_t();
dc1394_format7_get_mode_info(camera, mode, modeInfo);
// Calculate new ROI centered on target
int roiSize = 400; // 400x400 tracking window
// Ensure alignment with unit constraints
int unitX = modeInfo.unit_pos_x();
int unitY = modeInfo.unit_pos_y();
int left = ((targetX - roiSize/2) / unitX) * unitX;
int top = ((targetY - roiSize/2) / unitY) * unitY;
// Clamp to sensor bounds
left = Math.max(0, Math.min(left, modeInfo.max_size_x() - roiSize));
top = Math.max(0, Math.min(top, modeInfo.max_size_y() - roiSize));
// Update ROI
dc1394_format7_set_image_position(camera, mode, left, top);
dc1394_format7_set_image_size(camera, mode, roiSize, roiSize);
}// Calculate and set optimal packet size for bandwidth
void optimizePacketSize(dc1394camera_t camera, int mode) {
// Get current configuration
IntPointer width = new IntPointer(1);
IntPointer height = new IntPointer(1);
IntPointer colorCoding = new IntPointer(1);
dc1394_format7_get_image_size(camera, mode, width, height);
dc1394_format7_get_color_coding(camera, mode, colorCoding);
// Calculate data per frame
int bytesPerPixel = dc1394_get_color_coding_data_depth(colorCoding.get()) / 8;
long frameBytes = width.get() * height.get() * bytesPerPixel;
// Get packet constraints
dc1394format7mode_t modeInfo = new dc1394format7mode_t();
dc1394_format7_get_mode_info(camera, mode, modeInfo);
int packetUnit = modeInfo.packet_size_per_unit();
int maxPacket = modeInfo.packet_size_max();
// Calculate optimal packet size (balance between latency and efficiency)
int optimalPacket = (int)Math.min(maxPacket, frameBytes / 50); // ~50 packets per frame
optimalPacket = (optimalPacket / packetUnit) * packetUnit; // Align to unit
if (optimalPacket > 0) {
dc1394_format7_set_packet_size(camera, mode, optimalPacket);
System.out.println("Set packet size to " + optimalPacket + " bytes");
}
}unit_size_x, unit_size_y)unit_pos_x and unit_pos_y// Always validate Format7 parameters before use
boolean validateFormat7ROI(dc1394camera_t camera, int mode, int left, int top, int width, int height) {
dc1394format7mode_t modeInfo = new dc1394format7mode_t();
if (dc1394_format7_get_mode_info(camera, mode, modeInfo) != DC1394_SUCCESS) {
return false;
}
if (!modeInfo.present()) {
System.err.println("Format7 mode " + mode + " not available");
return false;
}
// Check size constraints
if (width % modeInfo.unit_size_x() != 0 || height % modeInfo.unit_size_y() != 0) {
System.err.println("Size not aligned to unit constraints");
return false;
}
// Check position constraints
if (left % modeInfo.unit_pos_x() != 0 || top % modeInfo.unit_pos_y() != 0) {
System.err.println("Position not aligned to unit constraints");
return false;
}
// Check bounds
if (left + width > modeInfo.max_size_x() || top + height > modeInfo.max_size_y()) {
System.err.println("ROI exceeds sensor bounds");
return false;
}
return true;
}Install with Tessl CLI
npx tessl i tessl/maven-org-bytedeco--libdc1394