/* * ***************************************************************** * * * * * Copyright (c) Fast Corporation, 1997 * * * * * * All Rights Reserved. Unpublished rights reserved under * * * the copyright laws of the Japan. * * * * * * The software contained on this media is proprietary to * * * and embodies the confidential technology of Fast * * * Corporation. Possession, use, duplication or * * * dissemination of the software and media is authorized only * * * pursuant to a valid written license from Fast Corporation. * * * * * ***************************************************************** */ /* CSC90X 矩形エリアの平均濃度計算 90xbave.c */ /*[作成者]A.Sekimori */ /*[概要] 濃淡メモリアクセスのサンプルソフトです。 */ /* 指定された処理範囲の平均濃度を求めます。 */ /* */ /* 目的: 関数: 履歴: Ver 1.0 00/04/27 注記:m_menu.hをインクルードして下さい。 m_menu.c及びm_note.cをリンクして下さい。 */ /* Include compiler runtime library */ #include #include #include /* Include CSC90X library */ #include "f_stdio.h" /* 標準入出力 */ #include "f_stdlib.h" /* メモリ領域割当 */ #include "f_gui.h" /* GUI */ #include "f_graph.h" /* モニタ表示 */ #include "f_pinf.h" /* システムパラメータ */ #include "f_video.h" /* ビデオ入力制御 */ #include "f_image.h" /* フレームバッファ */ #include "f_time.h" /* 時刻サービス */ #include "f_system.h" /* システム制御 */ /* Include CSC90X common local */ #include "m_menu.h" /* メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 2 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " SET ", " 処理範囲 " }, { " EXEC ", " 実 行 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 #define MASK 0x000000FF /* プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); void set_window( int *, int *, int *, int * ); void execute( int, int, int, int ); int calc_average( int, int, int, int, int, double * ); extern int message_note( void ); /* メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; int wxs,wys,wxe,wye; /* カーソル初期化 */ Lib_init_cursor(); /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; /* ビデオ入力の初期化 */ Lib_input_video_control( GRAY_PLANE ); /* 入力ビデオチャネル設定 */ Lib_xvideo_channel( WAITING, 0 ); /* ビデオ出力表示項目制御 */ Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* パラメタ初期化 */ xpos = INIT_CUR_POS_X; ypos = INIT_CUR_POS_Y; s_xpos = INIT_CUR_POS_X; s_ypos = INIT_CUR_POS_Y; wxs = 0; wys = 0; wxe = 511; wye = 479; /* ビデオ表示項目クリア */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* メインメニューの表示 */ main_menu_disp(); /* マウスカーソルの表示 */ Lib_draw_cursor( INIT_CUR_POS_X, INIT_CUR_POS_Y ); /* メニュー制御 */ for (;;) { sts = 0; /* マウス位置読みとり */ sts = Lib_see_current_position( &xpos, &ypos ); if ( s_xpos != xpos || s_ypos != ypos ) { /* マウス表示位置移動 */ Lib_move_cursor( xpos, ypos ); s_xpos = xpos; s_ypos = ypos; } /* 処理振り分け */ if( CURSOR_EXECUTE == sts ) { if ( xpos > MENU_1_XS && xpos < MENU_1_XE && ypos > MENU_1_YS && ypos < MENU_1_YE ) { /* 「処理範囲」が選択された */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); set_window( &wxs, &wys, &wxe, &wye ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); main_menu_disp(); } else if ( xpos > MENU_2_XS && xpos < MENU_2_XE && ypos > MENU_2_YS && ypos < MENU_2_YE ) { /* 「実行」が選択された */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); execute( wxs, wys, wxe, wye ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); main_menu_disp(); } else if ( xpos > MENU_H_XS && xpos < MENU_H_XE && ypos > MENU_H_YS && ypos < MENU_H_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); disp_help(); /* ヘルプ */ main_menu_disp(); } else if ( xpos > MENU_E_XS && xpos < MENU_E_XE && ypos > MENU_E_YS && ypos < MENU_E_YE ) { break; /* 終了 */ } } } } /* メインメニュー表示 */ void main_menu_disp( void ) { int iLanguage; /* 日本語/英語表示文字列切替情報取得 */ iLanguage = Lib_get_disp_language(); /* 整列キー表示 -> ( m_menu.c ) */ SUB_menu_disp4he( (char *)str_main_menu[0][iLanguage], (char *)str_main_menu[1][iLanguage], (char *)NULL, (char *)NULL ); } /* ヘルプ表示 */ void disp_help( void ) { Lib_chrdisp( 9, 8, "【機能\概要】 90XBAVE" ); Lib_chrdisp( 10, 10, "濃淡メモリアクセスのサンプルソ\フトです。" ); Lib_chrdisp( 10, 13, "指定された処理範囲の平均濃度を求めます。" ); Lib_chrdisp( 10, 15, "平均濃度のみ求めますので Lib_stddevi よりも" ); Lib_chrdisp( 10, 17, "処理時間が高速です。" ); } /***** 処理範囲設定 *****/ void set_window( int *xs, int *ys, int *xe, int *ye ) { PVAL value[2]; int pad_level; int no; int x_size,y_size; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); pad_level = Lib_view_open(); /* パッドのオープン */ x_size = *xe - *xs + 1; y_size = *ye - *ys + 1; Lib_view_set_title( pad_level, "処理範囲" ); /* パッドタイトルの登録 */ /* 各属性メニューの登録 */ Lib_view_set_box( pad_level, 10, 5, "W始点" , *xs , *ys , 3, 1, 0 ); Lib_view_set_box( pad_level, 10, 35, "Wサイズ", x_size, y_size, 3, 0, 1 ); /* パッドの表示位置の登録 */ Lib_view_set_size( pad_level, 30, 30, 5, 5 ); Lib_draw_menu( pad_level ); /* メニューパッドの表示 */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level, value ) ) ) /* メニュー値の取得 */ { switch( no ) { case 101: /*「実行」が選択された */ *xs = value[0].box_type.x; *ys = value[0].box_type.y; *xe = value[0].box_type.x + value[1].box_type.x - 1; *ye = value[0].box_type.y + value[1].box_type.y - 1; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); } /***** 実行 *****/ void execute( int wxs, int wys, int wxe, int wye ) { char ss[50]; int time,time2; double average; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_strtclk_count(); /* 画像の入力 */ Lib_freeze( TRANSMIT ); time = Lib_readclk_count(); Lib_box( wxs, wys, wxe, wye, SOLID_LINE ); if ( NORMAL_RETURN == calc_average( CURRENT_MEMORY, wxs, wys, wxe, wye, &average ) ) { time2 = Lib_readclk_count(); time2 -= time; time = ( time * 8138 ) / 10000; time2 = ( time2 * 8138 ) / 10000; Lib_sprintf( ss, "画像入力 %4d(msec)", time ); Lib_chrdisp( 1, 29, ss ); Lib_sprintf( ss, "平均濃度計算 %4d(msec)", time2 ); Lib_chrdisp( 1, 30, ss ); Lib_sprintf( ss, "平均濃度値 %5.1f", average ); Lib_chrdisp( 1, 28, ss ); } else Lib_chrdisp( 1, 30, "エラー:平均濃度計算異常終了" ); Lib_display_keyinput( 460, 0, "確認" ); Lib_freerun(); Lib_cls( ( LINE_PLANE | CHAR_PLANE | BIN_PLANE ), BLACK_COLOR ); } /************************************************************************************ * 濃淡メモリ指定範囲の濃度平均を求める * * [機能] 指定された濃淡メモリのウィンドウ内の濃度平均を求める * * [戻り値]正常:NORMAL_RETURN * * 異常:ERROR_RETURN * ************************************************************************************/ int calc_average( int mem_no, int xs, int ys, int xe, int ye, double *average ) { unsigned char *src_base_adr,*src_acc_adr; int status; int fx_size,fy_size; int ctx,cty; int data_num; int buf; if ( NULL != ( src_base_adr = (void *)Lib_adrs_gray_memory( mem_no ) ) ) { fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); data_num = ( xe - xs + 1 ) * ( ye - ys + 1 ); buf = 0; if ( 0 <= xs && xs <= (fx_size - 1) && 0 <= xe && xe <= (fx_size - 1) && 0 <= ys && ys <= (fy_size - 1) && 0 <= ye && ye <= (fy_size - 1) ) { for ( cty = ys; cty <= ye; cty++ ) { src_acc_adr = src_base_adr + xs + ( fx_size * cty ); for ( ctx = xs; ctx <= xe; ctx++ ) { buf += *src_acc_adr; src_acc_adr++; } } *average = (double)buf / (double)data_num; status = NORMAL_RETURN; } else status = ERROR_RETURN; } else status = ERROR_RETURN; return( status ); }