LoUtils.c

Go to the documentation of this file.
00001 /**
00002    \file  Robots/LoBot/irccm/LoUtils.c
00003    \brief Utility functions.
00004 */
00005 
00006 /*
00007  ************************************************************************
00008  * The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   *
00009  * by the University of Southern California (USC) and the iLab at USC.  *
00010  * See http://iLab.usc.edu for information about this project.          *
00011  *                                                                      *
00012  * Major portions of the iLab Neuromorphic Vision Toolkit are protected *
00013  * under the U.S. patent ``Computation of Intrinsic Perceptual Saliency *
00014  * in Visual Environments, and Applications'' by Christof Koch and      *
00015  * Laurent Itti, California Institute of Technology, 2001 (patent       *
00016  * pending; application number 09/912,225 filed July 23, 2001; see      *
00017  * http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     *
00018  ************************************************************************
00019  * This file is part of the iLab Neuromorphic Vision C++ Toolkit.       *
00020  *                                                                      *
00021  * The iLab Neuromorphic Vision C++ Toolkit is free software; you can   *
00022  * redistribute it and/or modify it under the terms of the GNU General  *
00023  * Public License as published by the Free Software Foundation; either  *
00024  * version 2 of the License, or (at your option) any later version.     *
00025  *                                                                      *
00026  * The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  *
00027  * that it will be useful, but WITHOUT ANY WARRANTY; without even the   *
00028  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      *
00029  * PURPOSE.  See the GNU General Public License for more details.       *
00030  *                                                                      *
00031  * You should have received a copy of the GNU General Public License    *
00032  * along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   *
00033  * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   *
00034  * Boston, MA 02111-1307 USA.                                           *
00035  ************************************************************************
00036 */
00037 
00038 /*
00039    Primary maintainer for this file: mviswana usc edu
00040    $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/irccm/LoUtils.c $
00041    $Id: LoUtils.c 13693 2010-07-24 21:59:05Z mviswana $
00042 */
00043 
00044 /*------------------------------ HEADERS ------------------------------*/
00045 
00046 // lobot headers
00047 #include "LoUtils.h"
00048 #include "LoTimer.h"
00049 
00050 // Standard C headers
00051 #include <stdlib.h>
00052 
00053 /*------------------------- NUMERIC FUNCTIONS -------------------------*/
00054 
00055 int lo_clamp(int n, int min, int max)
00056 {
00057    if (n < min)
00058       return min ;
00059    if (n > max)
00060       return max ;
00061    return n ;
00062 }
00063 
00064 char lo_sign(int n)
00065 {
00066    return (n < 0) ? -1 : +1 ;
00067 }
00068 
00069 // DEVNOTE: Computationally expensive function due to 32-bit division
00070 /*
00071 int lo_random(int min, int max)
00072 {
00073    static char seed ;
00074    if (! seed) {
00075       srandom(lo_ticks()) ;
00076       seed = 1 ;
00077    }
00078 
00079    long r = random() ;
00080    if (r == 0)
00081       ++r ;
00082 
00083    return min + (max - min)/((int)(((long) RANDOM_MAX)/r)) ;
00084 }
00085 // */
00086 
00087 /*--------------------------- BIT FIDDLING ----------------------------*/
00088 
00089 char lo_lobyte(int word)
00090 {
00091    return (char)(word & 0xFF) ;
00092 }
00093 
00094 char lo_hibyte(int word)
00095 {
00096    return (char)((word >> 8) & 0xFF) ;
00097 }
00098 
00099 int lo_make_word(char hi, char lo)
00100 {
00101    int word = ((int) hi) & 0x00FF ;
00102    word <<= 8 ;
00103    return word | (((int) lo) & 0x00FF) ;
00104 }
Generated on Sun May 8 08:41:30 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3