00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef ENVISION_APP_ENVISION_C_DEFINED
00039 #define ENVISION_APP_ENVISION_C_DEFINED
00040
00041 #include "Envision/env_alloc.h"
00042 #include "Envision/env_c_math_ops.h"
00043 #include "Envision/env_image.h"
00044 #include "Envision/env_image_ops.h"
00045 #include "Envision/env_mt_visual_cortex.h"
00046 #include "Envision/env_params.h"
00047 #include "Envision/env_pthread_interface.h"
00048 #include "Envision/env_visual_cortex.h"
00049
00050 #include <ctype.h>
00051 #include <stdarg.h>
00052 #include <stdio.h>
00053 #include <stdlib.h>
00054 #include <string.h>
00055 #include <sys/resource.h>
00056 #include <sys/time.h>
00057
00058
00059
00060 static void* malloc_thunk(env_size_t n)
00061 {
00062 return malloc(n);
00063 }
00064
00065
00066 static void assert_handler(const char* what, int custom_msg,
00067 const char* where, int line_no)
00068 __attribute__((noreturn));
00069
00070 static void assert_handler(const char* what, int custom_msg,
00071 const char* where, int line_no)
00072 {
00073 if (custom_msg)
00074 fprintf(stderr, "Assertion failed (%s:%d):\n\t%s\n\n",
00075 where, line_no, what);
00076 else
00077 fprintf(stderr, "Assertion failed (%s:%d):\n\texpected '%s'\n\n",
00078 where, line_no, what);
00079 abort();
00080 }
00081
00082
00083 int main(int argc, const char** argv)
00084 {
00085 if (argc != 1 && argc != 2 && argc != 4 && argc != 5)
00086 {
00087 fprintf(stderr,
00088 "usage: %s [numframes=100] [width=512] [height=512] [multithreaded?]\n",
00089 argv[0]);
00090 return 1;
00091 }
00092
00093 const int nframes = argc > 1 ? atoi(argv[1]) : 100;
00094 const int w = argc > 2 ? atoi(argv[2]) : 512;
00095 const int h = argc > 3 ? atoi(argv[3]) : 512;
00096 const int multithreaded = argc > 4 ? atoi(argv[4]) : 0;
00097 const struct env_dims indims = { w, h };
00098 const env_size_t insize = w * h;
00099
00100
00101 struct env_params envp;
00102 env_params_set_defaults(&envp);
00103
00104 envp.maxnorm_type = ENV_VCXNORM_MAXNORM;
00105 envp.scale_bits = 16;
00106
00107 env_assert_set_handler(&assert_handler);
00108 if (multithreaded)
00109 {
00110 env_init_pthread_alloc();
00111 env_init_pthread_job_server();
00112 }
00113 env_allocation_init(&malloc_thunk, &free);
00114
00115 if (nframes > 0)
00116 {
00117
00118
00119
00120
00121 struct env_rgb_pixel *in1 = (struct env_rgb_pixel*)
00122 env_allocate(insize * sizeof(struct env_rgb_pixel));
00123 struct env_rgb_pixel *in2 = (struct env_rgb_pixel*)
00124 env_allocate(insize * sizeof(struct env_rgb_pixel));
00125
00126 struct env_visual_cortex ivc;
00127 env_visual_cortex_init(&ivc, &envp);
00128
00129 fprintf(stderr, "%s: START: %d frames %dx%d... ",
00130 argv[0], nframes, w, h);
00131 fflush(stderr);
00132
00133 struct timeval real1, real2;
00134 gettimeofday(&real1, 0);
00135
00136 struct rusage ru1, ru2;
00137 getrusage(RUSAGE_SELF, &ru1);
00138
00139 for (int c = 0; c < nframes; ++c)
00140 {
00141 struct env_image ivcout = env_img_initializer;
00142 struct env_image intens = env_img_initializer;
00143 struct env_image color = env_img_initializer;
00144 struct env_image ori = env_img_initializer;
00145 # ifdef ENV_WITH_DYNAMIC_CHANNELS
00146 struct env_image flicker = env_img_initializer;
00147 struct env_image motion = env_img_initializer;
00148 # endif
00149
00150 env_mt_visual_cortex_input(multithreaded,
00151 &ivc, &envp, "visualcortex",
00152 c & 1 ? in2 : in1, 0,
00153 indims,
00154 0,
00155 0,
00156 &ivcout,
00157 &intens, &color, &ori
00158 # ifdef ENV_WITH_DYNAMIC_CHANNELS
00159 , &flicker, &motion
00160 # endif
00161 );
00162
00163 env_visual_cortex_rescale_ranges(
00164 &ivcout, &intens, &color, &ori
00165 # ifdef ENV_WITH_DYNAMIC_CHANNELS
00166 , &flicker, &motion
00167 # endif
00168 );
00169
00170 env_img_make_empty(&ivcout);
00171 env_img_make_empty(&intens);
00172 env_img_make_empty(&color);
00173 env_img_make_empty(&ori);
00174 # ifdef ENV_WITH_DYNAMIC_CHANNELS
00175 env_img_make_empty(&flicker);
00176 env_img_make_empty(&motion);
00177 # endif
00178 }
00179
00180 getrusage(RUSAGE_SELF, &ru2);
00181
00182 gettimeofday(&real2, 0);
00183
00184 const double real_secs =
00185 (real2.tv_sec - real1.tv_sec)
00186 + (real2.tv_usec - real1.tv_usec)
00187 / 1000000.0;
00188
00189 const double user_secs =
00190 (ru2.ru_utime.tv_sec - ru1.ru_utime.tv_sec)
00191 + (ru2.ru_utime.tv_usec - ru1.ru_utime.tv_usec)
00192 / 1000000.0;
00193
00194 const double sys_secs =
00195 (ru2.ru_stime.tv_sec - ru1.ru_stime.tv_sec)
00196 + (ru2.ru_stime.tv_usec - ru1.ru_stime.tv_usec)
00197 / 1000000.0;
00198
00199 const double frame_rate = nframes / real_secs;
00200 const double msec_per_frame = (1000.0*real_secs) / nframes;
00201
00202 fprintf(stderr, "DONE.\n");
00203 fprintf(stderr, "%s: real %.3fs; user %.3fs; "
00204 "sys %.3fs\n", argv[0], real_secs,
00205 user_secs, sys_secs);
00206 fprintf(stderr, "%s: %.3ffps; %.3fmsec/frame\n",
00207 argv[0], frame_rate, msec_per_frame);
00208 env_visual_cortex_destroy(&ivc);
00209 env_deallocate(in1);
00210 env_deallocate(in2);
00211 }
00212 env_allocation_cleanup();
00213
00214 return 0;
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224 #endif // ENVISION_APP_ENVISION_C_DEFINED