JavaCPP Presets for libdc1394 - Java bindings for controlling IEEE 1394 (FireWire) digital cameras following IIDC/DCAM specifications
—
Helper functions for format validation, error handling, and data conversion in libdc1394.
Helper functions for working with video modes, color coding, and image dimensions.
/**
* Gets image dimensions from a video mode
* @param camera Camera instance (or null for standard modes)
* @param video_mode Video mode identifier
* @param width Output parameter for image width
* @param height Output parameter for image height
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_get_image_size_from_video_mode(dc1394camera_t camera, int video_mode,
IntPointer width, IntPointer height);
/**
* Gets the color coding associated with a video mode
* @param camera Camera instance
* @param video_mode Video mode identifier
* @param color_coding Output parameter for color coding
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_get_color_coding_from_video_mode(dc1394camera_t camera, int video_mode,
IntPointer color_coding);
/**
* Gets the data depth (bits per pixel) for a color coding
* @param color_coding Color coding identifier
* @param bits Output parameter for bits per pixel
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_get_color_coding_data_depth(int color_coding, IntPointer bits);
/**
* Gets the bit size for a color coding
* @param color_coding Color coding identifier
* @param bits Output parameter for bit size
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_get_color_coding_bit_size(int color_coding, IntPointer bits);Usage Example:
import org.bytedeco.libdc1394.*;
import static org.bytedeco.libdc1394.global.dc1394.*;
import org.bytedeco.javacpp.IntPointer;
// Get image dimensions for a video mode
IntPointer width = new IntPointer(1);
IntPointer height = new IntPointer(1);
int err = dc1394_get_image_size_from_video_mode(camera, DC1394_VIDEO_MODE_640x480_RGB8,
width, height);
if (err == DC1394_SUCCESS) {
System.out.println("Image size: " + width.get() + "x" + height.get());
}
// Get color coding information
IntPointer color_coding = new IntPointer(1);
err = dc1394_get_color_coding_from_video_mode(camera, DC1394_VIDEO_MODE_640x480_RGB8,
color_coding);
if (err == DC1394_SUCCESS) {
IntPointer bits = new IntPointer(1);
dc1394_get_color_coding_data_depth(color_coding.get(), bits);
System.out.println("Color coding: " + color_coding.get() + ", Bits per pixel: " + bits.get());
}Functions to validate and query video mode properties.
/**
* Checks if a video mode is scalable (Format7)
* @param video_mode Video mode identifier
* @return true if mode is scalable, false otherwise
*/
boolean dc1394_is_video_mode_scalable(int video_mode);
/**
* Checks if a video mode is for still image capture
* @param video_mode Video mode identifier
* @return true if mode is for still images, false for video
*/
boolean dc1394_is_video_mode_still_image(int video_mode);
/**
* Checks if a color mode represents color data (vs monochrome)
* @param color_mode Color coding identifier
* @param is_color Output parameter: true if color, false if monochrome
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_is_color(int color_mode, IntPointer is_color);Usage Example:
import org.bytedeco.libdc1394.*;
import static org.bytedeco.libdc1394.global.dc1394.*;
import org.bytedeco.javacpp.IntPointer;
// Check video mode properties
int video_mode = DC1394_VIDEO_MODE_FORMAT7_0;
if (dc1394_is_video_mode_scalable(video_mode)) {
System.out.println("This is a scalable (Format7) video mode");
}
if (dc1394_is_video_mode_still_image(video_mode)) {
System.out.println("This mode is for still image capture");
} else {
System.out.println("This mode is for video capture");
}
// Check if color coding represents color data
IntPointer is_color = new IntPointer(1);
int err = dc1394_is_color(DC1394_COLOR_CODING_RGB8, is_color);
if (err == DC1394_SUCCESS) {
if (is_color.get() != 0) {
System.out.println("RGB8 is a color format");
} else {
System.out.println("RGB8 is a monochrome format");
}
}Convert between framerate enumerations and floating-point values.
/**
* Converts a framerate enumeration to floating-point frames per second
* @param framerate_enum Framerate identifier (DC1394_FRAMERATE_*)
* @param framerate Output parameter for framerate as float
* @return DC1394_SUCCESS on success, error code on failure
*/
int dc1394_framerate_as_float(int framerate_enum, FloatPointer framerate);Usage Example:
import org.bytedeco.libdc1394.*;
import static org.bytedeco.libdc1394.global.dc1394.*;
import org.bytedeco.javacpp.FloatPointer;
// Convert framerate enum to float
FloatPointer fps = new FloatPointer(1);
int err = dc1394_framerate_as_float(DC1394_FRAMERATE_30, fps);
if (err == DC1394_SUCCESS) {
System.out.println("Framerate: " + fps.get() + " fps");
}
// Convert all supported framerates
int[] framerates = {
DC1394_FRAMERATE_1_875, DC1394_FRAMERATE_3_75, DC1394_FRAMERATE_7_5,
DC1394_FRAMERATE_15, DC1394_FRAMERATE_30, DC1394_FRAMERATE_60,
DC1394_FRAMERATE_120, DC1394_FRAMERATE_240
};
System.out.println("Supported framerates:");
for (int framerate : framerates) {
FloatPointer rate = new FloatPointer(1);
if (dc1394_framerate_as_float(framerate, rate) == DC1394_SUCCESS) {
System.out.println(" " + framerate + " -> " + rate.get() + " fps");
}
}Utility functions for comparing camera instances and identifiers.
/**
* Checks if two camera identifiers refer to the same physical camera
* @param id1 First camera identifier
* @param id2 Second camera identifier
* @return true if cameras are the same, false otherwise
*/
boolean dc1394_is_same_camera(dc1394camera_id_t id1, dc1394camera_id_t id2);Usage Example:
import org.bytedeco.libdc1394.*;
import static org.bytedeco.libdc1394.global.dc1394.*;
// Compare camera identifiers
dc1394camera_list_t list = new dc1394camera_list_t();
dc1394_camera_enumerate(d, list);
if (list.num() >= 2) {
dc1394camera_id_t id1 = list.ids().position(0);
dc1394camera_id_t id2 = list.ids().position(1);
if (dc1394_is_same_camera(id1, id2)) {
System.out.println("Both IDs refer to the same camera");
} else {
System.out.println("Different cameras detected");
System.out.println("Camera 1 GUID: " + Long.toHexString(id1.guid()));
System.out.println("Camera 2 GUID: " + Long.toHexString(id2.guid()));
}
}Get human-readable strings for error codes and feature identifiers.
/**
* Gets a human-readable string for a feature identifier
* @param feature Feature identifier (DC1394_FEATURE_*)
* @return String representation of the feature name
*/
BytePointer dc1394_feature_get_string(int feature);
/**
* Gets a human-readable string for an error code
* @param error Error code returned by libdc1394 functions
* @return String representation of the error
*/
BytePointer dc1394_error_get_string(int error);Usage Example:
import org.bytedeco.libdc1394.*;
import static org.bytedeco.libdc1394.global.dc1394.*;
// Get feature name string
BytePointer feature_name = dc1394_feature_get_string(DC1394_FEATURE_BRIGHTNESS);
System.out.println("Feature name: " + feature_name.getString());
// Get error description
int err = dc1394_video_set_mode(camera, invalid_mode);
if (err != DC1394_SUCCESS) {
BytePointer error_desc = dc1394_error_get_string(err);
System.err.println("Error: " + error_desc.getString());
}
// Print all feature names
int[] features = {
DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_EXPOSURE, DC1394_FEATURE_SHARPNESS,
DC1394_FEATURE_WHITE_BALANCE, DC1394_FEATURE_HUE, DC1394_FEATURE_SATURATION,
DC1394_FEATURE_GAMMA, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_GAIN,
DC1394_FEATURE_IRIS, DC1394_FEATURE_FOCUS, DC1394_FEATURE_TEMPERATURE
};
System.out.println("Available features:");
for (int feature : features) {
BytePointer name = dc1394_feature_get_string(feature);
System.out.println(" " + feature + ": " + name.getString());
}CRC checksum calculation for data validation.
/**
* Calculates CRC16 checksum of a data buffer
* @param buffer Data buffer to checksum
* @param buffer_size Size of buffer in bytes
* @return CRC16 checksum value
*/
short dc1394_checksum_crc16(BytePointer buffer, int buffer_size);Usage Example:
import org.bytedeco.libdc1394.*;
import static org.bytedeco.libdc1394.global.dc1394.*;
import org.bytedeco.javacpp.BytePointer;
// Calculate checksum of frame data
dc1394video_frame_t frame = new dc1394video_frame_t();
// ... capture frame
BytePointer image_data = frame.image();
int image_size = (int)frame.image_bytes();
short crc = dc1394_checksum_crc16(image_data, image_size);
System.out.println("Frame CRC16: 0x" + Integer.toHexString(crc & 0xFFFF));
// Validate data integrity by comparing checksums
short expected_crc = calculateExpectedCRC(); // Your validation logic
if (crc == expected_crc) {
System.out.println("Frame data integrity verified");
} else {
System.err.println("Frame data corruption detected!");
}Here's a complete example showing how to use utility functions for robust format validation:
import org.bytedeco.libdc1394.*;
import static org.bytedeco.libdc1394.global.dc1394.*;
import org.bytedeco.javacpp.*;
public class FormatValidator {
public static boolean validateVideoMode(dc1394camera_t camera, int video_mode) {
try {
// Check if video mode is valid
IntPointer width = new IntPointer(1);
IntPointer height = new IntPointer(1);
int err = dc1394_get_image_size_from_video_mode(camera, video_mode, width, height);
if (err != DC1394_SUCCESS) {
System.err.println("Invalid video mode: " + video_mode);
return false;
}
// Get color coding
IntPointer color_coding = new IntPointer(1);
err = dc1394_get_color_coding_from_video_mode(camera, video_mode, color_coding);
if (err != DC1394_SUCCESS) {
System.err.println("Could not get color coding for video mode: " + video_mode);
return false;
}
// Check if it's a color or monochrome mode
IntPointer is_color = new IntPointer(1);
dc1394_is_color(color_coding.get(), is_color);
// Get bit depth
IntPointer bits = new IntPointer(1);
dc1394_get_color_coding_data_depth(color_coding.get(), bits);
// Print validation results
System.out.println("Video Mode Validation Results:");
System.out.println(" Mode: " + video_mode);
System.out.println(" Dimensions: " + width.get() + "x" + height.get());
System.out.println(" Color Coding: " + color_coding.get());
System.out.println(" Type: " + (is_color.get() != 0 ? "Color" : "Monochrome"));
System.out.println(" Bits per pixel: " + bits.get());
System.out.println(" Scalable: " + dc1394_is_video_mode_scalable(video_mode));
System.out.println(" Still image: " + dc1394_is_video_mode_still_image(video_mode));
return true;
} catch (Exception e) {
System.err.println("Exception during video mode validation: " + e.getMessage());
return false;
}
}
public static void printFramerateInfo(int framerate_enum) {
FloatPointer fps = new FloatPointer(1);
int err = dc1394_framerate_as_float(framerate_enum, fps);
if (err == DC1394_SUCCESS) {
System.out.println("Framerate " + framerate_enum + ": " + fps.get() + " fps");
} else {
System.err.println("Invalid framerate enum: " + framerate_enum);
}
}
}This utility functions documentation provides comprehensive coverage of the helper functions that make working with libdc1394 more convenient and robust.
Install with Tessl CLI
npx tessl i tessl/maven-org-bytedeco--libdc1394