Skip to content

Commit 4e5777b

Browse files
committed
first commit, includes example
0 parents  commit 4e5777b

File tree

15 files changed

+1325
-0
lines changed

15 files changed

+1325
-0
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.depend
2+
*.layout
3+
*.mode*v3
4+
*.pbxuser
5+
*.app*
6+
*.DS_*
7+
8+
.svn/
9+
obj/
10+
bin/
11+
build/
12+
!data/

example/bin/data/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore everything in here apart from the .gitignore file
2+
*
3+
!.gitignore

example/ofxEdsdkExample.xcodeproj/project.pbxproj

+632
Large diffs are not rendered by default.

example/openFrameworks-Info.plist

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleExecutable</key>
8+
<string>${EXECUTABLE_NAME}</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>com.yourcompany.openFrameworks</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundlePackageType</key>
14+
<string>APPL</string>
15+
<key>CFBundleSignature</key>
16+
<string>????</string>
17+
<key>CFBundleVersion</key>
18+
<string>1.0</string>
19+
</dict>
20+
</plist>

example/src/main.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "testApp.h"
2+
#include "ofAppGlutWindow.h"
3+
4+
int main() {
5+
ofAppGlutWindow window;
6+
ofSetupOpenGL(&window, 1056, 704, OF_WINDOW);
7+
ofRunApp(new testApp());
8+
}

example/src/testApp.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "testApp.h"
2+
3+
void testApp::setup() {
4+
ofSetVerticalSync(true);
5+
camera.setup();
6+
}
7+
8+
void testApp::update() {
9+
camera.update();
10+
if(camera.isFrameNew()) {
11+
}
12+
}
13+
14+
void testApp::draw() {
15+
camera.draw(0, 0);
16+
}

example/src/testApp.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "ofMain.h"
4+
5+
#include "ofxEdsdk.h"
6+
7+
class testApp : public ofBaseApp {
8+
public:
9+
void setup();
10+
void update();
11+
void draw();
12+
13+
ofxEdsdk::Camera camera;
14+
};

lib/EDSDK/Framework/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

lib/EDSDK/Framework/readme

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add these files here:
2+
DPP.framework
3+
EDSDK.framework

lib/EDSDK/Header/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

lib/EDSDK/Header/readme

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add these files here:
2+
EDSDK.h
3+
EDSDKErrors.h
4+
EDSDKTypes.h

src/EDSDKStringHelper.cpp

+316
Large diffs are not rendered by default.

src/EDSDKStringHelper.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#define __MACOS__
4+
#include "EDSDK.h"
5+
#include "EDSDKErrors.h"
6+
#include "EDSDKTypes.h"
7+
8+
#include <string>
9+
10+
std::string getEdsErrorString(EdsError error);
11+
std::string getEdsPropertyString(EdsPropertyID property);

src/ofxEdsdk.cpp

+242
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
#include "ofxEdsdk.h"
2+
3+
namespace ofxEdsdk {
4+
5+
void handleError(EdsError err, string msg) {
6+
if(err != EDS_ERR_OK) {
7+
cout << msg << " returned " << getEdsErrorString(err) << endl;
8+
}
9+
}
10+
11+
/*
12+
After calling startLiveView, we get:
13+
property event: kEdsPropID_Evf_OutputDevice / 0
14+
property event: kEdsPropID_Evf_DepthOfFieldPreview / 0
15+
property event: kEdsPropID_MeteringMode / 0
16+
property event: kEdsPropID_FocusInfo / 0
17+
property event: kEdsPropID_AFMode / 0
18+
property event: kEdsPropID_ExposureCompensation / 0
19+
property event: kEdsPropID_AFMode / 0
20+
property event: kEdsPropID_MeteringMode / 0
21+
*/
22+
EdsError EDSCALLBACK handlePropertyEvent(EdsPropertyEvent event, EdsPropertyID propertyId, EdsUInt32 param, EdsVoid* context) {
23+
cout << "property event: " << getEdsPropertyString(propertyId) << " / " << param << endl;
24+
25+
if(propertyId == kEdsPropID_Evf_OutputDevice) {
26+
((Camera*) context)->setLiveViewReady(true);
27+
}
28+
}
29+
30+
EdsError startLiveview(EdsCameraRef camera) {
31+
EdsError err = EDS_ERR_OK;
32+
33+
// Get the output device for the live view image
34+
EdsUInt32 device;
35+
err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device);
36+
37+
// PC live view starts by setting the PC as the output device for the live view image.
38+
if(err == EDS_ERR_OK) {
39+
device |= kEdsEvfOutputDevice_PC;
40+
err = EdsSetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device);
41+
}
42+
43+
// A property change event notification is issued from the camera if property settings are made successfully.
44+
// Start downloading of the live view image once the property change notification arrives.
45+
}
46+
47+
EdsError downloadEvfData(EdsCameraRef camera, ofPixels& pixels) {
48+
EdsError err = EDS_ERR_OK;
49+
EdsStreamRef stream = NULL;
50+
EdsEvfImageRef evfImage = NULL;
51+
52+
// Create memory stream.
53+
// This automatically allocates the stream if it's unallocated.
54+
// If you want to save some time, avoid reallocation by keeping the EdsStreamRef around.
55+
// Alternatively, you can prepare the memory yourself and use EdsCreateMemoryStreamFromPointer.
56+
if(err == EDS_ERR_OK) {
57+
err = EdsCreateMemoryStream(0, &stream);
58+
handleError(err, "EdsCreateMemoryStream");
59+
}
60+
61+
// Create EvfImageRef.
62+
if(err == EDS_ERR_OK) {
63+
err = EdsCreateEvfImageRef(stream, &evfImage);
64+
handleError(err, "EdsCreateEvfImageRef");
65+
}
66+
67+
// Download live view image data.
68+
if(err == EDS_ERR_OK) {
69+
err = EdsDownloadEvfImage(camera, evfImage);
70+
handleError(err, "EdsDownloadEvfImage");
71+
}
72+
73+
// Get the image data.
74+
EdsUInt32 length;
75+
if(err == EDS_ERR_OK) {
76+
EdsGetLength(stream, &length);
77+
handleError(err, "EdsGetLength");
78+
}
79+
80+
char* streamPointer;
81+
if(err == EDS_ERR_OK) {
82+
EdsGetPointer(stream, (EdsVoid**) &streamPointer);
83+
handleError(err, "EdsGetPointer");
84+
}
85+
86+
if(err == EDS_ERR_OK) {
87+
cout << "Copying image (" << length << ") to ofBuffer" << endl;
88+
ofBuffer imageBuffer;
89+
imageBuffer.set(streamPointer, length);
90+
91+
ofLoadImage(pixels, imageBuffer);
92+
}
93+
94+
/*
95+
// Get the metadata of the image.
96+
// Get the zoom ratio
97+
EdsUInt32 zoom;
98+
EdsGetPropertyData(evfImage, kEdsPropID_Evf_ZoomPosition, 0 , sizeof(zoom), &zoom);
99+
100+
// Get the focus and zoom border position
101+
EdsPoint point;
102+
EdsGetPropertyData(evfImage, kEdsPropID_Evf_ZoomPosition, 0 , sizeof(point), &point);
103+
*/
104+
105+
// Release stream
106+
if(stream != NULL) {
107+
EdsRelease(stream);
108+
handleError(err, "EdsRelease");
109+
stream = NULL;
110+
}
111+
112+
// Release evfImage
113+
if(evfImage != NULL) {
114+
EdsRelease(evfImage);
115+
handleError(err, "EdsRelease");
116+
evfImage = NULL;
117+
}
118+
119+
return err;
120+
}
121+
122+
EdsError endLiveview(EdsCameraRef camera) {
123+
EdsError err = EDS_ERR_OK;
124+
// Get the output device for the live view image
125+
EdsUInt32 device;
126+
err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device );
127+
// PC live view ends if the PC is disconnected from the live view image output device.
128+
if(err == EDS_ERR_OK) {
129+
device &= ~kEdsEvfOutputDevice_PC;
130+
err = EdsSetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0 , sizeof(device), &device);
131+
}
132+
}
133+
134+
Camera::Camera() :
135+
liveViewReady(false),
136+
frameNew(false) {
137+
}
138+
139+
Camera::~Camera() {
140+
if(liveViewReady) {
141+
endLiveview(camera);
142+
}
143+
144+
err = EdsCloseSession(camera);
145+
handleError(err, "EdsCloseSession");
146+
147+
err = EdsTerminateSDK();
148+
handleError(err, "EdsTerminateSDK");
149+
}
150+
151+
void Camera::setup() {
152+
cout << "EdsInitializeSDK()" << endl;
153+
err = EdsInitializeSDK();
154+
handleError(err, "EdsInitializeSDK");
155+
156+
EdsCameraListRef cameraList;
157+
err = EdsGetCameraList(&cameraList);
158+
159+
EdsUInt32 cameraCount;
160+
cout << "EdsGetChildCount()" << endl;
161+
err = EdsGetChildCount(cameraList, &cameraCount);
162+
handleError(err, "EdsGetChildCount");
163+
164+
cout << "Camera count: " << cameraCount << endl;
165+
166+
EdsInt32 cameraIndex = 0;
167+
cout << "EdsGetChildAtIndex()" << endl;
168+
err = EdsGetChildAtIndex(cameraList, cameraIndex, &camera);
169+
handleError(err, "EdsGetChildAtIndex");
170+
171+
cout << "EdsSetPropertyEventHandler()" << endl;
172+
err = EdsSetPropertyEventHandler(camera, kEdsPropertyEvent_All, handlePropertyEvent, this);
173+
handleError(err, "EdsSetPropertyEventHandler");
174+
175+
cout << "EdsOpenSession()" << endl;
176+
err = EdsOpenSession(camera);
177+
handleError(err, "EdsOpenSession");
178+
179+
cout << "starting live view" << endl;
180+
startLiveview(camera);
181+
}
182+
183+
void Camera::update() {
184+
if(liveViewReady) {
185+
cout << "downloadEvfData()" << endl;
186+
err = downloadEvfData(camera, livePixels);
187+
if(err == EDS_ERR_OK) {
188+
frameNew = true;
189+
if(liveTexture.getWidth() != livePixels.getWidth() ||
190+
liveTexture.getHeight() != livePixels.getHeight()) {
191+
liveTexture.allocate(livePixels.getWidth(), livePixels.getHeight(), GL_RGB8);
192+
}
193+
liveTexture.loadData(livePixels);
194+
}
195+
}
196+
}
197+
198+
bool Camera::isFrameNew() {
199+
if(frameNew) {
200+
frameNew = false;
201+
return true;
202+
} else {
203+
return false;
204+
}
205+
}
206+
207+
const ofPixels& Camera::getPixelsRef() const {
208+
return livePixels;
209+
}
210+
211+
ofPixels& Camera::getPixelsRef() {
212+
return livePixels;
213+
}
214+
215+
unsigned int Camera::getWidth() const {
216+
return livePixels.getWidth();
217+
}
218+
219+
unsigned int Camera::getHeight() const {
220+
return livePixels.getHeight();
221+
}
222+
223+
void Camera::draw(float x, float y) {
224+
draw(x, y, getWidth(), getHeight());
225+
}
226+
227+
void Camera::draw(float x, float y, float width, float height) {
228+
if(liveViewReady) {
229+
ofPushMatrix();
230+
ofTranslate(x, y);
231+
liveTexture.draw(0, 0, width, height);
232+
stringstream status;
233+
status << livePixels.getWidth() << "x" << livePixels.getHeight() << " @ " << (int) ofGetFrameRate() << " fps";
234+
ofDrawBitmapString(status.str(), 10, 20);
235+
ofPopMatrix();
236+
}
237+
}
238+
239+
void Camera::setLiveViewReady(bool liveViewReady) {
240+
this->liveViewReady = liveViewReady;
241+
}
242+
}

src/ofxEdsdk.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
3+
#include "ofMain.h"
4+
#include "EDSDKStringHelper.h"
5+
6+
namespace ofxEdsdk {
7+
8+
/*
9+
Camera is currently not threaded, so
10+
update() blocks and isFrameNew() is true.
11+
*/
12+
13+
class Camera {
14+
public:
15+
Camera();
16+
~Camera();
17+
void setup();
18+
void update();
19+
bool isFrameNew();
20+
21+
unsigned int getWidth() const;
22+
unsigned int getHeight() const;
23+
void draw(float x, float y);
24+
void draw(float x, float y, float width, float height);
25+
26+
const ofPixels& getPixelsRef() const;
27+
ofPixels& getPixelsRef();
28+
29+
void setLiveViewReady(bool liveViewReady);
30+
31+
protected:
32+
EdsError err;
33+
EdsCameraListRef cameraList;
34+
EdsCameraRef camera;
35+
36+
ofPixels livePixels;
37+
ofTexture liveTexture;
38+
bool liveViewReady;
39+
bool frameNew;
40+
};
41+
42+
}

0 commit comments

Comments
 (0)