-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello-world.c
More file actions
161 lines (136 loc) · 4.57 KB
/
hello-world.c
File metadata and controls
161 lines (136 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* A collection of example applications for the LeanXcam platform.
Copyright (C) 2008 Supercomputing Systems AG
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*!@file hello-world.c
* @brief Simple hello-world application.
* Initialize Framework, take a picture, modify and save it to a file.
*/
#include "oscar/staging/inc/oscar.h"
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#if defined(OSC_HOST)
#define HTTP_ROOT "/var/www"
#else
#define HTTP_ROOT "/home/httpd/"
#endif
/*********************************************************************//*!
* @brief Program entry.
*
* @param argc Command line argument count.
* @param argv Command line argument string.
* @return 0 on success
*//*********************************************************************/
int main(const int argc, const char * argv[])
{
/*! @brief Handle to framework instance. */
void *hFramework;
#if defined(OSC_HOST) || defined(OSC_SIM)
/*! @brief Handle to file name reader for camera images on the host. */
void *hFileNameReader;
#endif
static uint8 frameBuffer[OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT];
static uint8 colorPic[3 * OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT];
uint16 i;
uint8 * rawPic = NULL;
struct OSC_PICTURE pic;
enum EnBayerOrder enBayerOrder;
int32 opt_shutterWidth = 50000;
bool opt_debayer = false;
for (i = 1; i < argc; i += 1)
{
if (strcmp(argv[i], "-d") == 0)
{
opt_debayer = true;
}
else if (strcmp(argv[i], "-s") == 0)
{
i += 1;
if (i >= argc)
{
printf("Error: -s needs an argument.\n");
return 1;
}
opt_shutterWidth = atoi(argv[i]);
}
else if (strcmp(argv[i], "-h") == 0)
{
printf("Usage: hello-world [ -h ] [ -d ] [ -s <shutter-width> ]\n");
printf(" -h: Prints this help.");
printf(" -d: Debayers the image.");
printf(" -s <shutter-width>: Sets the shutter with in us.");
}
else
{
printf("Error: Unknown option: %s", argv[i]);
return 1;
}
}
/* Create framework */
OscCreate(&hFramework);
/* Load modules */
OscBmpCreate(hFramework);
OscCamCreate(hFramework);
OscVisCreate(hFramework);
OscGpioCreate(hFramework);
#if defined(OSC_HOST) || defined(OSC_SIM)
/* Setup file name reader (for host compiled version); read constant image */
OscFrdCreateConstantReader(&hFileNameReader, "imgCapture.bmp");
OscCamSetFileNameReader(hFileNameReader);
#endif
/* Configure camera */
OscCamSetShutterWidth(opt_shutterWidth);
OscCamSetAreaOfInterest(0, 0, OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT);
OscCamSetFrameBuffer(0, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, frameBuffer, TRUE);
/* Take a picture */
OscCamSetupCapture(0);
#if defined(OSC_TARGET)
/* This hacks around the camera chip activating settings only after the next image taken. */
OscGpioTriggerImage();
OscCamReadPicture(0, (void *) &rawPic, 0, 0);
OscCamSetShutterWidth(48);
OscCamSetupCapture(0);
OscGpioTriggerImage();
#endif
OscCamReadPicture(0, (void *) &rawPic, 0, 0);
/* Debayer (transform to colored picture) */
/* OscCamGetBayerOrder(&enBayerOrder, 0, 0); */
/* OscVisDebayer((uint8*)&rawPic, OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT, enBayerOrder, (uint8*)&colorPic);*/
/* Write picture to file */
pic.width = OSC_CAM_MAX_IMAGE_WIDTH;
pic.height = OSC_CAM_MAX_IMAGE_HEIGHT;
if (opt_debayer)
{
OscCamGetBayerOrder(&enBayerOrder, 0, 0);
OscVisDebayer(frameBuffer, OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT, enBayerOrder, colorPic);
pic.type = OSC_PICTURE_BGR_24;
pic.data = colorPic;
}
else
{
pic.type = OSC_PICTURE_GREYSCALE;
pic.data = rawPic;
}
OscBmpWrite(&pic, HTTP_ROOT "hello-world.bmp~");
rename(HTTP_ROOT "hello-world.bmp~", HTTP_ROOT "hello-world.bmp");
/* Destroy modules */
OscBmpDestroy(hFramework);
OscCamDestroy(hFramework);
OscVisDestroy(hFramework);
OscGpioDestroy(hFramework);
/* Destroy framework */
OscDestroy(hFramework);
return 0;
}