/* * Khoros: $Id$ */ #if !defined(__lint) && !defined(__CODECENTER__) static char rcsid[] = "Khoros: $Id$"; #endif /* * Copyright (C) 1993 - 1997, Khoral Research, Inc., ("KRI"). * All rights reserved. See $BOOTSTRAP/repos/license/License or run klicense. */ /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<< >>>> >>>> Main program for myimageenhancement >>>> >>>> Private: >>>> main >>>> >>>> Static: >>>> Public: >>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<< */ #include "myimageenhancement.h" clui_info_struct *clui_info = NULL; /*----------------------------------------------------------- | | Routine Name: main() - Image enhancement | | Purpose: main program for myimageenhancement | | Input: | char *clui_info->i_file; {First Input data object} | int clui_info->i_flag; {TRUE if -i specified} | | int clui_info->enhancement_toggle; {Flag toggle selection} | int clui_info->enhancement_flag; {TRUE if -enhancement specified} | | char *clui_info->o_file; {Resulting output data object} | int clui_info->o_flag; {TRUE if -o specified} | | Output: | Returns: | | Written By: | Date: July 1, 1997 | Modifications: | ------------------------------------------------------------*/ int main( int argc, char **argv) { /* -main_variable_list */ char *lib = "myimageenhancement_obj"; char *rtn = "main"; kobject in_object = NULL; kobject out_object = NULL; double *plane; double *res_plane; int w, h, d, t, e; int cw, ch, ct, pos; /* -main_variable_list_end */ khoros_init(argc, argv, "PROBA", PRODUCT_RELEASE_DATE, PRODUCT_RELEASE_NAME, PRODUCT_RELEASE_VERSION, PRODUCT_RELEASE_MAJOR, PRODUCT_RELEASE_MINOR, "$PROBA/objects/kroutine/myimageenhancement"); kexit_handler(myimageenhancement_free_args, NULL); /* -main_get_args_call */ kclui_init("PROBA", "myimageenhancement", KGEN_KROUTINE, &clui_uis_spec, myimageenhancement_usage_additions, myimageenhancement_get_args, myimageenhancement_free_args); /* -main_get_args_call_end */ /* -main_before_lib_call */ /* megnyitom az input es az output képet */ if ((in_object = kpds_open_input_object(clui_info->i_file)) == KOBJECT_INVALID) { kerror(lib, rtn, "Can not open input object %s.\n", clui_info->i_file); kexit(KEXIT_FAILURE); } if ((out_object = kpds_open_output_object(clui_info->o_file)) == KOBJECT_INVALID) { kerror(lib, rtn, "Can not open output object %s.\n", clui_info->o_file); kexit(KEXIT_FAILURE); } /* átmásolom az input képet az outputba */ if ( !kpds_copy_object( in_object, out_object ) ) { kerror(lib, rtn, "Can not copy input into the output object\n"); kexit(KEXIT_FAILURE); } /* mindkét kép adattípusát DOUBLE-ra állítom */ kpds_set_attribute( in_object, KPDS_VALUE_DATA_TYPE, KDOUBLE ); kpds_set_attribute( out_object, KPDS_VALUE_DATA_TYPE, KDOUBLE ); kpds_get_attribute( in_object, KPDS_VALUE_SIZE, &w, &h, &d, &t, &e ); /* lefoglalom a segédtömböket */ plane = (double* ) kmalloc ( w*h *sizeof( double) ); res_plane = ( double* ) kmalloc ( w*h *sizeof( double ) ); if ( !plane || !res_plane ) { kerror(lib, rtn, "Could not allocate memory for the image\n"); kexit(KEXIT_FAILURE); } /* -main_before_lib_call_end */ /* -main_library_call */ for ( ct = 0; ct < t; ct++ ) { kpds_set_attribute( in_object, KPDS_VALUE_POSITION, 0,0,0, ct, 0 ); kpds_get_data( in_object, KPDS_VALUE_PLANE, (kaddr) plane ); if ( clui_info->enhancement_toggle == 1 ) { /* ha az első gomb van benyomva, akkor logaritmust csináljuk */ for ( ch = 0; ch < h; ch++ ) { for ( cw = 0; cw < w; cw++ ) { pos = ch * w + cw; res_plane[ pos ] = log( plane[pos] ); } } } else { /* ha a második gomb van benyomva, akkor az intenzitások négyzetét számoljuk */ for ( ch = 0; ch < h; ch++ ) { for ( cw = 0; cw < w; cw++ ) { pos = ch * w + cw; res_plane[ pos ] = plane[pos] * plane[pos]; } } } kpds_set_attribute( out_object, KPDS_VALUE_POSITION, 0,0,0, ct, 0 ); kpds_put_data( out_object, KPDS_VALUE_PLANE, (kaddr) res_plane ); } /* -main_library_call_end */ /* -main_after_lib_call */ if (!kpds_set_attribute(out_object, KPDS_HISTORY, kpds_history_string())) { kerror(lib,rtn,"Unable to set history on the destination object"); kexit(KEXIT_FAILURE); } if ( plane ) kfree( plane ); if ( res_plane ) kfree( res_plane); kpds_close_object( in_object ); kpds_close_object( out_object ); /* -main_after_lib_call_end */ kexit(KEXIT_SUCCESS); } /*----------------------------------------------------------- | | Routine Name: myimageenhancement_usage_additions | | Purpose: Prints usage additions in myimageenhancement_usage routine | | Input: None | | Output: None | Written By: ghostwriter -oname myimageenhancement | Date: July 1, 1997 | Modifications: | ------------------------------------------------------------*/ void myimageenhancement_usage_additions(void) { kfprintf(kstderr, "\tImage enhancement\n"); /* -usage_additions */ /* -usage_additions_end */ } /*----------------------------------------------------------- | | Routine Name: myimageenhancement_free_args | | Purpose: Frees CLUI struct allocated in myimageenhancement_get_args() | | Input: None | | Output: None | Written By: ghostwriter -oname myimageenhancement | Date: July 1, 1997 | Modifications: | ------------------------------------------------------------*/ /* ARGSUSED */ void myimageenhancement_free_args( kexit_status status, kaddr client_data) { /* do the wild and free thing */ if (clui_info != NULL) { kfree_and_NULL(clui_info->i_file); kfree_and_NULL(clui_info->o_file); kfree_and_NULL(clui_info); } /* -free_handler_additions */ /* -free_handler_additions_end */ }