[45d5e8]: packages / web / 353 / php_top / snapfull.php Maximize Restore History

Download this file

snapfull.php    125 lines (122 with data), 5.0 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
#!/usr/local/sbin/php -q
<?php
/*!
*! PHP script
*! FILE NAME : snapfull.php
*! DESCRIPTION: acquiring a single-frame with different frame size than currently used (i.e. for streaming)
*! AUTHOR : Elphel, Inc.
*! Copyright (C) 2008 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: snapfull.php,v $
*! Revision 1.3 2009/10/12 19:20:24 elphel
*! Added "Content-Disposition" support to suggest filenames to save images
*!
*! Revision 1.2 2008/12/14 05:37:11 elphel
*! Added turning off autoexposure+white balance during snapshot sequence
*!
*! Revision 1.1.1.1 2008/11/27 20:04:03 elphel
*!
*!
*! Revision 1.5 2008/11/20 01:48:39 elphel
*! added streamer autostart
*!
*! Revision 1.4 2008/11/17 23:42:04 elphel
*! changed myval() to accept numbers in ""
*!
*! Revision 1.3 2008/11/15 20:24:39 elphel
*! added default left/top
*!
*! Revision 1.2 2008/11/15 20:16:39 elphel
*! removed debugging garbage
*!
*! Revision 1.1 2008/11/15 20:10:12 elphel
*! Added script to capture single frames of different resolution (usually full) than currently being streamed
*!
*/
$imgsrv='http://'.$_SERVER['HTTP_HOST'].':8081/';
$suggestSave=false;
$ahead=3;
$delay=2;
$sensorSize=array('SENSOR_WIDTH'=>0,'SENSOR_HEIGHT'=>0);
$sensorSize=elphel_get_P_arr($sensorSize);
/// Use default width, height, decimation and binning if they are not specified in the HTTP GET parameters
$parsForSnap=array('WB_EN'=>0,
'AUTOEXP_ON'=>0,
'WOI_WIDTH' => $sensorSize['SENSOR_WIDTH'],
'WOI_HEIGHT'=> $sensorSize['SENSOR_HEIGHT'],
'WOI_LEFT' => 0,
'WOI_TOP' => 0,
'DCM_HOR' => 1,
'DCM_VERT' => 1,
'BIN_HOR' => 1,
'BIN_VERT' => 1);
foreach($_GET as $key=>$value) switch ($key){
case 'save':
$suggestSave=true;
break;
case 'ahead':
$ahead=myval($value);
break;
case 'delay':
$delay=myval($value);
break;
default: /// treat as camera native parameters
$parsForSnap[$key]=myval($value);
}
/// Add default width, height, decimation and binning if they are not specified in the HTTP GET parameters
$parsSaved=elphel_get_P_arr($parsForSnap);
$thisFrameNumber=elphel_get_frame();
if ($ahead>5) {
elphel_wait_frame_abs($thisFrameNumber+$ahead-5);
$ahead-=5;
$thisFrameNumber=elphel_get_frame();
}
$pgmFrameNumber=$thisFrameNumber+$ahead;
///set modified parameters to the camera
elphel_set_P_arr ($parsForSnap, $pgmFrameNumber);
///set original parameters ($delay frames later)
elphel_wait_frame_abs($thisFrameNumber+$delay);
elphel_set_P_arr ($parsSaved, $pgmFrameNumber+$delay);
/// Wait for the frame to be acquired
elphel_wait_frame_abs($pgmFrameNumber+2); /// the frame should be in circbuf by then
$circbuf_pointers=elphel_get_circbuf_pointers(1); /// 1 - skip the vary oldest frame
$meta=end($circbuf_pointers);
if (!count($circbuf_pointers) || ($meta['frame'] < $pgmFrameNumber)) {
echo "compressor is turned off";
echo "<pre>\n";print_r($circbuf_pointers);echo "</pre>\n";
exit (0);
}
/// look in the circbuf array (in case we already missed it and it is not the latest)
while($meta['frame'] > $pgmFrameNumber) {
if (!prev($circbuf_pointers)) { /// failed to find the right frame in circbuf - probably overwritten
printf ("<pre>could not find the frame %d(0x%x) in the circbuf:\n",$pgmFrameNumber,$pgmFrameNumber);
print_r ($circbuf_pointers);
echo "\n</pre>";
exit (0);
}
$meta=current($circbuf_pointers);
}
/// Redirect browser to the imgsrv with the frame needed. Unfortunately "reload" button in the browser will not work
if ($suggestSave) header('Location: '.$imgsrv.$meta['circbuf_pointer'].'/sbimg');
else header('Location: '.$imgsrv.$meta['circbuf_pointer'].'/bimg');
exit();
function myval ($s) {
$s=trim($s,"\" ");
if (strtoupper(substr($s,0,2))=="0X") return intval(hexdec($s));
else return intval($s);
}
?>