/* * 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 mytranspose >>>> >>>> Private: >>>> main >>>> >>>> Static: >>>> Public: >>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<< */ #include "mytranspose.h" clui_info_struct *clui_info = NULL; /*----------------------------------------------------------- | | Routine Name: main() - A simple example for transpose a picture | | Purpose: main program for mytranspose | | 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 = "mytranspose_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, res_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/mytranspose"); kexit_handler(mytranspose_free_args, NULL); /* -main_get_args_call */ kclui_init("PROBA", "mytranspose", KGEN_KROUTINE, &clui_uis_spec, mytranspose_usage_additions, mytranspose_get_args, mytranspose_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); } /* most nem másoljuk át az input objektumot az eredmény objektumba, ezért létre kell hozni a Value szegmenst az adat számára */ kpds_create_value( out_object ); kpds_set_attribute(in_object, KPDS_VALUE_DATA_TYPE, KUBYTE); kpds_set_attribute(out_object, KPDS_VALUE_DATA_TYPE, KUBYTE); /* lekérdezzük az input kép méret attribútumát */ kpds_get_attribute(in_object, KPDS_VALUE_SIZE, &w, &h, &d, &t, &e); /* beállítjuk az output objektum méret attribútumát, a szélesség és magasság attribútumot felcseréljük */ kpds_set_attribute( out_object, KPDS_VALUE_SIZE, h, w, d, t, e ); /* lefoglaltjuk a memóriatömböket a képi adat számára, mindkét tömb ugyanakkora */ 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); } /* -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( unsigned char ) ); for ( ch = 0; ch < h; ch++) { for ( cw = 0; cw < w; cw++ ) { pos = ch*w + cw; res_pos = cw * h + ch; res_plane[ res_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: mytranspose_usage_additions | | Purpose: Prints usage additions in mytranspose_usage routine | | Input: None | | Output: None | Written By: ghostwriter -oname mytranspose | Date: July 1, 1997 | Modifications: | ------------------------------------------------------------*/ void mytranspose_usage_additions(void) { kfprintf(kstderr, "\tA simple example for transpose a picture\n"); /* -usage_additions */ /* -usage_additions_end */ } /*----------------------------------------------------------- | | Routine Name: mytranspose_free_args | | Purpose: Frees CLUI struct allocated in mytranspose_get_args() | | Input: None | | Output: None | Written By: ghostwriter -oname mytranspose | Date: July 1, 1997 | Modifications: | ------------------------------------------------------------*/ /* ARGSUSED */ void mytranspose_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 */ }