/* * ***************************************************************** * * * * * 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 画像保存ツール IMGHOLD2.C */ /*[作成者]Y.Takizawa */ /* 履歴: Ver 1.0 97/12/15 Ver 1.1 99/03/15 ファイル名を指定できるようにした by H.Yagi Ver 2.0 99/09/09 Bitmapファイルのロードとセーブを追加 一部プログラムの修正 by Y.Hori Ver 2.01 99/11/09 ロードファイル選択で、文字化けが起こる現象を修正 注記: */ /*--------------------------*/ /* インクルード・ファイル */ /*--------------------------*/ #include #include /* 標準C関数 */ #include /* 標準C関数 */ #include "f_math.h" /* 数値演算関連 */ #include "f_gui.h" /* GUI関連 */ #include "f_stdio.h" /* 標準入出力関連 */ #include "f_stdlib.h" /* メモリ領域割当関連 */ #include "f_graph.h" /* モニタTV表示関連 */ #include "f_image.h" /* 画像メモリ操作関連 */ #include "f_pinf.h" /* システムパラメータ関連 */ #include "f_system.h" /* システムパッド操作関連 */ #include "f_video.h" /* ビデオ入力制御関連 */ #include "f_gray.h" /* グレイ画像転送関連 */ #include "f_file.h" /* ファイル操作関連 */ #include "f_time.h" /* タイマ関連 */ /*--------------------------*/ /*   固定データ定義   */ /*--------------------------*/ #define MAX_IMAGE_DATA 16 /* 画像取り込みの最大面数(メモリが許せば何面でも良い 良いのだが、とりあえずここでは標準のGRAYMEM0.SYS〜 GRAYMEMF.SYSファイルを使用するので16面とする) */ #define GRAY_MEM_SIZE 245760L /* 512×480画素のサイズ */ #define INPUT_MEMORY 0 /* Lib_freeze()時の取り込み先メモリNo. */ #define NON_PICTURE 0 /* GRAYMEMx.SYSファイルに画像は入っていない=○ */ #define LOAD_PICTURE 1 /* PCカードからロードされた画像が入っている=◆ */ #define CAMERA_PICTURE 2 /* カメラから入力された画像が入っている =● */ #define FID_SIZE 7 /* ファイルID桁数 */ #define FKIND_SIZE 3 /* 拡張子桁数 */ #define MASK1 0x1 /* BMPオープンで使うマスク */ #define MASK2 0x3 /* BMPオープンで使うマスク */ #define MASK4 0xF /* BMPオープンで使うマスク */ /*--------------------------*/ /*   構造体定義    */ /*--------------------------*/ /*** BMPヘッダー ***/ typedef struct { unsigned int bfSize; /* ファイルサイズ */ unsigned int bfOffBits; /* ヘッダーサイズ */ unsigned int biSize; /* インフォヘッダーサイズ */ unsigned int biWidth; /* イメージ幅 */ unsigned int biHeight; /* イメージ高さ */ unsigned short biPlanes; /* プレーン数 */ unsigned short biBitCount; /* ピクセルあたりのビット数 */ unsigned int biXPelsPerMeter;/* 水平解像度(X Pels Per Meter) */ unsigned int biYPelsPerMeter;/* 垂直解像度(Y Pels Per Meter) */ }BMP_HEADER; /*** BMPパレット ***/ typedef struct { unsigned char rgbBlue; unsigned char rgbGreen; unsigned char rgbRed; unsigned char rgbReserved; }RGBQUAD; /*** ファイル情報 ***/ typedef struct { char baName[13]; unsigned long ulSize; }FILE_PARAM; /*--------------------------------*/ /* (サブルーチン間)共用エリア */ /*--------------------------------*/ static int max_image_count; /* メインメモリ上に保持できる画像の最大面数 */ static int store_index[MAX_IMAGE_DATA]; /* データ蓄積状態指標テーブル */ char fid[FID_SIZE+1], wwfid[FID_SIZE+1]; /*ファイルID*/ char fkind[FKIND_SIZE+1], wwfkind[FKIND_SIZE+1]; /*拡張子   */ int wBmp_on_off, wTemp_bmp_on_off; char temp_fkind[FKIND_SIZE+1]; /*----------------------------*/ /* 内部関数(サブルーチン) */ /*----------------------------*/ void main( void ); void sub_input( void ); /* 画像の取り込み */ void sub_display( void ); /* 蓄積画像の表示 */ void sub_save( void ); /* PCカードへセーブ */ void sub_delete( void ); /* PCカード内ファイルの削除 */ void sub_end( void ); /* 終了処理 */ static int sub_set_file_name( void ); /* ファイル名設定 */ static void sub_cut_space( char *, char * ); /* スペース除去 */ static void sub_load( void ); /* ファイルのロード */ static int fnSele_I_B( void ); /* BMPかIMGの選択 */ static int fnSelect_file( FILE_PARAM *, int, int ); /* ファイル名称選択 */ static void fnSort( FILE_PARAM *, FILE_PARAM *, int, int *, int * ); /* ソーティング */ static int fnOpen_bitmap( int, char *, unsigned long ); /* ビットマップのオープン */ static int fnSaveBmp( int, int, int, int, int, char * ); /* ビットマップのセーブ */ static void fnGetInt( char *, int, unsigned int * ); /* 配列からINT型を取り出す */ static void fnGetShort( char *, int, unsigned short * ); /* 配列からCHAR型を取り出す */ static void fnPrdm_form( int, int, PARADIGM * ); /**************************************************************/ /**** メイン・ルーチン ****************************************/ /**************************************************************/ void main( void ) { static char file_name[30], disp_buff[60]; int i, w, h, x, y, flag, key; FILE *fd; char *gray_mem_addr; unsigned long ulFile_size; int wBMP_op_rtn, rtn; /***** 画面表示初期化 *****/ Lib_input_video_control( GRAY_PLANE ); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_init_cursor(); Lib_draw_cursor( 256, 240 ); Lib_freerun(); Lib_freeze( NOT_TRANSMIT ); Lib_memory_clear( GRAY_PLANE ); /***** STORAGE上にメモリの許される限りGRAYMEMx.SYSを生成 *****/ while( ERROR_RETURN != ( i = Lib_alloc_gray_memory() ) ) Lib_gray_memory_cls( i ); for( i = 0; i <= MAX_IMAGE_DATA; i++ ) if( ERROR_RETURN == Lib_change_gray_memory( i ) ) break; if( 1 >= i ) { Lib_change_gray_memory( INPUT_MEMORY ); Lib_freeze( NOT_TRANSMIT ); Lib_memory_clear( GRAY_PLANE | CHAR_PLANE ); Lib_chrdisp( 20, 13, "STORAGEエリアの残容量が少なくて" ); Lib_chrdisp( 20, 14, "作業用メモリが確保できません。" ); Lib_chrdisp( 20, 15, "このままではプログラムは動けな" ); Lib_chrdisp( 20, 16, "いので処理を中止し、90Xシステム標準" ); Lib_chrdisp( 20, 17, "機能に戻ります。" ); for( Lib_strtclk(); Lib_readclk() < 1000; ) ; return; } max_image_count = i; /* 確保出来た面数。ただし最大"MAX_IMAGE_DATA"分まで */ Lib_change_gray_memory( INPUT_MEMORY ); strcpy( wwfid, "GRAYMEM" ); strcpy( wwfkind, "IMG" ); strcpy( fid, "GRAYMEM" ); strcpy( fkind, "IMG" ); wBmp_on_off = 0; rtn = sub_set_file_name( ); /*ファイル名設定*/ if( 0 == rtn || 1 == rtn ) wBmp_on_off = rtn; sub_cut_space( fid, wwfid ); sub_cut_space( fkind, wwfkind ); /***** PCカードに保存画像が有れば、それをロードすべきか聞く *****/ /***** 必要であればSTORAGE上にロードする *****/ store_index[0] = NON_PICTURE; for( flag = 0, i = 1; i < max_image_count; i++ ) { store_index[i] = NON_PICTURE; /* ファイル名 */ if ( 0 == wwfkind[0] ) { if( i < 10 ) Lib_sprintf( file_name, "\\FS0\\%s%01d", wwfid, i ); else Lib_sprintf( file_name, "\\FS0\\%s%01X", wwfid, i ); } else { if( i < 10 ) Lib_sprintf( file_name, "\\FS0\\%s%01d.%s", wwfid, i, wwfkind ); else Lib_sprintf( file_name, "\\FS0\\%s%01X.%s", wwfid, i, wwfkind ); } /* ファイルが存在するか確認・あったら開く */ if( ( FILE * )NULL != ( fd = Lib_fopen( file_name, "R" ) ) ) { ulFile_size = Lib_fsize( fd ); Lib_fclose( fd ); if( 0 == flag ) { Lib_chrdisp( 20, 10, "FS0には、過去にセーブしたと思われる" ); if ( 0 == wwfkind[0] ) Lib_sprintf( disp_buff, "画像データファイル( %sx )が", wwfid ); else Lib_sprintf( disp_buff, "画像データファイル( %sx.%s )が", wwfid, wwfkind ); Lib_chrdisp( 20, 11, disp_buff ); Lib_chrdisp( 20, 12, "存在しています。" ); Lib_chrdisp( 20, 13, "このファイルをロードしますか?" ); Lib_get_key_size( 8, &w, &h ); Lib_display_key( 180, 230, " はい ", 1 ); Lib_display_key( 210 + w, 230, " いいえ ", 1 ); for( ; ; ) { if( CURSOR_EXECUTE == Lib_get_current_position( &x, &y ) ) { if( 180 <= x && x <= 180 + w && 230 <= y && y <= 230 + h ) { Lib_display_key( 180, 230, " はい ", 2 ); key = 1; Lib_memory_clear( CHAR_PLANE ); break; } if( 210 + w <= x && x <= 210 + w * 2 && 230 <= y && y <= 230 + h ) { Lib_display_key( 210 + w, 230, " いいえ ", 2 ); key = 0; Lib_freerun(); Lib_memory_clear( CHAR_PLANE ); break; } } } flag = 1; if( 0 == key ) break; /* ロードしないならそのまま抜ける */ } /* 保存画像のロード */ gray_mem_addr = Lib_adrs_gray_memory( i ); Lib_sprintf( disp_buff, "現在[%s]をロード中・・・・・", &file_name[5] ); Lib_chrdisp( 15, 13, disp_buff ); /* ビットマップの場合 */ if( 0 == strcmp( wwfkind, "BMP" ) ) { if( 0 != ( wBMP_op_rtn = fnOpen_bitmap( i, file_name, ulFile_size ) )) { Lib_memory_clear( CHAR_PLANE ); Lib_sprintf( disp_buff, "%sをロード中にエラー発生!", &file_name[5] ); Lib_invdisp( 20, 13, disp_buff ); Lib_chrdisp( 20, 14, "STORAGEへのロードは中止します。" ); for( Lib_strtclk(); Lib_readclk() < 500; ) ; break; } else store_index[i] = LOAD_PICTURE; } /* それ以外のファイル */ else { if( GRAY_MEM_SIZE != Lib_fload( file_name, gray_mem_addr, GRAY_MEM_SIZE ) ) { Lib_memory_clear( CHAR_PLANE ); Lib_sprintf( disp_buff, "%sをロード中にエラー発生!", &file_name[5] ); Lib_invdisp( 20, 13, disp_buff ); Lib_chrdisp( 20, 14, "STORAGEへのロードは中止します。" ); for( Lib_strtclk(); Lib_readclk() < 500; ) ; break; } else store_index[i] = LOAD_PICTURE; } } } Lib_memory_clear( CHAR_PLANE ); Lib_freerun(); /************************************/ /* IDLE(トリガー待ち) */ /************************************/ Lib_get_key_size( 14, &w, &h ); for( ; ; ) { Lib_display_key( 0, 0, "画像の取り込み", 1 ); Lib_display_key( w - 1, 0, "蓄積画像の表\示", 1 ); Lib_display_key( 0, 455, "セーブ (→FS0)", 1 ); Lib_display_key( 512 - w, 0, "90Xシステムへ復帰 ", 1 ); Lib_display_key( 512 - w, 455, "FS0のファイル削除 ", 1 ); Lib_display_key( w - 1, 455, "ロード(FS0→)", 1 ); if( CURSOR_EXECUTE == Lib_get_current_position( &x, &y ) ) { if( 0 <= x && x <= w && 0 <= y && y <= h ) { Lib_display_key( 0, 0, "画像の取り込み", 2 ); sub_input(); } if( w - 1 <= x && x <= w * 2 - 2 && 0 <= y && y <= h ) { Lib_display_key( w - 1, 0, "蓄積画像の表\示", 2 ); sub_display(); } if( 0 <= x && x <= w && 455 <= y && y <= 455 + h ) { Lib_display_key( 0, 455, "セーブ (→FS0)", 2 ); sub_save(); } if( 512 - w <= x && x <= 512 && 0 <= y && y <= h ) { Lib_display_key( 512 - w, 0, "90Xシステムへ復帰 ", 2 ); sub_end(); break; } if( 512 - w <= x && x <= 512 && 455 <= y && y <= 455 + h ) { Lib_display_key( 512 - w, 455, "FS0のファイル削除 ", 2 ); sub_delete(); } if( w - 1 <= x && x <= w * 2 - 2 && 455 <= y && y <= 455 + h ) { Lib_display_key( w -1, 455, "ロード(FS0→)", 2 ); sub_load(); } } } /* 一応キーサイズを10に変更しておく */ Lib_set_pad_maxstring( 10 ); } /**************************************************************/ /**** 画像の取り込み(サブルーチン) **************************/ /**************************************************************/ void sub_input() { static char disp_buff[10]; int i, w, h, ew, eh, x, y; /* 画面クリア */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* タイトル表示 */ Lib_chrdisp( 15, 1, "★★★ 画像の取り込み 及び 蓄積 ★★★" ); /* キーサイズ取得 */ Lib_get_key_size( 8, &w, &h ); /* 取り込み可能面数分のキーを表示 */ for( i = 1; i < max_image_count; i++ ) { switch( store_index[i] ) { case NON_PICTURE: Lib_sprintf( disp_buff, "○画像%02d", i ); break; case LOAD_PICTURE: Lib_sprintf( disp_buff, "◆画像%02d", i ); break; case CAMERA_PICTURE: Lib_sprintf( disp_buff, "●画像%02d", i ); break; } Lib_display_key( 0, h * (i-1), disp_buff, 1 ); } /* 終了キー表示 */ Lib_get_key_size( 4, &ew, &eh ); Lib_display_key( 511 - ew, 0, "終了", 1 ); /* 取り込み作業 */ for( ; ; ) { if( CURSOR_EXECUTE == Lib_get_current_position( &x, &y ) ) { if( 0 <= x && x <= w && 0 <= y && y <= h * ( max_image_count - 1 ) ) { /* カーサー位置が何処のキー上にあるかチェック */ for( i = 1; i < max_image_count; i++ ) if( (i-1) * h <= y && y <= (i-1) * h + h ) break; /* その位置のキー表示をプッシュ、及び蓄積中状態にする */ Lib_sprintf( disp_buff, "●画像%02d", i ); Lib_display_key( 0, h * (i-1), disp_buff, 2 ); /* 指標テーブルを蓄積中にする */ store_index[i] = CAMERA_PICTURE; /* 画像凍結、及び蓄積 */ Lib_freeze( TRANSMIT ); /* 入力画像をキーで指標する画像メモリNo.へ複写 */ Lib_gray_memory_move( INPUT_MEMORY, i, 0xff ); /* 画像凍結解除 */ Lib_freerun(); } if( 511 - ew <= x && x <= 511 && 0 <= y && y <= eh ) { Lib_display_key( 511 - ew, 0, "終了", 2 ); break; } } } Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); } /**************************************************************/ /**** 蓄積画像の表示(サブルーチン) **************************/ /**************************************************************/ void sub_display() { static char disp_buff[10]; int i, w, h, ew, eh, x, y; /* 画像凍結 */ Lib_freeze( NOT_TRANSMIT ); /* 画面クリア */ Lib_memory_clear( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* タイトル表示 */ Lib_chrdisp( 15, 1, "★★★ 蓄積画像の表\示 ★★★" ); /* キーサイズ取得 */ Lib_get_key_size( 8, &w, &h ); /* 表示可能面数分のキーを表示 */ for( i = 1; i < max_image_count; i++ ) { switch( store_index[i] ) { case NON_PICTURE: Lib_sprintf( disp_buff, "○画像%02d", i ); break; case LOAD_PICTURE: Lib_sprintf( disp_buff, "◆画像%02d", i ); break; case CAMERA_PICTURE:Lib_sprintf( disp_buff, "●画像%02d", i ); break; } Lib_display_key( 0, h * (i-1), disp_buff, 1 ); } i = 0; /* 画像クリア表示 */ /* Lib_display_key( 0, h * 16, "画像クリア ", 1 );*/ /* 終了キー表示 */ Lib_get_key_size( 4, &ew, &eh ); Lib_display_key( 511 - ew, 0, "終了", 1 ); /* 表示作業 */ for( ; ; ) { if( CURSOR_EXECUTE == Lib_get_current_position( &x, &y ) ) { if( 0 <= x && x <= w && 0 <= y && y <= h * ( max_image_count - 1 ) ) { switch( store_index[i] ) { case LOAD_PICTURE: Lib_sprintf( disp_buff, "◆画像%02d", i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); break; case CAMERA_PICTURE:Lib_sprintf( disp_buff, "●画像%02d", i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); break; } /* カーサー位置が何処のキー上にあるかチェック */ for( i = 1; i < max_image_count; i++ ) if( (i-1) * h <= y && y <= (i-1) * h + h ) break; /* その位置のキー表示をプッシュ状態にする */ switch( store_index[i] ) { case NON_PICTURE: Lib_sprintf( disp_buff, "○画像%02d", i ); break; case LOAD_PICTURE: Lib_sprintf( disp_buff, "◆画像%02d", i ); break; case CAMERA_PICTURE:Lib_sprintf( disp_buff, "●画像%02d", i ); break; } Lib_display_key( 0, h * (i-1), disp_buff, 2 ); /* 表示 */ Lib_xvideo_transmit( i, GRAY_PLANE ); } /* if( 0 <= x && x <= w && h * 16 <= y && y <= h * 17 ) { Lib_display_key( 0, h * 16, "画像クリア ", 2 ); for( i = 0; i < max_image_count; i++ ) { Lib_gray_memory_cls( i ); store_index[i] = NON_PICTURE; Lib_sprintf( disp_buff, "○画像%02d", i ); Lib_display_key( 0, h * ( i - 1 ), disp_buff, 1 ); } Lib_memory_clear( GRAY_PLANE ); } */ if( 511 - ew <= x && x <= 511 && 0 <= y && y <= eh ) { Lib_display_key( 511 - ew, 0, "終了", 2 ); break; } } } Lib_freerun(); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); } /**************************************************************/ /**** 終了処理(サブルーチン) ********************************/ /**************************************************************/ void sub_end() { int i, w, h, x, y; Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_freeze( NOT_TRANSMIT ); Lib_memory_clear( GRAY_PLANE ); Lib_chrdisp( 17, 10, "STORAGE上にある一時蓄積用画像ファイル群" ); Lib_chrdisp( 17, 11, "( GRAYMEMx.SYS )を消去しますか?" ); Lib_get_key_size( 8, &w, &h ); Lib_display_key( 180, 200, " はい ", 1 ); Lib_display_key( 210 + w, 200, " いいえ ", 1 ); for( ; ; ) { if( CURSOR_EXECUTE == Lib_get_current_position( &x, &y ) ) { if( 180 <= x && x <= 180 + w && 200 <= y && y <= 200 + h ) { Lib_display_key( 180, 200, " はい ", 2 ); Lib_change_gray_memory( 0 ); for( i = 15; 0 < i; i-- ) Lib_free_gray_memory( i ); break; } if( 210 + w <= x && x <= 210 + w * 2 && 200 <= y && y <= 200 + h ) { Lib_display_key( 210 + w, 200, " いいえ ", 2 ); break; } } } Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_freerun(); } /**************************************************************/ /**** PCカードへのセーブ(サブルーチン) **********************/ /**************************************************************/ void sub_save( ) { static char file_name[30]; static char disp_buff[10]; int i, w, h, ew, eh, x, y; char *gray_mem_addr; int rtn; /* 画像凍結 */ Lib_freeze( NOT_TRANSMIT ); /* 画面クリア */ Lib_memory_clear( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* タイトル表示 */ Lib_chrdisp( 15, 1, "★★★ 蓄積画像のセーブ ★★★" ); /* キーサイズ取得 */ Lib_get_key_size( 8, &w, &h ); /* 表示可能面数分のキーを表示 */ for( i = 1; i < max_image_count; i++ ) { switch( store_index[i] ) { case NON_PICTURE: Lib_sprintf( disp_buff, "○画像%02d", i ); break; case LOAD_PICTURE: Lib_sprintf( disp_buff, "◆画像%02d", i ); break; case CAMERA_PICTURE: Lib_sprintf( disp_buff, "●画像%02d", i ); break; } Lib_display_key( 0, h * (i-1), disp_buff, 1 ); } /* セーブキー表示 */ Lib_display_key( 0, h * 16, "一括セーブ", 1 ); /* 終了キー表示 */ Lib_get_key_size( 4, &ew, &eh ); Lib_display_key( 511 - ew, 0, "終了", 1 ); /* 名称変更キー表示 */ Lib_display_key( 0, h * 18, "名称変更", 1 ); /* 表示作業 */ for( ; ; ) { if( CURSOR_EXECUTE == Lib_get_current_position( &x, &y ) ) { if( 0 <= x && x <= w && 0 <= y && y <= h * ( max_image_count - 1 ) ) { /* カーサー位置が何処のキー上にあるかチェック */ for( i = 1; i < max_image_count; i++ ) if( (i-1) * h <= y && y <= (i-1) * h + h ) break; /* その位置のキー表示をプッシュ状態にする */ switch( store_index[i] ) { case NON_PICTURE: Lib_sprintf( disp_buff, "○画像%02d", i ); break; case LOAD_PICTURE: Lib_sprintf( disp_buff, "◆画像%02d", i ); break; case CAMERA_PICTURE:Lib_sprintf( disp_buff, "●画像%02d", i ); break; } /* カーソル押された状態 */ Lib_display_key( 0, h * (i-1), disp_buff, 2 ); /* 画像が存在するか確認 */ if( NON_PICTURE != store_index[i] ) { /* セーブ画像の表示 */ Lib_xvideo_transmit( i, GRAY_PLANE ); /* セーブ先 */ if ( 0 == wwfkind[0] ) { if( i < 10 ) Lib_sprintf( file_name, "\\FS0\\%s%01d", wwfid, i ); else Lib_sprintf( file_name, "\\FS0\\%s%01X", wwfid, i ); } else { if( i < 10 ) Lib_sprintf( file_name, "\\FS0\\%s%01d.%s", wwfid, i, wwfkind ); else Lib_sprintf( file_name, "\\FS0\\%s%01X.%s", wwfid, i, wwfkind ); } /************************/ /* BMPファイルの保存 */ /************************/ if( 1 == wBmp_on_off ) { /* セーブ中メッセージの表示 */ Lib_chrdisp( 20, 15, "現在[画像 ]をセーブ中・・・・・" ); Lib_sprintf( disp_buff, "%02d", i ); Lib_chrdisp( 30, 15, disp_buff ); /* BMPセーブ実行 */ if( 0 != fnSaveBmp( i, 0, 0, 512, 480, file_name ) ) { Lib_memory_clear( GRAY_PLANE ); Lib_chrdisp( 20, 15, "[画像 ]をセーブ中にエラー発生!" ); Lib_chrdisp( 26, 15, disp_buff ); Lib_chrdisp( 20, 16, "これ以上セーブは続行できません。 " ); Lib_chrdisp( 20, 17, "PCカードの残容量を調べてください。" ); for( Lib_strtclk(); Lib_readclk() < 700; ) ; Lib_chrdisp( 20, 16, " " ); Lib_chrdisp( 20, 17, " " ); switch( store_index[i] ) { case NON_PICTURE: Lib_sprintf( disp_buff, "○画像%02d", i ); break; case LOAD_PICTURE: Lib_sprintf( disp_buff, "◆画像%02d", i ); break; case CAMERA_PICTURE:Lib_sprintf( disp_buff, "●画像%02d", i ); break; } Lib_display_key( 0, h * (i-1), disp_buff, 1 ); } else { Lib_sprintf( disp_buff, "○画像%02d", i ); Lib_gray_memory_cls( i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); store_index[i] = NON_PICTURE; } } /************************/ /* IMGファイルの保存 */ /************************/ else { /* セーブ中メッセージの表示 */ Lib_chrdisp( 20, 15, "現在[画像 ]をセーブ中・・・・・" ); Lib_sprintf( disp_buff, "%02d", i ); Lib_chrdisp( 30, 15, disp_buff ); /* アドレスの取得 */ gray_mem_addr = Lib_adrs_gray_memory( i ); if( GRAY_MEM_SIZE != Lib_fsave( file_name, gray_mem_addr, GRAY_MEM_SIZE ) ) { Lib_memory_clear( GRAY_PLANE ); Lib_chrdisp( 20, 15, "[画像 ]をセーブ中にエラー発生!" ); Lib_chrdisp( 26, 15, disp_buff ); Lib_chrdisp( 20, 16, "これ以上セーブは続行できません。 " ); Lib_chrdisp( 20, 17, "PCカードの残容量を調べてください。" ); for( Lib_strtclk(); Lib_readclk() < 700; ) ; Lib_chrdisp( 20, 16, " " ); Lib_chrdisp( 20, 17, " " ); switch( store_index[i] ) { case NON_PICTURE: Lib_sprintf( disp_buff, "○画像%02d", i ); break; case LOAD_PICTURE: Lib_sprintf( disp_buff, "◆画像%02d", i ); break; case CAMERA_PICTURE:Lib_sprintf( disp_buff, "●画像%02d", i ); break; } Lib_display_key( 0, h * (i-1), disp_buff, 1 ); } else { Lib_sprintf( disp_buff, "○画像%02d", i ); Lib_gray_memory_cls( i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); store_index[i] = NON_PICTURE; } } Lib_chrdisp( 20, 15, " " ); Lib_memory_clear( GRAY_PLANE ); } } /***************************/ /* 一括セーブ */ /***************************/ if( 0 <= x && x <= w && h * 16 <= y && y <= h * 17 ) { Lib_display_key( 0, h * 16, "一括セーブ", 2 ); for( i = 1; i < max_image_count; i++ ) { if( CAMERA_PICTURE == store_index[i] || LOAD_PICTURE == store_index[i] ) { /* セーブ画像の表示 */ Lib_xvideo_transmit( i, GRAY_PLANE ); /* セーブ中メッセージの表示 */ Lib_chrdisp( 20, 15, "現在[画像 ]をセーブ中・・・・・" ); Lib_sprintf( disp_buff, "%02d", i ); Lib_chrdisp( 30, 15, disp_buff ); if( 0 == wwfkind[0] ) { if( i < 10 ) Lib_sprintf( file_name, "\\FS0\\%s%01d", wwfid, i ); else Lib_sprintf( file_name, "\\FS0\\%s%01X", wwfid, i ); } else { if( i < 10 ) Lib_sprintf( file_name, "\\FS0\\%s%01d.%s", wwfid, i, wwfkind ); else Lib_sprintf( file_name, "\\FS0\\%s%01X.%s", wwfid, i, wwfkind ); } /* BMP保存の場合 */ if( 1 == wBmp_on_off ) { /* BMPセーブ実行 */ if( 0 != fnSaveBmp( i, 0, 0, 512, 480, file_name ) ) { Lib_memory_clear( GRAY_PLANE ); Lib_chrdisp( 20, 15, "[画像 ]をセーブ中にエラー発生!" ); Lib_chrdisp( 26, 15, disp_buff ); Lib_chrdisp( 20, 16, "これ以上セーブは続行できません。 " ); Lib_chrdisp( 20, 17, "PCカードの残容量を調べてください。" ); for( Lib_strtclk(); Lib_readclk() < 700; ) ; Lib_chrdisp( 20, 16, " " ); Lib_chrdisp( 20, 17, " " ); Lib_sprintf( disp_buff, "●画像%02d", i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); break; } else { Lib_sprintf( disp_buff, "○画像%02d", i ); Lib_gray_memory_cls( i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); store_index[i] = NON_PICTURE; } } /* IMG保存の場合 */ else { /* セーブ */ gray_mem_addr = Lib_adrs_gray_memory( i ); if( GRAY_MEM_SIZE != Lib_fsave( file_name, gray_mem_addr, GRAY_MEM_SIZE ) ) { Lib_memory_clear( GRAY_PLANE ); Lib_chrdisp( 20, 15, "[画像 ]をセーブ中にエラー発生!" ); Lib_chrdisp( 26, 15, disp_buff ); Lib_chrdisp( 20, 16, "これ以上セーブは続行できません。 " ); Lib_chrdisp( 20, 17, "PCカードの残容量を調べてください。" ); for( Lib_strtclk(); Lib_readclk() < 700; ) ; Lib_chrdisp( 20, 16, " " ); Lib_chrdisp( 20, 17, " " ); Lib_sprintf( disp_buff, "●画像%02d", i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); break; } else { Lib_sprintf( disp_buff, "○画像%02d", i ); Lib_gray_memory_cls( i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); store_index[i] = NON_PICTURE; } } } } Lib_chrdisp( 20, 15, " " ); Lib_memory_clear( GRAY_PLANE ); } /* 名称変更の場合 */ if( 0 <= x && x <= w && h * 18 <= y && y <= h * 19 ) { rtn = sub_set_file_name( ); /*ファイル名設定*/ if( 0 == rtn || 1 == rtn ) wBmp_on_off = rtn; sub_cut_space( fid, wwfid ); sub_cut_space( fkind, wwfkind ); } /* 終了の場合 */ if( 511 - ew <= x && x <= 511 && 0 <= y && y <= eh ) { Lib_display_key( 511 - ew, 0, "終了", 2 ); break; } } } Lib_freerun(); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); } /**************************************************************/ /* PCカード上に存在する画像保存ファイルを削除(サブルーチン) */ /**************************************************************/ void sub_delete() { Lib_system_process( FILE_MENU ); } /***************************************************************/ /* PCカード上に存在する画像保存ファイルをロード(サブルーチン)*/ /***************************************************************/ static void sub_load( void ) { static char disp_buff[10]; int i, j, k, w, h, ew, eh, x, y; char baFile_path[256]; int wOp_rtn; int wRtn, rtn, wSele_rtn; int wFile_N, wPoint, wMax; int wBNF; int wRead, wWrite, wRandom; int wQuit, wPage, wOpen_num; int wFile_count; unsigned long ulFile_size; char baFile_name[13]; char baBmp[5]; char file_id[FID_SIZE+1], file_kind[FKIND_SIZE+1]; char *gray_adrs; FILE *fd; FILE_PARAM *tFile_param, *tParam_bu; /* 画像凍結 */ Lib_freeze( NOT_TRANSMIT ); /* 画面クリア */ Lib_memory_clear( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* タイトル表示 */ Lib_chrdisp( 17, 1, "★★★ 画像のロード ★★★" ); /* キーサイズ取得 */ Lib_get_key_size( 8, &w, &h ); /* 表示可能面数分のキーを表示 */ for( i = 1; i < max_image_count; i++ ) { switch( store_index[i] ) { case NON_PICTURE: Lib_sprintf( disp_buff, "○画像%02d", i ); break; case LOAD_PICTURE: Lib_sprintf( disp_buff, "◆画像%02d", i ); break; case CAMERA_PICTURE:Lib_sprintf( disp_buff, "●画像%02d", i ); break; } Lib_display_key( 0, h * (i-1), disp_buff, 1 ); } /* 一括ロードキー表示 */ Lib_display_key( 0, h * 16, "一括ロード", 1 ); /* 終了キー表示 */ Lib_get_key_size( 4, &ew, &eh ); Lib_display_key( 511 - ew, 0, "終了", 1 ); /* 表示作業 */ for( ; ; ) { if( CURSOR_EXECUTE == Lib_get_current_position( &x, &y ) ) { if( 0 <= x && x <= w && 0 <= y && y <= h * ( max_image_count - 1 ) ) { /* カーサー位置が何処のキー上にあるかチェック */ for( i = 1; i < max_image_count; i++ ) if( (i-1) * h <= y && y <= (i-1) * h + h ) break; /* その位置のキー表示をプッシュ状態にする */ switch( store_index[i] ) { case NON_PICTURE: Lib_sprintf( disp_buff, "○画像%02d", i ); break; case LOAD_PICTURE: Lib_sprintf( disp_buff, "◆画像%02d", i ); break; case CAMERA_PICTURE:Lib_sprintf( disp_buff, "●画像%02d", i ); break; } /* カーソル押された状態 */ Lib_display_key( 0, h * (i-1), disp_buff, 2 ); /* 画面クリア */ Lib_memory_clear( GRAY_PLANE ); /* IMGかBMPを選択 */ wSele_rtn = fnSele_I_B( ); /* FS0のファイル数を取得 */ wFile_N = Lib_get_reg_files( "FS0" ); strcpy( baBmp, ".BMP" ); wFile_count = 0; if( 1 == wSele_rtn || 2 == wSele_rtn ) { if( NULL == ( tFile_param = ( FILE_PARAM * )Lib_mlalloc( sizeof( FILE_PARAM ) * wFile_N ))) Lib_display_message( 150, 150, "エラー", "メモリ不足です" ); else { for( j = 0; j < wFile_N; j++ ) { /* ディレクトリの情報を得る */ Lib_fdir( "FS0", j, baFile_name, &ulFile_size, &wRead, &wWrite, &wRandom ); /* IMG形式が選択されたら */ if( 1 == wSele_rtn ) { /* サイズが245760のファイルを探す */ if( 245760 == ulFile_size ) { strcpy( tFile_param[wFile_count].baName, baFile_name ); tFile_param[wFile_count].ulSize = ulFile_size; wFile_count++; } } /* BMPファイルが選択されたら */ else if( 2 == wSele_rtn ) { for( k = 0; k < 9; k++ ) /* 文字列13(NULL除くと12)で拡張子4文字。よって8まで */ { /* 拡張子 .BMPのファイルを探す */ if( 0 == strncmp( &baFile_name[k], baBmp, 4 ) ) { strcpy( tFile_param[wFile_count].baName, baFile_name ); tFile_param[wFile_count].ulSize = ulFile_size; wFile_count++; break; } } } } /* ソーティング */ wPoint = 0; wMax = 0; if( NULL != ( tParam_bu = ( FILE_PARAM * )Lib_mlalloc( sizeof( FILE_PARAM ) * wFile_N )) ) { for( k = 0; k < wFile_count; k++ ) fnSort( tFile_param, tParam_bu, k, &wPoint, &wMax ); for( k = 0; k < wFile_count; k++ ) tFile_param[k] = tParam_bu[k]; Lib_lfree( ( char * )tParam_bu ); } /* パッドのコントロール */ wQuit = 0; wPage = 0; while( 0 == wQuit ) { wRtn = fnSelect_file( tFile_param, wFile_count, wPage ); if( 12 == wRtn ) wPage--; else if( 13 == wRtn ) wPage++; else wQuit = 1; } /* ファイルのオープン */ if( 0 <= wRtn && wRtn < 12 ) { /* セーブ中メッセージの表示 */ Lib_chrdisp( 20, 15, "現在[画像 ]をロード中・・・・・" ); Lib_sprintf( disp_buff, "%02d", i ); Lib_chrdisp( 30, 15, disp_buff ); wOpen_num = wPage * 12 + wRtn; Lib_sprintf( baFile_path, "\\FS0\\%s", tFile_param[wOpen_num].baName ); /* IMG画像なら */ if( 1 == wSele_rtn ) { gray_adrs = Lib_adrs_gray_memory( i ); if( 0 != Lib_fload( baFile_path, gray_adrs, GRAY_MEM_SIZE ) ) { Lib_sprintf( disp_buff, "◆画像%02d", i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); store_index[i] = LOAD_PICTURE; Lib_xvideo_transmit( i, GRAY_PLANE ); } } /* BMP画像なら */ else if( 2 == wSele_rtn ) { /* BMPオープン */ wOp_rtn = fnOpen_bitmap( i, baFile_path, tFile_param[wOpen_num].ulSize ); if( -1 == wOp_rtn ) { Lib_chrdisp( 20, 13, "ロード中にエラー発生" ); Lib_chrdisp( 20, 14, "メモリ不足です" ); Lib_chrdisp( 20, 15, "STORAGEへのロードは中止します。" ); Lib_time_delay( 1000 ); Lib_chrdisp( 20, 13, "          " ); Lib_chrdisp( 20, 14, "       " ); Lib_chrdisp( 20, 15, "                " ); } else if( -2 == wOp_rtn ) { Lib_chrdisp( 20, 13, "ロード中にエラー発生" ); Lib_chrdisp( 20, 14, "ファイルのロードに失敗しました" ); Lib_chrdisp( 20, 15, "STORAGEへのロードは中止します。" ); Lib_time_delay( 1000 ); Lib_chrdisp( 20, 13, "          " ); Lib_chrdisp( 20, 14, "               " ); Lib_chrdisp( 20, 15, "                " ); } else if( -3 == wOp_rtn ) { Lib_chrdisp( 20, 13, "ロード中にエラー発生" ); Lib_chrdisp( 20, 14, "このファイルはBMPではありません" ); Lib_chrdisp( 20, 15, "STORAGEへのロードは中止します。" ); Lib_time_delay( 1000 ); Lib_chrdisp( 20, 13, "          " ); Lib_chrdisp( 20, 14, "                " ); Lib_chrdisp( 20, 15, "                " ); } else { Lib_sprintf( disp_buff, "◆画像%02d", i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); store_index[i] = LOAD_PICTURE; Lib_xvideo_transmit( i, GRAY_PLANE ); } } Lib_chrdisp( 20, 15, "                 " ); } /* メモリの開放 */ Lib_lfree( (char * )tFile_param ); } } } /* 一括ロード */ if( 0 <= x && x <= w && h * 16 <= y && y <= h * 17 ) { Lib_display_key( 0, h * 16, "一括ロード", 2 ); wBNF = wBmp_on_off; if( 102 != ( rtn = sub_set_file_name( )) ) /*ファイル名設定*/ { if( 0 == rtn || 1 == rtn ) wBNF = rtn; sub_cut_space( fid, file_id ); sub_cut_space( fkind, file_kind ); for( i = 1; i < max_image_count; i++ ) { if( 0 == wwfkind[0] ) { if( i < 10 ) Lib_sprintf( baFile_path, "\\FS0\\%s%01d", file_id, i ); else Lib_sprintf( baFile_path, "\\FS0\\%s%01X", file_id, i ); } else { if( i < 10 ) Lib_sprintf( baFile_path, "\\FS0\\%s%01d.%s", file_id, i, file_kind ); else Lib_sprintf( baFile_path, "\\FS0\\%s%01X.%s", file_id, i, file_kind ); } /* ファイルが存在するか確認 */ if( ( FILE * )NULL != ( fd = Lib_fopen( baFile_path, "R" ) ) ) { ulFile_size = Lib_fsize( fd ); Lib_fclose( fd ); /* セーブ中メッセージの表示 */ Lib_chrdisp( 20, 15, "現在[画像 ]をロード中・・・・・" ); Lib_sprintf( disp_buff, "%02d", i ); Lib_chrdisp( 30, 15, disp_buff ); /* BMPオープン */ if( 1 == wBNF ) { wOp_rtn = fnOpen_bitmap( i, baFile_path, ulFile_size ); if( -1 == wOp_rtn ) { Lib_chrdisp( 20, 13, "ロード中にエラー発生" ); Lib_chrdisp( 20, 14, "メモリ不足です" ); Lib_chrdisp( 20, 15, "STORAGEへのロードは中止します。" ); Lib_time_delay( 1000 ); Lib_chrdisp( 20, 13, "          " ); Lib_chrdisp( 20, 14, "       " ); Lib_chrdisp( 20, 15, "                  " ); break; } else if( -2 == wOp_rtn ) { Lib_chrdisp( 20, 13, "ロード中にエラー発生" ); Lib_chrdisp( 20, 14, "ファイルのロードに失敗しました" ); Lib_chrdisp( 20, 15, "STORAGEへのロードは中止します。" ); Lib_time_delay( 1000 ); Lib_chrdisp( 20, 13, "          " ); Lib_chrdisp( 20, 14, "                " ); Lib_chrdisp( 20, 15, "                  " ); break; } else if( -3 == wOp_rtn ) { Lib_chrdisp( 20, 13, "ロード中にエラー発生" ); Lib_chrdisp( 20, 14, "このファイルはBMPではありません" ); Lib_chrdisp( 20, 15, "STORAGEへのロードは中止します。" ); Lib_time_delay( 1000 ); Lib_chrdisp( 20, 13, "          " ); Lib_chrdisp( 20, 14, "                " ); Lib_chrdisp( 20, 15, "                  " ); break; } else { Lib_sprintf( disp_buff, "◆画像%02d", i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); store_index[i] = LOAD_PICTURE; Lib_xvideo_transmit( i, GRAY_PLANE ); } } /* IMGオープン */ else { gray_adrs = Lib_adrs_gray_memory( i ); if( 0 != Lib_fload( baFile_path, gray_adrs, GRAY_MEM_SIZE ) ) { Lib_sprintf( disp_buff, "◆画像%02d", i ); Lib_display_key( 0, h * (i-1), disp_buff, 1 ); store_index[i] = LOAD_PICTURE; Lib_xvideo_transmit( i, GRAY_PLANE ); } } Lib_chrdisp( 20, 15, "                   " ); } } Lib_time_delay( 1000 ); Lib_memory_clear( GRAY_PLANE ); } } /* 終了キーが押されたら */ if( 511 - ew <= x && x <= 511 && 0 <= y && y <= eh ) { Lib_display_key( 511 - ew, 0, "終了", 2 ); break; } } } Lib_freerun(); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); } /*******************************************************************/ /***** ソーティング *********************************************/ /*******************************************************************/ static void fnSort( tFile_param, tParam_bu, wObj, wPoint, wMax ) FILE_PARAM *tFile_param; FILE_PARAM *tParam_bu; int wObj; int *wPoint; int *wMax; { int i, j; if( 0 == *wPoint ) { /* wPointに入れる */ for( i = *wMax-1; i >= *wPoint; i-- ) tParam_bu[i+1] = tParam_bu[i]; tParam_bu[*wPoint] = tFile_param[wObj]; *wMax += 1; *wPoint = *wMax; } else { /* 先頭文字が同じ場合 */ if( tParam_bu[*wPoint-1].baName[0] == tFile_param[wObj].baName[0] ) { /* 全体チェックを行なう */ for( j = 1; j < 12; j++ ) { if( tParam_bu[*wPoint-1].baName[j] < tFile_param[wObj].baName[j] ) { /* wPointに入れる */ for( i = *wMax-1; i >= *wPoint; i-- ) tParam_bu[i+1] = tParam_bu[i]; tParam_bu[*wPoint] = tFile_param[wObj]; *wMax += 1; *wPoint = *wMax; break; } if( tParam_bu[*wPoint-1].baName[j] > tFile_param[wObj].baName[j] ) { *wPoint -= 1; fnSort( tFile_param, tParam_bu, wObj, wPoint, wMax ); break; } } } /* wObjの先頭文字が大きい場合 */ else if( tParam_bu[*wPoint-1].baName[0] < tFile_param[wObj].baName[0] ) { /* wPointに入れる */ for( i = *wMax-1; i >= *wPoint; i-- ) tParam_bu[i+1] = tParam_bu[i]; tParam_bu[*wPoint] = tFile_param[wObj]; *wMax += 1; *wPoint = *wMax; } /* wObjの先頭文字が小さい場合 */ else if( tParam_bu[*wPoint-1].baName[0] > tFile_param[wObj].baName[0] ) { *wPoint -= 1; fnSort( tFile_param, tParam_bu, wObj, wPoint, wMax ); } } } /******************************************************************* **  BMPかIMGかの選択パッド ** *******************************************************************/ static int fnSele_I_B( void ) { int wPad_level; int wWidth, wHeight; int wNo, wRtn=0; /* パッド表示文字数の設定 */ Lib_set_pad_maxstring( 12 ); /* メニューサイズの取得 */ Lib_get_standard_key_size( &wWidth, &wHeight ); /* パッドのオープン */ wPad_level = Lib_view_open( ); /* パッドのタイトル */ Lib_view_set_title( wPad_level, "選択" ); /* メニューの登録 */ Lib_view_set_null( wPad_level, 10, 10, "90x形式", 0 ); Lib_view_set_null( wPad_level, 25+wWidth, 10, "BMP形式", 1 ); /* パッドの表示位置 */ Lib_view_set_size( wPad_level, 130, 100, 10, 10 ); /* パッドの表示 */ Lib_draw_command( wPad_level ); if( ERROR_RETURN != ( wNo = Lib_process_command( wPad_level )) ) { switch( wNo ) { case 0: wRtn = 1; break; case 1: wRtn = 2; break; case 102: wRtn = 102; break; } } else wRtn = -1; Lib_erase_command( wPad_level ); /* コマンドパッドを消す */ Lib_view_close( wPad_level ); /* パッドのクローズ */ Lib_set_pad_maxstring( 10 ); return( wRtn ); } /*************************************************************************** ** ファイル名表示 ** ** 画像ファイルのファイル名をコマンドパッドのメニューとして ** ** 表示します。 ** ** 引数は名前群、ファイル数、ページ番号 ** ***************************************************************************/ static int fnSelect_file( FILE_PARAM *tFile_param, int wFile_N, int wPage ) { int wPad_level; /* パッドレベル */ int wWidth,wHeight; /* キーサイズ */ int wNo,wRtn=0; /* 戻り値代入 */ int i; int wXs, wYs; int wKey_N; /* 1ページあたりのメニュー数 */ int wMax_page; /* 最大のページ番号を入れる */ char baStr[64]; /* 文字列バッファ */ int p, s; if( 0 == wFile_N ) { Lib_display_message( 130, 150, "確認", "画像ファイルが存在しません" ); wRtn = -1; } else { /* マックスページ-(0ページからMaxページ)の取得 */ wMax_page = ( wFile_N - 1 ) / 12; /* メニュー文字列 */ Lib_set_pad_maxstring( 14 ); /* メニューサイズの取得 */ Lib_get_standard_key_size(&wWidth, &wHeight); /* パッドのオープン */ wPad_level = Lib_view_open( ); /* パッドのタイトル */ Lib_view_set_title( wPad_level, "ファイル名称" ); /* 最終ページなら、余りのファイル数 */ if( wPage == wMax_page ) wKey_N = wFile_N - wPage * 12; else wKey_N = 12; /* メニューの登録 */ for( i = 0; i < wKey_N; i++ ) { p = i % 3; s = i / 3; Lib_sprintf( baStr, "%s", tFile_param[i+wPage * 12].baName ); Lib_view_set_null( wPad_level, 5+5*p+wWidth*p, 5+3*(s+1)+wHeight*s, baStr, i ); } s++; p=0; if( 0 != wPage ) { Lib_view_set_null( wPad_level, 5, 5+3*s+wHeight*s, "前頁", i ); i++; } if( wMax_page != wPage ) Lib_view_set_null( wPad_level, 15+wWidth*2, 5+3*s+wHeight*s, "次頁", i ); /* パッド始点取得 */ Lib_get_start_pad( wPad_level, &wXs, &wYs ); /* パッドの表示位置 */ Lib_view_set_size( wPad_level, wXs, wYs, 5, 5); /* パッドの表示 */ Lib_draw_command( wPad_level ); for( ; ; ) { if( ERROR_RETURN != ( wNo = Lib_process_command( wPad_level )) ) { /* ページ番号がmax_pageよりも少ないなら */ if( wPage < wMax_page && 0 != wPage ) { wRtn = wNo; break; } /* それ以外でファイル名なら */ else if( wNo < wKey_N ) { wRtn = wNo; break; } else if( wPage == wMax_page && wNo == wKey_N ) { wRtn = 12; break; } else if( 0 == wPage && wNo == wKey_N ) { wRtn = 13; break; } /* 終了が押されたなら */ else if( 102 == wNo ) { wRtn = wNo; break; } } } Lib_erase_command( wPad_level ); /* コマンドパッドを消す */ Lib_view_close( wPad_level ); /* パッドのクローズ */ /* キーサイズ */ Lib_set_pad_maxstring( 10 ); } return( wRtn ); } /******************************************************************* **  ビットマップファイルのオープン ** *******************************************************************/ static int fnOpen_bitmap( wMem, bpFile_name, ulSize ) int wMem; /* グレイメモリの番号 */ char *bpFile_name; /* ファイルパス */ unsigned long ulSize; /* ファイルサイズ */ { BMP_HEADER tBmph; /* ビットマップヘッダー */ RGBQUAD tPalette[256]; /* パレットデータ */ unsigned long ulOp_size; /* ロードされたBMPデータのサイズ */ unsigned char *ubpBmp; /* ロードされたビットマップデータの先頭アドレス */ unsigned char *bpMem1_adrs; /* グレイメモリ1の先頭アドレス */ unsigned char ubPt, ubZ; /* ビットマップデータから取り出した1バイトのデータ */ unsigned int uwTemp; unsigned int i, j, k, r, m; unsigned int uwPosition, uwPosition2; /* 読み取り位置、書き込み位置 */ unsigned int wFx, wFy; /* グレイメモリサイズ */ unsigned int uwWid, uwHei; /* オープンするサイズ */ unsigned int uwRead_byte, uwLine_byte; /* 一行あたりの読み込むバイト数、一行あたりのバイト数 */ unsigned int uwEnd; /* 終了バイト数 */ unsigned int uwWidth_b; /* 一行あたりのビット数 */ int wColor; /* 色 */ int uwWidth_bit, uwZero_N; /* 一行あたりのビット数と0の数 */ int wError_code; wError_code = 0; /* グレイメモリ1のアドレス取得 */ bpMem1_adrs = (unsigned char *)Lib_adrs_gray_memory( wMem ); /* グレイメモリ1のクリア */ Lib_gray_memory_cls( wMem ); /* メモリの確保 */ if( NULL == ( ubpBmp = (unsigned char * )Lib_mlalloc( ulSize ) )) wError_code = -1; else { /* ファイルのロード */ if( 0 == ( ulOp_size = Lib_fload( bpFile_name, (char *)ubpBmp, ulSize ) ) ) wError_code = -2; else { /* ロードされたバイト数と要求したバイト数が一致するか確認 */ if( ulOp_size != ulSize ) wError_code = -2; else { /******** ヘッダーのファイルIDチェック ********/ if( ubpBmp[0] != 0x42 || ubpBmp[1] != 0x4D ) wError_code = -3; /* BMPファイルじゃない */ else { /******* ヘッダーからデータの取得 *******/ /* ファイルサイズの取得 */ fnGetInt( (char *)ubpBmp, 2, &tBmph.bfSize ); /* ヘッダーサイズの取得 */ fnGetInt( (char *)ubpBmp, 10, &tBmph.bfOffBits ); /* インフォヘッダーサイズ */ fnGetInt( (char *)ubpBmp, 14, &tBmph.biSize ); /* イメージ幅 */ fnGetInt( (char *)ubpBmp, 18, &tBmph.biWidth ); /* イメージ高さ */ fnGetInt( (char *)ubpBmp, 22, &tBmph.biHeight ); /* プレーン数 */ fnGetShort( (char *)ubpBmp, 26, &tBmph.biPlanes ); /* ピクセルあたりのビット数 */ fnGetShort( (char *)ubpBmp, 28, &tBmph.biBitCount ); /* 水平解像度 */ fnGetInt( (char *)ubpBmp, 38, &tBmph.biXPelsPerMeter ); /* 垂直解像度 */ fnGetInt( (char *)ubpBmp, 42, &tBmph.biYPelsPerMeter ); /******** パレットデータの取得 ********/ uwTemp = tBmph.bfOffBits - tBmph.biSize - 14; /* 14はファイルヘッダーサイズ */ if( 0 < uwTemp ) /* パレットデータがある場合 */ { for( i = tBmph.biSize + 14, j = 0; i < tBmph.bfOffBits; i+=4, j++ ) { tPalette[j].rgbBlue = ubpBmp[i]; tPalette[j].rgbGreen = ubpBmp[i+1]; tPalette[j].rgbRed = ubpBmp[i+2]; tPalette[j].rgbReserved = ubpBmp[i+3]; } } /* 画像サイズの取得 */ wFx = (unsigned int)Lib_get_fx_size( ); wFy = (unsigned int)Lib_get_fy_size( ); /* 1行のデータビット数 */ uwWidth_bit = (int)tBmph.biWidth * (int)tBmph.biBitCount; /* 1行あたりのゼロビット数 */ uwZero_N = uwWidth_bit % 32; /* 32bit */ if( 0 != uwZero_N ) uwZero_N = 32 - uwZero_N; /* 512、480以上でないか確認 */ if( tBmph.biWidth > wFx ) uwWid = wFx; else uwWid = tBmph.biWidth; if( tBmph.biHeight > wFy ) uwHei = wFy; else uwHei = tBmph.biHeight; uwZero_N = uwZero_N / 8; /* ビットからバイトに変換 */ /******** IMGデータに変換 ********/ /******** 24bit colorの場合 ********/ if( 24 == tBmph.biBitCount ) { for( j = tBmph.biHeight - uwHei, m = 0; j < tBmph.biHeight; j++, m++ ) { for( i = 0; i < uwWid; i++ ) { /* 読み取り位置の計算 */ uwPosition = tBmph.bfOffBits + i * 3 + ( 3 * tBmph.biWidth + uwZero_N ) * j; /* データの取得 */ wColor = 0; for( k = 0; k < 3; k++ ) wColor += (int)ubpBmp[uwPosition+k]; wColor = wColor / 3; /* 書き込み位置の計算 */ uwPosition2 = wFx * ( uwHei - m - 1 ) + i; /* 書き込み */ bpMem1_adrs[uwPosition2] = ( unsigned char )wColor; } } } /******* 24bit未満(256色以下)の場合 *******/ else { /* 1行のバイト数 */ uwLine_byte = uwWidth_bit / 8; if( 0 != uwWidth_bit % 8 ) uwLine_byte++; /* 1行の読み取る量のバイト数 */ uwWidth_b = uwWid * (unsigned int)tBmph.biBitCount; uwRead_byte = uwWidth_b / 8; /* 1行あたりのバイト数 */ if( 0 != uwWidth_bit % 8 ) uwRead_byte++; for( j = tBmph.biHeight - uwHei, m = 0; j < tBmph.biHeight; j++, m++ ) { for( i = 0; i < uwRead_byte; i++ ) { /* 読み取り位置の計算 */ uwPosition = tBmph.bfOffBits + i + ( uwLine_byte + uwZero_N ) * j; /* 1バイト取得 */ ubPt = ubpBmp[uwPosition]; /* 行の最後かどうか確認 */ if( i != uwRead_byte -1 ) uwEnd = 8; else if( 8 == tBmph.biBitCount ) uwEnd = 8; else uwEnd = uwWidth_bit % 8; /* 必要なビットだけ取り出す */ for( r = 0; r < uwEnd; r += tBmph.biBitCount ) { /* 1ビットの場合、白黒 */ if( 1 == tBmph.biBitCount ) ubZ = MASK1 & ( ubPt >> r ); /* 2ビットの場合、4色 */ else if( 2 == tBmph.biBitCount ) ubZ = MASK2 & ( ubPt >> r ); /* 4ビットの場合、16色 */ else if( 4 == tBmph.biBitCount ) ubZ = MASK4 & ( ubPt >> r ); /* 8ビットの場合、256色 */ else if( 8 == tBmph.biBitCount ) ubZ = ubPt; /* カラーパレットからデータを取得 */ wColor = (int)tPalette[ubZ].rgbBlue; wColor += (int)tPalette[ubZ].rgbGreen; wColor += (int)tPalette[ubZ].rgbRed; wColor = wColor / 3; /* 書き込む位置を計算 */ uwPosition2 = wFx * ( uwHei - m - 1 ) + i * ( 8 / tBmph.biBitCount ) + ( 8 / tBmph.biBitCount - r - 1 ); /* 書き込む */ bpMem1_adrs[uwPosition2] = ( unsigned char )wColor; } } } } } } } /* メモリの開放 */ Lib_lfree( (char * )ubpBmp ); } return( wError_code ); } /******************************************************************* ** int型データを取得 ** *******************************************************************/ static void fnGetInt( bpStart, wOff, wInt ) char *bpStart; int wOff; unsigned int *wInt; /* 出力int型 */ { int i; unsigned char baChar[4]; for( i = 0; i < 4; i++ ) baChar[i] = (unsigned char)( *( bpStart + wOff + i )); *wInt = 0x00000000; for( i = 0; i < 4; i++ ) /* char型からint型へ変換 */ *wInt = *wInt | ( unsigned int )( baChar[i] << ( 8*i ) ); } /******************************************************************* ** short型データを取得 ** *******************************************************************/ static void fnGetShort( bpStart, wOff, sShort ) char *bpStart; int wOff; unsigned short *sShort; { int i; unsigned char baChar[2]; for( i = 0; i < 2; i++ ) baChar[i] = (unsigned char)( *( bpStart + wOff + i )); *sShort = 0x0000; for( i = 0; i < 2; i++ ) *sShort = *sShort | ( unsigned short )( baChar[i] << ( 8*i ) ); } /******************************************************************* ** BMP保存(グレイONLY) ** *******************************************************************/ static int fnSaveBmp( wMem, wStr_x, wStr_y, wSize_x, wSize_y, bpName ) int wMem; /* グレイメモリ番号 */ int wStr_x; /* 保存領域 左上x */ int wStr_y; /* 保存領域 左上y */ int wSize_x; /* 保存領域 サイズx */ int wSize_y; /* 保存領域 サイズy */ char *bpName; /* セーブファイル・パス */ { BMP_HEADER tSave_bmp; /* ヘッダー */ unsigned long uwFile_size; /* セーブファイルのサイズ */ unsigned int uwZero_N; /* 1行あたりのゼロの数 */ unsigned int Z; /* ファイル最後のゼロの数 */ int wRtn; /* 戻り値 */ int sx, sy, ex, ey; /* 始点終点 */ unsigned char *ubpBMP; /* 保存ビットマップ先頭アドレス */ int i, k, wPosi; int wPt; int wFx; /* 画面サイズ */ int x, y; unsigned long ulSize; char *bpAdrs; /* グレイメモリの先頭アドレス */ bpAdrs = Lib_adrs_gray_memory( wMem ); /* 関数の戻り値を初期化 */ wRtn = 0; /* 画面サイズを取得 */ wFx = Lib_get_fx_size( ); /* 始点終点を計算 */ sx = wStr_x; sy = wStr_y; ex = wStr_x + wSize_x - 1; ey = wStr_y + wSize_y - 1; /* 1行あたりの0の数を計算 */ uwZero_N = 4 - ( (unsigned int)wSize_x % 4 ); /* 行の後につける0の数 4は4BYTESの意味 */ if( 4 == uwZero_N ) uwZero_N = 0; /* ファイルの最後につける0の数を計算 */ uwFile_size = 1078 + ( (unsigned long)wSize_x + (unsigned long)uwZero_N ) * (unsigned long)wSize_y; Z = (int)( 4 - (uwFile_size % 4 )) ; /* ファイルの最後につける0の数 4は4BYTESの意味 */ uwFile_size += (unsigned long)Z; /* メモリの確保 */ if( NULL == ( ubpBMP = ( unsigned char *)Lib_mlalloc( uwFile_size ) )) wRtn = -1; else { /* 初期化 */ for( i = 0; i < uwFile_size; i++ ) ubpBMP[i] = 0; /* ヘッダーに数値を入れる */ tSave_bmp.bfSize = uwFile_size; tSave_bmp.bfOffBits = 1078; tSave_bmp.biSize = 40; tSave_bmp.biWidth = (unsigned int )wSize_x; tSave_bmp.biHeight = (unsigned int )wSize_y; tSave_bmp.biPlanes = 1; tSave_bmp.biBitCount = 8; tSave_bmp.biXPelsPerMeter = 3780; tSave_bmp.biYPelsPerMeter = 3780; /******** 代入 ********/ /* ファイルID */ ubpBMP[0] = 0x42; ubpBMP[1] = 0x4D; /* ヘッダー */ for( i = 0 ; i < 4; i++ ) ubpBMP[2+i] = ( char )( tSave_bmp.bfSize >> ( 8*i ) ); for( i = 0 ; i < 4; i++ ) ubpBMP[10+i] = ( char )( tSave_bmp.bfOffBits >> ( 8*i ) ); for( i = 0 ; i < 4; i++ ) ubpBMP[14+i] = ( char )( tSave_bmp.biSize >> ( 8*i ) ); for( i = 0 ; i < 4; i++ ) ubpBMP[18+i] = ( char )( tSave_bmp.biWidth >> ( 8*i ) ); for( i = 0 ; i < 4; i++ ) ubpBMP[22+i] = ( char )( tSave_bmp.biHeight >> ( 8*i ) ); for( i = 0 ; i < 2; i++ ) ubpBMP[26+i] = ( char )( tSave_bmp.biPlanes >> ( 8*i ) ); for( i = 0 ; i < 2; i++ ) ubpBMP[28+i] = ( char )( tSave_bmp.biBitCount >> ( 8*i ) ); for( i = 0 ; i < 4; i++ ) ubpBMP[38+i] = ( char )( tSave_bmp.biXPelsPerMeter >> ( 8*i ) ); for( i = 0 ; i < 4; i++ ) ubpBMP[42+i] = ( char )( tSave_bmp.biYPelsPerMeter >> ( 8*i ) ); /* パレットデータ */ for( i = 0; i < 256; i++ ) { ubpBMP[54+4*i] = i; ubpBMP[54+4*i+1] = i; ubpBMP[54+4*i+2] = i; ubpBMP[54+4*i+3] = 0; } /* データ */ wPt = 0; for( y = ey; y >= sy ; y-- ) { for( x = sx; x <= ex; x++ ) { wPosi = wFx * y + x; ubpBMP[1078 + wPt] = ( unsigned char )bpAdrs[wPosi]; wPt++; } for( k = 0; k < uwZero_N; k++ ) { ubpBMP[1078+wPt] = 0; wPt++; } } /* ファイルの最後 */ for( k = 0; k < Z; k++ ) { ubpBMP[1078+wPt] = 0; wPt++; } /* セーブ実行 */ if( 0 == ( ulSize = Lib_fsave( bpName, (char *)ubpBMP, uwFile_size )) ) wRtn = -2; if( ulSize != uwFile_size ) wRtn = -2; /* メモリの開放 */ Lib_lfree( (char *)ubpBMP ); } return( wRtn ); } /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ /*** ファイル名設定 **/ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ static int sub_set_file_name( void ) { int no; int wWidth, wHeight; int pad_level; PVAL value[4]; char *bpaSelect[2] = { "90x形式", "BMP形式" }; int rtn = 0; char baStr[64]; pad_level = Lib_view_open( ); Lib_view_set_title( pad_level, "ファイル名設定" ); Lib_get_standard_key_size( &wWidth, &wHeight ); strcpy( value[1].string_type, wwfid ); strcpy( temp_fkind, wwfkind ); Lib_sprintf( baStr, "拡張子は %3s です", temp_fkind ); Lib_chrdisp( 40, 30, baStr ); if( 0 == strcmp( temp_fkind, "BMP" ) ) strcpy( temp_fkind, "IMG" ); wTemp_bmp_on_off = wBmp_on_off; Lib_view_set_comment ( pad_level, 3, 5, "ファイル名(拡張子不要) ", 0 ); Lib_view_set_uniq_string ( pad_level, 5, 11+wHeight, "ファイルID", value[1].string_type, 7, 1 ); Lib_view_set_comment ( pad_level, 3, 20+wHeight*2, "保存形式", 2 ); Lib_view_set_select ( pad_level, 5, 26+wHeight*3, "保存形式", wBmp_on_off, 2, bpaSelect, 3 ); Lib_set_paradigm( pad_level, 3, END_TIMING, fnPrdm_form ); Lib_view_set_size( pad_level, 100, 100, 5, 5 ); Lib_draw_menu( pad_level ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level, value ) ) ) { if( PAD_EXECUTE == no ) { strcpy( fid, value[1].string_type ); rtn = value[3].select_type; if( 1 == value[3].select_type ) strcpy( fkind, "BMP" ); else strcpy( fkind, temp_fkind ); Lib_chrdisp( 40, 30, "       " ); } else { Lib_chrdisp( 40, 30, "       " ); rtn = 102; } } else { Lib_chrdisp( 1, 28, "pad err" ); rtn = -1; } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); return( rtn ); } static void fnPrdm_form( wTiming, n, val ) int wTiming; int n; PARADIGM val[]; { char baStr[64]; if( 0 == val[0].int_type ) { Lib_set_pad_execute_field( "YES", "は い" ); Lib_set_pad_cancel_field( "N O", "いいえ" ); Lib_sprintf( baStr, "拡張子は %3s です", temp_fkind ); Lib_chrdisp( 40, 30, baStr ); Lib_move_cursor( 350, 220 ); Lib_sprintf( baStr, "拡張子は %3s です。変更しますか?", temp_fkind ); if( PAD_EXECUTE == Lib_display_message2( 80, 200, "確 認", baStr ) ) { strcpy( temp_fkind, " " ); Lib_get_string_by_keyboad( 70, 200, 3, temp_fkind ); } Lib_sprintf( baStr, "拡張子は %3s です", temp_fkind ); Lib_chrdisp( 40, 30, baStr ); Lib_set_pad_default_execute_field( ); Lib_set_pad_default_cancel_field( ); wTemp_bmp_on_off = 0; } else if( 1 == val[0].int_type ) { wTemp_bmp_on_off = 1; Lib_chrdisp( 40, 30, "拡張子は BMP です" ); } } /*********************************************************************/ /* スペース除去                        */ /*********************************************************************/ static void sub_cut_space( instr, otstr ) char *instr; char *otstr; { for(;;) { if ( ' ' != *instr ) *otstr++ = *instr; if ( 0x00 == *instr ) break; instr++; } }