Пример #1
0
 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;
 }
Пример #2
0
 /**
  * Checks whether live view is allowed to be activated (enabled) and alternately whether the
  * camera is actively transmitting live view images.
  *
  * <p>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.
  *
  * <p>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}.
  *
  * <p>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.
  *
  * @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;
 }
Пример #3
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()
            + ")");
  }