/* * 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 myhistogramstretch >>>> >>>> Private: >>>> main >>>> >>>> Static: >>>> Public: >>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<< */ #include "myhistogramstretch.h" clui_info_struct *clui_info = NULL; /*----------------------------------------------------------- | | Routine Name: main() - My Histogram Stretch | | Purpose: main program for myhistogramstretch | | Input: | char *clui_info->i_file; {First Input data object} | int clui_info->i_flag; {TRUE if -i 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 = "myhistorgramstretch_obj"; char *rtn = "main"; kobject in_object = NULL; kobject out_object = NULL; unsigned char *plane; unsigned char *res_plane; int w, h, d, t, e; int cw, ch, ct, pos; int histw, min, max; /* segédváltozók a hisztogram szélésségének meghatározásához */ /* -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/myhistogramstretch"); kexit_handler(myhistogramstretch_free_args, NULL); /* -main_get_args_call */ kclui_init("PROBA", "myhistogramstretch", KGEN_KROUTINE, &clui_uis_spec, myhistogramstretch_usage_additions, myhistogramstretch_get_args, myhistogramstretch_free_args); /* -main_get_args_call_end */ /* -main_before_lib_call */ 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); } if (!kpds_copy_object(in_object, out_object)) { kerror(lib, rtn, "Can not copy input object to output object.\n"); kexit(KEXIT_FAILURE); } kpds_set_attribute(in_object, KPDS_VALUE_DATA_TYPE, KUBYTE); kpds_set_attribute(out_object, KPDS_VALUE_DATA_TYPE, KUBYTE); kpds_get_attribute(in_object, KPDS_VALUE_SIZE, &w, &h, &d, &t, &e); plane = (unsigned char *)kmalloc(w*h*sizeof(unsigned char)); res_plane = (char *)kmalloc(w*h*sizeof(unsigned char)); 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++) { min = 255; max = 0; kpds_set_attribute(in_object, KPDS_VALUE_POSITION, 0, 0, 0, ct, 0); kpds_get_data(in_object, KPDS_VALUE_PLANE, (kaddr)plane); kmemset(res_plane, 0, w*h*sizeof(char)); /* meghatározzuk a hisztogram szélességét */ for (ch = 0; ch < h; ch++) { for (cw = 0; cw < w; cw++) { pos = ch*w + cw; if ( min > plane[pos] ) min = plane[pos]; if ( max < plane[pos] ) max = plane[pos]; } } histw = max - min; /* a szélesség a maximum és minimum különbsége lesz */ /* eltoljuk a hisztogramot a 0-ba */ for (ch = 0; ch < h; ch++) { for (cw = 0; cw < w; cw++) { pos = ch*w + cw; res_plane[pos] = plane[pos] - min; } } /* transzformáljuk a hisztogramot 0-255 közé */ for (ch = 0; ch < h; ch++) { for (cw = 0; cw < w; cw++) { pos = ch*w + cw; res_plane[pos] = res_plane[pos] * 255 / histw; } } 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: myhistogramstretch_usage_additions | | Purpose: Prints usage additions in myhistogramstretch_usage routine | | Input: None | | Output: None | Written By: ghostwriter -oname myhistogramstretch | Date: July 1, 1997 | Modifications: | ------------------------------------------------------------*/ void myhistogramstretch_usage_additions(void) { kfprintf(kstderr, "\tMy Histogram Stretch\n"); /* -usage_additions */ /* -usage_additions_end */ } /*----------------------------------------------------------- | | Routine Name: myhistogramstretch_free_args | | Purpose: Frees CLUI struct allocated in myhistogramstretch_get_args() | | Input: None | | Output: None | Written By: ghostwriter -oname myhistogramstretch | Date: July 1, 1997 | Modifications: | ------------------------------------------------------------*/ /* ARGSUSED */ void myhistogramstretch_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 */ }