//----------------------------------------------------------------------------- // Copyright © 2006 - Philip Howard - All rights reserved // // 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 2 // 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, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //----------------------------------------------------------------------------- // package libh/arith // homepage http://libh.slashusr.org/ //----------------------------------------------------------------------------- // author Philip Howard // email libh at ipal dot org // homepage http://phil.ipal.org/ //----------------------------------------------------------------------------- // This file is best viewed using a fixed spaced font such as Courier // and in a display at least 120 columns wide. //----------------------------------------------------------------------------- __FMACRO_BEGIN__ //----------------------------------------------------------------------------- // macro pix_itof // // purpose Convert an integer (int) pixel intensity value in the range // 0 .. N-1 to a gamma adjusted floating point (double pixel // intensity value in the range 0.0 .. 1.0. // // arguments 1 (double) gamma correction factor to use // 2 (int) pixel intensity from 0 to N-1 // 3 (int) integer scale N // // returns (double) pixel intensity in the range 0.0 .. 1.0 //----------------------------------------------------------------------------- #define pix_itof(g,v,s) ({ \ int libh__value; \ int libh__scale; \ libh__value = (v); \ libh__scale = (s); \ ( libh__scale <= 1 ) ? 0.0 : \ ( libh__value >= libh__scale ) ? 1.0 : \ ( libh__value <= 0 ) ? 0.0 : \ ({ double libh__gvtmp; \ libh__gvtmp = (g); \ if ( libh__gvtmp <= 0.0 ) libh__gvtmp = PIX_DEFAULT_GAMMA; \ libh__gvtmp = exp( log( (double) libh__value / (double) ( libh__scale - 1 ) ) * libh__gvtmp ); \ ( libh__gvtmp <= 0.0 ) ? 0.0 : ( libh__gvtmp >= 1.0 ) ? 1.0 : libh__gvtmp; \ }) \ }) __FMACRO_END__