/* * ***************************************************************** * * * * * 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 2値メモリアクセスサンプルソフト 90xbmem.c */ /*[作成者]A.Sekimori */ /*[概要] 2値メモリアクセスのサンプルソフトです。 */ /* 指定された処理範囲を指定した色で塗りつぶします。 */ /* また、指定した色の画素数を数えます。 */ /* */ /* 目的: 関数: 履歴: Ver 1.0 97/09/24 注記: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 3 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " SET ", " 設 定 " }, { " PAINT ", "塗りつぶし" }, { " COUNT ", " カウント " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 /* 表示メニュー */ #define D_KEY1_XS 1 /* キー「設定」の表示位置(X) */ #define D_KEY_YS 455 /* キーの表示位置(Y) */ #define D_STR 8 /* キーの表示文字数 */ #define BL_MIN 0 #define BL_MAX 255 typedef struct { int bin_level; /* 2値レベル */ int color; /* 対象物の色 */ } BIN_P; typedef struct { int xs; /* 処理範囲始点X */ int ys; /* 処理範囲始点Y */ int x_size; /* 処理範囲サイズX */ int y_size; /* 処理範囲サイズY */ } WINDOW; static BIN_P bp; static WINDOW win; static char *select_c[2] = { "黒", "白" }; static int pad_level; /* プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); void video_init( void ); void data_init( void ); void set_param( void ); void set_bin_level( int, int, PARADIGM * ); void paint_execute( void ); void count_execute( void ); int count_bin_pixel( int, int, int, int, int, int ); void white_paint( int, int, int, int, int ); void black_paint( int, int, int, int, int ); extern int message_note( void ); /* メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; /* カーソル初期化 */ Lib_init_cursor(); /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; data_init(); /* パラメータの初期化 */ /* 2値レベル初期設定 */ Lib_video_bin_level( bp.bin_level ); /* ビデオ入力の初期化 */ video_init(); /* パラメタ初期化 */ xpos = INIT_CUR_POS_X; ypos = INIT_CUR_POS_Y; s_xpos = INIT_CUR_POS_X; s_ypos = INIT_CUR_POS_Y; /* ビデオ表示項目クリア */ 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_param(); 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 ); paint_execute(); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); main_menu_disp(); } else if ( xpos > MENU_3_XS && xpos < MENU_3_XE && ypos > MENU_3_YS && ypos < MENU_3_YE ) { /* 「カウント」が選択された */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); count_execute(); 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 *)str_main_menu[2][iLanguage], (char *)NULL ); } /* ヘルプ表示 */ void disp_help( void ) { Lib_chrdisp( 9, 8, "【機能\概要】 90XBMEM" ); Lib_chrdisp( 10, 10, "2値メモリアクセスサンプルソ\フトです。" ); Lib_chrdisp( 10, 13, "【設定】 各種設定を行います。" ); Lib_chrdisp( 10, 15, "【塗りつぶし】処理範囲を指定色で塗りつぶします。" ); Lib_chrdisp( 10, 17, "【カウント】 処理範囲内の指定色の画素を数えます。" ); } /***** データ初期化 *****/ void data_init( void ) { /* 2値・パラメータ */ bp.bin_level = 128; /* 2値レベル */ bp.color = BLACK_COLOR; /* 対象物の色 */ /* 処理範囲 */ win.xs = 0; /* ウィンドウ始点X */ win.ys = 0; /* ウィンドウ始点Y */ win.x_size = 512; /* ウィンドウサイズX */ win.y_size = 480; /* ウィンドウサイズY */ } /***** ビデオ入力の初期化 *****/ void video_init( void ) { /* 入力ビデオ制御 */ Lib_input_video_control( GRAY_PLANE ); /* 入力ビデオチャネル設定 */ Lib_xvideo_channel( WAITING, 0 ); /* ビデオ出力表示項目制御 */ Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* 2値レベル更新 */ Lib_video_bin_level( bp.bin_level ); } /***** パラメータ設定 *****/ void set_param( void ) { PVAL value[5]; int no; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); pad_level = Lib_view_open(); /* パッドのオープン */ Lib_view_set_title( pad_level, "設定" ); /* パッドタイトルの登録 */ /* 各属性メニューの登録 */ Lib_view_set_uniq_numeral( pad_level, 5, 5, "2値レベル" , bp.bin_level, BL_MIN , BL_MAX , 0 ); Lib_view_set_select ( pad_level, 5, 35, "対象物の色", bp.color, 2, select_c, 1 ); Lib_view_set_comment ( pad_level, 5, 70, "処理範囲" , 2 ); Lib_view_set_box ( pad_level, 10, 100, "W始点" , win.xs , win.ys , 3, 4, 3 ); Lib_view_set_box ( pad_level, 10, 130, "Wサイズ" , win.x_size, win.y_size, 3, 3, 4 ); Lib_set_paradigm( pad_level, 0, WHOLE_TIMING, set_bin_level ); /* パッドの表示位置の登録 */ 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: /*「実行」が選択された */ bp.bin_level = value[0].value_type; bp.color = value[1].select_type; win.xs = value[3].box_type.x; win.ys = value[3].box_type.y; win.x_size = value[4].box_type.x; win.y_size = value[4].box_type.y; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); } /***** 2値レベル設定(パラダイム) *****/ void set_bin_level( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { if ( Timing == START_TIMING ) { Lib_erase_menu( pad_level ); Lib_input_video_control( BIN_PLANE ); Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_memory_clear( BIN_PLANE ); } else if ( Timing == END_TIMING ) { Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_input_video_control( GRAY_PLANE ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_draw_menu( pad_level ); } Lib_video_bin_level( (int)val[0].long_type ); Lib_freerun(); } /***** 塗りつぶし実行 *****/ void paint_execute( void ) { char ss[50]; int xe,ye; int time,time2,time3; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_input_video_control( BIN_PLANE ); Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_strtclk_count(); /* 画像の入力 */ Lib_freeze( NOT_TRANSMIT ); time = Lib_readclk_count(); xe = win.xs + win.x_size - 1; ye = win.ys + win.y_size - 1; Lib_box( win.xs, win.ys, xe, ye, SOLID_LINE ); if ( BLACK_COLOR == bp.color ) black_paint( CURRENT_MEMORY, win.xs, win.ys, xe, ye ); else if ( WHITE_COLOR == bp.color ) white_paint( CURRENT_MEMORY, win.xs, win.ys, xe, ye ); time2 = Lib_readclk_count(); /* 画像の表示 */ Lib_xvideo_transmit( CURRENT_MEMORY, BIN_PLANE ); time3 = Lib_readclk_count(); time3 -= time2; time2 -= time; time = ( time * 8138 ) / 10000; time2 = ( time2 * 8138 ) / 10000; time3 = ( time3 * 8138 ) / 10000; Lib_sprintf( ss, "画像入力 %4d(msec)", time ); Lib_chrdisp( 1, 28, ss ); Lib_sprintf( ss, "塗りつぶし %4d(msec)", time2 ); Lib_chrdisp( 1, 29, ss ); Lib_sprintf( ss, "画像転送 %4d(msec)", time3 ); Lib_chrdisp( 1, 30, ss ); Lib_display_keyinput( 460, 0, "確認" ); Lib_freerun(); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_input_video_control( GRAY_PLANE ); Lib_cls( ( LINE_PLANE | CHAR_PLANE | BIN_PLANE ), BLACK_COLOR ); } /***** カウント実行 *****/ void count_execute( void ) { char ss[50]; int xe,ye; int time,time2; int count; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_input_video_control( BIN_PLANE ); Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_strtclk_count(); Lib_freeze( TRANSMIT ); time = Lib_readclk_count(); xe = win.xs + win.x_size - 1; ye = win.ys + win.y_size - 1; Lib_box( win.xs, win.ys, xe, ye, SOLID_LINE ); count = count_bin_pixel( CURRENT_MEMORY, win.xs, win.ys, xe, ye, bp.color ); time2 = Lib_readclk_count(); time2 -= time; time = ( time * 8138 ) / 10000; time2 = ( time2 * 8138 ) / 10000; Lib_sprintf( ss, "画素数 %d", count ); Lib_chrdisp( 1, 28, ss ); Lib_sprintf( ss, "画像入力 %4d(msec)", time ); Lib_chrdisp( 1, 29, ss ); Lib_sprintf( ss, "カウント %4d(msec)", time2 ); Lib_chrdisp( 1, 30, ss ); Lib_display_keyinput( 460, 0, "確認" ); Lib_freerun(); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_input_video_control( GRAY_PLANE ); Lib_cls( ( LINE_PLANE | CHAR_PLANE | BIN_PLANE ), BLACK_COLOR ); } /************************************************************************************ * 2値メモリ指定範囲の指定色をカウント * * [機能] 指定された2値メモリのウィンドウ内の指定色の画素数を数える * * [戻り値]正常:画素数 * * 異常:ERROR_RETURN * ************************************************************************************/ int count_bin_pixel( mem_no, xs, ys, xe, ye, color ) int mem_no; int xs, ys, xe, ye; int color; { int *base_adr,*acc_adr; int block; int data; int amari_xs,amari_xe; int start_bit,end_bit; int fx_size,fy_size; int sbn,ebn; int ctx,cty; unsigned int mask; int count; int i; int buf; fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); if ( xs < 0 ) xs = 0; if ( ys < 0 ) ys = 0; if ( fx_size <= xe ) xe = fx_size - 1; if ( fy_size <= ye ) ye = fy_size - 1; block = fx_size / 32; /* 32ビットが何ブロックか? */ if ( NULL != ( base_adr = ( void *)Lib_adrs_bin_memory( mem_no ) ) ) { count = 0; sbn = xs / 32; /* 始点の属するブロック番号 */ ebn = xe / 32; /* 終点の属するブロック番号 */ amari_xs = xs % 32; /* 始点のビット位置算出 */ amari_xe = xe % 32; /* 終点のビット位置算出 */ for ( cty = ys; cty <= ye; cty++ ) { acc_adr = base_adr + sbn + ( block * cty ); for ( ctx = sbn; ctx <= ebn; ctx++ ) { data = *acc_adr; mask = 0x80000000; if ( sbn != ebn ) /* 始点終点が同一ブロックでない */ { if ( sbn == ctx ) { start_bit = amari_xs; end_bit = 32; mask = mask >> amari_xs; } else if ( ebn == ctx ) { start_bit = 0; end_bit = amari_xe + 1; } else { start_bit = 0; end_bit = 32; } } else if ( sbn == ebn ) /* 始点終点が同一ブロック */ { start_bit = amari_xs; end_bit = amari_xe + 1; mask = mask >> amari_xs; } for ( i = start_bit; i < end_bit; i++ ) { buf = ( data & mask ); if ( BLACK_COLOR == color ) { if ( mask != buf ) { count++; /* x = ctx * 32 + i; Lib_pset( x, cty, GRAPH_DRAW ); */ } } else if ( WHITE_COLOR == color ) { if ( mask == buf ) { count++; /* x = ctx * 32 + i; Lib_pset( x, cty, GRAPH_DRAW ); */ } } mask = mask >> 1; } acc_adr++; } } } else count = ERROR_RETURN; return ( count ); } /************************************************************************************ * 2値メモリ塗りつぶし処理(白) * * [機能] 指定された2値メモリのウィンドウ内を白く塗りつぶす。 * ************************************************************************************/ void white_paint( mem_no, xs, ys, xe, ye ) int mem_no; int xs, ys, xe, ye; { unsigned int *base_adr,*strx_adr,*acc_adr; int fx_size,fy_size; unsigned int block; int sbn,ebn; unsigned int amari_xs,amari_xe; unsigned int shift_xs,shift_xe; unsigned int mask_xs,mask_xe,mask_xsxe; int ctx,cty; fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); if ( fx_size <= xe ) xe = fx_size - 1; if ( fy_size <= ye ) ye = fy_size - 1; block = fx_size / 32; /* 32ビットが何ブロックか? */ if ( NULL != ( base_adr = ( unsigned int *)Lib_adrs_bin_memory( mem_no ) ) ) { strx_adr = base_adr + ( xs / 32 ); /* ウィンドウ始点Xのアドレス */ sbn = xs / 32; /* 始点の属するブロック番号 */ ebn = xe / 32; /* 終点の属するブロック番号 */ if ( sbn != ebn ) /* 終点始点が同一ブロックか?(複数ブロックマスク)*/ { sbn += 1; /* 最初のブロックの次のブロック番号 */ ebn -= 1; /* 最後のブロックの前のブロック番号 */ amari_xs = xs % 32; /* 始点のビット位置算出 */ amari_xe = xe % 32; /* 終点のビット位置算出 */ if ( 0 != amari_xs ) /* 始端ブロックのマスク作成 */ { shift_xs = amari_xs; mask_xs = 0xffffffff; mask_xs = mask_xs << shift_xs; mask_xs = mask_xs >> shift_xs; } if ( 0 != amari_xe ) /* 終端ブロックのマスク作成 */ { shift_xe = 32 - amari_xe; mask_xe = 0xffffffff; mask_xe = mask_xe >> shift_xe; mask_xe = mask_xe << shift_xe; } /* マスク処理 */ for ( cty = ys; cty <= ye; cty++ ) { acc_adr = strx_adr + ( block * cty ); /* 始端ブロック */ if ( 0 == amari_xs ) { *acc_adr = 0xffffffff; acc_adr++; } else { *acc_adr = ( *acc_adr | mask_xs ); acc_adr++; } /* 内側ブロック */ for ( ctx = sbn; ctx <= ebn; ctx++ ) { *acc_adr = 0xffffffff; acc_adr++; } /* 終端ブロック */ if ( 0 == amari_xe ) { *acc_adr = 0xffffffff; acc_adr++; } else { *acc_adr = ( *acc_adr | mask_xe ); acc_adr++; } } } else /* 1ブロックのみマスク */ { /* マスク作成 */ shift_xs = 32 - amari_xs; mask_xs = 0xffffffff; mask_xs = mask_xs >> shift_xs; mask_xs = mask_xs << shift_xs; shift_xe = amari_xe; mask_xe = 0xffffffff; mask_xe = mask_xe << shift_xe; mask_xe = mask_xe >> shift_xe; mask_xsxe = ( mask_xs | mask_xe ); /* マスク処理 */ for ( cty = ys; cty <= ye; cty++ ) { acc_adr = strx_adr + ( block * cty ); *acc_adr = ( *acc_adr | mask_xsxe ); } } } } /************************************************************************************ * 2値メモリ塗りつぶし処理(黒) * * [機能] 指定された2値メモリのウィンドウ内を黒く塗りつぶす。 * ************************************************************************************/ void black_paint( mem_no, xs, ys, xe, ye ) int mem_no; int xs,ys,xe,ye; { unsigned int *base_adr,*strx_adr,*acc_adr; int fx_size,fy_size; unsigned int block; int sbn,ebn; unsigned int amari_xs,amari_xe; unsigned int shift_xs,shift_xe; unsigned int mask_xs,mask_xe,mask_xsxe; int ctx,cty; fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); if ( fx_size <= xe ) xe = fx_size - 1; if ( fy_size <= ye ) ye = fy_size - 1; block = fx_size / 32; /* 32ビットが何ブロックか? */ if ( NULL != ( base_adr = ( unsigned int *)Lib_adrs_bin_memory( mem_no ) ) ) { strx_adr = base_adr + ( xs / 32 ); /* ウィンドウ始点Xのアドレス */ sbn = xs / 32; /* 始点の属するブロック番号 */ ebn = xe / 32; /* 終点の属するブロック番号 */ if ( sbn != ebn ) /* 終点始点が同一ブロックか?(複数ブロックマスク)*/ { sbn += 1; /* 最初のブロックの次のブロック番号 */ ebn -= 1; /* 最後のブロックの前のブロック番号 */ amari_xs = xs % 32; /* 始点のビット位置算出 */ amari_xe = ( xe + 1 ) % 32; /* 終点のビット位置算出 */ if ( 0 != amari_xs ) /* 始端ブロックのマスク作成 */ { shift_xs = 32 - amari_xs; mask_xs = 0xffffffff; mask_xs = mask_xs >> shift_xs; mask_xs = mask_xs << shift_xs; } if ( 0 != amari_xe ) /* 終端ブロックのマスク作成 */ { shift_xe = amari_xe; mask_xe = 0xffffffff; mask_xe = mask_xe << shift_xe; mask_xe = mask_xe >> shift_xe; } /* マスク処理 */ for ( cty = ys; cty <= ye; cty++ ) { acc_adr = strx_adr + ( block * cty ); /* 始端ブロック */ if ( 0 == amari_xs ) { *acc_adr = 0x00000000; acc_adr++; } else { *acc_adr = ( *acc_adr & mask_xs ); acc_adr++; } /* 内側ブロック */ for ( ctx = sbn; ctx <= ebn; ctx++ ) { *acc_adr = 0x00000000; acc_adr++; } /* 終端ブロック */ if ( 0 == amari_xe ) { *acc_adr = 0x00000000; acc_adr++; } else { *acc_adr = ( *acc_adr & mask_xe ); acc_adr++; } } } else /* 1ブロックのみマスク */ { /* マスク作成 */ shift_xs = 32 - amari_xs; mask_xs = 0xffffffff; mask_xs = mask_xs >> shift_xs; mask_xs = mask_xs << shift_xs; shift_xe = amari_xe; mask_xe = 0xffffffff; mask_xe = mask_xe << shift_xe; mask_xe = mask_xe >> shift_xe; mask_xsxe = ( mask_xs | mask_xe ); /* マスク処理 */ for ( cty = ys; cty <= ye; cty++ ) { acc_adr = strx_adr + ( block * cty ); *acc_adr = ( *acc_adr & mask_xsxe ); } } } }