/* jd350e.c * * White balancing and brightness correction for the Jenoptik * JD350 entrance camera * * Copyright 2001 Michael Trawny * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ #include "config.h" #include #include #include #include #include "jd350e.h" #include "jd350e_red.h" /*#include "jd350e_blue.h"*/ #define GP_MODULE "jd350e" #define THRESHOLD 0xf8 #define RED(p,x,y,w) *((p)+3*((y)*(w)+(x)) ) #define GREEN(p,x,y,w) *((p)+3*((y)*(w)+(x))+1) #define BLUE(p,x,y,w) *((p)+3*((y)*(w)+(x))+2) #define SWAP(a,b) {unsigned char t=(a); (a)=(b); (b)=t;} #define MINMAX(a,min,max) { (min)=MIN(min,a); (max)=MAX(max,a); } #ifndef MAX # define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif #ifndef MIN # define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif int jd350e_postprocessing(int width, int height, unsigned char* rgb){ int x,y, red_min=255, red_max=0, blue_min=255, blue_max=0, green_min=255, green_max=0; double min, max, amplify; /* reverse image row by row... */ for( y=0; y red_max ){ #endif /* outdoor daylight : red color correction curve*/ GP_DEBUG( "daylight mode"); for( y=0; y blue_max ){ /* indoor electric light */ GP_DEBUG( "electric light mode"); for( y=0; y (b) ? (a) : (b)) #endif #ifndef MIN # define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif for(i=0; i<(width*height*3); i++) MINMAX( rgb[i], min, max ); amplify = 255.0/(max-min); for(i=0; i<(width*height*3); i++) { int val = amplify * (rgb[i] - min); if(val < brightness_adjust) rgb[i] = val * 2; else if (val > (255 - brightness_adjust)) rgb[i] = 255; else rgb[i] = val + brightness_adjust; } return GP_OK; }