/* * 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 myaveragesmooth >>>> >>>> Private: >>>> main >>>> >>>> Static: >>>> Public: >>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<< */ #include "myaveragesmooth.h" clui_info_struct *clui_info = NULL; /*----------------------------------------------------------- | | Routine Name: main() - A simple 3x3 average smooth | | Purpose: main program for myaveragesmooth | | 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 = "myaveragesmooth_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, i; int sum; int env3x3[9]; /* -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/myaveragesmooth"); kexit_handler(myaveragesmooth_free_args, NULL); /* -main_get_args_call */ kclui_init("PROBA", "myaveragesmooth", KGEN_KROUTINE, &clui_uis_spec, myaveragesmooth_usage_additions, myaveragesmooth_get_args, myaveragesmooth_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 = (unsigned 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); } /* beírjuk a tömbbe a környezeti indexeket */ env3x3[0] = -w-1; env3x3[1] = -w; env3x3[2] = -w+1; env3x3[3] = -1; env3x3[4] = 0; env3x3[5] = 1; env3x3[6] = w-1; env3x3[7] = w; env3x3[8] = w+1; /* -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); kmemset(res_plane, 0, w*h*sizeof(char)); for (ch = 1; ch < h-1; ch++) { for (cw = 1; cw < w-1; cw++) { pos = ch*w + cw; /* kiszámoljuk a környezet átlagát */ sum = 0; for ( i = 0; i < 9; i++ ) { sum += plane[pos + env3x3[i]]; } sum /= 9; res_plane[pos] = sum; } } 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: myaveragesmooth_usage_additions | | Purpose: Prints usage additions in myaveragesmooth_usage routine | | Input: None | | Output: None | Written By: ghostwriter -oname myaveragesmooth | Date: July 1, 1997 | Modifications: | ------------------------------------------------------------*/ void myaveragesmooth_usage_additions(void) { kfprintf(kstderr, "\tA simple 3x3 average smooth\n"); /* -usage_additions */ /* -usage_additions_end */ } /*----------------------------------------------------------- | | Routine Name: myaveragesmooth_free_args | | Purpose: Frees CLUI struct allocated in myaveragesmooth_get_args() | | Input: None | | Output: None | Written By: ghostwriter -oname myaveragesmooth | Date: July 1, 1997 | Modifications: | ------------------------------------------------------------*/ /* ARGSUSED */ void myaveragesmooth_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 */ }