* @param needreverse 0 if only cumulative histogram is needed, >0 if the reverse is also needed
* @return <0 if histogram can not be found fo the specified frame (i.e. too late), otherwise it is an index in histogram cache.
*/
intget_histogram_index(longport,longsub_chn,longcolor,longframe,longneedreverse){/// histogram is availble for previous frame, not for the current one
intget_histogram_index(longport,longsub_chn,longcolor,longframe,longneedreverse){/// histogram is available for previous frame, not for the current one
longhist_index;
if((color<0)||(color>=4))return-1;/// wrong color
if((port<0)||(port>=SENSOR_PORTS))return-1;
if((sub_chn<0)||(sub_chn>=MAX_SENSORS))return-1;
lseek(ELPHEL_G(fd_histogram_cache),LSEEK_HIST_SET_CHN+(4<<port)+(1<<sub_chn),SEEK_END);/// specify port/sub-channel is needed
lseek(ELPHEL_G(fd_histogram_cache),LSEEK_HIST_SET_CHN+(4*port)+sub_chn,SEEK_END);/// specify port/sub-channel is needed
if(color==COLOR_Y_NUMBER)lseek(ELPHEL_G(fd_histogram_cache),LSEEK_HIST_WAIT_Y,SEEK_END);/// wait for just Y (G1)
elselseek(ELPHEL_G(fd_histogram_cache),LSEEK_HIST_WAIT_C,SEEK_END);/// wait for all histograms, not just Y (G1)
lseek(ELPHEL_G(fd_histogram_cache),LSEEK_HIST_NEEDED+((1<<color)<<(needreverse?8:4)),SEEK_END);/// specify what color is needed and if reverse is needed