apps/php-5.2.1/ext/elphel/elphel_php.c File Reference

#include <sys/mman.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <asm/byteorder.h>
#include <errno.h>
#include "php.h"
#include "php_ini.h"
#include "elphel_php.h"

Include dependency graph for elphel_php.c:

Go to the source code of this file.

Defines

#define saferead255(f, d, l)   read(f,d,((l)<256)?(l):255)
#define HIST_LEN   256 * 4 * 4
#define GAMMA_LEN   256 * 4 * 2

Functions

static void init_sens ()
 call before any access to sensor parameters/functions
 PHP_FUNCTION (elphel_flush_cache)
long createExifDirectory (int rebuild)
 PHP_FUNCTION (elphel_get_circbuf_pointers)
 PHP_FUNCTION (elphel_get_exif_elphel)
 PHP_FUNCTION (elphel_update_exif)
 PHP_FUNCTION (elphel_get_exif_field)
 PHP_FUNCTION (elphel_set_exif_field)
 PHP_FUNCTION (elph_hello)
 this function below is just for experiments
 PHP_FUNCTION (elphel_wait_frame)
 wait for the next frame to be compressed (and related parameters updated
 PHP_FUNCTION (elphel_autoexposure_set)
 Set autoexposure parameters according to the ones written.
 PHP_FUNCTION (elphel_autoexposure_get)
 copy window and exposure parameters to autoexp_state
 PHP_FUNCTION (elphel_get_histogram)
 PHP_FUNCTION (elphel_get_gamma)
 PHP_FUNCTION (elphel_gamma)
 PHP_FUNCTION (elphel_histogram)
int calcWhiteBalance (int thrsh, int min_pixels, double diffGains[3], long use_green2)
 PHP_FUNCTION (elphel_white_balance)
 PHP_FUNCTION (elphel_get_P_arr)
 PHP_FUNCTION (elphel_get_P_warr)
 Same as above, but reads _written_ parameters, not the output ones.
 PHP_FUNCTION (elphel_set_P_arr)
 PHP_FUNCTION (elphel_fpga_read)
 Low-level, direct FPGA read/write.
 PHP_FUNCTION (elphel_fpga_write)
 PHP_FUNCTION (elphel_get_P_value)
 PHP_FUNCTION (elphel_set_P_value)
 Set acquisition/compression parameters. Second half (>=1024) maps to the read parameters (see above).
 PHP_FUNCTION (elphel_get_state)
 Get sensor state, usually 7- sensor is running, compressor is stopped, 8 - compressor is runing.
 PHP_FUNCTION (elphel_program_sensor)
 program sesnor/compressor according to the parameters specified. Argument==0 - restart the sensor, 1 - do it "on the fly"
 PHP_FUNCTION (elphel_compressor_cmd)
 Send arbitrary command to the FPGA compressor.
 PHP_FUNCTION (elphel_compressor_reset)
 Reset FPGA compressor (reinitialize, may need to issue twice in a row).
 PHP_FUNCTION (elphel_compressor_run)
 Start FPGA compressor.
 PHP_FUNCTION (elphel_compressor_stop)
 Stop FPGA comressor (need to wait when it is stopped).
 PHP_FUNCTION (elphel_compressor_frame)
 Acquire one frame to the buffer.
 PHP_FUNCTION (elphel_is_compressor_idle)
 return 1 if compressor is actually stopped
 PHP_FUNCTION (elphel_reset_sensor)
 reset sensor, and re-initialize it
 PHP_FUNCTION (elphel_set_fpga_time)
 PHP_FUNCTION (elphel_get_fpga_time)
 Get current FPGA time as (double) seconds.
 PHP_FUNCTION (elphel_trigger)
 Program trigger parameters, start/restart trigger.
static void php_elphel_init_globals (zend_elphel_globals *elphel_globals)
 PHP_RINIT_FUNCTION (elphel)
 PHP_MINIT_FUNCTION (elphel)
 PHP_MSHUTDOWN_FUNCTION (elphel)
 PHP_MINFO_FUNCTION (elphel)

Variables

static function_entry elphel_functions []
 include <asm/elphel/c313a.h> - is now in the elphel_php.h
zend_module_entry elphel_module_entry


Define Documentation

#define GAMMA_LEN   256 * 4 * 2

Definition at line 561 of file elphel_php.c.

#define HIST_LEN   256 * 4 * 4

Definition at line 560 of file elphel_php.c.

#define saferead255 ( f,
d,
 )     read(f,d,((l)<256)?(l):255)

Definition at line 248 of file elphel_php.c.

Referenced by PHP_FUNCTION().


Function Documentation

int calcWhiteBalance ( int  thrsh,
int  min_pixels,
double  diffGains[3],
long  use_green2 
)

*********************************** WHITE BALANCE ****************************************** This function can be used for white balance. It will find percentiles ("cent" means 0x100 here) for 4 colors (both greens separate) so that the highest value of 4 will be equal to thrsh (should be less than 255). after compensation for non-linear "gamma" (for the values close to 255 it can be linearly approximated) these values can be used to directly adjust color balance - just reverse proportionally to the ratio of this result. returns 0 - OK, <0 error

copying arrays, so they will be "frozen", not updated with the new frames

continue by lowering threshold to match the minimal number of pixels

continue down, lowering thrsh until min_pixels is met.

could not satisfy min_pixels - wrong min_pixels?

continue down, looking when other colors will get the same number of pixels (smax), then linear interpolate fractions.

problem with the histogram

unapply gamma (histogram is calculated _after_ "gamma" but we need the _before_ gamma values here

OK

Parameters:
use_green2  third parameter Green1/Green (index2/index1)

Definition at line 653 of file elphel_php.c.

References ELPHEL_G, GAMMA_LEN, hist_gamma_mmap, HIST_LEN, and memcpy().

long createExifDirectory ( int  rebuild  ) 

Definition at line 172 of file elphel_php.c.

References ELPHEL_G, exif_dir, Exif_GPSInfo_CompassDirection, Exif_GPSInfo_CompassDirection_Index, Exif_GPSInfo_CompassDirectionRef, Exif_GPSInfo_CompassDirectionRef_Index, Exif_GPSInfo_CompassPitch, Exif_GPSInfo_CompassPitch_Index, Exif_GPSInfo_CompassPitchRef, Exif_GPSInfo_CompassPitchRef_Index, Exif_GPSInfo_CompassRoll, Exif_GPSInfo_CompassRoll_Index, Exif_GPSInfo_CompassRollRef, Exif_GPSInfo_CompassRollRef_Index, Exif_GPSInfo_GPSAltitude, Exif_GPSInfo_GPSAltitude_Index, Exif_GPSInfo_GPSAltitudeRef, Exif_GPSInfo_GPSAltitudeRef_Index, Exif_GPSInfo_GPSDateStamp, Exif_GPSInfo_GPSDateStamp_Index, Exif_GPSInfo_GPSLatitude, Exif_GPSInfo_GPSLatitude_Index, Exif_GPSInfo_GPSLatitudeRef, Exif_GPSInfo_GPSLatitudeRef_Index, Exif_GPSInfo_GPSLongitude, Exif_GPSInfo_GPSLongitude_Index, Exif_GPSInfo_GPSLongitudeRef, Exif_GPSInfo_GPSLongitudeRef_Index, Exif_GPSInfo_GPSMeasureMode, Exif_GPSInfo_GPSMeasureMode_Index, Exif_GPSInfo_GPSTimeStamp, Exif_GPSInfo_GPSTimeStamp_Index, Exif_Image_FrameNumber, Exif_Image_FrameNumber_Index, Exif_Image_ImageDescription, Exif_Image_ImageDescription_Index, Exif_Photo_DateTimeOriginal, Exif_Photo_DateTimeOriginal_Index, Exif_Photo_ExposureTime, Exif_Photo_ExposureTime_Index, Exif_Photo_SubSecTimeOriginal, Exif_Photo_SubSecTimeOriginal_Index, exif_size, ExifKmlNumber, fd_exifdir, exif_dir_table_t::ltag, memcpy(), and read.

Referenced by PHP_FUNCTION().

static void init_sens (  )  [static]

call before any access to sensor parameters/functions

Definition at line 162 of file elphel_php.c.

References ELPHEL_G, fd_sens, imageParamsR, LSEEK_INIT_SENSOR, and P_SENSOR.

Referenced by PHP_FUNCTION().

static void php_elphel_init_globals ( zend_elphel_globals *  elphel_globals  )  [static]

Definition at line 1119 of file elphel_php.c.

References AUTOEXP_DEV_NAME, EXIF_DEV_NAME, EXIFDIR_DEV_NAME, EXIFMETA_DEV_NAME, P_NUMBER, return, and TABLES_LEN.

Referenced by PHP_MINIT_FUNCTION().

PHP_FUNCTION ( elphel_trigger   ) 

Program trigger parameters, start/restart trigger.

Definition at line 1112 of file elphel_php.c.

PHP_FUNCTION ( elphel_get_fpga_time   ) 

Get current FPGA time as (double) seconds.

Definition at line 1102 of file elphel_php.c.

PHP_FUNCTION ( elphel_set_fpga_time   ) 

set FPGA clock. Input parameter - (double) seconds (i.e. from 01/01/1970) This clock is used to timestamp each image returns same time rounded to microseconds (as written to FPGA)

Definition at line 1085 of file elphel_php.c.

PHP_FUNCTION ( elphel_reset_sensor   ) 

reset sensor, and re-initialize it

reset circbuf and DMA

reset senosr

re-initialize sensor

Definition at line 1075 of file elphel_php.c.

PHP_FUNCTION ( elphel_is_compressor_idle   ) 

return 1 if compressor is actually stopped

Definition at line 1066 of file elphel_php.c.

PHP_FUNCTION ( elphel_compressor_frame   ) 

Acquire one frame to the buffer.

Definition at line 1059 of file elphel_php.c.

PHP_FUNCTION ( elphel_compressor_stop   ) 

Stop FPGA comressor (need to wait when it is stopped).

Definition at line 1053 of file elphel_php.c.

PHP_FUNCTION ( elphel_compressor_run   ) 

Start FPGA compressor.

Definition at line 1045 of file elphel_php.c.

PHP_FUNCTION ( elphel_compressor_reset   ) 

Reset FPGA compressor (reinitialize, may need to issue twice in a row).

Definition at line 1038 of file elphel_php.c.

PHP_FUNCTION ( elphel_compressor_cmd   ) 

Send arbitrary command to the FPGA compressor.

Definition at line 1028 of file elphel_php.c.

PHP_FUNCTION ( elphel_program_sensor   ) 

program sesnor/compressor according to the parameters specified. Argument==0 - restart the sensor, 1 - do it "on the fly"

Definition at line 1014 of file elphel_php.c.

PHP_FUNCTION ( elphel_get_state   ) 

Get sensor state, usually 7- sensor is running, compressor is stopped, 8 - compressor is runing.

Definition at line 1008 of file elphel_php.c.

PHP_FUNCTION ( elphel_set_P_value   ) 

Set acquisition/compression parameters. Second half (>=1024) maps to the read parameters (see above).

Definition at line 989 of file elphel_php.c.

PHP_FUNCTION ( elphel_get_P_value   ) 

Read value from the sensor/compressor parameters ("read" parameters, verified by the driver), see asm/elphel/c313a.h Second half (>=1024) maps to write parameters (to be used by the camera driver)

Definition at line 975 of file elphel_php.c.

PHP_FUNCTION ( elphel_fpga_write   ) 

Definition at line 950 of file elphel_php.c.

PHP_FUNCTION ( elphel_fpga_read   ) 

Low-level, direct FPGA read/write.

32-bit registers, not bytes

Definition at line 929 of file elphel_php.c.

PHP_FUNCTION ( elphel_set_P_arr   ) 

This function reads associative array and writes values to the camera registers, using "ELPHEL_* constants" to determine register address from the provided key in each key/value pair All non-numerical values are ignored Returns number of values written

Definition at line 891 of file elphel_php.c.

PHP_FUNCTION ( elphel_get_P_warr   ) 

Same as above, but reads _written_ parameters, not the output ones.

Definition at line 857 of file elphel_php.c.

PHP_FUNCTION ( elphel_get_P_arr   ) 

This function reads associative array and uses the keys as a template for the result array. If mey is one of the defined P_VALUE names (same as global constant but w/o "ELPHEL_" prefix) then the result array will have element with the same key and the value equal to the value of the camera parameter

Definition at line 828 of file elphel_php.c.

PHP_FUNCTION ( elphel_white_balance   ) 

elphel_white_balance ([double thrsh [, double minfrac [, double rscale [,double bscale]]]]); needs program non_stop to apply calculated results returns 0 if OK, else - negative (error number)

R/G, B/G. G1/G

threshold (0..255) for the "brightest color"

minimal number of pixels above threshold for the brightest color (threshold will be lowered to satisfy min_pixels)

error, negative

apply color correction (if any) to the result

program the calculated values make sure that with small steps the integer values are changed by at least 1

Definition at line 769 of file elphel_php.c.

PHP_FUNCTION ( elphel_histogram   ) 

Definition at line 617 of file elphel_php.c.

PHP_FUNCTION ( elphel_gamma   ) 

*********************************** GAMMA ****************************************** Uses gamma table selected by first parameter (0 - R, 1 - G, 2 - GB, 3 - B) and the fraction (0..1.0) to find (and interpolate) the output value

wrong channel

copying array, so they will be "frozen", not updated with the new frames here - no need to copy...

Definition at line 596 of file elphel_php.c.

PHP_FUNCTION ( elphel_get_gamma   ) 

Definition at line 578 of file elphel_php.c.

PHP_FUNCTION ( elphel_get_histogram   ) 

Definition at line 566 of file elphel_php.c.

PHP_FUNCTION ( elphel_autoexposure_get   ) 

copy window and exposure parameters to autoexp_state

Definition at line 553 of file elphel_php.c.

PHP_FUNCTION ( elphel_autoexposure_set   ) 

Set autoexposure parameters according to the ones written.

Definition at line 546 of file elphel_php.c.

PHP_FUNCTION ( elphel_wait_frame   ) 

wait for the next frame to be compressed (and related parameters updated

Definition at line 538 of file elphel_php.c.

PHP_FUNCTION ( elph_hello   ) 

this function below is just for experiments

this below works

Definition at line 525 of file elphel_php.c.

PHP_FUNCTION ( elphel_set_exif_field   ) 

Definition at line 493 of file elphel_php.c.

PHP_FUNCTION ( elphel_get_exif_field   ) 

Definition at line 460 of file elphel_php.c.

PHP_FUNCTION ( elphel_update_exif   ) 

Definition at line 455 of file elphel_php.c.

PHP_FUNCTION ( elphel_get_exif_elphel   ) 

Definition at line 249 of file elphel_php.c.

PHP_FUNCTION ( elphel_get_circbuf_pointers   ) 

Definition at line 219 of file elphel_php.c.

PHP_FUNCTION ( elphel_flush_cache   ) 

Definition at line 166 of file elphel_php.c.

PHP_MINFO_FUNCTION ( elphel   ) 

Definition at line 1237 of file elphel_php.c.

References PHP_ELPHEL_VERSION.

PHP_MINIT_FUNCTION ( elphel   ) 

Definition at line 1205 of file elphel_php.c.

References DEFINE_P_NAMES, and php_elphel_init_globals().

PHP_MSHUTDOWN_FUNCTION ( elphel   ) 

Definition at line 1222 of file elphel_php.c.

References ccam_dma_buf, ELPHEL_G, fd_autoexp, fd_circ, fd_exif, fd_exifdir, fd_exifmeta, fd_sens, hist_gamma_mmap, and imageParamsR.

PHP_RINIT_FUNCTION ( elphel   ) 

Definition at line 1198 of file elphel_php.c.


Variable Documentation

function_entry elphel_functions[] [static]

include <asm/elphel/c313a.h> - is now in the elphel_php.h

*************************************************************************** ! FILE NAME : elphel_php.c ! DESCRIPTION: Implementation of elphel extension module for PHP ! Copyright (C) 2002-2007 Elphel, Inc. ! -----------------------------------------------------------------------------** ! This program is free software: you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation, either version 3 of the License, or ! (at your option) any later version. ! ! This program 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 General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. ! -----------------------------------------------------------------------------** !

Log
elphel_php.c,v
! Revision 1.21 2008/05/02 15:12:09 elphel ! minor comment edit ! ! Revision 1.20 2008/05/01 01:32:04 elphel ! support for the frame number - combining hardware frame counter used by i2c (3-bit) and software one ! ! Revision 1.19 2008/04/25 21:31:35 elphel ! Added Exif_Photo_ExposureTime to be returned by elphel_get_exif_elphel() ! ! Revision 1.18 2008/04/24 18:16:40 elphel ! New function to retrieve circbuf structure (frame pointers and Exif pointers) ! ! Revision 1.17 2008/04/22 22:14:08 elphel ! Added functions related to Exif data ! ! Revision 1.16 2008/04/20 06:49:04 elphel ! Added histogram related functions ! ! Revision 1.15 2008/04/17 22:36:07 elphel ! Bug fix, new function added - elphel_is_compressor_idle() ! ! Revision 1.14 2008/03/20 22:25:09 elphel ! elphel_trigger - programming synchronization parameters ! ! Revision 1.13 2008/03/15 23:04:21 elphel ! added FPGA registers R/W ! ! Revision 1.12 2008/01/27 06:23:17 elphel ! New function - elphel_wait_frame (wait fro the next frame to be compressed) ! ! Revision 1.11 2008/01/12 06:53:23 elphel ! 7.1.7.2 - added elphel_autoexposure_get() function to elphel php extension ! ! Revision 1.10 2008/01/11 07:47:44 elphel ! added elphel_autoexposure_set() function ! ! Revision 1.9 2008/01/10 02:43:37 elphel ! Added balance of 2 greens in Bayer mosaic ! ! Revision 1.8 2008/01/09 10:22:02 elphel ! Implemented elphel_white_balance() function ! ! Revision 1.7 2007/12/14 22:38:53 elphel ! cleaned up after fixing cache bug ! ! Revision 1.6 2007/12/06 19:05:33 elphel ! 2 new functions - arbitrary compressor command (elphel_compressor_cmd) and elphel_compressor_reset ! ! Revision 1.5 2007/12/05 23:41:04 elphel ! Fixing minor in bugs in the sensor reset code ! ! Revision 1.4 2007/12/05 22:01:19 elphel ! added handling etrax fs mmap cach problem when communicating between PHP extension and the driver ! ! Revision 1.3 2007/12/04 06:41:11 elphel ! Implementation of 2 additional functions: elphel_get_P_arr, elphel_set_P_arr !

Definition at line 96 of file elphel_php.c.

zend_module_entry elphel_module_entry

Initial value:

 {



    PHP_ELPHEL_EXTNAME,
    elphel_functions,
    PHP_MINIT(elphel),
    PHP_MSHUTDOWN(elphel),
    PHP_RINIT(elphel),
    NULL,
    PHP_MINFO(elphel),



    STANDARD_MODULE_PROPERTIES
}

Definition at line 134 of file elphel_php.c.


Generated on Thu Aug 7 16:19:49 2008 for elphel by  doxygen 1.5.1