apps/autoexposure/hdr_control.c

Go to the documentation of this file.
00001 /*!***************************************************************************
00002 *! FILE NAME  : hdr_control.c
00003 *! DESCRIPTION: HDR part of the autoexposure/white balance/hdr daemon
00004 *! Copyright (C) 2008 Elphel, Inc.
00005 *! -----------------------------------------------------------------------------**
00006 *!  This program is free software: you can redistribute it and/or modify
00007 *!  it under the terms of the GNU General Public License as published by
00008 *!  the Free Software Foundation, either version 3 of the License, or
00009 *!  (at your option) any later version.
00010 *!
00011 *!  This program is distributed in the hope that it will be useful,
00012 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *!  GNU General Public License for more details.
00015 *!
00016 *!  You should have received a copy of the GNU General Public License
00017 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 *! -----------------------------------------------------------------------------**
00019 *!
00020 *!  $Log: hdr_control.c,v $
00021 *!  Revision 1.1.1.1  2008/11/27 20:04:01  elphel
00022 *!
00023 *!
00024 *!  Revision 1.1  2008/11/15 23:08:24  elphel
00025 *!  8.0.alpha17 - split autoexposure source file
00026 *!
00027 *!
00028 */ 
00029 
00030 #include "autoexposure.h"
00031 //#define P_HDR_DUR        168 // 0 - HDR 0ff, >1 - duration of same exposure (currently 1 or 2 - for free running)
00032 //#define P_HDR_VEXPOS     169 // if less than 0x10000 - number of lines of exposure, >=10000 - relative to "normal" exposure
00033 int exposureHDR (int frame, int target_frame) {
00034    unsigned long write_data[4]; 
00035    int target_frame8=target_frame & PARS_FRAMES_MASK;
00036    int HDR_mode;
00037    int vexpos, vexpos_HDR;
00038    int rslt;
00039    if (!((HDR_mode=framePars[target_frame8].pars[P_HDR_DUR])))  return 0; 
00040    if ((HDR_mode<1) || (HDR_mode<1)) {
00041      ELP_FERR(fprintf(stderr, "Wrong HDR mode %d (only 1 or 2 are supported)\n",HDR_mode));
00042      return -1;
00043    }
00044    vexpos=    framePars[target_frame8].pars[P_VEXPOS]; 
00045    vexpos_HDR=framePars[target_frame8].pars[P_HDR_VEXPOS];
00046    if (vexpos_HDR>0x10000) vexpos_HDR= (((long long) vexpos_HDR) * vexpos) >> 16;
00047    write_data[0]= FRAMEPARS_SETFRAME;
00048    write_data[2]= P_VEXPOS; // | FRAMEPAIR_FORCE_NEWPROC ?
00050    MDF5(fprintf(stderr,">>>>>HDR_mode=%d, write: %08lx  %08lx %08lx %08lx\n",HDR_mode,write_data[0],write_data[1],write_data[2],write_data[3]));
00051 
00052    switch (HDR_mode) {
00053      case 1:
00054        write_data[1]= target_frame+1;
00055        write_data[3]= vexpos_HDR;
00056        rslt=write(fd_fparmsall, write_data, sizeof(write_data));
00057       MDF5(fprintf(stderr,"write: %08lx  %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
00058        if (rslt < sizeof(write_data)) return -errno;
00059        write_data[1]= target_frame+2;
00060        write_data[3]= vexpos;
00061        rslt=write(fd_fparmsall, write_data, sizeof(write_data));
00062        if (rslt < sizeof(write_data)) return -errno;
00063       MDF5(fprintf(stderr,"write: %08lx  %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
00064      break;
00065      case 2:
00066        write_data[1]= target_frame+2;
00067        write_data[3]= vexpos_HDR;
00068        rslt=write(fd_fparmsall, write_data, sizeof(write_data));
00069        if (rslt < sizeof(write_data)) return -errno;
00070       MDF5(fprintf(stderr,"write: %08lx  %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
00071      break;
00072    }
00074    lseek(fd_fparmsall, frame + 2+LSEEK_FRAME_WAIT_ABS, SEEK_END);
00075    switch (HDR_mode) {
00076      case 1:
00077        write_data[1]= target_frame+3;
00078        write_data[3]= vexpos_HDR;
00079        rslt=write(fd_fparmsall, write_data, sizeof(write_data));
00080        if (rslt < sizeof(write_data)) return -errno;
00081       MDF5(fprintf(stderr,"write: %08lx  %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
00082        write_data[1]= target_frame+4;
00083        write_data[3]= vexpos;
00084        rslt=write(fd_fparmsall, write_data, sizeof(write_data));
00085        if (rslt < sizeof(write_data)) return -errno;
00086       MDF5(fprintf(stderr,"write: %08lx  %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
00087      break;
00088      case 2:
00089        write_data[1]= target_frame+4;
00090        write_data[3]= vexpos;
00091        rslt=write(fd_fparmsall, write_data, sizeof(write_data));
00092        if (rslt < sizeof(write_data)) return -errno;
00093       MDF5(fprintf(stderr,"write: %08lx  %08lx %08lx %08lx -> %d\n",write_data[0],write_data[1],write_data[2],write_data[3],rslt));
00094      break;
00095    }
00096    return 1;
00097 }
00098 
00099 
00100 
00106 int skipHDR(int mode, unsigned long frame) {
00107   int patt;
00108   int skip;
00109   switch (mode) {
00110    case 0: return 0;
00111    case 1: patt=HDR_PATTERN1;
00112            break;
00113    case 2: patt=HDR_PATTERN2;
00114            break;
00115    default: return -1;
00116   }
00117   patt >>= (frame & PARS_FRAMES_MASK);
00118   if (patt & 1) return 0;
00119   skip=0;
00120   while (patt && !(patt & 1)) { 
00121     patt >>= 1;
00122     skip++;
00123   }
00124   lseek(fd_histogram_cache, LSEEK_HIST_WAIT_Y,     SEEK_END); 
00125   lseek(fd_histogram_cache, LSEEK_HIST_NEEDED + 0, SEEK_END); 
00126 //  lseek(fd_histogram_cache, skip,                  SEEK_CUR); /// just wait until the Y histogram will available for non-HDR frame
00127   lseek(fd_histogram_cache, skip-1,                SEEK_CUR); 
00128   return 1;
00129 }

Generated on Fri Nov 28 00:06:21 2008 for elphel by  doxygen 1.5.1