Beispiel #1
0
  /**
   * Creates a stream and corresponding live view image. Don't forget to 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};
  }
Beispiel #2
0
  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;
  }
Beispiel #3
0
 /**
  * @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()
           + ")");
 }
Beispiel #4
0
  // TODO: this method isn't very safe to leave public, perhaps some
  // setPropertyData[String/UInt32/etc.] methods would be better
  // hansi: i like having as much as possible public. it's nice for people who know what they're
  // doing.
  @SuppressWarnings("unchecked")
  public static <T> 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()
            + ")");
  }
Beispiel #5
0
  /**
   * Download a live view image from the camera and convert it directly into a bufferd image.
   *
   * @param camera
   * @return
   */
  public static BufferedImage getLiveViewImage(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) {
        e.printStackTrace();
      } finally {
        CanonUtils.release(imageRef, streamRef);
      }
    }

    return null;
  }