camfeatures.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*****************************************************************
  2. * Copyright (C) 2012 Marco Bavagnoli - lil.deimos@gmail.com *
  3. ******************************************************************/
  4. #include "camfeatures.h"
  5. #include <QGraphicsVideoItem>
  6. #include <QCameraImageCapture>
  7. cameraFeatures::cameraFeatures(QDeclarativeItem *parent) :
  8. QDeclarativeItem(parent),
  9. m_camera(0),
  10. m_featuredAcquired(false)
  11. {
  12. // Get all available camera devices
  13. foreach (const QByteArray array, QCamera::availableDevices()) {
  14. availableDevices << QString(array);
  15. }
  16. }
  17. void cameraFeatures::startGetFeatures(QString device)
  18. {
  19. m_featuredAcquired=false;
  20. m_camera = new QCamera(device.toLatin1(), this);
  21. connect(m_camera, SIGNAL(stateChanged(QCamera::State)), this, SLOT(getFeatures(QCamera::State)));
  22. m_camera->load();
  23. }
  24. //////////////////////////////////////////////////////
  25. // Retrieve available camera features functions
  26. void cameraFeatures::getFeatures(QCamera::State state)
  27. {
  28. if (state == QCamera::UnloadedState) {
  29. if ( m_featuredAcquired ) {
  30. delete m_camera;
  31. m_camera=0;
  32. emit featuresRetrieved();
  33. return;
  34. }
  35. }
  36. QCameraImageCapture *cameraImageCapture = new QCameraImageCapture(m_camera);
  37. availableResolutionsSpeedModes = cameraImageCapture->supportedResolutions();
  38. delete cameraImageCapture;
  39. // Get all available exposure modes
  40. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureManual)) availableExposures << ExposureManual;
  41. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureAuto)) availableExposures << ExposureAuto;
  42. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureNight)) availableExposures << ExposureNight;
  43. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureBacklight)) availableExposures << ExposureBacklight;
  44. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureSpotlight)) availableExposures << ExposureSpotlight;
  45. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureSports)) availableExposures << ExposureSports;
  46. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureSnow)) availableExposures << ExposureSnow;
  47. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureBeach)) availableExposures << ExposureBeach;
  48. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureLargeAperture)) availableExposures << ExposureLargeAperture;
  49. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureSmallAperture)) availableExposures << ExposureSmallAperture;
  50. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposurePortrait)) availableExposures << ExposurePortrait;
  51. if (m_camera->exposure()->isExposureModeSupported(QCameraExposure::ExposureModeVendor)) availableExposures << ExposureModeVendor;
  52. // Get all available flash modes
  53. if (m_camera->exposure()->isFlashModeSupported(QCameraExposure::FlashOff)) availableFlashModes << FlashOff;
  54. if (m_camera->exposure()->isFlashModeSupported(QCameraExposure::FlashOn)) availableFlashModes << FlashOn;
  55. if (m_camera->exposure()->isFlashModeSupported(QCameraExposure::FlashAuto)) availableFlashModes << FlashAuto;
  56. if (m_camera->exposure()->isFlashModeSupported(QCameraExposure::FlashRedEyeReduction)) availableFlashModes << FlashRedEyeReduction;
  57. if (m_camera->exposure()->isFlashModeSupported(QCameraExposure::FlashFill)) availableFlashModes << FlashFill;
  58. if (m_camera->exposure()->isFlashModeSupported(QCameraExposure::FlashTorch)) availableFlashModes << FlashTorch;
  59. if (m_camera->exposure()->isFlashModeSupported(QCameraExposure::FlashSlowSyncFrontCurtain)) availableFlashModes << FlashSlowSyncFrontCurtain;
  60. if (m_camera->exposure()->isFlashModeSupported(QCameraExposure::FlashSlowSyncRearCurtain)) availableFlashModes << FlashSlowSyncRearCurtain;
  61. if (m_camera->exposure()->isFlashModeSupported(QCameraExposure::FlashManual)) availableFlashModes << FlashManual;
  62. // Get all available w/b modes
  63. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto)) availableWhiteBalanceModes << WhiteBalanceAuto;
  64. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceManual)) availableWhiteBalanceModes << WhiteBalanceManual;
  65. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceSunlight)) availableWhiteBalanceModes << WhiteBalanceSunlight;
  66. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceCloudy)) availableWhiteBalanceModes << WhiteBalanceCloudy;
  67. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceShade)) availableWhiteBalanceModes << WhiteBalanceShade;
  68. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceTungsten)) availableWhiteBalanceModes << WhiteBalanceTungsten;
  69. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceFluorescent)) availableWhiteBalanceModes << WhiteBalanceFluorescent;
  70. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceIncandescent)) availableWhiteBalanceModes << WhiteBalanceIncandescent;
  71. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceFlash)) availableWhiteBalanceModes << WhiteBalanceFlash;
  72. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceSunset)) availableWhiteBalanceModes << WhiteBalanceSunset;
  73. if (m_camera->imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceVendor)) availableWhiteBalanceModes << WhiteBalanceVendor;
  74. // Get all available isos
  75. availableIsoModes = m_camera->exposure()->supportedIsoSensitivities();
  76. // Get all available apertures
  77. availableApertureModes = m_camera->exposure()->supportedApertures();
  78. // Get all available isos
  79. availableShutterSpeedModes = m_camera->exposure()->supportedShutterSpeeds();
  80. // Fill EV compensations list
  81. availableCompensationModes << "-2" << "-1.5" << "-1" << "-0.5"
  82. << "0" << "+0.5" << "+1" << "+1.5" << "+2";
  83. m_featuredAcquired=true;
  84. m_camera->unload();
  85. }
  86. QStringList cameraFeatures::getAvailableDevices()
  87. {
  88. return availableDevices;
  89. }
  90. bool cameraFeatures::isExposureSupported(ExposureMode state)
  91. {
  92. return availableExposures.indexOf(state)>=0;
  93. }
  94. bool cameraFeatures::isFlashModeSupported(FlashMode state)
  95. {
  96. return availableFlashModes.indexOf(state)>=0;
  97. }
  98. bool cameraFeatures::isWhiteBalanceSupported(WhiteBalanceMode state)
  99. {
  100. return availableWhiteBalanceModes.indexOf(state)>=0;
  101. }
  102. QList<int> cameraFeatures::getIsoModesSupportedList()
  103. {
  104. return availableIsoModes;
  105. }
  106. QList<qreal> cameraFeatures::getSupportedAperturesList()
  107. {
  108. return availableApertureModes;
  109. }
  110. QList<qreal> cameraFeatures::getSupportedShutterSpeedsList()
  111. {
  112. return availableShutterSpeedModes;
  113. }
  114. QStringList cameraFeatures::getCompensationsModes()
  115. {
  116. return availableCompensationModes;
  117. }
  118. QList<QSize> cameraFeatures::getSupportedResolutionsList()
  119. {
  120. return availableResolutionsSpeedModes;
  121. }