/* * ***************************************************************** * * * * * 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 矩形エリアの画像コピー 90xbcopy.c */ /*[作成者]A.Sekimori */ /*[概要] 濃淡メモリアクセスのサンプルソフトです。 */ /* 指定された処理範囲の画像をコピーします。 */ /* */ /* 目的: 関数: 履歴: Ver 1.0 00/05/09 注記: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 /* プロトタイプ宣言 */ 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, int ); int gray_memory_copy32( int, 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; int src_mem_no; int dst_mem_no; int wxs,wys,wxe,wye; /* カーソル初期化 */ Lib_init_cursor(); /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; src_mem_no = Lib_get_gray_memory(); if ( ERROR_RETURN != ( dst_mem_no = Lib_alloc_gray_memory() ) ) { /* ビデオ入力の初期化 */ 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( src_mem_no, dst_mem_no, 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; /* 終了 */ } } } Lib_free_gray_memory( dst_mem_no ); } else Lib_display_message( 100, 200, "エラー", "結果格納用メモリが確保できません" ); } /* メインメニュー表示 */ 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, "【機能\概要】 90XBCOPY" ); Lib_chrdisp( 10, 10, "濃淡メモリアクセスのサンプルソ\フトです。" ); Lib_chrdisp( 10, 12, "Lib_gray_memory_moveでは処理範囲は全面ですが、" ); Lib_chrdisp( 10, 14, "このサンプルは指定された処理範囲の画像のみを" ); Lib_chrdisp( 10, 16, "他の濃淡画像メモリにコピーできます。" ); Lib_chrdisp( 10, 18, "処理範囲内のみの処理なので処理時間が高速です。" ); } /***** 処理範囲設定 *****/ 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 src_mem_no, int dst_mem_no, int wxs, int wys, int wxe, int wye ) { char ss[50]; int time,time2; 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 ); Lib_gray_memory_cls( dst_mem_no ); if ( NORMAL_RETURN == gray_memory_copy32( src_mem_no, dst_mem_no, wxs, wys, wxe, wye ) ) { 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_xvideo_transmit( dst_mem_no, GRAY_PLANE ); } else Lib_chrdisp( 1, 30, "エラー:画像コピー異常終了" ); Lib_display_keyinput( 460, 0, "確認" ); Lib_freerun(); Lib_cls( ( LINE_PLANE | CHAR_PLANE | BIN_PLANE ), BLACK_COLOR ); } /************************************************************************************ * 濃淡画像メモリコピー(32bitアクセス高速版) * * [機能] 濃淡メモリsrc_memからdst_memへ画像をコピーします。 * * Lib_gray_memory_moveの処理範囲が全面なので指定できるように作成。 * * [戻り値]正常:NORMAL_RETURN * * 異常:ERROR_RETURN * ************************************************************************************/ int gray_memory_copy32( src_mem, dst_mem, xs, ys, xe, ye ) int src_mem; int dst_mem; int xs,ys,xe,ye; { unsigned int *src_base_adr,*src_acc_adr; unsigned int *dst_base_adr,*dst_acc_adr; int status; int block; int amari_xs,amari_xe; int fx_size,fy_size; int sbn,ebn; int ctx,cty; int mask,s_mask,e_mask; if ( NULL != ( src_base_adr = (void *)Lib_adrs_gray_memory( src_mem ) ) ) { if ( NULL != ( dst_base_adr = (void *)Lib_adrs_gray_memory( dst_mem ) ) ) { fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); 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) ) { block = fx_size / 4; /* 4byteが何ブロックか? */ sbn = xs / 4; /* 始点の属するブロック番号 */ ebn = xe / 4; /* 終点の属するブロック番号 */ amari_xs = xs % 4; /* 始点のビット位置算出 */ amari_xe = xe % 4; /* 終点のビット位置算出 */ if ( 0 == amari_xs ) s_mask = 0xffffffff; else if ( 1 == amari_xs ) s_mask = 0xffffff00; else if ( 2 == amari_xs ) s_mask = 0xffff0000; else if ( 3 == amari_xs ) s_mask = 0xff000000; if ( 0 == amari_xe ) e_mask = 0x000000ff; else if ( 1 == amari_xe ) e_mask = 0x0000ffff; else if ( 2 == amari_xe ) e_mask = 0x00ffffff; else if ( 3 == amari_xe ) e_mask = 0xffffffff; if ( sbn != ebn ) /* 始点終点が同一ブロックでない */ { for ( cty = ys; cty <= ye; cty++ ) { src_acc_adr = src_base_adr + sbn + ( block * cty ); dst_acc_adr = dst_base_adr + sbn + ( block * cty ); /* 始点を含むはじめの1ブロック */ *dst_acc_adr = *src_acc_adr & s_mask; src_acc_adr++; dst_acc_adr++; /* 中間ブロック */ for ( ctx = sbn+1; ctx < ebn; ctx++ ) { *dst_acc_adr = *src_acc_adr; src_acc_adr++; dst_acc_adr++; } /* 終点を含む最後の1ブロック */ *dst_acc_adr = *src_acc_adr & e_mask; } } else if ( sbn == ebn ) /* 始点終点が同一ブロック */ { for ( cty = ys; cty <= ye; cty++ ) { src_acc_adr = src_base_adr + sbn + ( block * cty ); dst_acc_adr = dst_base_adr + sbn + ( block * cty ); mask = s_mask & e_mask; *dst_acc_adr = ( *src_acc_adr & mask ); } } status = NORMAL_RETURN; } else status = ERROR_RETURN; } else status = ERROR_RETURN; } else status = ERROR_RETURN; return ( status ); }