EdsError EDSCALLBACK Camera::handleObjectEvent(EdsUInt32 inEvent, EdsBaseRef inRef, EdsVoid* inContext) {
     Camera* c = (Camera*)inContext;
     CameraRef camera = CameraBrowser::instance()->cameraForPortName(c->getPortName());
     switch (inEvent) {
         case kEdsObjectEvent_DirItemRequestTransfer: {
             EdsDirectoryItemRef directoryItem = (EdsDirectoryItemRef)inRef;
             CameraFileRef file = NULL;
             try {
                 file = CameraFile::create(directoryItem);
             } catch (...) {
                 EdsRelease(directoryItem);
                 break;
             }
             EdsRelease(directoryItem);
             directoryItem = NULL;
             if (camera->mFileAddedHandler) {
                 camera->mFileAddedHandler(camera, file);
             }
             break;
         }
         default:
             if (inRef) {
                 EdsRelease(inRef);
                 inRef = NULL;
             }
             break;
     }
     return EDS_ERR_OK;
 }
    EdsError Camera::requestDownloadEvfData( QImage& img )
    {
        if( !mIsLiveView ){
            std::cerr << "No live view" << std::endl;
            startLiveView();
            return EDS_ERR_OK;
        }
        
		
        EdsError err = EDS_ERR_OK;
        EdsStreamRef stream = NULL;
        EdsEvfImageRef evfImage = NULL;
        
        // Create memory stream.
		err = EdsCreateMemoryStream(0, &stream);
        
        // Create EvfImageRef.
        if(err == EDS_ERR_OK) {
			//std::cout << " memoryOK" << std::endl;
            err = EdsCreateEvfImageRef(stream, &evfImage);
        }
        
        // Download live view image data.
        if(err == EDS_ERR_OK){
			//std::cout << " dataOK" << std::endl;
            err = EdsDownloadEvfImage(mCamera, evfImage);
        }
        
        // Display image
        EdsUInt32 length;
        unsigned char* image_data;
        EdsGetLength( stream, &length );
        if( length <= 0 ) return EDS_ERR_OK;
        
        EdsGetPointer( stream, (EdsVoid**)&image_data );
		
		//std::cout << "length:" << length << " " << sizeof(image_data) << std::endl;
        // reserve memory
        img = QImage::fromData(image_data, length, "JPG");
	
        //    Buffer buffer( image_data, length );
        //    surface = Surface( loadImage( DataSourceBuffer::create(buffer), ImageSource::Options(), "jpg" ) );
        
        // Release stream
        if(stream != NULL) {
            EdsRelease(stream);
            stream = NULL;
        }
        // Release evfImage
        if(evfImage != NULL) {
            EdsRelease(evfImage);
            evfImage = NULL;
        }
        
        return EDS_ERR_OK;
    }
Example #3
0
int getNumberOfImages(EdsCameraRef handle) {
	EdsVolumeRef volume;
	EdsGetChildAtIndex(handle, 0, &volume);
	EdsDirectoryItemRef dcim;
	EdsGetChildAtIndex(volume, 0 , &dcim);
	int numFiles = getNumberOfImages_sub(dcim);
	EdsRelease(dcim);
	EdsRelease(volume);
	return numFiles;
}
int CanonEDCamera::Shutdown()
{
   // save images on the memory card
   if (isLegacy_)
      EdsSendStatusCommand (camera_,  kEdsCameraStatusCommand_UILock, 0);
   EdsSaveTo toCamera = kEdsSaveTo_Camera;
   EdsError err = EdsSetPropertyData(camera_,  kEdsPropID_SaveTo, 0 , sizeof(EdsSaveTo),  &toCamera);
   if (isLegacy_)
      EdsSendStatusCommand (camera_,  kEdsCameraStatusCommand_UIUnLock, 0);

   // Close session with camera 
   err = EdsCloseSession(camera_); 
    
   // Release camera 
   if(camera_ != NULL) 
   { 
      EdsRelease(camera_); 
   } 
    
   // Terminate SDK 
   if(isSDKLoaded_) 
   { 
      EdsTerminateSDK(); 
   }

   return DEVICE_OK;
}
Example #5
0
CPropertyString::~CPropertyString(void)
{
	if(m_ImgRef!=NULL)	EdsRelease(m_ImgRef);
	if(m_propItem!=NULL)	delete m_propItem;
	m_ImgRef = NULL;
	m_propItem = NULL;
}
Example #6
0
CameraList::~CameraList()
{
  if (list_) {
    EdsRelease(list_);
    list_ = nullptr;
  }
}
EdsError EDSCALLBACK handleObjectEvent( EdsObjectEvent event,
									   EdsBaseRef object,
									   EdsVoid * context)
{
	//printf("object event (context=\"%s\").\n", (char *)context);
	//printf("object event (object=\"%s\").\n", (char *)object);
	// do something
	switch(event)
	{
	case kEdsObjectEvent_DirItemRequestTransfer:
	   //printf("download!\n");
		downloadImage(object, (char*)context);
		break;
	default:
		break;
	}
	
	// Object must be released
	if(object){
		EdsRelease(object);
	}
	if ( callback != NULL )
		callback((char*)context);
	return EDS_ERR_OK;
}
EdsError  CanonEDCamera::getFirstCamera(EdsCameraRef  *camera) 
{ 
    EdsError err = EDS_ERR_OK; 
    EdsCameraListRef  cameraList = NULL; 
    EdsUInt32  count = 0; 
    
    // Get camera list 
    err = EdsGetCameraList(&cameraList); 
    
    // Get number of cameras 
    if(err == EDS_ERR_OK) 
    { 
       err = EdsGetChildCount(cameraList,  &count); 
       if(count == 0) 
       { 
          err = EDS_ERR_DEVICE_NOT_FOUND; 
       } 
    } 

    // Get first camera retrieved 
   if(err == EDS_ERR_OK) 
   {  
       err = EdsGetChildAtIndex(cameraList ,  0 ,  camera); 
   } 
 
   // Release camera list 
   if(cameraList != NULL) 
   {  
      EdsRelease(cameraList); 
      cameraList = NULL; 
   } 

   return err;

}
Example #9
0
EdsError CPropertyString::SetImageRef(EdsImageRef	imageRef)
{
	if(m_ImgRef!=NULL)	EdsRelease(m_ImgRef);
	if(m_propItem!=NULL)	delete m_propItem;
	m_ImgRef = imageRef;
	EdsRetain(m_ImgRef);
	return EDS_ERR_OK;
}
Example #10
0
CAFFrameDlg::~CAFFrameDlg()
{
	if(m_ImageRef!=NULL){
		EdsRelease(m_ImageRef);
	}
	if(m_pDrawImage!=NULL)delete m_pDrawImage;
	m_ImageRef = NULL;
	m_pDrawImage = NULL;
}
bool CanonTaskDownload::execute() {
  if(canon->isLegacy()) {
    canon->lockUI();
  }

  EdsError err = EDS_ERR_OK;
  EdsStreamRef stream = NULL;
  EdsDirectoryItemInfo dir_item_info;
  bool result = true;
  
  err = EdsGetDirectoryItemInfo(item, &dir_item_info);
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    result = false;
    goto done;
  }

  err = EdsCreateFileStream(dir_item_info.szFileName, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    result = false;
    goto done;
  }

  err = EdsSetProgressCallback(stream, canon_download_progress, kEdsProgressOption_Periodically, (EdsVoid*) this);
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    result = false;
    goto done;
  }

  err = EdsDownload(item, dir_item_info.size, stream);
  if(err == EDS_ERR_OK) {
    err = EdsDownloadComplete(item);
    if(err != EDS_ERR_OK) {
      CANON_ERROR(err);
      result = false;
      goto done;
    }
  }
  else {
    CANON_ERROR(err);
  }

 done:
  if(canon->isLegacy()) {
    canon->unlockUI();
  }

  if(stream) {
    EdsRelease(stream);
    stream = NULL;
  }
  return result;
}
Example #12
0
void closeCamera(EdsCameraRef handle) {
	EdsError err = EdsCloseSession(handle);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Release camera
	if (handle != NULL) {
		EdsRelease(handle);
	}
}
CanonCamera::CanonCamera(void)
{
	liveView = false;
	camID = numOfCameras;
	numOfCameras++;

	windowName = "Camera ";
	windowName += '1' + camID;
	windowName += " Window";

	EdsCameraListRef cameraList = NULL;
	
	EdsGetCameraList(&cameraList);

	EdsUInt32	 camCount = 0;
	EdsGetChildCount(cameraList, &camCount);


	if(camCount==0)
	{
		std::cout<<"No Camera Found"<<". Press Any Key to Exit.";
		getch();
		exit(-1);
	}
	else
	{
		std::cout<<camCount<<" Camera(s) found!\n";
	} 

	EdsError err = EDS_ERR_OK;

	err = EdsGetChildAtIndex(cameraList , camID , &camera);

	//Release camera list
	if(cameraList != NULL)
	{
		EdsRelease(cameraList);
	}

	detectedCams=camCount;

	//open sesion
	err=EdsOpenSession(camera);

	if(err!=EDS_ERR_OK)
	{
		std::cout<<"Problem with Camera connection"<<". Press Any Key to Exit";
		getch();
		exit(-1);
	}
	

}
Example #14
0
EdsError EDSCALLBACK CallbackHandler::HandleObjectEvent(EdsObjectEvent event, EdsBaseRef object, EdsVoid* context)
{
	CallbackHandler* that = (CallbackHandler*)context;
	switch (event) {
		case kEdsObjectEvent_DirItemRequestTransfer: {
			that->task_runner_->InsertTask(new DownloadTask(that->camera_, (EdsDirectoryItemRef)object, that->complete_message_destination_, that->download_target_));
			return EDS_ERR_OK;
		}
	}
	// object is normally released by the task, but since no task matches this event, we need to delete it here
	if (NULL != object)
		EdsRelease(object);
	return EDS_ERR_OK;
}
EdsError downloadImage(EdsDirectoryItemRef directoryItem, char* filename)
{
	EdsError err = EDS_ERR_OK;
	EdsStreamRef stream = NULL;
	// Get directory item information
	EdsDirectoryItemInfo dirItemInfo;
	err = EdsGetDirectoryItemInfo(directoryItem, & dirItemInfo);
	//printf("err EdsGetDirectoryItemInfo: %d\n", err);
	// Create file stream for transfer destination
	if(err == EDS_ERR_OK)
	{
		err = EdsCreateFileStream( theFileName,
			kEdsFileCreateDisposition_CreateAlways,
			kEdsAccess_ReadWrite, &stream);
	   //printf("err EdsCreateFileStream: %X\n", err);
	}
	// Download image
	if(err == EDS_ERR_OK)
	{
		err = EdsDownload( directoryItem, dirItemInfo.size, stream);
	//printf("err EdsDownload: %d\n", err);

	}
	// Issue notification that download is complete
	char* buf = NULL;
	if(err == EDS_ERR_OK)
	{
		err = EdsDownloadComplete(directoryItem);
		//printf("err EdsDownloadComplete: %d\n", err);
		buf = new char [strlen(theFileName)+1];
		strcpy_s(buf, strlen(theFileName)+1, theFileName);
		theFileName[0] = '\0';
	}
	// Release stream
	if( stream != NULL)
	{
		EdsRelease(stream);
		stream = NULL;
	}
	pictureProgress = CAMERA_COMPLETE;
	resetPictureTaking();

	// Notify done downloading
	if (buf) {
		/*std::cout << "snapped " << buf << std::endl;
		std::flush(std::cout);*/
		delete [] buf; buf = NULL;
	}
	return err;
}
 void Camera::requestReadFile(const CameraFileRef& file, const std::function<void(EdsError error, QImage img)>& callback) {
    QImage img;
 
    EdsStreamRef stream = NULL;
    EdsError error = EdsCreateMemoryStream(0, &stream);
    if (error != EDS_ERR_OK) {
        std::cerr << "ERROR - failed to create memory stream" << std::endl;
        goto read_cleanup;
    }
 
    error = EdsDownload(file->mDirectoryItem, file->getSize(), stream);
    if (error != EDS_ERR_OK) {
        std::cerr << "ERROR - failed to download" << std::endl;
        goto read_cleanup;
    }
 
    error = EdsDownloadComplete(file->mDirectoryItem);
    if (error != EDS_ERR_OK) {
        std::cerr << "ERROR - failed to mark download as complete" << std::endl;
        goto read_cleanup;
    }
 
    unsigned char* data;
    error = EdsGetPointer(stream, (EdsVoid**)&data);
    if (error != EDS_ERR_OK) {
        std::cerr << "ERROR - failed to get pointer from stream" << std::endl;
        goto read_cleanup;
    }
 
    EdsUInt32 length;
    error = EdsGetLength(stream, &length);
    if (error != EDS_ERR_OK) {
        std::cerr << "ERROR - failed to get stream length" << std::endl;
        goto read_cleanup;
    }
 
    img = QImage::fromData(data, length, "JPG");
 
 read_cleanup:
    if (stream) {
        EdsRelease(stream);
    }
 
    callback(error, img);
 }
boolean disconFromFirstCamera(){

	EdsError err = EDS_ERR_OK;
	// Close session with camera
	err = EdsCloseSession(camera);

	// Release camera
	if(camera != NULL)
	{
		EdsRelease(camera);
	}
	// Terminate SDK
	if(isSDKLoaded)
	{
		EdsTerminateSDK();
	}
	pictureProgress = CAMERA_RESET;
	return err == EDS_ERR_OK;
}
Example #18
0
unsigned queryCamera() {

	EdsCameraListRef cameraList = NULL;
	EdsError err = EdsGetCameraList(&cameraList);
	if (err != EDS_ERR_OK) {
	}

	EdsUInt32 numCameras = 0;
	err = EdsGetChildCount(cameraList, &numCameras);
	if (err == EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Release camera list
	if (cameraList != NULL) {
		EdsRelease(cameraList);
		cameraList = NULL;
	}

	return (unsigned) numCameras;
}
Example #19
0
int getNumberOfImages_sub(EdsDirectoryItemRef directoryItem) {

	EdsUInt32 numChildren;
	EdsGetChildCount(directoryItem, &numChildren);
	EdsDirectoryItemInfo directoryItemInfo;
	EdsGetDirectoryItemInfo(directoryItem, &directoryItemInfo);
	int numFiles = 0;
	EdsDirectoryItemRef childItem;
	EdsDirectoryItemInfo childItemInfo;
	for (int iter = 0; iter < numChildren; ++iter) {
		EdsGetChildAtIndex(directoryItem, iter, &childItem);
		EdsGetDirectoryItemInfo(childItem, &childItemInfo);
		if (childItemInfo.isFolder == true) {
			numFiles += getNumberOfImages_sub(childItem);
		} else {
			++numFiles;
		}
		EdsRelease(childItem);
	}
	return numFiles;
}
 void Camera::requestDownloadFile(const CameraFileRef& file, const QDir& destinationFolderPath, const std::function<void(EdsError error, QString outputFilePath)>& callback) {
     // check if destination exists and create if not
     if ( !destinationFolderPath.exists() ) {
         bool status = destinationFolderPath.mkpath(".");
         if (!status) {
             std::cerr << "ERROR - failed to create destination folder path '" << destinationFolderPath.dirName().toStdString() << "'" << std::endl;
             return callback(EDS_ERR_INTERNAL_ERROR, NULL);
         }
     }
     
     QString filePath = destinationFolderPath.filePath(QString::fromStdString(file->getName()));
     
     EdsStreamRef stream = NULL;
     EdsError error = EdsCreateFileStream(filePath.toStdString().c_str(), kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
     if (error != EDS_ERR_OK) {
         std::cerr << "ERROR - failed to create file stream" << std::endl;
         goto download_cleanup;
     }
     
     error = EdsDownload(file->mDirectoryItem, file->getSize(), stream);
     if (error != EDS_ERR_OK) {
         std::cerr << "ERROR - failed to download" << std::endl;
         goto download_cleanup;
     }
     
     error = EdsDownloadComplete(file->mDirectoryItem);
     if (error != EDS_ERR_OK) {
         std::cerr << "ERROR - failed to mark download as complete" << std::endl;
         goto download_cleanup;
     }
     
 download_cleanup:
     if (stream) {
         EdsRelease(stream);
     }
     
     callback(error, filePath);
 }
boolean connectToFirstCamera(){
	
	EdsError err = EDS_ERR_OK;

	// Initialize SDK
	err = EdsInitializeSDK();
	if ( err == EDS_ERR_OK )
		isSDKLoaded = true;


/*	// Get first camera
	if(err == EDS_ERR_OK)
	{
		err = getFirstCamera();
	}*/

	EdsCameraListRef cameraList = NULL;
	EdsUInt32 count = 0;

	// Get camera list
	err = EdsGetCameraList(&cameraList);

	// Get number of cameras
	if(err == EDS_ERR_OK)
	{
		err = EdsGetChildCount(cameraList, &count);
		if(count == 0)
		{
			err = EDS_ERR_DEVICE_NOT_FOUND;
		}
	}

	// Get first camera retrieved
	if(err == EDS_ERR_OK)
	{
		err = EdsGetChildAtIndex(cameraList , 0 , &camera);
	}

	// Release camera list
	if(cameraList != NULL)
	{
		EdsRelease(cameraList);
		cameraList = NULL;
	}

	//Open Session
	if(err == EDS_ERR_OK)
	{
		err = EdsOpenSession(camera);
	}

	//Set save to host
	if (err == EDS_ERR_OK ) {
		EdsUInt32 wkSaveTo = kEdsSaveTo_Host ;
		do {
			err = EdsSetPropertyData ( camera, kEdsPropID_SaveTo, 
				0, 4, (void*)&wkSaveTo ) ;
			if (err != EDS_ERR_OK) {
				std::cout << "warning: camera busy, waiting..." << std::endl;
				std::flush(std::cout);
				Sleep(100);
			}
		} while (err != EDS_ERR_OK);
	}

	// Set host capacity
	EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
	err = EdsSetCapacity ( camera, capacity );

	return err == EDS_ERR_OK;
}
void CanonCamera::UpdateView()
{

	if(!liveView)
		return;

    EdsError err = EDS_ERR_OK;
    EdsStreamRef stream = NULL;
    EdsEvfImageRef evfImage = NULL;

    // Create memory stream.
    err = EdsCreateMemoryStream(0, &stream);
  
	if(err != EDS_ERR_OK)
    {
        printf("Error in EdsCreateMemoryStream: 0x%X\n", err);
    }    

    err = EdsCreateEvfImageRef(stream, &evfImage);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsCreateEvfImageRef: 0x%X\n", err);  
    }    

	
	bool wait = true;

    int numTries = 0;
    
	while(wait && numTries++ < 20)
    {
        err = EdsDownloadEvfImage(camera, evfImage);
        if(err != EDS_ERR_OK && err != EDS_ERR_OBJECT_NOTREADY)
        {
            printf("Error in EdsDownloadEvfImage: 0x%X\n", err);

        }
        if(err == EDS_ERR_OBJECT_NOTREADY)
        {
            Sleep(250);
        }
        else
        {
            wait = false;
        }
    }
    if(numTries > 20)
    {
        printf("ERROR: camera is taking too long for EdsDownloadEvfImage\n");

    }

    unsigned char* pByteImage = NULL;

    // Get image (JPEG) pointer.
    err = EdsGetPointer(stream, (EdsVoid**)&pByteImage );
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsGetPointer Histogram: 0x%X\n", err);
  
    }

    EdsUInt32 size;
    err = EdsGetLength(stream, &size);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsGetLength Histogram: 0x%X\n", err);
 
    }

    EdsImageRef image = NULL;
    EdsImageInfo imageInfo;

    err = EdsCreateImageRef(stream, &image);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsCreateImageRef: 0x%X\n", err);
 
    }

    err = EdsGetImageInfo(image, kEdsImageSrc_FullView, &imageInfo);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsGetImageInfo: 0x%X\n", err);

    }

    if(imageInfo.componentDepth != 8)
    {
        printf("Error imageInfo.componentDepth != 8\n");

    }

	liveImage = cvCreateImage(cvSize(imageInfo.width, imageInfo.height), IPL_DEPTH_8U, imageInfo.numOfComponents);

    
    EdsUInt32 DataSize = 0;

    CImage cImage;
    HRESULT hr;

    CComPtr<IStream> iStream = NULL;
    HGLOBAL hMem = GlobalAlloc(GHND, size);
    LPVOID pBuff = GlobalLock(hMem);
    memcpy(pBuff, pByteImage, size);
    GlobalUnlock(hMem);
    hr = CreateStreamOnHGlobal(hMem, TRUE, &iStream);

    // Get the bitmap image from the stream
    if ((hr = cImage.Load(iStream)) == S_OK)
    {
        
        int pitch = cImage.GetPitch();
        int height = cImage.GetHeight();
        BYTE* pBits = (BYTE*)cImage.GetBits();
        if (pitch < 0)
            pBits += (pitch *(height -1));
        memcpy(liveImage->imageData, pBits, abs(pitch) * height);
		
    }

	cImage.~CImage();
    
    GlobalFree(hMem);
	

    cvFlip(liveImage, NULL, 0);

    // Release stream
    if(stream != NULL)
    {
        err = EdsRelease(stream);
        if(err != EDS_ERR_OK)
        {
            printf("Error in EdsRelease: 0x%X\n", err);

        }
        stream = NULL;
    }

   
   if(evfImage != NULL)
    {
        err = EdsRelease(evfImage);
        if(err != EDS_ERR_OK)
        {
            printf("Error in EdsRelease: 0x%X\n", err);

        }
        evfImage = NULL;
    }

	EdsRelease(image);
	
	cvShowImage(windowName.c_str(), liveImage);

	cvReleaseImage(&liveImage);
    
}
void
Controller::handleStateEvent(
	EdsStateEvent	inEvent,
	EdsUInt32	inEventData )
{
    switch( inEvent ) {
	/*
	 *  Camera has lost connection to host computer, either because
	 *  it was disconnected by unplugging a cord, opening the
	 *  compact flash compartment, turning the camera off, auto
	 *  shut-off, or by other means.
	 */
	case kEdsStateEvent_Shutdown:
	    if( camera->handle() != 0 ) {
		stopLiveView();
		EdsCloseSession( camera->handle() );
		EdsRelease( camera->handle() );
		camera->setHandle( 0 );
	    }
	    // signal view of change in connection status
	    camera->initialize();
	    emit propertyChanged( kEdsPropID_ProductName, 0 );
	    emit eventReport( new Event( Event::ConnectionLost ) );
	    break;
	/*
	 *  Notifies of whether or not (0/1) there are objects waiting to
	 *  be transferred to the host computer. This is useful when
	 *  ensuring all shot images have been transferred when the
	 *  application is closed. A value of 1 is passed initially
	 *  (whether it is a single shot or a burst of shots to download),
	 *  followed by a 0 when downloading has completed.
	 */
	case kEdsStateEvent_JobStatusChanged:
	    camera->setObjectsWaiting( inEventData );
	    break;
	/*
	 *  Notifies that the camera will shut down after a specific period. 
	 *  Generated only if auto shut-off is set. Exactly when notification
	 *  is issued (that is, the number of seconds until shutdown) varies
	 *  depending on the camera model. If the camera is allowed to shut
	 *  down, the connection will be lost and can only be reestablished
	 *  by pressing the camera's shutter button half-way (or pressing
	 *  menu, disp). To continue operation without having the camera
	 *  shut down, use EdsSendCommand to extend the auto shut-off timer.
	 *  inEventData contains the number of seconds to shutdown.
	 */
	case kEdsStateEvent_WillSoonShutDown:
	    EdsSendCommand( camera->handle(),
			    kEdsCameraCommand_ExtendShutDownTimer,
			    0 );
	    break;
	/*
	 *  As the counterpart event to kEdsStateEvent_WillSoonShutDown,
	 *  this event notifies of updates to the number of seconds until
	 *  a camera shuts down. After the update, the period until shutdown
	 *  is model-dependent. Not all cameras notify of this event.
	 */
	case kEdsStateEvent_ShutDownTimerUpdate:
	    // ignore
	    break;
	/*
	 *  Notifies that a requested release has failed, due to focus
	 *  failure or similar factors: inEventData contains error code.
	 *  Hasn't occurred yet.
	 */
	case kEdsStateEvent_CaptureError:
	    emit eventReport( new Event( Event::CaptureFailure, inEventData ) );
	    break;
	/*
	 *  Notifies of internal SDK errors. If this error event is received,
	 *  the issuing device will probably not be able to continue working
	 *  properly, so cancel the remote connection.
	 */
	case kEdsStateEvent_InternalError:
	    stopLiveView();
	    closeSessionCommand();
	    camera->initialize();
	    // signal view of change in connection status
	    emit propertyChanged( kEdsPropID_ProductName, 0 );
	    emit eventReport( new Event( Event::ConnectionLost ) );
	    break;
	/*
	 *  Not documented and hasn't occurred yet.
	 */
	case kEdsStateEvent_AfResult:
	    emit eventReport(
		new Event( Event::AFResultUnhandled, inEventData ) );
	    break;
	/*
	 *  Notifies of the exposure time during bulb shooting. Events are
	 *  issued in about one-second intervals during bulb shooting. This
	 *  event is only issued when bulb shooting is started on the computer.
	 *  inEventData contains the exposure time in seconds.
	 */
	case kEdsStateEvent_BulbExposureTime:
	    emit eventReport(
		new Event( Event::BulbExposureTime, inEventData ) );
	    break;
    }
}
Example #24
0
//////////////////////////////////////////////////////
/// A picture is acquired from the target EdsImageRef and an acquisition picture is registered into a drawing instance.
void CAFFrameDlg::LoadImage()
{
	/// The picture of a drawing instance is cleared.
	m_pDrawImage->Clear(0);
	if( m_ImageRef == NULL )
		return;

	EdsImageSource source = kEdsImageSrc_RAWThumbnail;
	EdsImageInfo imageInfo;
	EdsGetImageInfo( m_ImageRef , source, &imageInfo); 

	/// Demand size is adjusted so that an aspect ratio may not change.
	EdsSize viewSize;
	float ratio;
	viewSize.width = m_pDrawImage->GetWidth();
	viewSize.height = m_pDrawImage->GetHeight();
	if(imageInfo.effectiveRect.size.width>imageInfo.effectiveRect.size.height)
	{
		ratio = (float)imageInfo.effectiveRect.size.width / viewSize.width;
		if((EdsInt32)(imageInfo.effectiveRect.size.height/ratio) > viewSize.height)
			ratio = (float)imageInfo.effectiveRect.size.height / viewSize.height;
	}
	else
	{
		ratio = (float)imageInfo.effectiveRect.size.height / viewSize.height;
		if((EdsInt32)(imageInfo.effectiveRect.size.width/ratio) > viewSize.width)
			ratio = (float)imageInfo.effectiveRect.size.width / viewSize.width;	
	}
	EdsSize size;
	size.width = (EdsInt32)(imageInfo.effectiveRect.size.width/ratio);
	size.height = (EdsInt32)(imageInfo.effectiveRect.size.height/ratio);

	/// Creation of an output stream.
	EdsStreamRef DstStreamRef;
	EdsError err = EdsCreateMemoryStream( 0 , &DstStreamRef );

	/// A picture is acquired from EdsImageRef.
	err = EdsGetImage( m_ImageRef , source , kEdsTargetImageType_RGB , imageInfo.effectiveRect , size , DstStreamRef );
	if( err == EDS_ERR_OK )
	{
		/// The start address of the acquired picture is acquired.
		EdsVoid* pBuff;
		EdsGetPointer( DstStreamRef , &pBuff );
		/// A picture is updated to a drawing instance.
		m_pDrawImage->SetImage( size.width , size.height , pBuff );
	}
	else
	{
		AfxMessageBox("The error occurred with the EdsGetImage function.");
	}
	/// The output stream is released.
	EdsRelease(DstStreamRef);

	// FocusInfo
	EdsFocusInfo	focusInfo = {0};
	err= EdsGetPropertyData( m_ImageRef, kEdsPropID_FocusInfo , 0 , sizeof(focusInfo), &focusInfo );
	m_focusInfo = focusInfo;
	if(err == EDS_ERR_OK)
	{
		float xRatio = 1;
		float yRatio = 1;

		xRatio = (float)size.width/focusInfo.imageRect.size.width;
		yRatio = (float)size.height/focusInfo.imageRect.size.height;
		for(EdsUInt32 i = 0; i < focusInfo.pointNumber; i++)
		{
			m_focusInfo.focusPoint[i].rect.point.x = (EdsUInt32)(m_focusInfo.focusPoint[i].rect.point.x * xRatio);
			m_focusInfo.focusPoint[i].rect.point.y = (EdsUInt32)(m_focusInfo.focusPoint[i].rect.point.y * yRatio);
			m_focusInfo.focusPoint[i].rect.size.width = (EdsUInt32)(m_focusInfo.focusPoint[i].rect.size.width * xRatio);
			m_focusInfo.focusPoint[i].rect.size.height = (EdsUInt32)(m_focusInfo.focusPoint[i].rect.size.height * yRatio);
		}
		RedrawWindow();
	}
}
 CameraFile::~CameraFile() {
     EdsRelease(mDirectoryItem);
     mDirectoryItem = NULL;
 }
EdsError EDSCALLBACK CanonEDCamera::handleObjectEvent( EdsObjectEvent event, EdsBaseRef  object, EdsVoid * context) 
{ 
   printf ("Object Event triggered\n");

   CanonEDCamera* mmCanon = (CanonEDCamera*) g_Self;
  
   switch(event) 
   { 
      case kEdsObjectEvent_DirItemRequestTransfer: 
         {
            EdsError err = EDS_ERR_OK;
            EdsStreamRef stream = NULL;

            EdsDirectoryItemInfo dirItemInfo;
            err = EdsGetDirectoryItemInfo(object, &dirItemInfo);

            // do we need to notify the camera?
            /*
             if (err == EDS_ERR_OK)
             {
             CameraEvent e("DownloadStart");
             _model->notifyObservers(&e);
             }
             */

            if (err == EDS_ERR_OK)
            {
               //err = EdsCreateFileStream(dirItemInfo.szFileName, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
               err = EdsCreateMemoryStream(0, &stream);
            }

            // Set Progress Callback???

            // Download Image
            if (err == EDS_ERR_OK)
            {
               err = EdsDownload(object,  dirItemInfo.size, stream);
            }

            if (err == EDS_ERR_OK)
            {
               err = EdsDownloadComplete(object);
            }

            EdsImageRef imageRef = NULL;

            if (err == EDS_ERR_OK)
            {
               err = EdsCreateImageRef(stream, &imageRef);
            }

            EdsImageInfo imageInfo;

            if (err == EDS_ERR_OK)
            {
               err = EdsGetImageInfo(imageRef, kEdsImageSrc_FullView, &imageInfo);
            }
            if (err == EDS_ERR_OK)
            {
               printf ("Image Width: %d\n", imageInfo.width);
            }


         }
         break; 
        
         default: 
          
         break; 
      } 
    
 
   // Object must be released 
   if(object) 
   { 
      EdsRelease(object); 
   } 
} 
Example #27
0
EdsCameraRef openCamera() {
	EdsCameraListRef cameraList = NULL;
	// Get camera list
	EdsError err = EdsGetCameraList(&cameraList);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	EdsUInt32 numCameras = 0;
	// Get number of cameras
	err = EdsGetChildCount(cameraList, &numCameras);
	if (err == EDS_ERR_OK) {
		handleErrorCode(err);
	}

	if (numCameras > 1) {
		mexWarnMsgTxt("Warning: more than one available cameras found. Multiple cameras are not well supported.");
	} else if (numCameras <= 0) {
		mexErrMsgIdAndTxt(ERROR_ID, "No available camera found.");
		return NULL;
	}

	EdsCameraRef handle;
	// Get first camera retrieved
	err = EdsGetChildAtIndex(cameraList , 0 , &handle);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Release camera list
	if (cameraList != NULL) {
		EdsRelease(cameraList);
		cameraList = NULL;
	}

	// Set object event handler
	err = EdsSetObjectEventHandler(handle, kEdsObjectEvent_All, handleObjectEvent, NULL);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Set property event handler
	err = EdsSetPropertyEventHandler(handle, kEdsPropertyEvent_All, handlePropertyEvent, NULL);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Set camera state event handler
	err = EdsSetCameraStateEventHandler(handle, kEdsStateEvent_All, handleStateEvent, NULL);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Open session with camera
	err = EdsOpenSession(handle);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	return handle;
}
    //---------------------------------------------------------------------
    bool CanonCameraWrapper::setup(int cameraID){
        if( theCamera != NULL || theCameraList != NULL){
            destroy();
        }

        EdsError err = EDS_ERR_OK;
        EdsUInt32 cameraCount = 0 ;

        err = EdsInitializeSDK();

        if(err != EDS_ERR_OK){
           printf("Couldn't open sdk!\n");
            return false;
        }else{
            printf("Opening the sdk\n");
            sdkRef++;
        }
		
		ofSleepMillis(3000);

        // Initialize
        // Get the camera list
        err = EdsGetCameraList(&theCameraList);

        // Get the number of cameras.
        if( err == EDS_ERR_OK ){
            err = EdsGetChildCount( theCameraList, &cameraCount );
            if ( cameraCount == 0 ){
                err = EDS_ERR_DEVICE_NOT_FOUND;
                printf("No devices found!\n");
                return false;
            }
        }

        // Get the camera
        if ( err == EDS_ERR_OK ){
            if (cameraID >= cameraCount){
                printf("No camera of id %i exists - number of cameras is %i\n", cameraID, cameraCount);
                return false;
            }

            printf("We are opening camera %i!\n", cameraID);

            err = EdsGetChildAtIndex( theCameraList , cameraID , &theCamera );
			
			//Release camera list
			if(theCameraList != NULL){
				EdsRelease(theCameraList);
			}
			
            if(err == EDS_ERR_OK){
                printf("We are connected!\n");
                state = CAMERA_READY;
                //return true;
            }else{
                printf("We are not connected!\n");
                state = CAMERA_UNKNOWN;
                return false;
            }
			
            registerCallback();		
			return true;			
        }
    }
void
Controller::handleObjectEvent(
	EdsObjectEvent	inEvent,
	EdsBaseRef	inRef )
{
    switch( inEvent ) {
	/*
	 *  Notifies that the volume (memory card) has been:
	 *    1. added
	 *    2. removed
	 *    3. changed
	 *    4. formatted
	 *  Use EdsGetVolumeInfo to get volume information.
	 *  Get subitems of the designated volume again as needed.
	 */
	case kEdsObjectEvent_VolumeAdded:
	case kEdsObjectEvent_VolumeRemoved:
	case kEdsObjectEvent_VolumeInfoChanged:
	case kEdsObjectEvent_VolumeUpdateItems:
	    //static_cast<EdsVolumeRef>(inRef)
	    EdsRelease( inRef );
	    break;
	/*
	 *  Notifies that images were deleted in a designated folder on camera.
	 *  If notification of this event is received, get sub-items of the
	 *  designated folder again as needed. Changed folders (specifically,
	 *  directory item objects) can be retrieved from event data.
	 */
	case kEdsObjectEvent_FolderUpdateItems:
	    break;
	/*
	 *  Notifies of the creation of objects such as new folders or files,
	 *  such as a movie file, on a camera compact flash card or the like.
	 *  Newly created objects are indicated by event data.
	 */
	case kEdsObjectEvent_DirItemCreated:
	    if( camera->getSaveTo() == kEdsSaveTo_Camera ) {
		registerFile( static_cast<EdsDirectoryItemRef>(inRef) );
	    }
	    else
	    if( isMovieFile( static_cast<EdsDirectoryItemRef>(inRef) ) ) {
		downloadFile( static_cast<EdsDirectoryItemRef>(inRef), true );
	    }
	    else {
		EdsRelease( inRef );
	    }
	    break;
	/*
	 *  Notifies of the deletion of objects such as folders or files on a
	 *  camera compact flash card or the like. Deleted objects are indicated
	 *  in event data.
	 */
	case kEdsObjectEvent_DirItemRemoved:
	    break;
	/*
	 *  Notifies that information of DirItem objects has been
	 *  changed. Changed objects are indicated by event data. The changed
	 *  value can be retrieved by means of EdsGetDirectoryItemInfo.
	 */
	case kEdsObjectEvent_DirItemInfoChanged:
	    break;
	/*
	 *  Notifies that header information has been updated, as for rotation
	 *  information of image files on the camera. If this event is received,
	 *  get the file header information again, as needed.
	 */
	case kEdsObjectEvent_DirItemContentChanged:
	    break;
	/*
	 *  Notifies that there are objects on a camera to be transferred to
	 *  a computer. This event is generated after remote release from a
	 *  computer or local release from a camera.
	 */
	case kEdsObjectEvent_DirItemRequestTransfer:
	    downloadFile( static_cast<EdsDirectoryItemRef>(inRef) );
	    break;
	/*
	 *  Notifies that camera's direct transfer button was pressed.
	 */
	case kEdsObjectEvent_DirItemRequestTransferDT:
	    EdsDownloadCancel( static_cast<EdsDirectoryItemRef>(inRef) );
	    EdsRelease( inRef );
	    break;
	/*
	 *  Notifies that camera's direct transfer cancel button was pressed.
	 */
	case kEdsObjectEvent_DirItemCancelTransferDT:
	    // ignore
	    break;
    }
}