* as published by Sam Hocevar. See the COPYING file for more details.
*
* @author hansi
<<<<<<< HEAD
* @author Ananta Palani
*
=======
>>>>>>> a0560a3efd37b3c0f25a1a05cff3f3a3c019985b
*/
// TODO: think about having CanonUtils handle state/property changes to handle cases described by CanonUtils.isLiveViewEnabled()
public class CanonUtils {
Solution content
* as published by Sam Hocevar. See the COPYING file for more details.
*
* @author hansi
* @author Ananta Palani
*
*/
// TODO: think about having CanonUtils handle state/property changes to handle cases described by CanonUtils.isLiveViewEnabled()
public class CanonUtils {
File
CanonUtils.java
Developer's decision
Version 1
Kind of conflict
Comment
Chunk
Conflicting content
*/
}
).intValue();
}
// TODO: think about having CanonUtils handle state/property changes to handle cases described by CanonUtils.isLiveViewEnabled()
public class CanonUtils {
<<<<<<< HEAD
public static final int classIntField( final Class klass,
final String fieldName ) {
Throwable t = null;
try {
final int value = klass.getField( fieldName ).getInt( null );
return value;
}
catch ( final IllegalArgumentException e ) {
t = e;
}
catch ( final IllegalAccessException e ) {
t = e;
}
catch ( final NoSuchFieldException e ) {
t = e;
}
catch ( final SecurityException e ) {
t = e;
}
throw new IllegalArgumentException( klass.getCanonicalName() +
" does not contain field " +
fieldName, t );
}
/**
* Finds the filename for a directory item
*
* @param directoryItem The item you want to download
* @return Either null, or the filename of the item
*/
public static EdsDirectoryItemInfo getDirectoryItemInfo( final EdsDirectoryItemRef directoryItem ) {
EdsError err = EdsError.EDS_ERR_OK;
final EdsDirectoryItemInfo dirItemInfo = new EdsDirectoryItemInfo();
try {
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetDirectoryItemInfo( directoryItem, dirItemInfo ) );
}
catch ( final Exception e ) {
e.printStackTrace();
}
return err == EdsError.EDS_ERR_OK ? dirItemInfo : null;
}
/**
* Downloads an image and saves it somewhere.
*
* @param directoryItem The item you want to download
* @param destination A path in the filesystem where you want to save the
* file. Can also be null or a directory. In case of null the
* temp directory will be used, in case of a directory the file
* name of the item will be used.
* @param appendFileExtension Adds the extension of the photo onto File to
* ensure that supplied File name extension matches the image
* being downloaded from the camera. This is especially important
* if the camera is set to RAW+JPEG where the order of the images
* is not consistent.
* @return Either null, or the location the file was ultimately saved to on
* success.
*/
public static File download( final EdsDirectoryItemRef directoryItem,
File destination,
final boolean appendFileExtension ) {
EdsError err = EdsError.EDS_ERR_OK;
final EdsStreamRef.ByReference stream = new EdsStreamRef.ByReference();
final EdsDirectoryItemInfo dirItemInfo = new EdsDirectoryItemInfo();
boolean success = false;
//final long timeStart = System.currentTimeMillis();
try {
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetDirectoryItemInfo( directoryItem, dirItemInfo ) );
if ( err == EdsError.EDS_ERR_OK ) {
if ( destination == null ) {
destination = new File( System.getProperty( "java.io.tmpdir" ) );
}
if ( destination.isDirectory() ) {
destination = new File( destination, Native.toString( dirItemInfo.szFileName ) );
} else if ( appendFileExtension ) {
final String sourceFileName = Native.toString( dirItemInfo.szFileName );
final int i = sourceFileName.lastIndexOf( "." );
if ( i > 0 ) {
final String extension = sourceFileName.substring( i );
if ( !destination.getName().toLowerCase().endsWith( extension ) ) {
destination = new File( destination.getPath() +
extension );
}
}
}
if ( destination.getParentFile() != null ) {
destination.getParentFile().mkdirs();
}
/*
* System.out.println( "Downloading image " +
* Native.toString( dirItemInfo.szFileName ) +
* " to " + destination.getCanonicalPath() );
*/
// TODO: see if using an EdsCreateMemoryStream would be faster and whether the image could be read directly without saving to file first - see: http://stackoverflow.com/questions/1083446/canon-edsdk-memorystream-image
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsCreateFileStream( Native.toByteArray( destination.getCanonicalPath() ), EdsFileCreateDisposition.kEdsFileCreateDisposition_CreateAlways.value(), EdsAccess.kEdsAccess_ReadWrite.value(), stream ) );
}
if ( err == EdsError.EDS_ERR_OK ) {
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsDownload( directoryItem, dirItemInfo.size, stream.getValue() ) );
}
if ( err == EdsError.EDS_ERR_OK ) {
/*
* System.out.println( "Image downloaded in " +
* ( System.currentTimeMillis() - timeStart ) +
* " ms" );
*/
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsDownloadComplete( directoryItem ) );
success = true;
}
if ( stream != null ) {
CanonCamera.EDSDK.EdsRelease( stream.getValue() );
}
}
catch ( final Exception e ) {
e.printStackTrace();
}
return success ? destination : null;
}
public static EdsError setPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final DescriptiveEnum value ) {
return CanonUtils.setPropertyDataAdvanced( ref, property, 0, value.value().longValue() );
}
public static EdsError setPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long param,
final DescriptiveEnum value ) {
return CanonUtils.setPropertyDataAdvanced( ref, property, param, value.value().longValue() );
}
public static EdsError setPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long value ) {
return CanonUtils.setPropertyDataAdvanced( ref, property, 0, value );
}
public static EdsError setPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long param, final long value ) {
return CanonUtils.setPropertyDataAdvanced( ref, property, param, value );
}
public static EdsError setPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long param, final int size,
final Pointer data ) {
return CanonUtils.toEdsError( CanonCamera.EDSDK.EdsSetPropertyData( ref, new NativeLong( property.value() ), new NativeLong( param ), new NativeLong( size ), data ) );
}
public static EdsError setPropertyDataAdvanced( final EdsBaseRef ref,
final EdsPropertyID property,
final Object value ) {
return CanonUtils.setPropertyDataAdvanced( ref, property, 0, value );
}
/**
* Only use this if you know that the type of the property you input is
* compatible with the value you supply.
*
* @param ref Camera/image/live view reference
* @param property Property to get from the camera
* @param param See EDSDK API
* @return
* @throws IllegalStateException
*/
//TODO: this method isn't very safe to leave public, perhaps some setPropertyData[String/UInt32/etc.] methods would be better
public static EdsError setPropertyDataAdvanced( final EdsBaseRef ref,
final EdsPropertyID property,
final long param,
final Object value ) throws IllegalStateException {
final EdsDataType type = CanonUtils.getPropertyType( ref, property, param );
final Pointer pointer;
final int size;
switch ( type ) {
case kEdsDataType_String: { //EdsChar[]
final String string = (String) value;
size = string.length() + 1;
pointer = new Memory( size );
pointer.setString( 0, string );
break;
}
case kEdsDataType_Int8: //EdsInt8
case kEdsDataType_UInt8: { //EdsUInt8
size = 1;
pointer = new Memory( size );
pointer.setByte( 0, (Byte) value );
break;
}
case kEdsDataType_Int16: //EdsInt16
case kEdsDataType_UInt16: { //EdsUInt16
size = 2;
pointer = new Memory( size );
pointer.setShort( 0, (Short) value );
break;
}
case kEdsDataType_Int32: //EdsInt32
case kEdsDataType_UInt32: { //EdsUInt32
size = 4;
pointer = new Memory( size );
pointer.setNativeLong( 0, new NativeLong( (Long) value ) );
break;
}
case kEdsDataType_Int64: //EdsInt64
case kEdsDataType_UInt64: { //EdsUInt64
size = 8;
pointer = new Memory( size );
pointer.setLong( 0, (Long) value );
break;
}
case kEdsDataType_Float: { //EdsFloat
size = 4;
pointer = new Memory( size );
pointer.setFloat( 0, (Float) value );
break;
}
case kEdsDataType_Double: { //EdsDouble
size = 8;
pointer = new Memory( size );
pointer.setDouble( 0, (Double) value );
break;
}
case kEdsDataType_ByteBlock: { //Byte Block // TODO: According to API, is either EdsInt8[] or EdsUInt32[], but perhaps former is a typo or an old value
final int[] array = (int[]) value;
size = 4 * array.length;
pointer = new Memory( size );
pointer.write( 0, array, 0, array.length );
break;
}
case kEdsDataType_Rational: //EdsRational
case kEdsDataType_Point: //EdsPoint
case kEdsDataType_Rect: //EdsRect
case kEdsDataType_Time: //EdsTime
case kEdsDataType_FocusInfo: //EdsFocusInfo
case kEdsDataType_PictureStyleDesc: { //EdsPictureStyleDesc
final Structure structure = (Structure) value;
structure.write();
pointer = structure.getPointer();
size = structure.size();
break;
}
case kEdsDataType_Int8_Array: //EdsInt8[]
case kEdsDataType_UInt8_Array: { //EdsUInt8[]
final byte[] array = (byte[]) value;
size = array.length;
pointer = new Memory( size );
pointer.write( 0, array, 0, array.length );
break;
}
case kEdsDataType_Int16_Array: //EdsInt16[]
case kEdsDataType_UInt16_Array: { //EdsUInt16[]
final short[] array = (short[]) value;
size = 2 * array.length;
pointer = new Memory( size );
pointer.write( 0, array, 0, array.length );
break;
}
case kEdsDataType_Int32_Array: //EdsInt32[]
case kEdsDataType_UInt32_Array: { //EdsUInt32[]
final int[] array = (int[]) value;
size = 4 * array.length;
pointer = new Memory( size );
pointer.write( 0, array, 0, array.length );
break;
}
case kEdsDataType_Bool: //EdsBool // TODO: implement
case kEdsDataType_Bool_Array: //EdsBool[] // TODO: implement
case kEdsDataType_Rational_Array: //EdsRational[] // TODO: implement
case kEdsDataType_Unknown: //Unknown
default:
throw new IllegalStateException( type.description() + " (" +
type.name() +
") is not currently supported by GetPropertyCommand" );
}
return CanonUtils.setPropertyData( ref, property, param, size, pointer );
}
public static Long getPropertyData( final EdsBaseRef ref,
final EdsPropertyID property ) {
return CanonUtils.getPropertyDataAdvanced( ref, property, 0 );
}
public static Long getPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long param ) {
return CanonUtils.getPropertyDataAdvanced( ref, property, param );
}
public static EdsError getPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long param, final long size,
final Pointer data ) {
return CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPropertyData( ref, new NativeLong( property.value() ), new NativeLong( param ), new NativeLong( size ), data ) );
}
public static T getPropertyDataAdvanced( final EdsBaseRef ref,
final EdsPropertyID property ) {
return CanonUtils.getPropertyDataAdvanced( ref, property, 0 );
}
/**
* Only use this if you know that the type of the property you input is
* compatible with the return type assignment you expect.
*
* @param ref Camera/image/live view reference
* @param property Property to get from the camera
* @param param See EDSDK API
* @return
* @throws IllegalArgumentException
* @throws IllegalStateException
*/
//TODO: this method isn't very safe to leave public, perhaps some setPropertyData[String/UInt32/etc.] methods would be better
@SuppressWarnings( "unchecked" )
public static T getPropertyDataAdvanced( final EdsBaseRef ref,
final EdsPropertyID property,
final long param ) throws IllegalArgumentException, IllegalStateException {
final int size = (int) CanonUtils.getPropertySize( ref, property, param );
final EdsDataType type = CanonUtils.getPropertyType( ref, property, param );
final Memory memory = new Memory( size > 0 ? size : 1 );
final EdsError err = CanonUtils.getPropertyData( ref, property, param, size, memory );
if ( err == EdsError.EDS_ERR_OK ) {
switch ( type ) {
case kEdsDataType_Unknown: //Unknown
return null;
case kEdsDataType_String: //EdsChar[]
return (T) memory.getString( 0 );
case kEdsDataType_Int8: //EdsInt8
case kEdsDataType_UInt8: //EdsUInt8
return (T) Byte.valueOf( memory.getByte( 0 ) );
case kEdsDataType_Int16: //EdsInt16
}
case kEdsDataType_UInt16: //EdsUInt16
return (T) Short.valueOf( memory.getShort( 0 ) );
case kEdsDataType_Int32: //EdsInt32
case kEdsDataType_UInt32: //EdsUInt32
return (T) Long.valueOf( memory.getNativeLong( 0 ).longValue() );
case kEdsDataType_Int64: //EdsInt64
case kEdsDataType_UInt64: //EdsUInt64
return (T) Long.valueOf( memory.getLong( 0 ) );
case kEdsDataType_Float: //EdsFloat
return (T) Float.valueOf( memory.getFloat( 0 ) );
case kEdsDataType_Double: //EdsDouble
return (T) Double.valueOf( memory.getDouble( 0 ) );
case kEdsDataType_ByteBlock: //Byte Block // TODO: According to API, is either EdsInt8[] or EdsUInt32[], but perhaps former is a typo or an old value
return (T) memory.getIntArray( 0, size / 4 );
case kEdsDataType_Rational: //EdsRational
return (T) new EdsRational( memory );
case kEdsDataType_Point: //EdsPoint
return (T) new EdsPoint( memory );
case kEdsDataType_Rect: //EdsRect
return (T) new EdsRect( memory );
case kEdsDataType_Time: //EdsTime
return (T) new EdsTime( memory );
case kEdsDataType_FocusInfo: //EdsFocusInfo
return (T) new EdsFocusInfo( memory );
case kEdsDataType_PictureStyleDesc: //EdsPictureStyleDesc
return (T) new EdsPictureStyleDesc( memory );
case kEdsDataType_Int8_Array: //EdsInt8[]
case kEdsDataType_UInt8_Array: //EdsUInt8[]
return (T) memory.getByteArray( 0, size );
case kEdsDataType_Int16_Array: //EdsInt16[]
case kEdsDataType_UInt16_Array: //EdsUInt16[]
return (T) memory.getShortArray( 0, size / 2 );
case kEdsDataType_Int32_Array: //EdsInt32[]
case kEdsDataType_UInt32_Array: //EdsUInt32[]
return (T) memory.getIntArray( 0, size / 4 );
case kEdsDataType_Bool: //EdsBool // TODO: implement
case kEdsDataType_Bool_Array: //EdsBool[] // TODO: implement
case kEdsDataType_Rational_Array: //EdsRational[] // TODO: implement
default:
throw new IllegalStateException( type.description() + " (" +
type.name() +
") is not currently supported by GetPropertyCommand" );
}
}
throw new IllegalArgumentException( "An error occurred while getting " +
property.name() + " data (error " +
err.value() + ": " + err.name() +
" - " + err.description() + ")" );
}
public static EdsDataType getPropertyType( final EdsBaseRef ref,
final EdsPropertyID property ) {
return CanonUtils.getPropertyType( ref, property, 0 );
}
public static EdsDataType getPropertyType( final EdsBaseRef ref,
final EdsPropertyID property,
final long param ) {
final int bufferSize = 1;
final IntBuffer type = IntBuffer.allocate( bufferSize );
final NativeLongByReference number = new NativeLongByReference( new NativeLong( bufferSize ) );
final EdsError err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPropertySize( ref, new NativeLong( property.value() ), new NativeLong( param ), type, number ) );
if ( err == EdsError.EDS_ERR_OK ) {
final EdsDataType edsDataType = EdsDataType.enumOfValue( type.get( 0 ) );
if ( edsDataType != null ) {
//System.out.println( " > property type = " + edsDataType.value() + " : " + edsDataType.name() + " : " + edsDataType.description() );
return edsDataType;
}
}
// TODO: would it be better to return NULL if EDS_ERR_NOT_SUPPORTED is returned?
return EdsDataType.kEdsDataType_Unknown;
}
public static long getPropertySize( final EdsBaseRef ref,
final EdsPropertyID property ) {
return CanonUtils.getPropertySize( ref, property, 0 );
}
public static long getPropertySize( final EdsBaseRef ref,
final EdsPropertyID property,
final long param ) {
final int bufferSize = 1;
final IntBuffer type = IntBuffer.allocate( bufferSize );
final NativeLongByReference number = new NativeLongByReference( new NativeLong( bufferSize ) );
final EdsError err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPropertySize( ref, new NativeLong( property.value() ), new NativeLong( param ), type, number ) );
if ( err == EdsError.EDS_ERR_OK ) {
//System.out.println( "> property size = " + number.getValue().longValue() );
return number.getValue().longValue();
}
return -1;
}
/**
* Returns an array of DescriptiveEnum values for a given EdsPropertyID
* enum. Some of the EdsPropertyID enums that this function is known to
* support are listed in the EDSDK documentation, others were obtained by
* trial-and-error. Note that not all EdsPropertyID values are supported in
* all camera modes or with all models.
*
* @param camera The camera to get the available property settings of
* @param property
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_DriveMode
* kEdsPropID_DriveMode}
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_ISOSpeed
* kEdsPropID_ISOSpeed},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_MeteringMode
* kEdsPropID_MeteringMode},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_AFMode
* kEdsPropID_AFMode},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_Av
* kEdsPropID_Av},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_Tv
* kEdsPropID_Tv},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_ExposureCompensation
* kEdsPropID_ExposureCompensation},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_AEMode
* kEdsPropID_AEMode},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_ImageQuality
* kEdsPropID_ImageQuality},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_WhiteBalance
* kEdsPropID_WhiteBalance},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_ColorSpace
* kEdsPropID_ColorSpace},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_PictureStyle
* kEdsPropID_PictureStyle},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_Evf_WhiteBalance
* kEdsPropID_Evf_WhiteBalance}, or
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_Evf_AFMode
* kEdsPropID_Evf_AFMode}
* @return A DescriptiveEnum array of the available settings for the given
* property
*/
public static final DescriptiveEnum[] getPropertyDesc( final EdsCameraRef camera,
final EdsPropertyID property ) throws IllegalArgumentException, IllegalStateException {
/*
* System.out.println( "Getting available property values for " +
* property.description() + " (" + property.name() +
* ")" );
*/
final EdsPropertyDesc propertyDesc = CanonUtils.getPropertyDesc( (EdsBaseRef) camera, property );
if ( propertyDesc.numElements.intValue() > 0 ) {
/*
* System.out.println( "Number of elements: " +
* propertyDesc.numElements );
*/
final NativeLong[] propDesc = propertyDesc.propDesc;
final DescriptiveEnum[] properties = new DescriptiveEnum[propertyDesc.numElements.intValue()];
for ( int i = 0; i < propertyDesc.numElements.intValue(); i++ ) {
DescriptiveEnum de = null;
switch ( property ) {
case kEdsPropID_DriveMode:
de = EdsDriveMode.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_ISOSpeed:
de = EdsISOSpeed.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_MeteringMode:
de = EdsMeteringMode.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_AFMode:
de = EdsAFMode.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_Av:
de = EdsAv.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_Tv:
de = EdsTv.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_ExposureCompensation:
de = EdsExposureCompensation.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_AEMode:
de = EdsAEMode.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_ImageQuality:
de = EdsImageQuality.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_WhiteBalance:
de = EdsWhiteBalance.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_ColorSpace:
de = EdsColorSpace.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_PictureStyle:
de = EdsPictureStyle.enumOfValue( propDesc[i].intValue() );
break;
// Doesn't seem possible to query available output devices
// case kEdsPropID_Evf_OutputDevice:
// de = EdsEvfOutputDevice.enumOfValue( propDesc[i].intValue() );
// break;
case kEdsPropID_Evf_WhiteBalance:
de = EdsWhiteBalance.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_Evf_AFMode:
de = EdsEvfAFMode.enumOfValue( propDesc[i].intValue() );
break;
default:
throw new IllegalArgumentException( "Property '" +
property.name() +
"' is not supported." );
}
if ( de == null ) {
throw new IllegalStateException( "Could not find " +
property.name() +
" enum with value of: " +
propDesc[i].intValue() );
} else {
//System.out.println( e.name() + " ( " + e.value() + " ) " + e.description() );
}
properties[i] = de;
}
//System.out.println( "DONE!\n" );
return properties;
}
return null;
}
/**
*
* @param ref The camera to get the available property settings of
* @param property One of the supported EdsPropertyID values
* @return The EdsPropertyDesc containing the available settings for the
* given property
*/
if(err == EdSdkLibrary.EDS_ERR_OK ){
public static EdsPropertyDesc getPropertyDesc( final EdsBaseRef ref,
final EdsPropertyID property ) throws IllegalArgumentException {
final EdsPropertyDesc propertyDesc = new EdsPropertyDesc();
final EdsError err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPropertyDesc( ref, new NativeLong( property.value() ), propertyDesc ) );
if ( err == EdsError.EDS_ERR_OK ) {
//System.out.println( "> available values = " + propertyDesc.numElements );
return propertyDesc;
}
throw new IllegalArgumentException( "An error occurred while getting detailed " +
property.name() +
" data (error " +
err.value() +
": " +
err.name() +
" - " + err.description() + ")" );
}
public static EdsError setCapacity( final EdsCameraRef ref ) {
return CanonUtils.setCapacity( ref, Integer.MAX_VALUE );
}
public static EdsError setCapacity( final EdsCameraRef ref,
final int capacity ) {
final EdsCapacity.ByValue edsCapacity = new EdsCapacity.ByValue();
edsCapacity.bytesPerSector = new NativeLong( 512 );
edsCapacity.numberOfFreeClusters = new NativeLong( capacity /
edsCapacity.bytesPerSector.intValue() );
edsCapacity.reset = 1;
return CanonUtils.toEdsError( CanonCamera.EDSDK.EdsSetCapacity( ref, edsCapacity ) );
}
public static boolean isMirrorLockupEnabled( final EdsCameraRef camera ) {
try {
return 1l == CanonUtils.getPropertyData( camera, EdsPropertyID.kEdsPropID_CFn, EdsCustomFunction.kEdsCustomFunction_MirrorLockup.value() );
}
catch ( final IllegalArgumentException e ) {
System.err.println( "Could not check if mirror lockup enabled: " +
e.getMessage() );
}
return false;
}
public static boolean beginLiveView( final EdsCameraRef camera ) {
EdsError err = EdsError.EDS_ERR_OK;
NativeLongByReference number = new NativeLongByReference( new NativeLong( 1 ) );
Pointer data = number.getPointer();
err = CanonUtils.setPropertyData( camera, EdsPropertyID.kEdsPropID_Evf_Mode, 0, NativeLong.SIZE, data );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Could not start live view (set image mode) (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
return false;
}
number = new NativeLongByReference( new NativeLong( EdsEvfOutputDevice.kEdsEvfOutputDevice_PC.value() ) );
data = number.getPointer();
err = CanonUtils.setPropertyData( camera, EdsPropertyID.kEdsPropID_Evf_OutputDevice, 0, NativeLong.SIZE, data );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Could not start live view (set output device) (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
return false;
}
return true;
}
public static boolean endLiveView( final EdsCameraRef camera ) {
EdsError err = EdsError.EDS_ERR_OK;
NativeLongByReference number = new NativeLongByReference( new NativeLong( EdsEvfOutputDevice.kEdsEvfOutputDevice_TFT.value() ) );
Pointer data = number.getPointer();
err = CanonUtils.setPropertyData( camera, EdsPropertyID.kEdsPropID_Evf_OutputDevice, 0, NativeLong.SIZE, data );
if ( err != EdsError.EDS_ERR_OK ) {
/*
* System.err.println( "Could not end live view (error " +
* err.value() + ": " + err.name() + " - " +
* err.description() + ")" );
*/
return false;
}
// Create memory stream.
//TODO: decide whether skip deactivating the live view system. Canon's EOS Utility leaves it enabled, so should consider leaving it enabled as well.
number = new NativeLongByReference( new NativeLong( 0 ) );
data = number.getPointer();
err = CanonUtils.setPropertyData( camera, EdsPropertyID.kEdsPropID_Evf_Mode, 0, NativeLong.SIZE, data );
if ( err != EdsError.EDS_ERR_OK ) {
/*
* System.err.println( "Could not end live view (error " +
* err.value() + ": " + err.name() + " - " +
* err.description() + ")" );
*/
return false;
}
return true;
}
/**
* Checks whether live view is allowed to be activated (enabled) and
* alternately whether the camera is actively transmitting live view images.
*
* The default result from the camera may be misleading since
* {@link CanonConstants.EdsPropertyID#kEdsPropID_Evf_Mode
* kEdsPropID_Evf_Mode} only indicates whether live view is allowed to be
* enabled or not, not whether it is currently active and transmitting
* images.
*
* Additionally, we cannot simply query
* {@link CanonConstants.EdsPropertyID#kEdsPropID_Evf_OutputDevice
* kEdsPropID_Evf_OutputDevice} because the camera seems to give
* inconsistent results, sometimes providing an answer but mostly returning
* {@code 0xFFFFFFFF}.
*
* Instead, if {@code checkLiveViewActive} is {@code true} this function
* will try to download a live view frame and if it cannot, the function
* assumes that live view is off and {@code false} is returned.
*
* Note that if {@code checkLiveViewActive} is {@code true}, then if live
* view is turned off while
* {@link CanonUtils#getLiveViewImageReference(EdsCameraRef)
* getLiveViewImageReference()} is queried, the tread will hang because the
* EDSDK will not return, so call this from a thread-handled environment
* such as {@link CanonCamera}.
*
* @param camera the camera to query
* @param checkLiveViewActive set {@code true} to check whether the camera
* is actively transmitting live view images
* @return {@code true} if live view is allowed to be enabled, or if
* checkLiveViewActive, then {@code true} if the camera is actively
* transmitting live view images
*/
public static boolean isLiveViewEnabled( final EdsCameraRef camera,
final boolean checkLiveViewActive ) {
try {
if ( checkLiveViewActive ) {
final EdsBaseRef.ByReference[] references = CanonUtils.getLiveViewImageReference( camera );
if ( references != null ) {
CanonUtils.release( references );
return true;
}
return false;
}
return 1 == CanonUtils.getPropertyData( camera, EdsPropertyID.kEdsPropID_Evf_Mode );
}
catch ( final IllegalArgumentException e ) {
System.err.println( "Could not check live view status: " +
e.getMessage() );
}
return false;
}
/**
* Creates a stream and corresponding live view image. You MUST call
* {@link CanonUtils#release(edsdk.bindings.EdSdkLibrary.EdsBaseRef.ByReference...)
* release()} on the returned array when you are done using it or
* you will cause a memory leak!
*
* @param camera the camera to query
* @return EdsEvfImageRef.ByReference and EdsStreamRef.ByReference as
* indexes 0 and 1 respectively
*/
public static EdsBaseRef.ByReference[] getLiveViewImageReference( final EdsCameraRef camera ) {
EdsError err = EdsError.EDS_ERR_OK;
final EdsStreamRef.ByReference streamRef = new EdsStreamRef.ByReference();
final EdsEvfImageRef.ByReference imageRef = new EdsEvfImageRef.ByReference();
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsCreateMemoryStream( new NativeLong( 0 ), streamRef ) );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Failed to download live view image, memory stream could not be created (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
CanonUtils.release( imageRef, streamRef );
return null;
}
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsCreateEvfImageRef( new EdsStreamRef( streamRef.getPointer().getPointer( 0 ) ), imageRef ) );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Failed to download live view image, image ref could not be created (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
CanonUtils.release( imageRef, streamRef );
return null;
}
// Now try to follow the guidelines from
// http://tech.groups.yahoo.com/group/CanonSDK/message/1225
// instead of what the edsdk example has to offer!
// Download live view image data.
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsDownloadEvfImage( camera, imageRef.getValue() ) );
if ( err != EdsError.EDS_ERR_OK ) {
/*
* System.err.println( "Failed to download live view image (error "
* +
* err.value() + ": " + err.name() + " - " +
* err.description() + ")" );
*/
CanonUtils.release( imageRef, streamRef );
return null;
}
return new EdsBaseRef.ByReference[] { imageRef, streamRef };
}
public static BufferedImage downloadLiveViewImage( final EdsCameraRef camera ) {
EdsError err = EdsError.EDS_ERR_OK;
final EdsBaseRef.ByReference[] references = CanonUtils.getLiveViewImageReference( camera );
if ( references != null ) {
final EdsStreamRef.ByReference streamRef = (EdsStreamRef.ByReference) references[1];
final EdsEvfImageRef.ByReference imageRef = (EdsEvfImageRef.ByReference) references[0];
// // Get the incidental data of the image.
// NativeLongByReference zoom = new NativeLongByReference( new NativeLong( 0 ) );
// Pointer data = zoom.getPointer();
// err = getPropertyData( image.getValue(), EdSdkLibrary.kEdsPropID_Evf_ZoomPosition, 0, NativeLong.SIZE, data );
// if( err != EdsError.EDS_ERR_OK ){
// System.err.println( "Failed to download live view image, zoom value wasn't read (error "+ err.value() + ": "+ err.name() + " - " + err.description() + ")" );
// return null;
// }
//
// // Get the focus and zoom border position
// EdsPoint point = new EdsPoint();
// data = point.getPointer();
// err = getPropertyData( image.getValue(), EdSdkLibrary.kEdsPropID_Evf_ZoomPosition, 0 , sizeof( point ), data );
// if( err != EdsError.EDS_ERR_OK ){
// System.err.println( "Failed to download live view image, focus point wasn't read (error "+ err.value() + ": "+ err.name() + " - " + err.description() + ")" );
// return null;
// }
final NativeLongByReference length = new NativeLongByReference();
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetLength( streamRef.getValue(), length ) );
if ( err != EdsError.EDS_ERR_OK ) {
}
System.err.println( "Failed to download live view image, failed to read stream length (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
CanonUtils.release( imageRef, streamRef );
return null;
}
final PointerByReference ref = new PointerByReference();
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPointer( streamRef.getValue(), ref ) );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Failed to download live view image, failed to get reference to image in memory (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
CanonUtils.release( imageRef, streamRef );
return null;
}
final byte[] data = ref.getValue().getByteArray( 0, length.getValue().intValue() );
try {
final BufferedImage img = ImageIO.read( new ByteArrayInputStream( data ) );
return img;
}
catch ( final IOException e ) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
CanonUtils.release( imageRef, streamRef );
}
}
return null;
}
public static EdsError toEdsError( final NativeLong value ) {
return CanonUtils.toEdsError( value.intValue() );
}
public static EdsError toEdsError( final long value ) {
return CanonUtils.toEdsError( value );
}
public static EdsError toEdsError( final int value ) {
final EdsError error = EdsError.enumOfValue( value );
if ( error != null ) {
return error;
}
return EdsError.EDS_ERR_UNEXPECTED_EXCEPTION;
}
public static void release( final EdsBaseRef.ByReference ... objects ) {
for ( final EdsBaseRef.ByReference obj : objects ) {
if ( obj != null ) {
CanonUtils.release( obj.getValue() );
}
}
}
public static void release( final EdsBaseRef ... objects ) {
for ( final EdsBaseRef obj : objects ) {
if ( obj != null ) {
CanonCamera.EDSDK.EdsRelease( obj );
}
}
}
=======
/**
* Converts a bunch of bytes to a string.
* This is a little different from new String( myBytes ) because
* byte-arrays received from C will be crazy long and just have a null-terminator
* somewhere in the middle.
*/
public static String toString( byte bytes[] ){
for( int i = 0; i < bytes.length; i++ ){
if( bytes[i] == 0 ){
return new String( bytes, 0, i );
}
}
return new String( bytes );
}
/**
* Tries to find name of an error code.
*
* @param errorCode
* @return
*/
public static String toString( int errorCode ){
Field[] fields = EdSdkLibrary.class.getFields();
for( Field field : fields ){
try {
if( field.getType().toString().equals( "int" ) && field.getInt( EdSdkLibrary.class ) == errorCode ){
if( field.getName().startsWith( "EDS_" ) ){
return field.getName();
}
}
}
catch(Exception e) {
e.printStackTrace();
return "unknown error code";
}
public static String propertyIdToString(long property) {
Field[] fields = EdSdkLibrary.class.getFields();
for( Field field : fields ){
try {
if( field.getType().toString().equals( "int" ) && field.getInt( EdSdkLibrary.class ) == property ){
if( field.getName().startsWith( "kEdsPropID_" ) ){
return field.getName();
}
}
}
catch(Exception e) {
e.printStackTrace();
}
}
return "unknown error code";
}
public static String getQualityDescriptionForShortDescription( String str ){
/* Jpeg Only */
if("LJ".equals( str ) ) return "Jpeg Large";
if("M1J".equals( str ) ) return "Jpeg Middle1";
if("M2J".equals( str ) ) return "Jpeg Middle2";
if("SJ".equals( str ) ) return "Jpeg Small";
if("LJF".equals( str ) ) return "Jpeg Large Fine";
if("LJN".equals( str ) ) return "Jpeg Large Normal";
if("MJF".equals( str ) ) return "Jpeg Middle Fine";
if("MJN".equals( str ) ) return "Jpeg Middle Normal";
if("SJF".equals( str ) ) return "Jpeg Small Fine";
if("SJN".equals( str ) ) return "Jpeg Small Normal";
if("S1JF".equals( str ) ) return "Jpeg Small1 Fine";
if("S1JN".equals( str ) ) return "Jpeg Small1 Normal";
if("S2JF".equals( str ) ) return "Jpeg Small2";
if("S3JF".equals( str ) ) return "Jpeg Small3";
/* RAW + Jpeg */
if("LR".equals( str ) ) return "RAW";
if("LRLJF".equals( str ) ) return "RAW + Jpeg Large Fine";
if("LRLJN".equals( str ) ) return "RAW + Jpeg Large Normal";
if("LRMJF".equals( str ) ) return "RAW + Jpeg Middle Fine";
if("LRMJN".equals( str ) ) return "RAW + Jpeg Middle Normal";
if("LRSJF".equals( str ) ) return "RAW + Jpeg Small Fine";
if("LRSJN".equals( str ) ) return "RAW + Jpeg Small Normal";
if("LRS1JF".equals( str ) ) return "RAW + Jpeg Small1 Fine";
if("LRS1JN".equals( str ) ) return "RAW + Jpeg Small1 Normal";
if("LRS2JF".equals( str ) ) return "RAW + Jpeg Small2";
if("LRS3JF".equals( str ) ) return "RAW + Jpeg Small3";
if("LRLJ".equals( str ) ) return "RAW + Jpeg Large";
if("LRM1J".equals( str ) ) return "RAW + Jpeg Middle1";
if("LRM2J".equals( str ) ) return "RAW + Jpeg Middle2";
if("LRSJ".equals( str ) ) return "RAW + Jpeg Small";
/* MRAW(SRAW1) + Jpeg */
if("MR".equals( str ) ) return "MRAW(SRAW1)";
if("MRLJF".equals( str ) ) return "MRAW(SRAW1) + Jpeg Large Fine";
if("MRLJN".equals( str ) ) return "MRAW(SRAW1) + Jpeg Large Normal";
if("MRMJF".equals( str ) ) return "MRAW(SRAW1) + Jpeg Middle Fine";
if("MRMJN".equals( str ) ) return "MRAW(SRAW1) + Jpeg Middle Normal";
if("MRSJF".equals( str ) ) return "MRAW(SRAW1) + Jpeg Small Fine";
if("MRSJN".equals( str ) ) return "MRAW(SRAW1) + Jpeg Small Normal";
if("MRS1JF".equals( str ) ) return "MRAW(SRAW1) + Jpeg Small1 Fine";
if("MRS1JN".equals( str ) ) return "MRAW(SRAW1) + Jpeg Small1 Normal";
if("MRS2JF".equals( str ) ) return "MRAW(SRAW1) + Jpeg Small2";
if("MRS3JF".equals( str ) ) return "MRAW(SRAW1) + Jpeg Small3";
if("MRLJ".equals( str ) ) return "MRAW(SRAW1) + Jpeg Large";
if("MRM1J".equals( str ) ) return "MRAW(SRAW1) + Jpeg Middle1";
if("MRM2J".equals( str ) ) return "MRAW(SRAW1) + Jpeg Middle2";
if("MRSJ".equals( str ) ) return "MRAW(SRAW1) + Jpeg Small";
/* SRAW(SRAW2) + Jpeg */
if("SR".equals( str ) ) return "SRAW(SRAW2)";
if("SRLJF".equals( str ) ) return "SRAW(SRAW2) + Jpeg Large Fine";
if("SRLJN".equals( str ) ) return "SRAW(SRAW2) + Jpeg Large Normal";
if("SRMJF".equals( str ) ) return "SRAW(SRAW2) + Jpeg Middle Fine";
if("SRMJN".equals( str ) ) return "SRAW(SRAW2) + Jpeg Middle Normal";
if("SRSJF".equals( str ) ) return "SRAW(SRAW2) + Jpeg Small Fine";
if("SRSJN".equals( str ) ) return "SRAW(SRAW2) + Jpeg Small Normal";
if("SRS1JF".equals( str ) ) return "SRAW(SRAW2) + Jpeg Small1 Fine";
if("SRS1JN".equals( str ) ) return "SRAW(SRAW2) + Jpeg Small1 Normal";
if("SRS2JF".equals( str ) ) return "SRAW(SRAW2) + Jpeg Small2";
if("SRS3JF".equals( str ) ) return "SRAW(SRAW2) + Jpeg Small3";
if("SRLJ".equals( str ) ) return "SRAW(SRAW2) + Jpeg Large";
if("SRM1J".equals( str ) ) return "SRAW(SRAW2) + Jpeg Middle1";
if("SRM2J".equals( str ) ) return "SRAW(SRAW2) + Jpeg Middle2";
if("SRSJ".equals( str ) ) return "SRAW(SRAW2) + Jpeg Small";
return "Unknown Image Quality";
}
/**
* Finds the size of a class
* Use only with JNA stuff!
*/
public static int sizeof( Object o ){
int size = 0;
for(Field field : o.getClass().getDeclaredFields()) {
Class fieldtype = field.getType();
if( fieldtype.equals( NativeLong.class ) ){
size += NativeLong.SIZE;
}
else{
System.out.println( "unknown field type: " + field );
}
// sofern nur char[] m�glich, keinerlei weitere Pr�fung, ansonsten typenpr�fung anbauen
//char[] sub =(char[]) field.get(o);
//size+=sub.length;
}
return size;
}
/**
* Finds the filename for a directory item
* @param directoryItem The item you want to download
* @return Either null, or the filename of the item
*/
public static EdsDirectoryItemInfo getDirectoryItemInfo( __EdsObject directoryItem ){
int err = EdSdkLibrary.EDS_ERR_OK;
EdsDirectoryItemInfo dirItemInfo = new EdsDirectoryItemInfo();
err = CanonCamera.EDSDK.EdsGetDirectoryItemInfo(directoryItem, dirItemInfo).intValue();
if (err == EdSdkLibrary.EDS_ERR_OK) {
return dirItemInfo;
}
else{
return null;
}
}
/**
* Downloads an image and saves it somewhere
* @param directoryItem The item you want to download
* @param destination A path in the filesystem where you want to save the file. Can also be null or a directory. In case of null the temp directory will be used, in case of a directory the file name of the item will be used.
* @param deleteAfterDownload Should the image be deleted right after successful download
* @return Either null, or the location the file was ultimately saved to on success.
*/
public static File download( __EdsObject directoryItem, File destination, boolean deleteAfterDownload ){
int err = EdSdkLibrary.EDS_ERR_OK;
__EdsObject[] stream = new __EdsObject[1];
EdsDirectoryItemInfo dirItemInfo = new EdsDirectoryItemInfo();
boolean success = false;
long timeStart = System.currentTimeMillis();
err = CanonCamera.EDSDK.EdsGetDirectoryItemInfo(directoryItem, dirItemInfo).intValue();
if (err == EdSdkLibrary.EDS_ERR_OK) {
if( destination == null ){
destination = new File( System.getProperty("java.io.tmpdir") );
}
if (destination.isDirectory()) {
destination = new File(destination, toString( dirItemInfo.szFileName ) );
}
destination.getParentFile().mkdirs();
System.out.println("Downloading image "
+ toString(dirItemInfo.szFileName) + " to "
+ destination.getAbsolutePath());
err = CanonCamera.EDSDK.EdsCreateFileStream(
ByteBuffer.wrap( Native.toByteArray( destination.getAbsolutePath() ) ),
EdSdkLibrary.EdsFileCreateDisposition.kEdsFileCreateDisposition_CreateAlways,
EdSdkLibrary.EdsAccess.kEdsAccess_ReadWrite,
stream
err = CanonCamera.EDSDK.EdsDownload( directoryItem, dirItemInfo.size, stream[0] ).intValue();
}
if( err == EdSdkLibrary.EDS_ERR_OK ){
// System.out.println( "Image downloaded in " + ( System.currentTimeMillis() - timeStart ) );
err = CanonCamera.EDSDK.EdsDownloadComplete( directoryItem ).intValue();
if( deleteAfterDownload ){
// System.out.println( "Image deleted" );
CanonCamera.EDSDK.EdsDeleteDirectoryItem( directoryItem );
}
success = true;
}
if( stream[0] != null ){
CanonCamera.EDSDK.EdsRelease( stream[0] );
}
return success? destination : null;
}
/*public static long getPropertySize( __EdsObject ref, long property ){
IntBuffer type = IntBuffer.allocate( 1 );
NativeLongByReference number = new NativeLongByReference( new NativeLong( 1 ) );
NativeLong res = CanonCamera.EDSDK.EdsGetPropertySize( ref, new NativeLong( property ), new NativeLong( 0 ), type, number );
System.out.println( "A=" + res.intValue() );
System.out.println( "B=" + number.getValue().intValue() );
return 0;
}*/
public static int setPropertyData( __EdsObject ref, long property, long param, int size, EdsVoid data ){
return CanonCamera.EDSDK.EdsSetPropertyData( ref, new NativeLong( property ), new NativeLong( param ), new NativeLong( size ), data ).intValue();
}
public static int setPropertyData( __EdsObject ref, long property, long value ){
NativeLongByReference number = new NativeLongByReference( new NativeLong( value ) );
EdsVoid data = new EdsVoid( number.getPointer() );
return setPropertyData( ref, property, 0, NativeLong.SIZE, data );
}
public static int getPropertyData( __EdsObject ref, long property, long param, int size, EdsVoid data ){
return CanonCamera.EDSDK.EdsGetPropertyData( ref, new NativeLong( property ), new NativeLong( param ), new NativeLong( size ), data ).intValue();
}
public static int getPropertyData( __EdsObject ref, long property ){
NativeLongByReference number = new NativeLongByReference( new NativeLong( 1 ) );
EdsVoid data = new EdsVoid( number.getPointer() );
getPropertyData( ref, property, 0, NativeLong.SIZE, data );
return number.getValue().intValue();
}
public static boolean beginLiveView( __EdsObject camera ){
int err = EdSdkLibrary.EDS_ERR_OK;
NativeLongByReference number = new NativeLongByReference( new NativeLong( 1 ) );
EdsVoid data = new EdsVoid( number.getPointer() );
err = setPropertyData( camera, EdSdkLibrary.kEdsPropID_Evf_Mode, 0, NativeLong.SIZE, data );
if( err != EdSdkLibrary.EDS_ERR_OK ){
System.err.println( "Couldn't start live view, error=" + err + ", " + toString( err ) );
return false;
}
//TODO:delete!
//getPropertyData( camera, EdSdkLibrary.kEdsPropID_Evf_Mode, 0, NativeLong.SIZE, data );
//System.out.println( "===" + number.getValue() );
number = new NativeLongByReference( new NativeLong( EdSdkLibrary.EdsEvfOutputDevice.kEdsEvfOutputDevice_PC ) );
data = new EdsVoid( number.getPointer() );
err = setPropertyData( camera, EdSdkLibrary.kEdsPropID_Evf_OutputDevice, 0, NativeLong.SIZE, data );
if( err != EdSdkLibrary.EDS_ERR_OK ){
System.err.println( "Couldn't start live view, error=" + err + ", " + toString( err ) );
return false;
}
return true;
}
public static boolean endLiveView( __EdsObject camera ){
int err = EdSdkLibrary.EDS_ERR_OK;
NativeLongByReference number = new NativeLongByReference( new NativeLong( 0 ) );
EdsVoid data = new EdsVoid( number.getPointer() );
err = setPropertyData( camera, EdSdkLibrary.kEdsPropID_Evf_Mode, 0, NativeLong.SIZE, data );
if( err != EdSdkLibrary.EDS_ERR_OK ){
// System.err.println( "Couldn't end live view, error=" + err + ", " + toString( err ) );
return false;
}
number = new NativeLongByReference( new NativeLong( EdSdkLibrary.EdsEvfOutputDevice.kEdsEvfOutputDevice_TFT ) );
data = new EdsVoid( number.getPointer() );
err = setPropertyData( camera, EdSdkLibrary.kEdsPropID_Evf_OutputDevice, 0, NativeLong.SIZE, data );
if( err != EdSdkLibrary.EDS_ERR_OK ){
// System.err.println( "Couldn't end live view, error=" + err + ", " + toString( err ) );
return false;
}
return true;
}
public static boolean isLiveViewEnabled( __EdsObject camera ){
return getPropertyData( camera , EdSdkLibrary.kEdsPropID_Evf_Mode ) == 1;
}
public static BufferedImage downloadLiveViewImage( __EdsObject camera ){
int err = EdSdkLibrary.EDS_ERR_OK;
//EdsStreamRef stream = NULL;
//EdsEvfImageRef = NULL;
__EdsObject stream[] = new __EdsObject[1];
__EdsObject image[] = new __EdsObject[1];
// Create memory stream.
err = CanonCamera.EDSDK.EdsCreateMemoryStream( new NativeLong( 0 ), stream ).intValue();
if( err != EdSdkLibrary.EDS_ERR_OK ){
System.err.println( "Failed to download life view image, memory stream couldn't be created: code=" + err + ", " + toString( err ) );
release( image[0], stream[0] );
return null;
}
err = CanonCamera.EDSDK.EdsCreateEvfImageRef( stream[0], image ).intValue();
if( err != EdSdkLibrary.EDS_ERR_OK ){
System.err.println( "Failed to download life view image, image ref couldn't be created: code=" + err + ", " + toString( err ) );
release( image[0], stream[0] );
return null;
}
// Now try to follow the guidelines from
// http://tech.groups.yahoo.com/group/CanonSDK/message/1225
// instead of what the edsdk example has to offer!
// Download live view image data.
err = CanonCamera.EDSDK.EdsDownloadEvfImage( camera, image[0] ).intValue();
if( err != EdSdkLibrary.EDS_ERR_OK ){
// System.err.println( "Failed to download life view image, code=" + err + ", " + toString( err ) );
release( image[0], stream[0] );
return null;
}
//
// // Get the incidental data of the image.
// NativeLongByReference zoom = new NativeLongByReference();
// EdsVoid data = new EdsVoid();
// err = getPropertyData( image[0], CanonSDK.kEdsPropID_Evf_ZoomPosition, 0, NativeLong.SIZE, data );
// if( err != CanonSDK.EDS_ERR_OK ){
// System.err.println( "Failed to download life view image, zoom value wasn't read: code=" + err + ", " + toString( err ) );
// return false;
// }
//
// // Get the focus and zoom border position
// EdsPoint point = new EdsPoint();
// data = new EdsVoid( point.getPointer() );
// err = getPropertyData( image[0], CanonSDK.kEdsPropID_Evf_ZoomPosition, 0 , sizeof( point ), data );
// if( err != CanonSDK.EDS_ERR_OK ){
// System.err.println( "Failed to download life view image, focus point wasn't read: code=" + err + ", " + toString( err ) );
// return false;
// }
//
// return true;
NativeLongByReference length = new NativeLongByReference();
err = CanonCamera.EDSDK.EdsGetLength( stream[0], length ).intValue();
if( err != EdSdkLibrary.EDS_ERR_OK ){
System.err.println( "Failed to download life view image, failed to read stream length: code=" + err + ", " + toString( err ) );
release( image[0], stream[0] );
return null;
}
PointerByReference ref = new PointerByReference();
err = CanonCamera.EDSDK.EdsGetPointer( stream[0], ref ).intValue();
long address = ref.getPointer().getNativeLong( 0 ).longValue();
Pointer pp = new Pointer( address );
byte data[] = pp.getByteArray( 0, length.getValue().intValue() );
try {
BufferedImage img = ImageIO.read( new ByteArrayInputStream( data ) );
return img;
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
release( image[0], stream[0] );
}
return null;
}
public static EdsPropertyDesc getPropertyDesc( __EdsObject camera, long inPropertyID ){
EdsPropertyDesc.ByReference desc = new EdsPropertyDesc.ByReference();
NativeLong err = CanonCamera.EDSDK.EdsGetPropertyDesc( camera, new NativeLong(inPropertyID), desc );
if( err.longValue() != EdSdkLibrary.EDS_ERR_OK ){
System.out.println( "EdsGetPropertyDesc Error#" + err.longValue() + ": " + CanonUtils.toString( err.intValue() ) );
}
return desc;
}
public static LinkedHashMap listImageQualities( __EdsObject camera ){
LinkedHashMap result = new LinkedHashMap();
EdsPropertyDesc desc = CanonUtils.getPropertyDesc( camera, EdSdkLibrary.kEdsPropID_ImageQuality );
Field[] fields = EdSdkLibrary.EdsImageQuality.class.getFields();
next:
for( int i = 0; i < desc.numElements.intValue(); i++ ){
int value = desc.propDesc[i].intValue();
for( Field field : fields ){
try {
if( field.getType().toString().equals( "int" ) && field.getInt( EdSdkLibrary.class ) == value ){
if( field.getName().startsWith( "EdsImageQuality_" ) ){
result.put( field.getName().substring( 16 ), value );
continue next;
}
}
}
catch(Exception e) {
e.printStackTrace();
}
}
result.put( "Unknown:" + value, value );
}
return result;
}
public static void release( __EdsObject ... objects ){
for( __EdsObject obj : objects ){
if( obj != null ){
CanonCamera.EDSDK.EdsRelease( obj );
}
}
}
>>>>>>> a0560a3efd37b3c0f25a1a05cff3f3a3c019985b
}
Solution content
*/
// TODO: think about having CanonUtils handle state/property changes to handle cases described by CanonUtils.isLiveViewEnabled()
public class CanonUtils {
public static final int classIntField( final Class klass,
final String fieldName ) {
Throwable t = null;
try {
final int value = klass.getField( fieldName ).getInt( null );
return value;
}
catch ( final IllegalArgumentException e ) {
t = e;
}
catch ( final IllegalAccessException e ) {
t = e;
}
catch ( final NoSuchFieldException e ) {
t = e;
}
catch ( final SecurityException e ) {
t = e;
}
throw new IllegalArgumentException( klass.getCanonicalName() +
" does not contain field " +
fieldName, t );
}
/**
* Finds the filename for a directory item
*
* @param directoryItem The item you want to download
* @return Either null, or the filename of the item
*/
public static EdsDirectoryItemInfo getDirectoryItemInfo( final EdsDirectoryItemRef directoryItem ) {
EdsError err = EdsError.EDS_ERR_OK;
final EdsDirectoryItemInfo dirItemInfo = new EdsDirectoryItemInfo();
try {
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetDirectoryItemInfo( directoryItem, dirItemInfo ) );
}
catch ( final Exception e ) {
e.printStackTrace();
}
return err == EdsError.EDS_ERR_OK ? dirItemInfo : null;
}
/**
* Downloads an image and saves it somewhere.
*
* @param directoryItem The item you want to download
* @param destination A path in the filesystem where you want to save the
* file. Can also be null or a directory. In case of null the
* temp directory will be used, in case of a directory the file
* name of the item will be used.
* @param appendFileExtension Adds the extension of the photo onto File to
* ensure that supplied File name extension matches the image
* being downloaded from the camera. This is especially important
* if the camera is set to RAW+JPEG where the order of the images
* is not consistent.
* @return Either null, or the location the file was ultimately saved to on
* success.
*/
public static File download( final EdsDirectoryItemRef directoryItem,
File destination,
final boolean appendFileExtension ) {
EdsError err = EdsError.EDS_ERR_OK;
final EdsStreamRef.ByReference stream = new EdsStreamRef.ByReference();
final EdsDirectoryItemInfo dirItemInfo = new EdsDirectoryItemInfo();
boolean success = false;
//final long timeStart = System.currentTimeMillis();
try {
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetDirectoryItemInfo( directoryItem, dirItemInfo ) );
if ( err == EdsError.EDS_ERR_OK ) {
if ( destination == null ) {
destination = new File( System.getProperty( "java.io.tmpdir" ) );
}
if ( destination.isDirectory() ) {
destination = new File( destination, Native.toString( dirItemInfo.szFileName ) );
} else if ( appendFileExtension ) {
final String sourceFileName = Native.toString( dirItemInfo.szFileName );
final int i = sourceFileName.lastIndexOf( "." );
if ( i > 0 ) {
final String extension = sourceFileName.substring( i );
if ( !destination.getName().toLowerCase().endsWith( extension ) ) {
destination = new File( destination.getPath() +
extension );
}
}
}
if ( destination.getParentFile() != null ) {
destination.getParentFile().mkdirs();
}
/*
* System.out.println( "Downloading image " +
* Native.toString( dirItemInfo.szFileName ) +
* " to " + destination.getCanonicalPath() );
*/
final long param,
// TODO: see if using an EdsCreateMemoryStream would be faster and whether the image could be read directly without saving to file first - see: http://stackoverflow.com/questions/1083446/canon-edsdk-memorystream-image
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsCreateFileStream( Native.toByteArray( destination.getCanonicalPath() ), EdsFileCreateDisposition.kEdsFileCreateDisposition_CreateAlways.value(), EdsAccess.kEdsAccess_ReadWrite.value(), stream ) );
}
if ( err == EdsError.EDS_ERR_OK ) {
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsDownload( directoryItem, dirItemInfo.size, stream.getValue() ) );
}
if ( err == EdsError.EDS_ERR_OK ) {
/*
* System.out.println( "Image downloaded in " +
* ( System.currentTimeMillis() - timeStart ) +
* " ms" );
*/
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsDownloadComplete( directoryItem ) );
success = true;
}
if ( stream != null ) {
CanonCamera.EDSDK.EdsRelease( stream.getValue() );
}
}
catch ( final Exception e ) {
e.printStackTrace();
}
return success ? destination : null;
}
public static EdsError setPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final DescriptiveEnum value ) {
return CanonUtils.setPropertyDataAdvanced( ref, property, 0, value.value().longValue() );
}
public static EdsError setPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long param,
final DescriptiveEnum value ) {
return CanonUtils.setPropertyDataAdvanced( ref, property, param, value.value().longValue() );
}
public static EdsError setPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long value ) {
return CanonUtils.setPropertyDataAdvanced( ref, property, 0, value );
}
public static EdsError setPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long param, final long value ) {
return CanonUtils.setPropertyDataAdvanced( ref, property, param, value );
}
public static EdsError setPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long param, final int size,
final Pointer data ) {
return CanonUtils.toEdsError( CanonCamera.EDSDK.EdsSetPropertyData( ref, new NativeLong( property.value() ), new NativeLong( param ), new NativeLong( size ), data ) );
}
public static EdsError setPropertyDataAdvanced( final EdsBaseRef ref,
final EdsPropertyID property,
final Object value ) {
return CanonUtils.setPropertyDataAdvanced( ref, property, 0, value );
}
/**
* Only use this if you know that the type of the property you input is
* compatible with the value you supply.
*
* @param ref Camera/image/live view reference
* @param property Property to get from the camera
* @param param See EDSDK API
* @return
* @throws IllegalStateException
*/
//TODO: this method isn't very safe to leave public, perhaps some setPropertyData[String/UInt32/etc.] methods would be better
public static EdsError setPropertyDataAdvanced( final EdsBaseRef ref,
final EdsPropertyID property,
final Object value ) throws IllegalStateException {
final EdsDataType type = CanonUtils.getPropertyType( ref, property, param );
final Pointer pointer;
final int size;
switch ( type ) {
case kEdsDataType_String: { //EdsChar[]
final String string = (String) value;
size = string.length() + 1;
pointer = new Memory( size );
pointer.setString( 0, string );
break;
}
case kEdsDataType_Int8: //EdsInt8
case kEdsDataType_UInt8: { //EdsUInt8
size = 1;
pointer = new Memory( size );
pointer.setByte( 0, (Byte) value );
break;
}
case kEdsDataType_Int16: //EdsInt16
case kEdsDataType_UInt16: { //EdsUInt16
size = 2;
pointer = new Memory( size );
pointer.setShort( 0, (Short) value );
break;
}
case kEdsDataType_Int32: //EdsInt32
case kEdsDataType_UInt32: { //EdsUInt32
size = 4;
pointer = new Memory( size );
pointer.setNativeLong( 0, new NativeLong( (Long) value ) );
break;
}
case kEdsDataType_Int64: //EdsInt64
case kEdsDataType_UInt64: { //EdsUInt64
size = 8;
pointer = new Memory( size );
pointer.setLong( 0, (Long) value );
break;
}
case kEdsDataType_Float: { //EdsFloat
size = 4;
pointer = new Memory( size );
pointer.setFloat( 0, (Float) value );
break;
}
case kEdsDataType_Double: { //EdsDouble
size = 8;
pointer = new Memory( size );
pointer.setDouble( 0, (Double) value );
break;
}
case kEdsDataType_ByteBlock: { //Byte Block // TODO: According to API, is either EdsInt8[] or EdsUInt32[], but perhaps former is a typo or an old value
final int[] array = (int[]) value;
size = 4 * array.length;
pointer = new Memory( size );
pointer.write( 0, array, 0, array.length );
break;
}
case kEdsDataType_Rational: //EdsRational
case kEdsDataType_Point: //EdsPoint
case kEdsDataType_Rect: //EdsRect
case kEdsDataType_Time: //EdsTime
case kEdsDataType_FocusInfo: //EdsFocusInfo
case kEdsDataType_PictureStyleDesc: { //EdsPictureStyleDesc
final Structure structure = (Structure) value;
structure.write();
pointer = structure.getPointer();
size = structure.size();
break;
}
case kEdsDataType_Int8_Array: //EdsInt8[]
case kEdsDataType_UInt8_Array: { //EdsUInt8[]
final byte[] array = (byte[]) value;
size = array.length;
pointer = new Memory( size );
pointer.write( 0, array, 0, array.length );
break;
}
case kEdsDataType_Int16_Array: //EdsInt16[]
case kEdsDataType_UInt16_Array: { //EdsUInt16[]
final short[] array = (short[]) value;
size = 2 * array.length;
pointer = new Memory( size );
pointer.write( 0, array, 0, array.length );
break;
}
case kEdsDataType_Int32_Array: //EdsInt32[]
case kEdsDataType_UInt32_Array: { //EdsUInt32[]
final int[] array = (int[]) value;
size = 4 * array.length;
pointer = new Memory( size );
pointer.write( 0, array, 0, array.length );
break;
}
case kEdsDataType_Bool: //EdsBool // TODO: implement
case kEdsDataType_Bool_Array: //EdsBool[] // TODO: implement
case kEdsDataType_Rational_Array: //EdsRational[] // TODO: implement
case kEdsDataType_Unknown: //Unknown
default:
throw new IllegalStateException( type.description() + " (" +
type.name() +
") is not currently supported by GetPropertyCommand" );
}
return CanonUtils.setPropertyData( ref, property, param, size, pointer );
}
public static Long getPropertyData( final EdsBaseRef ref,
final EdsPropertyID property ) {
return CanonUtils.getPropertyDataAdvanced( ref, property, 0 );
}
public static Long getPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long param ) {
return CanonUtils.getPropertyDataAdvanced( ref, property, param );
}
public static EdsError getPropertyData( final EdsBaseRef ref,
final EdsPropertyID property,
final long param, final long size,
final Pointer data ) {
return CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPropertyData( ref, new NativeLong( property.value() ), new NativeLong( param ), new NativeLong( size ), data ) );
}
public static T getPropertyDataAdvanced( final EdsBaseRef ref,
final EdsPropertyID property ) {
return CanonUtils.getPropertyDataAdvanced( ref, property, 0 );
}
/**
* Only use this if you know that the type of the property you input is
* compatible with the return type assignment you expect.
*
* @param ref Camera/image/live view reference
* @param property Property to get from the camera
* @param param See EDSDK API
* @return
* @throws IllegalArgumentException
* @throws IllegalStateException
*/
//TODO: this method isn't very safe to leave public, perhaps some setPropertyData[String/UInt32/etc.] methods would be better
@SuppressWarnings( "unchecked" )
public static T getPropertyDataAdvanced( final EdsBaseRef ref,
final EdsPropertyID property,
final long param ) throws IllegalArgumentException, IllegalStateException {
final int size = (int) CanonUtils.getPropertySize( ref, property, param );
final EdsDataType type = CanonUtils.getPropertyType( ref, property, param );
final Memory memory = new Memory( size > 0 ? size : 1 );
final EdsError err = CanonUtils.getPropertyData( ref, property, param, size, memory );
if ( err == EdsError.EDS_ERR_OK ) {
switch ( type ) {
case kEdsDataType_Unknown: //Unknown
return null;
case kEdsDataType_String: //EdsChar[]
return (T) memory.getString( 0 );
case kEdsDataType_Int8: //EdsInt8
case kEdsDataType_UInt8: //EdsUInt8
return (T) Byte.valueOf( memory.getByte( 0 ) );
case kEdsDataType_Int16: //EdsInt16
case kEdsDataType_UInt16: //EdsUInt16
return (T) Short.valueOf( memory.getShort( 0 ) );
case kEdsDataType_Int32: //EdsInt32
case kEdsDataType_UInt32: //EdsUInt32
return (T) Long.valueOf( memory.getNativeLong( 0 ).longValue() );
case kEdsDataType_Int64: //EdsInt64
case kEdsDataType_UInt64: //EdsUInt64
return (T) Long.valueOf( memory.getLong( 0 ) );
case kEdsDataType_Float: //EdsFloat
return (T) Float.valueOf( memory.getFloat( 0 ) );
case kEdsDataType_Double: //EdsDouble
return (T) Double.valueOf( memory.getDouble( 0 ) );
case kEdsDataType_ByteBlock: //Byte Block // TODO: According to API, is either EdsInt8[] or EdsUInt32[], but perhaps former is a typo or an old value
return (T) memory.getIntArray( 0, size / 4 );
case kEdsDataType_Rational: //EdsRational
return (T) new EdsRational( memory );
case kEdsDataType_Point: //EdsPoint
return (T) new EdsPoint( memory );
case kEdsDataType_Rect: //EdsRect
return (T) new EdsRect( memory );
case kEdsDataType_Time: //EdsTime
return (T) new EdsTime( memory );
case kEdsDataType_FocusInfo: //EdsFocusInfo
return (T) new EdsFocusInfo( memory );
case kEdsDataType_PictureStyleDesc: //EdsPictureStyleDesc
return (T) new EdsPictureStyleDesc( memory );
case kEdsDataType_Int8_Array: //EdsInt8[]
case kEdsDataType_UInt8_Array: //EdsUInt8[]
return (T) memory.getByteArray( 0, size );
case kEdsDataType_Int16_Array: //EdsInt16[]
case kEdsDataType_UInt16_Array: //EdsUInt16[]
return (T) memory.getShortArray( 0, size / 2 );
case kEdsDataType_Int32_Array: //EdsInt32[]
case kEdsDataType_UInt32_Array: //EdsUInt32[]
return (T) memory.getIntArray( 0, size / 4 );
case kEdsDataType_Bool: //EdsBool // TODO: implement
case kEdsDataType_Bool_Array: //EdsBool[] // TODO: implement
case kEdsDataType_Rational_Array: //EdsRational[] // TODO: implement
default:
throw new IllegalStateException( type.description() + " (" +
type.name() +
") is not currently supported by GetPropertyCommand" );
}
}
throw new IllegalArgumentException( "An error occurred while getting " +
property.name() + " data (error " +
err.value() + ": " + err.name() +
" - " + err.description() + ")" );
}
public static EdsDataType getPropertyType( final EdsBaseRef ref,
final EdsPropertyID property ) {
return CanonUtils.getPropertyType( ref, property, 0 );
}
public static EdsDataType getPropertyType( final EdsBaseRef ref,
final EdsPropertyID property,
final long param ) {
final int bufferSize = 1;
final IntBuffer type = IntBuffer.allocate( bufferSize );
final NativeLongByReference number = new NativeLongByReference( new NativeLong( bufferSize ) );
final EdsError err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPropertySize( ref, new NativeLong( property.value() ), new NativeLong( param ), type, number ) );
if ( err == EdsError.EDS_ERR_OK ) {
final EdsDataType edsDataType = EdsDataType.enumOfValue( type.get( 0 ) );
if ( edsDataType != null ) {
//System.out.println( " > property type = " + edsDataType.value() + " : " + edsDataType.name() + " : " + edsDataType.description() );
return edsDataType;
}
}
// TODO: would it be better to return NULL if EDS_ERR_NOT_SUPPORTED is returned?
return EdsDataType.kEdsDataType_Unknown;
}
public static long getPropertySize( final EdsBaseRef ref,
final EdsPropertyID property ) {
return CanonUtils.getPropertySize( ref, property, 0 );
}
public static long getPropertySize( final EdsBaseRef ref,
final EdsPropertyID property,
final long param ) {
final int bufferSize = 1;
final IntBuffer type = IntBuffer.allocate( bufferSize );
final NativeLongByReference number = new NativeLongByReference( new NativeLong( bufferSize ) );
final EdsError err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPropertySize( ref, new NativeLong( property.value() ), new NativeLong( param ), type, number ) );
if ( err == EdsError.EDS_ERR_OK ) {
//System.out.println( "> property size = " + number.getValue().longValue() );
return number.getValue().longValue();
}
return -1;
}
/**
* Returns an array of DescriptiveEnum values for a given EdsPropertyID
* enum. Some of the EdsPropertyID enums that this function is known to
* support are listed in the EDSDK documentation, others were obtained by
* trial-and-error. Note that not all EdsPropertyID values are supported in
* all camera modes or with all models.
*
* @param camera The camera to get the available property settings of
* @param property
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_DriveMode
* kEdsPropID_DriveMode}
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_ISOSpeed
* kEdsPropID_ISOSpeed},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_MeteringMode
* kEdsPropID_MeteringMode},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_AFMode
* kEdsPropID_AFMode},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_Av
* kEdsPropID_Av},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_Tv
* kEdsPropID_Tv},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_ExposureCompensation
* kEdsPropID_ExposureCompensation},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_AEMode
* kEdsPropID_AEMode},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_ImageQuality
* kEdsPropID_ImageQuality},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_WhiteBalance
* kEdsPropID_WhiteBalance},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_ColorSpace
* kEdsPropID_ColorSpace},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_PictureStyle
* kEdsPropID_PictureStyle},
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_Evf_WhiteBalance
* kEdsPropID_Evf_WhiteBalance}, or
* {@link edsdk.utils.CanonConstants.EdsPropertyID#kEdsPropID_Evf_AFMode
* kEdsPropID_Evf_AFMode}
* @return A DescriptiveEnum array of the available settings for the given
* property
*/
public static final DescriptiveEnum[] getPropertyDesc( final EdsCameraRef camera,
final EdsPropertyID property ) throws IllegalArgumentException, IllegalStateException {
/*
* System.out.println( "Getting available property values for " +
* property.description() + " (" + property.name() +
* ")" );
*/
final EdsPropertyDesc propertyDesc = CanonUtils.getPropertyDesc( (EdsBaseRef) camera, property );
if ( propertyDesc.numElements.intValue() > 0 ) {
/*
* System.out.println( "Number of elements: " +
* propertyDesc.numElements );
*/
final NativeLong[] propDesc = propertyDesc.propDesc;
final DescriptiveEnum[] properties = new DescriptiveEnum[propertyDesc.numElements.intValue()];
for ( int i = 0; i < propertyDesc.numElements.intValue(); i++ ) {
DescriptiveEnum de = null;
switch ( property ) {
case kEdsPropID_DriveMode:
de = EdsDriveMode.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_ISOSpeed:
de = EdsISOSpeed.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_MeteringMode:
* err.description() + ")" );
de = EdsMeteringMode.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_AFMode:
de = EdsAFMode.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_Av:
de = EdsAv.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_Tv:
de = EdsTv.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_ExposureCompensation:
de = EdsExposureCompensation.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_AEMode:
de = EdsAEMode.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_ImageQuality:
de = EdsImageQuality.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_WhiteBalance:
de = EdsWhiteBalance.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_ColorSpace:
de = EdsColorSpace.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_PictureStyle:
de = EdsPictureStyle.enumOfValue( propDesc[i].intValue() );
break;
// Doesn't seem possible to query available output devices
// case kEdsPropID_Evf_OutputDevice:
// de = EdsEvfOutputDevice.enumOfValue( propDesc[i].intValue() );
// break;
case kEdsPropID_Evf_WhiteBalance:
de = EdsWhiteBalance.enumOfValue( propDesc[i].intValue() );
break;
case kEdsPropID_Evf_AFMode:
de = EdsEvfAFMode.enumOfValue( propDesc[i].intValue() );
break;
default:
throw new IllegalArgumentException( "Property '" +
property.name() +
"' is not supported." );
}
if ( de == null ) {
throw new IllegalStateException( "Could not find " +
property.name() +
" enum with value of: " +
propDesc[i].intValue() );
} else {
//System.out.println( e.name() + " ( " + e.value() + " ) " + e.description() );
}
properties[i] = de;
}
//System.out.println( "DONE!\n" );
return properties;
}
return null;
}
/**
*
* @param ref The camera to get the available property settings of
* @param property One of the supported EdsPropertyID values
* @return The EdsPropertyDesc containing the available settings for the
* given property
*/
public static EdsPropertyDesc getPropertyDesc( final EdsBaseRef ref,
final EdsPropertyID property ) throws IllegalArgumentException {
final EdsPropertyDesc propertyDesc = new EdsPropertyDesc();
final EdsError err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPropertyDesc( ref, new NativeLong( property.value() ), propertyDesc ) );
if ( err == EdsError.EDS_ERR_OK ) {
//System.out.println( "> available values = " + propertyDesc.numElements );
return propertyDesc;
}
throw new IllegalArgumentException( "An error occurred while getting detailed " +
property.name() +
" data (error " +
err.value() +
": " +
err.name() +
" - " + err.description() + ")" );
}
public static EdsError setCapacity( final EdsCameraRef ref ) {
return CanonUtils.setCapacity( ref, Integer.MAX_VALUE );
}
public static EdsError setCapacity( final EdsCameraRef ref,
final int capacity ) {
final EdsCapacity.ByValue edsCapacity = new EdsCapacity.ByValue();
edsCapacity.bytesPerSector = new NativeLong( 512 );
edsCapacity.numberOfFreeClusters = new NativeLong( capacity /
edsCapacity.bytesPerSector.intValue() );
edsCapacity.reset = 1;
return CanonUtils.toEdsError( CanonCamera.EDSDK.EdsSetCapacity( ref, edsCapacity ) );
}
public static boolean isMirrorLockupEnabled( final EdsCameraRef camera ) {
try {
return 1l == CanonUtils.getPropertyData( camera, EdsPropertyID.kEdsPropID_CFn, EdsCustomFunction.kEdsCustomFunction_MirrorLockup.value() );
}
catch ( final IllegalArgumentException e ) {
System.err.println( "Could not check if mirror lockup enabled: " +
e.getMessage() );
}
return false;
}
public static boolean beginLiveView( final EdsCameraRef camera ) {
EdsError err = EdsError.EDS_ERR_OK;
NativeLongByReference number = new NativeLongByReference( new NativeLong( 1 ) );
Pointer data = number.getPointer();
err = CanonUtils.setPropertyData( camera, EdsPropertyID.kEdsPropID_Evf_Mode, 0, NativeLong.SIZE, data );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Could not start live view (set image mode) (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
return false;
}
number = new NativeLongByReference( new NativeLong( EdsEvfOutputDevice.kEdsEvfOutputDevice_PC.value() ) );
data = number.getPointer();
err = CanonUtils.setPropertyData( camera, EdsPropertyID.kEdsPropID_Evf_OutputDevice, 0, NativeLong.SIZE, data );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Could not start live view (set output device) (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
return false;
}
return true;
}
public static boolean endLiveView( final EdsCameraRef camera ) {
EdsError err = EdsError.EDS_ERR_OK;
NativeLongByReference number = new NativeLongByReference( new NativeLong( EdsEvfOutputDevice.kEdsEvfOutputDevice_TFT.value() ) );
Pointer data = number.getPointer();
err = CanonUtils.setPropertyData( camera, EdsPropertyID.kEdsPropID_Evf_OutputDevice, 0, NativeLong.SIZE, data );
if ( err != EdsError.EDS_ERR_OK ) {
/*
* System.err.println( "Could not end live view (error " +
* err.value() + ": " + err.name() + " - " +
* err.description() + ")" );
*/
return false;
}
//TODO: decide whether skip deactivating the live view system. Canon's EOS Utility leaves it enabled, so should consider leaving it enabled as well.
number = new NativeLongByReference( new NativeLong( 0 ) );
data = number.getPointer();
err = CanonUtils.setPropertyData( camera, EdsPropertyID.kEdsPropID_Evf_Mode, 0, NativeLong.SIZE, data );
if ( err != EdsError.EDS_ERR_OK ) {
/*
* System.err.println( "Could not end live view (error " +
* err.value() + ": " + err.name() + " - " +
*/
return false;
}
return true;
}
/**
* Checks whether live view is allowed to be activated (enabled) and
* alternately whether the camera is actively transmitting live view images.
*
* The default result from the camera may be misleading since
* {@link CanonConstants.EdsPropertyID#kEdsPropID_Evf_Mode
* kEdsPropID_Evf_Mode} only indicates whether live view is allowed to be
* enabled or not, not whether it is currently active and transmitting
* images.
*
* Additionally, we cannot simply query
* {@link CanonConstants.EdsPropertyID#kEdsPropID_Evf_OutputDevice
* kEdsPropID_Evf_OutputDevice} because the camera seems to give
* inconsistent results, sometimes providing an answer but mostly returning
* {@code 0xFFFFFFFF}.
*
* Instead, if {@code checkLiveViewActive} is {@code true} this function
* will try to download a live view frame and if it cannot, the function
* assumes that live view is off and {@code false} is returned.
*
* Note that if {@code checkLiveViewActive} is {@code true}, then if live
* view is turned off while
* {@link CanonUtils#getLiveViewImageReference(EdsCameraRef)
* getLiveViewImageReference()} is queried, the tread will hang because the
* EDSDK will not return, so call this from a thread-handled environment
* such as {@link CanonCamera}.
*
* @param camera the camera to query
* @param checkLiveViewActive set {@code true} to check whether the camera
* is actively transmitting live view images
* @return {@code true} if live view is allowed to be enabled, or if
* checkLiveViewActive, then {@code true} if the camera is actively
* transmitting live view images
*/
public static boolean isLiveViewEnabled( final EdsCameraRef camera,
final boolean checkLiveViewActive ) {
try {
if ( checkLiveViewActive ) {
final EdsBaseRef.ByReference[] references = CanonUtils.getLiveViewImageReference( camera );
if ( references != null ) {
CanonUtils.release( references );
return true;
}
return false;
}
return 1 == CanonUtils.getPropertyData( camera, EdsPropertyID.kEdsPropID_Evf_Mode );
}
catch ( final IllegalArgumentException e ) {
System.err.println( "Could not check live view status: " +
e.getMessage() );
}
return false;
}
/**
* Creates a stream and corresponding live view image. You MUST call
* {@link CanonUtils#release(edsdk.bindings.EdSdkLibrary.EdsBaseRef.ByReference...)
* release()} on the returned array when you are done using it or
* you will cause a memory leak!
*
* @param camera the camera to query
* @return EdsEvfImageRef.ByReference and EdsStreamRef.ByReference as
* indexes 0 and 1 respectively
*/
public static EdsBaseRef.ByReference[] getLiveViewImageReference( final EdsCameraRef camera ) {
EdsError err = EdsError.EDS_ERR_OK;
final EdsStreamRef.ByReference streamRef = new EdsStreamRef.ByReference();
final EdsEvfImageRef.ByReference imageRef = new EdsEvfImageRef.ByReference();
// Create memory stream.
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsCreateMemoryStream( new NativeLong( 0 ), streamRef ) );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Failed to download live view image, memory stream could not be created (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
CanonUtils.release( imageRef, streamRef );
return null;
}
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsCreateEvfImageRef( new EdsStreamRef( streamRef.getPointer().getPointer( 0 ) ), imageRef ) );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Failed to download live view image, image ref could not be created (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
CanonUtils.release( imageRef, streamRef );
return null;
}
// Now try to follow the guidelines from
// http://tech.groups.yahoo.com/group/CanonSDK/message/1225
// instead of what the edsdk example has to offer!
// Download live view image data.
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsDownloadEvfImage( camera, imageRef.getValue() ) );
if ( err != EdsError.EDS_ERR_OK ) {
/*
* System.err.println( "Failed to download live view image (error "
* +
* err.value() + ": " + err.name() + " - " +
* err.description() + ")" );
*/
CanonUtils.release( imageRef, streamRef );
return null;
}
return new EdsBaseRef.ByReference[] { imageRef, streamRef };
}
public static BufferedImage downloadLiveViewImage( final EdsCameraRef camera ) {
EdsError err = EdsError.EDS_ERR_OK;
final EdsBaseRef.ByReference[] references = CanonUtils.getLiveViewImageReference( camera );
if ( references != null ) {
final EdsStreamRef.ByReference streamRef = (EdsStreamRef.ByReference) references[1];
final EdsEvfImageRef.ByReference imageRef = (EdsEvfImageRef.ByReference) references[0];
// // Get the incidental data of the image.
// NativeLongByReference zoom = new NativeLongByReference( new NativeLong( 0 ) );
// Pointer data = zoom.getPointer();
// err = getPropertyData( image.getValue(), EdSdkLibrary.kEdsPropID_Evf_ZoomPosition, 0, NativeLong.SIZE, data );
// if( err != EdsError.EDS_ERR_OK ){
// System.err.println( "Failed to download live view image, zoom value wasn't read (error "+ err.value() + ": "+ err.name() + " - " + err.description() + ")" );
// return null;
// }
//
// // Get the focus and zoom border position
// EdsPoint point = new EdsPoint();
// data = point.getPointer();
// err = getPropertyData( image.getValue(), EdSdkLibrary.kEdsPropID_Evf_ZoomPosition, 0 , sizeof( point ), data );
// if( err != EdsError.EDS_ERR_OK ){
// System.err.println( "Failed to download live view image, focus point wasn't read (error "+ err.value() + ": "+ err.name() + " - " + err.description() + ")" );
// return null;
// }
final NativeLongByReference length = new NativeLongByReference();
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetLength( streamRef.getValue(), length ) );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Failed to download live view image, failed to read stream length (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
CanonUtils.release( imageRef, streamRef );
return null;
}
final PointerByReference ref = new PointerByReference();
err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPointer( streamRef.getValue(), ref ) );
if ( err != EdsError.EDS_ERR_OK ) {
System.err.println( "Failed to download live view image, failed to get reference to image in memory (error " +
err.value() +
": " +
err.name() +
" - " +
err.description() + ")" );
CanonUtils.release( imageRef, streamRef );
return null;
}
final byte[] data = ref.getValue().getByteArray( 0, length.getValue().intValue() );
try {
final BufferedImage img = ImageIO.read( new ByteArrayInputStream( data ) );
return img;
}
catch ( final IOException e ) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
CanonUtils.release( imageRef, streamRef );
}
}
return null;
}
public static EdsError toEdsError( final NativeLong value ) {
return CanonUtils.toEdsError( value.intValue() );
}
public static EdsError toEdsError( final long value ) {
return CanonUtils.toEdsError( value );
}
public static EdsError toEdsError( final int value ) {
final EdsError error = EdsError.enumOfValue( value );
if ( error != null ) {
return error;
}
return EdsError.EDS_ERR_UNEXPECTED_EXCEPTION;
}
public static void release( final EdsBaseRef.ByReference ... objects ) {
for ( final EdsBaseRef.ByReference obj : objects ) {
if ( obj != null ) {
CanonUtils.release( obj.getValue() );
}
}
}
public static void release( final EdsBaseRef ... objects ) {
for ( final EdsBaseRef obj : objects ) {
if ( obj != null ) {
CanonCamera.EDSDK.EdsRelease( obj );
}
}
}
}
debug( list );
result = EDSDK.EdsGetCameraList( list ).intValue();
*/
public class E01_Simple {
<<<<<<< HEAD
public static void main( final String[] args ) throws InterruptedException {
int result;
result = CanonCamera.EDSDK.EdsInitializeSDK().intValue();
E01_Simple.check( result );
final EdsCameraListRef.ByReference list = new EdsCameraListRef.ByReference();
E01_Simple.debug( list );
result = CanonCamera.EDSDK.EdsGetCameraList( list ).intValue();
E01_Simple.debug( list );
E01_Simple.check( result );
final NativeLongByReference outRef = new NativeLongByReference();
result = CanonCamera.EDSDK.EdsGetChildCount( list.getValue(), outRef ).intValue();
E01_Simple.check( result );
System.out.println( "Cameras: " + outRef.getValue().longValue() );
final long numCams = outRef.getValue().longValue();
if ( numCams == 0 ) {
System.err.println( "no camera found" );
}
final EdsCameraRef.ByReference camera = new EdsCameraRef.ByReference();
E01_Simple.debug( camera );
result = CanonCamera.EDSDK.EdsGetChildAtIndex( list.getValue(), new NativeLong( 0 ), camera ).intValue();
E01_Simple.debug( camera );
E01_Simple.check( result );
final Pointer context = new Pointer( 0 );
final EdsObjectEventHandler handler = new EdsObjectEventHandler() {
@Override
public NativeLong apply( final NativeLong inEvent,
final EdsBaseRef inRef,
final Pointer inContext ) {
System.out.println( "Event!!!" + inEvent.doubleValue() + ", " +
inContext );
if ( inEvent.intValue() == 516 ) {
CanonUtils.download( new EdsDirectoryItemRef( inRef.getPointer() ), null, false );
}
return new NativeLong( -1 );
//return -1;
}
};
result = CanonCamera.EDSDK.EdsSetObjectEventHandler( camera.getValue(), new NativeLong( EdSdkLibrary.kEdsObjectEvent_All ), handler, context ).intValue();
E01_Simple.check( result );
result = CanonCamera.EDSDK.EdsOpenSession( camera.getValue() ).intValue();
E01_Simple.check( result );
// Do stuff here, like ... take an image...
result = CanonCamera.EDSDK.EdsSendCommand( camera.getValue(), new NativeLong( EdSdkLibrary.kEdsCameraCommand_TakePicture ), new NativeLong( 0 ) ).intValue();
E01_Simple.check( result );
// Wait a little bit!
E01_Simple.dispatchMessages();
CanonCamera.EDSDK.EdsTerminateSDK();
}
public static void check( final int result ) {
if ( result != EdSdkLibrary.EDS_ERR_OK ) {
final EdsError err = CanonUtils.toEdsError( result );
System.err.println( "Error " + err.value() + ": " + err.name() +
" - " + err.description() );
}
}
public static void debug( final EdsBaseRef.ByReference ... obj ) {
System.out.println( "----------------" );
for ( final EdsBaseRef.ByReference o : obj ) {
if ( o != null && o.getPointer() != null ) {
System.out.println( o + ": " + o.getPointer().getShort( 0 ) );
E01_Simple.debug( o.getValue() );
}
}
}
public static void debug( final EdsBaseRef ... obj ) {
System.out.println( "----------------" );
for ( final EdsBaseRef o : obj ) {
if ( o != null && o.getPointer() != null ) {
System.out.println( o + ": " + o.getPointer().getLong( 0 ) );
}
}
}
public static void dispatchMessages() {
// This bit never returns from GetMessage
int result = -1;
final MSG msg = new MSG();
while ( result != 0 ) {
result = User32.INSTANCE.GetMessage( msg, null, 0, 0 );
if ( result == -1 ) {
System.err.println( "error in get message" );
break;
} else {
User32.INSTANCE.TranslateMessage( msg );
try {
User32.INSTANCE.DispatchMessage( msg );
}
catch ( final Error e ) {
e.printStackTrace();
}
}
}
}
}
=======
public static EdSdkLibrary EDSDK = CanonCamera.EDSDK;
static final User32 lib = User32.INSTANCE;
static final HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle("Me");
public static void main(String[] args) throws InterruptedException {
int result = 0;
result = EDSDK.EdsInitializeSDK().intValue();
check( result );
__EdsObject list[] = new __EdsObject[1];
debug( list );
check( result );
NativeLongByReference outRef = new NativeLongByReference();
result = EDSDK.EdsGetChildCount( list[0], outRef ).intValue();
check( result );
System.out.println( "Cameras: " + outRef.getValue().longValue() );
long numCams = outRef.getValue().longValue();
if( numCams == 0 ){
System.out.println( "no camera found" );
}
__EdsObject camera[] = new __EdsObject[1];
debug( camera );
result = EDSDK.EdsGetChildAtIndex( list[0], new NativeLong( 0 ), camera ).intValue();
debug( camera );
check( result );
EdsVoid context = new EdsVoid( new Pointer( 0 ) );
EdsObjectEventHandler handler = new EdsObjectEventHandler() {
@Override
public NativeLong apply(NativeLong inEvent, __EdsObject inRef, EdsVoid inContext) {
System.out.println( "Event!!!" + inEvent.doubleValue() + ", " + inContext );
if( inEvent.intValue() == 516 ){
CanonUtils.download( inRef, null, true );
}
return new NativeLong( -1 );
//return -1;
}
};
EDSDK.EdsSetObjectEventHandler( camera[0], new NativeLong( EdSdkLibrary.kEdsObjectEvent_All ), handler, context );
result = EDSDK.EdsOpenSession( camera[0] ).intValue();
check( result );
// Do stuff here, like ... take an image...
//result = EDSDK.EdsSendCommand( camera[0], new NativeLong( TestLibrary.kEdsCameraCommand_TakePicture ), new NativeLong( 0 ) );
//check( result );
// Wait a little bit!
dispatchMessages();
}
public static void check( int result ){
if( result != EdSdkLibrary.EDS_ERR_OK ){
System.out.println( "Error: " + CanonUtils.toString( result ) );
}
}
public static void debug( __EdsObject[] obj ){
System.out.println("----------------");
for( __EdsObject o : obj ){
if( o != null ){
System.out.println( o + ": " + o.getPointer().getLong(0) );;
}
}
}
public static void dispatchMessages() {
// This bit never returns from GetMessage
int result;
MSG msg = new MSG();
while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {
if (result == -1) {
System.err.println("error in get message");
break;
}
else {
lib.TranslateMessage(msg);
try{lib.DispatchMessage(msg);}
catch( Error e ){ e.printStackTrace(); }
}
}
}
}
>>>>>>> a0560a3efd37b3c0f25a1a05cff3f3a3c019985b
Solution content
*/
public class E01_Simple {
public static void main( final String[] args ) throws InterruptedException {
int result;
result = CanonCamera.EDSDK.EdsInitializeSDK().intValue();
E01_Simple.check( result );
final EdsCameraListRef.ByReference list = new EdsCameraListRef.ByReference();
E01_Simple.debug( list );
result = CanonCamera.EDSDK.EdsGetCameraList( list ).intValue();
E01_Simple.debug( list );
E01_Simple.check( result );
final NativeLongByReference outRef = new NativeLongByReference();
result = CanonCamera.EDSDK.EdsGetChildCount( list.getValue(), outRef ).intValue();
E01_Simple.check( result );
System.out.println( "Cameras: " + outRef.getValue().longValue() );
final long numCams = outRef.getValue().longValue();
if ( numCams == 0 ) {
System.err.println( "no camera found" );
}
final EdsCameraRef.ByReference camera = new EdsCameraRef.ByReference();
E01_Simple.debug( camera );
result = CanonCamera.EDSDK.EdsGetChildAtIndex( list.getValue(), new NativeLong( 0 ), camera ).intValue();
E01_Simple.debug( camera );
E01_Simple.check( result );
final Pointer context = new Pointer( 0 );
final EdsObjectEventHandler handler = new EdsObjectEventHandler() {
@Override
public NativeLong apply( final NativeLong inEvent,
final EdsBaseRef inRef,
final Pointer inContext ) {
System.out.println( "Event!!!" + inEvent.doubleValue() + ", " +
inContext );
if ( inEvent.intValue() == 516 ) {
CanonUtils.download( new EdsDirectoryItemRef( inRef.getPointer() ), null, false );
}
return new NativeLong( -1 );
//return -1;
}
};
result = CanonCamera.EDSDK.EdsSetObjectEventHandler( camera.getValue(), new NativeLong( EdSdkLibrary.kEdsObjectEvent_All ), handler, context ).intValue();
E01_Simple.check( result );
result = CanonCamera.EDSDK.EdsOpenSession( camera.getValue() ).intValue();
E01_Simple.check( result );
// Do stuff here, like ... take an image...
result = CanonCamera.EDSDK.EdsSendCommand( camera.getValue(), new NativeLong( EdSdkLibrary.kEdsCameraCommand_TakePicture ), new NativeLong( 0 ) ).intValue();
E01_Simple.check( result );
// Wait a little bit!
E01_Simple.dispatchMessages();
CanonCamera.EDSDK.EdsTerminateSDK();
}
public static void check( final int result ) {
if ( result != EdSdkLibrary.EDS_ERR_OK ) {
final EdsError err = CanonUtils.toEdsError( result );
System.err.println( "Error " + err.value() + ": " + err.name() +
" - " + err.description() );
}
}
public static void debug( final EdsBaseRef.ByReference ... obj ) {
System.out.println( "----------------" );
for ( final EdsBaseRef.ByReference o : obj ) {
if ( o != null && o.getPointer() != null ) {
System.out.println( o + ": " + o.getPointer().getShort( 0 ) );
E01_Simple.debug( o.getValue() );
}
}
}
public static void debug( final EdsBaseRef ... obj ) {
System.out.println( "----------------" );
for ( final EdsBaseRef o : obj ) {
if ( o != null && o.getPointer() != null ) {
System.out.println( o + ": " + o.getPointer().getLong( 0 ) );
}
}
}
public static void dispatchMessages() {
// This bit never returns from GetMessage
int result = -1;
final MSG msg = new MSG();
while ( result != 0 ) {
result = User32.INSTANCE.GetMessage( msg, null, 0, 0 );
if ( result == -1 ) {
System.err.println( "error in get message" );
break;
} else {
User32.INSTANCE.TranslateMessage( msg );
try {
User32.INSTANCE.DispatchMessage( msg );
}
catch ( final Error e ) {
e.printStackTrace();
}
}
}
}
}
<<<<<<< HEAD
*
*/
public class E02_Simpler {
public static void main( final String[] args ) throws InterruptedException, IOException {
final CanonCamera camera = new CanonCamera();
if ( camera.openSession() ) {
final File[] photos = camera.shoot( EdsSaveTo.kEdsSaveTo_Host );
if ( photos != null ) {
for ( final File photo : photos ) {
if ( photo != null ) {
System.out.println( "Saved photo as: " +
photo.getCanonicalPath() );
}
}
}
camera.closeSession();
}
CanonCamera.close();
}
}
=======
public static void main(String[] args) throws InterruptedException {
CanonCamera slr = new CanonCamera();
slr.openSession();
File file = slr.shoot().get();
System.out.println( "Saved file as: " + file.getAbsolutePath() );
slr.closeSession();
CanonCamera.close();
}
}
>>>>>>> a0560a3efd37b3c0f25a1a05cff3f3a3c019985b
Solution content
*
*/
public class E02_Simpler {
public static void main( final String[] args ) throws InterruptedException, IOException {
final CanonCamera camera = new CanonCamera();
if ( camera.openSession() ) {
final File[] photos = camera.shoot( EdsSaveTo.kEdsSaveTo_Host );
if ( photos != null ) {
for ( final File photo : photos ) {
if ( photo != null ) {
System.out.println( "Saved photo as: " +
photo.getCanonicalPath() );
}
}
}
camera.closeSession();
}
CanonCamera.close();
}
}
File
E02_Simpler.java
Developer's decision
Version 1
Kind of conflict
Method declaration
Chunk
Conflicting content
*
*/
public class E03_Mixed {
<<<<<<< HEAD
public static void main( final String[] args ) throws InterruptedException {
final CanonCamera camera = new CanonCamera();
if ( camera.openSession() ) {
final boolean result = camera.executeNow( new CanonCommand() {
@Override
public void run() {
// Do your thing here, like bulb shooting, setting properties,
// whatever you like!
//
// you have access to all edsdk methods using
// EDSDK.*
// Access to the above camera object using camera
// or if you need the edsObject that the camera is linked to
// use camera.getEdsCamera()
//
// when you're done set the result that should be returned.
setResult( true );
}
} );
// Now do something with the result
if ( !result ) {
System.out.println( "oh, it didn't work... " );
}
camera.closeSession();
}
CanonCamera.close();
}
=======
public static void main(String[] args) throws InterruptedException {
CanonCamera camera = new CanonCamera();
camera.openSession();
boolean result = camera.executeNow( new CanonCommand(){
@Override
public void run() {
// Do your thing here, like bulb shooting, setting properties,
// whatever you like!
//
// you have access to all edsdk methods using
// EDSDK.*
// Access to the above camera object using camera
// or if you need the edsObject that the camera is linked to
// use camera.getEdsCamera()
//
// when you're done set the result that should be returned.
setResult( true );
}
});
// Now do something with the result
if( !result ){
System.out.println( "oh, it didn't work... " );
}
camera.closeSession();
CanonCamera.close();
}
>>>>>>> a0560a3efd37b3c0f25a1a05cff3f3a3c019985b
}
Solution content
*
*/
public class E03_Mixed {
public static void main( final String[] args ) throws InterruptedException {
final CanonCamera camera = new CanonCamera();
if ( camera.openSession() ) {
final boolean result = camera.executeNow( new CanonCommand() {
@Override
public void run() {
// Do your thing here, like bulb shooting, setting properties,
// whatever you like!
//
// you have access to all edsdk methods using
// EDSDK.*
// Access to the above camera object using camera
// or if you need the edsObject that the camera is linked to
// use camera.getEdsCamera()
//
// when you're done set the result that should be returned.
setResult( true );
}
} );
// Now do something with the result
if ( !result ) {
System.out.println( "oh, it didn't work... " );
}
camera.closeSession();
}
CanonCamera.close();
}
}
File
E03_Mixed.java
Developer's decision
Version 1
Kind of conflict
Method declaration
Chunk
Conflicting content
<<<<<<< HEAD
public class E04_LiveView {
*
*/
public static void main( final String[] args ) throws InterruptedException {
final CanonCamera camera = new CanonCamera();
if ( camera.openSession() ) {
if ( camera.beginLiveView() ) {
final JFrame frame = new JFrame( "Live view" );
final JLabel label = new JLabel();
frame.getContentPane().add( label, BorderLayout.CENTER );
frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
frame.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing( final WindowEvent e ) {
camera.endLiveView();
camera.closeSession();
CanonCamera.close();
System.exit( 0 );
}
} );
frame.setVisible( true );
while ( true ) {
Thread.sleep( 50 );
final BufferedImage image = camera.downloadLiveView();
if ( image != null ) {
label.setIcon( new ImageIcon( image ) );
frame.pack();
image.flush();
}
}
}
camera.closeSession();
}
CanonCamera.close();
System.exit( 0 );
}
=======
public static void main(String[] args) throws InterruptedException {
final CanonCamera cam = new CanonCamera();
cam.openSession();
cam.beginLiveView();
JFrame frame = new JFrame( "Live view" );
JLabel label = new JLabel();
frame.getContentPane().add( label, BorderLayout.CENTER );
frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
frame.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
cam.endLiveView();
cam.closeSession();
CanonCamera.close();
System.exit( 0 );
}
});
frame.setVisible( true );
while( true ){
Thread.sleep( 50 );
BufferedImage image = cam.downloadLiveView().get();
if( image != null ){
label.setIcon( new ImageIcon( image ) );
frame.pack();
image.flush();
}
}
}
>>>>>>> a0560a3efd37b3c0f25a1a05cff3f3a3c019985b
}
Solution content
*
*/
public class E04_LiveView {
public static void main( final String[] args ) throws InterruptedException {
final CanonCamera camera = new CanonCamera();
if ( camera.openSession() ) {
if ( camera.beginLiveView() ) {
final JFrame frame = new JFrame( "Live view" );
final JLabel label = new JLabel();
frame.getContentPane().add( label, BorderLayout.CENTER );
frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
frame.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing( final WindowEvent e ) {
camera.endLiveView();
camera.closeSession();
CanonCamera.close();
System.exit( 0 );
}
} );
frame.setVisible( true );
while ( true ) {
Thread.sleep( 50 );
final BufferedImage image = camera.downloadLiveView();
if ( image != null ) {
label.setIcon( new ImageIcon( image ) );
frame.pack();
image.flush();
}
}
}
camera.closeSession();
}
CanonCamera.close();
System.exit( 0 );
}
}