/** * @brief Initialize the Eina library. * * @return 1 or greater on success, 0 on error. * * This function sets up all the eina modules. It returns 0 on * failure (that is, when one of the module fails to initialize), * otherwise it returns the number of times it has already been * called. * * When Eina is not used anymore, call eina_shutdown() to shut down * the Eina library. */ EAPI int eina_init(void) { const struct eina_desc_setup *itr, *itr_end; if (EINA_LIKELY(_eina_main_count > 0)) return ++_eina_main_count; if (!eina_log_init()) { fprintf(stderr, "Could not initialize eina logging system.\n"); return 0; } _eina_log_dom = eina_log_domain_register("eina", EINA_LOG_COLOR_DEFAULT); if (_eina_log_dom < 0) { EINA_LOG_ERR("Could not register log domain: eina"); eina_log_shutdown(); return 0; } itr = _eina_desc_setup; itr_end = itr + _eina_desc_setup_len; for (; itr < itr_end; itr++) { if (!itr->init()) { ERR("Could not initialize eina module '%s'.", itr->name); _eina_shutdown_from_desc(itr); return 0; } } _eina_main_count = 1; return 1; }
int log_shutdown(void) { if (EINA_LIKELY(__log_dom >= 0)) { eina_log_domain_unregister(__log_dom); __log_dom = -1; } return 0; }
static Eina_Bool _eeze_mount_lock_mtab(void) { // DBG("Locking mlock: %s", mnt_lock_get_linkfile(_eeze_mtab_lock)); if (EINA_LIKELY(access("/etc/mtab", W_OK))) { INF("Insufficient privs for mtab lock, continuing without lock"); return EINA_TRUE; } if (mnt_lock_file(_eeze_mtab_lock)) { ERR("Couldn't lock mtab!"); return EINA_FALSE; } _mtab_locked = EINA_TRUE; return EINA_TRUE; }
EAPI int eina_init(void) { const struct eina_desc_setup *itr, *itr_end; if (EINA_LIKELY(_eina_main_count > 0)) return ++_eina_main_count; srand(time(NULL)); while (eina_seed == 0) eina_seed = rand(); #ifdef MT if ((getenv("EINA_MTRACE")) && (getenv("MALLOC_TRACE"))) { _mt_enabled = 1; mtrace(); } #endif if (!eina_log_init()) { fprintf(stderr, "Could not initialize eina logging system.\n"); return 0; } _eina_log_dom = eina_log_domain_register("eina", EINA_LOG_COLOR_DEFAULT); if (_eina_log_dom < 0) { EINA_LOG_ERR("Could not register log domain: eina"); eina_log_shutdown(); return 0; } EINA_ERROR_NOT_MAIN_LOOP = eina_error_msg_static_register( EINA_ERROR_NOT_MAIN_LOOP_STR); #ifdef EFL_HAVE_THREADS # ifdef _WIN32 _eina_main_loop = GetCurrentThreadId(); # else _eina_main_loop = pthread_self(); # endif _eina_pid = getpid(); #endif #ifdef EINA_HAVE_DEBUG_THREADS pthread_mutex_init(&_eina_tracking_lock, NULL); if (getenv("EINA_DEBUG_THREADS")) _eina_threads_debug = atoi(getenv("EINA_DEBUG_THREADS")); #endif itr = _eina_desc_setup; itr_end = itr + _eina_desc_setup_len; for (; itr < itr_end; itr++) { if (!itr->init()) { ERR("Could not initialize eina module '%s'.", itr->name); _eina_shutdown_from_desc(itr); return 0; } } eina_cpu_count_internal(); _eina_main_count = 1; return 1; }
static Eina_Bool _bump_map_cpu_alpha_rgba(Evas_Filter_Command *cmd) { DATA8 *src, *map, *map_y1, *map_y2; DATA32 *dst; DATA32 dark, color, white, col; //DATA32 *phong; Eina_Bool compensate; int x, y, w, h, lx, ly, lz, gz, NL, diffusion, gzlz, gz2; double xyangle, zangle, sf, lxy, elevation; w = cmd->input->w; h = cmd->input->h; EINA_SAFETY_ON_FALSE_RETURN_VAL(w > 2 && h > 2, EINA_FALSE); src = ((RGBA_Image *) cmd->input->backing)->image.data8; map = ((RGBA_Image *) cmd->mask->backing)->image.data8; dst = ((RGBA_Image *) cmd->output->backing)->image.data; EINA_SAFETY_ON_NULL_RETURN_VAL(src, EINA_FALSE); EINA_SAFETY_ON_NULL_RETURN_VAL(map, EINA_FALSE); EINA_SAFETY_ON_NULL_RETURN_VAL(dst, EINA_FALSE); xyangle = cmd->bump.xyangle; zangle = cmd->bump.zangle; sf = cmd->bump.specular_factor; compensate = cmd->bump.compensate; elevation = cmd->bump.elevation; dark = cmd->bump.dark; white = cmd->bump.white; color = cmd->bump.color; // Compute appropriate lx, ly if (fabs(zangle) >= 90.) { WRN("Z angle was defined as %.0f, out of range. Defaults to %.0f.", zangle, DEFAULT_ZANGLE); zangle = DEFAULT_ZANGLE; } lxy = 255. * cos(zangle * M_PI / 180.); lx = (int) (lxy * cos(xyangle * M_PI / 180.)); ly = (int) (lxy * sin(xyangle * M_PI / 180.)); lz = (int) (255. * sin(zangle)); INF("Using light vector (%d,%d,%d)", lx, ly, lz); if (elevation <= 0) { WRN("Invalid elevation value of %.0f, using 10 instead.", elevation); elevation = 10.0; } gz = (6*255) / elevation; gzlz = gz * lz; gz2 = gz * gz; // Generate light table // FIXME: phong LUT not used (we need two) //phong = malloc(256 * 256 * sizeof(*phong)); //EINA_SAFETY_ON_NULL_RETURN_VAL(phong, EINA_FALSE); //_phong_rgba_generate(phong, 1.5, sf, 20, dark, color, white); // FIXME: x=0 and x=w-1 are NOT implemented. for (y = 0; y < h; y++) { int gx, gy; if (!y) { map_y1 = map; map_y2 = map + w; } else if (y == (h - 1)) { map_y1 = map - w; map_y2 = map; } else { map_y1 = map - w; map_y2 = map + w; } for (x = 0; x < w; x++, dst++, src++, map++, map_y1++, map_y2++) { if (!*src) continue; /* Color intensity is defined as: * I = Kd*N.L*Cd + Ks*N.H*Cs * Where Ks and Kd are 1 in this implementation * And Cs is white, Cd is color */ /* Compute N.L * N = (gx,gy,gz) * L = (lx,ly,lz) |L| = 255 */ if (EINA_LIKELY(x && (x < (w - 1)))) { gx = map[-1] + map_y1[-1] + map_y2[-1] - map[1] - map_y1[1] - map_y2[1]; gy = map_y2[-1] + map_y2[0] + map_y2[1] - map_y1[-1] - map_y1[0] - map_y1[1]; } else if (!x) { gx = map[0] + map_y1[0] + map_y2[0] - map[1] - map_y1[1] - map_y2[1]; gy = map_y2[0] + map_y2[1] + map_y2[1] - map_y1[0] - map_y1[1] - map_y1[1]; } else { gx = map[-1] + map_y1[-1] + map_y2[-1] - map[0] - map_y1[0] - map_y2[0]; gy = map_y2[-1] + map_y2[0] + map_y2[0] - map_y1[-1] - map_y1[0] - map_y1[0]; } NL = gx*lx + gy*ly + gzlz; if (0 && NL < 0) { // TODO: Check this diffusion = lz; } else { int g2 = gx*gx + gy*gy + gz2; diffusion = NL / sqrt(MAX(g2, 1)); //diffusion += MAX(0, lz - diffusion); } if (compensate) diffusion = diffusion * 255 / lz; diffusion = CLAMP(1, diffusion + 1, 256); col = INTERP_256(diffusion, color, dark); if (sf > 0) { /* Compute N.H * H = (L+V) / |L+V| * V = (0,0,255) * L = (lx,ly,lz) |L| = 255 */ // FIXME: All these doubles :) int shine; const double hnorm = sqrt(lx*lx + ly*ly + (lz+255)*(lz+255)); const double hx = (double) lx / hnorm; const double hy = (double) ly / hnorm; const double hz = (double) (lz+255) / hnorm; double NHx = hx*gx / 255.0; double NHy = hy*gy / 255.0; double nz = sqrt(255.0*255.0 - gx*gx - gy*gy); double NHz = (hz*nz) / 255.0; double NH = NHx + NHy + NHz; double specular = NH > 0 ? pow(NH, sf) : 0; if (compensate) { const double basespecular = pow(hz, sf); shine = (specular - basespecular) * 255.0 / (1.0 - basespecular); } else shine = specular * 255.0; col = INTERP_256(CLAMP(1, shine + 1, 256), white, col); } *dst = INTERP_256(*src + 1, col, *dst); } } return EINA_TRUE; }