AnsiString GenericUtils::ConvertPathWindowsToCygwin(AnsiString original){
    //In case of source path I have to fix the Drive letter as well
    AnsiString driveLetter = ExtractFileDrive(original);
    if(driveLetter != ""){
        original = "/cygdrive/" + AnsiString(driveLetter[1]).LowerCase() + "/" + original.SubString(4, original.Length());
    }

    AnsiString answer;

    for(int i = 1; i <= original.Length(); i++){
        if(original[i] == '\\'){
            original[i] = '/';
        }
    }

    return original;
    /*
    for(int i = 1; i <= original.Length(); i++){
        if(original[i] == ' '){
            answer += "\\ ";
        }else{
            answer += original[i];
        }
    }
    return answer;
    */
}
예제 #2
0
파일: eccMisc.cpp 프로젝트: ChakaZulu/ecc
bool DriveIsRemovable(String drive)
{
	drive = ExtractFileDrive(drive);
	unsigned int dtype = GetDriveType( drive.c_str() );

	return (dtype == DRIVE_REMOVABLE);
}
예제 #3
0
void __fastcall TfmLauncher::ProcessCommandLine()
{
  if (ParamCount > 0){
    FileName = ParamStr(1);
    if (FileExists(FileName))
      RootDirectory = ExtractFileDrive(FileName);
  }
}
예제 #4
0
//---------------------------------------------------------------------------
// Return the amount of free space on the volume that a file resides on.
//
__int64 GetFreeDiskSpace(AnsiString FileName)
{
  unsigned __int64 FreeBytesAvailable, TotalBytes, TotalFreeBytes;
  bool success;

  success = ::GetDiskFreeSpaceEx((ExtractFileDrive(FileName) + "\\").c_str(), (ULARGE_INTEGER *)&FreeBytesAvailable, (ULARGE_INTEGER *)&TotalBytes, (ULARGE_INTEGER *)&TotalFreeBytes);
  if (success)
    return FreeBytesAvailable;
  else
    return 0;
}  // __int64 GetFreeSpace(AnsiString FileName)
//===========================================================================
//ディスクの空き容量を調べる
//===========================================================================
__int64 __fastcall TAttacheCaseFileDecrypt1::GetDiskFreeSpaceNum(String FilePath)
{

int i;
int flag;

__int64 FreeSpace;

String DriveName = ExtractFileDrive(FilePath)+":";
String DirPath = IncludeTrailingPathDelimiter(ExtractFileDir(FilePath));

OSVERSIONINFO ovi;   // バージョン情報を格納する構造体
ovi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );

// バージョン情報取得
GetVersionEx( (LPOSVERSIONINFO)&ovi );

// Windows95 OSR2以前
if( ( ovi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
		&& ( int( ovi.dwBuildNumber & 0xffff ) <= 1000 ) ){

	DWORD SCluster,BSector,FCluster,TCluster;

	if ( GetDiskFreeSpaceW(String(DriveName).c_str(), &SCluster, &BSector, &FCluster, &TCluster) > 0){
		FreeSpace = SCluster*BSector*FCluster;
	}
	else{
		//ネットワークサーバ上は取得できずエラーとなる
		FreeSpace = -1;
	}

}
// OSR2以降~
else{

	ULARGE_INTEGER pqwFreeCaller;
	ULARGE_INTEGER pqwTot;
	ULARGE_INTEGER pqwFree;

	if(::GetDiskFreeSpaceExW(String(DirPath).c_str(), &pqwFreeCaller, &pqwTot, &pqwFree)){
		//64bit Integerで返す
		FreeSpace = pqwFreeCaller.QuadPart;
	}
	else{
		FreeSpace = -1;
	}

}

return(FreeSpace);

}//end GetDiskFreeSpaceNum;
예제 #6
0
//---------------------------------------------------------------------------
// Returns the type of filesystem that a file resides on.
//
AnsiString GetFileSystemType(AnsiString FileName)
{
  AnsiString retval;
  char *VolumeName, *FileSystemName;
  DWORD VolumeSerialNumber, MaxComponentLength, FileSystemFlags;
  bool success;

  VolumeName = new char[MAX_PATH];
  FileSystemName = new char[MAX_PATH];
  success = GetVolumeInformation((ExtractFileDrive(FileName) + "\\").c_str(), VolumeName, MAX_PATH, &VolumeSerialNumber, &MaxComponentLength, &FileSystemFlags, FileSystemName, 64);
  if (success)
    retval = String(FileSystemName);
  delete VolumeName;
  delete FileSystemName;

  return String(FileSystemName);
}  // AnsiString GetFileSystemType(AnsiString FileName)
예제 #7
0
파일: eccMisc.cpp 프로젝트: ChakaZulu/ecc
bool GetDriveFreeSpace(String dir, String &freeBytesStr, __int64 &freeBytes)
{
	__int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
	bool fResult;
    dir = IncludeTrailingPathDelimiter(ExtractFileDrive(dir));

	fResult = GetDiskFreeSpaceEx(
			dir.c_str(),
			(PULARGE_INTEGER)&i64FreeBytesToCaller,
			(PULARGE_INTEGER)&i64TotalBytes,
			(PULARGE_INTEGER)&i64FreeBytes
		);

	freeBytes = i64FreeBytes;	/* TODO : Use i64FreeBytesToCaller? */
	freeBytesStr.printf("%I64d", freeBytes);

	// fResult is zero on failure.
	return !fResult;
}
예제 #8
0
//---------------------------------------------------------------------------
void __fastcall TCopyDialog::FormCloseQuery(TObject * /*Sender*/,
      bool &CanClose)
{
  if (ModalResult == DefaultResult(this))
  {
    if (!RemotePaths() && ((FOptions & coTemp) == 0))
    {
      UnicodeString Dir = Directory;
      UnicodeString Drive = ExtractFileDrive(Dir);
      if (!DirectoryExists(Dir))
      {
        if (MessageDialog(MainInstructions(FMTLOAD(CREATE_LOCAL_DIRECTORY, (Dir))),
              qtConfirmation, qaOK | qaCancel, HELP_NONE) != qaCancel)
        {
          if (!ForceDirectories(Dir))
          {
            SimpleErrorDialog(FMTLOAD(CREATE_LOCAL_DIR_ERROR, (Dir)));
            CanClose = false;
          }
        }
        else
        {
          CanClose = False;
        }
      }

      if (!CanClose)
      {
        DirectoryEdit->SelectAll();
        DirectoryEdit->SetFocus();
      }
    };

    if (CanClose)
    {
      ExitActiveControl(this);
    }
  }
}
예제 #9
0
bool TActionSevenZip::execute()
{
	if (!_inited) return false;
	if (_error || _aborted) return false;

	f_Action->logB(_("Note:"), 1);
	f_Action->log(_("7-Zip requires the source files to be on one drive."));
	f_Action->log(" " + _("The 7-Zip executable will be called for every drive."), -1);

	String drive, prevDrive, file;

	// Call 7z.exe for every drive:

	std::ifstream ifs(f_Action->abtFileList->incFileName.c_str());
	if (!ifs)
	{
		f_Action->logError(ASPF(_("Could not open file: %s"),
                ecc::QuoteStr(f_Action->abtFileList->incFileName)) );
		_error = true;
		return false;
	}

	drive = prevDrive = "";

	_deleteFileListFile();
	int filesLeft = 0;
	char line[2048];

	while (ifs.getline(line, 2048))
	{
		// Test for reading more than 2048 chars or another error:
		if (ifs.fail())
		{
			f_Action->logError(__FUNC__ ": [Error while reading stream]");
			_error = true;
			break;
		}
		file = String(line);

        /* TODO 3 : drive should become (optionable) StorePath (like Zip) */
		drive = IncludeTrailingPathDelimiter(ExtractFileDrive(file));

        /* 093b1 (b.324): use OEM or UTF-8 to encode filenames in 7z listfile: */
        if (PGlobals->OEMlistfile7Zip)
            CharToOem(file.c_str(), file.c_str());
        else
            file = AnsiToUtf8(file);    // UTF-8 is default encoding in releases NEWER than 7-Zip 4.32.

		file = file.Delete(1, drive.Length());
		if (drive != prevDrive)
		{
			if (filesLeft)
				_call7ZipExe(prevDrive);    // Tests and sets _error and _aborted.
			filesLeft = 0;
			if (_error || _aborted)
				break;
			prevDrive = drive;
		}
		abtAppendStrToFile(ecc::QuoteStr(file), _fileListFile, false);
		++filesLeft;
	}
	// Do the remains:
	if (filesLeft)
		_call7ZipExe(prevDrive);    // Tests and sets _error and _aborted.
	_inited = false;    // Reset.

    // Display 7-Zip archive details:
    if ((!_aborted) && (!_error))
    {
        TFileProperties fp(_destFileName);
        if (!fp.failed())
        {
		    f_Action->logB(_("7-Zip Archive Details:"), 1);
            f_Action->log(ASPF(_("Compressed Size: %s (%s Bytes)"),
                    ecc::FloatToHumanFileSize(fp.getSize()), IntToStr(fp.getSize())) );
        }
    }

	if (_error || _aborted)
		_deleteFileListFile();

	return !(_error || _aborted);
}
예제 #10
0
bool TActionSevenZip::init()
{
	_error          = false;
	_aborted        = false;
	_inited         = false;
    __compressingFileCount = 0;
	_destFileName   = "";
    _fileListFile = _getDestDir() + f_Action->getDestName() + "~.txt";

    // == Test of 7-Zip executable exists:
	if (!FileExists(PGlobals->ExePath7Zip))
	{
		f_Action->logError(_("Could not find 7-Zip executable.")
            + " " + ASPF(_("File does not exist: %s"), ecc::AposStr(PGlobals->ExePath7Zip)) );
		_error = true;
        return false;
	}

	// == Display Destination Drive Information:
    String destDir = f_Action->getDestDir();
    if (!f_Action->testCreateDestDir(destDir))
    {
        // If dest-dir does not exist and/or will not be auto-created, set _error to true:
        _error = true;
        return false;
    }
    // Added 092rc1:
 	f_Action->log( ASPF(_("Destination Drive: %s"), ecc::QuoteStr(ExtractFileDrive(destDir))) );

	bool destDriveIsRemovable = ecc::DriveIsRemovable(destDir);
    f_Action->log( ASPF("- " + _("Removable: %s"),
            destDriveIsRemovable ? String(_("No")) : String(_("Yes")) ) );

    unsigned int dtype = ::GetDriveType( ExtractFileDrive(destDir).c_str() );
    if (dtype == DRIVE_CDROM)
        f_Action->log( "- " + _("Type: CD/DVD") );

	String diskFreeSpaceStr;
	__int64 diskFreeSpace;
	ecc::GetDriveFreeSpace(destDir, diskFreeSpaceStr, diskFreeSpace);
    f_Action->log( ASPF("- " + _("Free Space: %s (%s Bytes)"),
            ecc::FloatToHumanFileSize(diskFreeSpace), diskFreeSpaceStr) );

    // == Display Temporary Directory and it's free space:
    // Added 092rc1:
	ecc::GetDriveFreeSpace(PGlobals->getTempDir(), diskFreeSpaceStr, diskFreeSpace);
 	f_Action->log( ASPF(_("Temporary Directory: %s"),
            ecc::QuoteStr(PGlobals->getTempDir()) ) );
 	f_Action->log( ASPF("- " + _("Free Space: %s (%s Bytes)"),
            ecc::FloatToHumanFileSize(diskFreeSpace), diskFreeSpaceStr) );


 	if (!_error)
	{
        _commandLine    = _build7zCommandLine(false);
        _commandLineGui = _build7zCommandLine(true);
        //  Note: _destFileName is set in function _build7zCommandLine() and
        //  its value will be used throughout the 7-Zip action.
		if (_destFileName.IsEmpty())
		{
			f_Action->logError(_("Destination archive has no name."));
			_error = true;
		}
	}

	if (!_error)
	{
        // == Display password usage:
        f_Action->log(ASPF(_("Using Password: %s"),
                PProfile->config.Actions.SevenZip->tPassword->value.IsEmpty()
                    ? String(_("No")) : String(_("Yes")) ) );
	}

 	if (!_error)
	{
        f_Action->log(_("Calling 7-Zip with command line:"));
        f_Action->log( _commandLineGui );
    }

	_inited = true;
	return !(_error || _aborted);
}
void __fastcall TForm1::TabControl1Change(TObject *Sender)
{
	
	switch( TabControl1 -> TabIndex )
	{
		
		case 0:
		{
			
			TabControl1 -> Tabs -> Strings[ TabControl1 -> TabIndex ] = ExtractFileName( FileListBox1 -> FileName );
			
			Image4 -> Picture -> LoadFromFile( FileListBox1 -> FileName );
			TabControl1->Width=Image4->Picture->Width;
			TabControl1->Height=Image4->Picture->Height;
			
			break;
			
		}
		
		case 1:
		{
			
			char ToneOldFile[ 150 ];
			
			strcpy( ToneOldFile, FileListBox1 -> FileName.c_str() );
			
			sprintf( strrchr( ToneOldFile, '.' ), "_ToneOld.emf" );
			
			if( !FileExists( ToneOldFile ) )
			{
				
				char filename[ 150 ];
				
				int LDomain[ 100 ];
				
				int L_index;
				
				memset( LDomain, 0, sizeof( LDomain ) );
				
				strcpy( filename,  FileListBox1 -> FileName.c_str() );
				
				ReadBMPData( filename );
				
				for( int i = 0 ; i < imageHeight; i ++ )
					for( int j = 0; j < imageWidth * 3; j += 3 )
					{
						
						RGB2Lab( ImageDataBlock[ i ][ j + 0 ], ImageDataBlock[ i ][ j + 1 ], ImageDataBlock[ i ][ j + 2 ],
							&Lab_buf[ i ][ j + 0 ], &Lab_buf[ i ][ j + 1 ], &Lab_buf[ i ][ j + 2 ] );
						
						L_index = ( int )( Lab_buf[ i ][ j + 0 ] + 0.5 );
						
						LDomain[ L_index ] ++;
						
					}
				
				FILE *ToneOldData = fopen( "ToneOldData.dat", "w" );
				
				// write L domain value in data file
				for( int i = 0; i <= 99; i ++ )
					//if( LDomain[ i ] >= 300 )
						fprintf( ToneOldData, "%d %d\n", i, LDomain[ i ] );
					
				fclose( ToneOldData );
				
				char PresentWorkingDirectory[ 150 ];
				
				sprintf( PresentWorkingDirectory, "%s", ExtractFileDir( FileListBox1 -> FileName ) );
				
				FILE *fp_domain_script = fopen( "histogram.dem", "w" );
				fprintf( fp_domain_script, "cd '%s'\n", PresentWorkingDirectory );
				
				fprintf( fp_domain_script, "set terminal emf\n" );
				fprintf( fp_domain_script, "set xrange [ 0 : 100 ]\n" );
				fprintf( fp_domain_script, "set xlabel 'L'\n" );
				fprintf( fp_domain_script, "set ylabel 'intensity'\n" );
				
				fprintf( fp_domain_script, "set grid\n" );
				
				fprintf( fp_domain_script, "set output '%s'\n", ToneOldFile );
				
				fprintf( fp_domain_script, "plot 'ToneOldData.dat' title '%s' with impulses 1 4\n", "ToneOld.dat" );
				
				fclose( fp_domain_script );
				
				char command[ 200 ];
				sprintf( command, "%s\\gnuplot\\bin\\wgnuplot.exe histogram.dem", ExtractFileDrive( FileListBox1 -> FileName ) );
				
				system( command );
				
				remove( "histogram.dem" );
				remove( "ToneOldData.dat" );
				
			}
			
			Image4 -> Picture -> LoadFromFile( ToneOldFile );
			TabControl1->Width=Image4->Picture->Width;
			TabControl1->Height=Image4->Picture->Height;
			
			break;
		}
		
		case 2:
		{
			
			char ToneOutPutFile[ 150 ];
			
			strcpy( ToneOutPutFile, FileListBox1 -> FileName.c_str() );
			
			sprintf( strrchr( ToneOutPutFile, '.' ), "_tone.bmp" );
			
			if( !FileExists( ToneOutPutFile ) )
			{
				
				char filename[ 150 ];
				
				strcpy( filename,  FileListBox1 -> FileName.c_str() );
				
				ReadBMPData( filename );
				
				MacroBlock block[ imageHeight / 16 ][ imageWidth / 16 ];
				
				memset( block, 0, sizeof( block ) );
				
				double LSum = 0;
				double aSum = 0;
				double bSum = 0;
				
				for( int i = 0; i < imageHeight / 16; i ++ )
					for( int j = 0; j < imageWidth / 16; LSum = 0, aSum = 0, bSum = 0, j ++ )
					{
						for( int k = i * 16; k <= ( i * 16 + 15 ); k ++ )
							for( int m = j * 16 * 3; m <= ( j * 16 + 15 ) * 3; m += 3 )
							{
								
								RGB2Lab( ImageDataBlock[ k ][ m + 0 ], ImageDataBlock[ k ][ m + 1 ], ImageDataBlock[ k ][ m + 2 ],
									&Lab_buf[ k ][ m + 0 ], &Lab_buf[ k ][ m + 1 ], &Lab_buf[ k ][ m + 2 ] );
								
								LSum += Lab_buf[ k ][ m + 0 ];
								aSum += Lab_buf[ k ][ m + 1 ];
								bSum += Lab_buf[ k ][ m + 2 ];
								
							}
						
						block[ i ][ j ].DCL = LSum / 256.0;
						block[ i ][ j ].DCa = aSum / 256.0;
						block[ i ][ j ].DCb = bSum / 256.0;
					
					}
				
				int num = 0;
				
				double L_sort[ Len_pri ];
				
				//  make Macroblock in one dimension
				for( int i = 1; i < imageHeight / 16 - 1; i ++ )
					for( int j = 1; j < imageWidth / 16 - 1; j ++, num ++ )
						L_sort[ num ] = block[ i ][ j ].DCL;
				
				// sort L from small to big
				exchange_sort( L_sort, Len_pri );
				
				double WeightTotalFinal = 0;
				
				for( int i = 1; i < imageHeight / 16 - 1; i ++ )
					for( int j = 1; j < imageWidth / 16 - 1; j ++ )
					{
						
						block[ i ][ j ].WeightL
						
							= pow( block[ i ][ j ].DCL - block[ i - 1 ][ j - 1 ].DCL, 2 )
							+ pow( block[ i ][ j ].DCL - block[ i - 1 ][ j      ].DCL, 2 )
							+ pow( block[ i ][ j ].DCL - block[ i - 1 ][ j + 1 ].DCL, 2 )
							
							+ pow( block[ i ][ j ].DCL - block[ i     ][ j - 1 ].DCL, 2 )
							+ pow( block[ i ][ j ].DCL - block[ i     ][ j + 1 ].DCL, 2 )
							
							+ pow( block[ i ][ j ].DCL - block[ i + 1 ][ j - 1 ].DCL, 2 )
							+ pow( block[ i ][ j ].DCL - block[ i + 1 ][ j     ].DCL, 2 )
							+ pow( block[ i ][ j ].DCL - block[ i + 1 ][ j + 1 ].DCL, 2 );
					
						block[ i ][ j ].Weighta                                            
						
							= pow( block[ i ][ j ].DCa - block[ i - 1 ][ j - 1 ].DCa, 2 )
							+ pow( block[ i ][ j ].DCa - block[ i - 1 ][ j     ].DCa, 2 )
							+ pow( block[ i ][ j ].DCa - block[ i - 1 ][ j + 1 ].DCa, 2 )
							
							+ pow( block[ i ][ j ].DCa - block[ i     ][ j - 1 ].DCa, 2 )
							+ pow( block[ i ][ j ].DCa - block[ i     ][ j + 1 ].DCa, 2 )
							
							+ pow( block[ i ][ j ].DCa - block[ i + 1 ][ j - 1 ].DCa, 2 )
							+ pow( block[ i ][ j ].DCa - block[ i + 1 ][ j     ].DCa, 2 )
							+ pow( block[ i ][ j ].DCa - block[ i + 1 ][ j + 1 ].DCa, 2 );
					
						block[ i ][ j ].Weightb                                            
						
							= pow( block[ i ][ j ].DCb - block[ i - 1 ][ j - 1 ].DCb, 2 )
							+ pow( block[ i ][ j ].DCb - block[ i - 1 ][ j     ].DCb, 2 )
							+ pow( block[ i ][ j ].DCb - block[ i - 1 ][ j + 1 ].DCb, 2 )
							
							+ pow( block[ i ][ j ].DCb - block[ i     ][ j - 1 ].DCb, 2 )
							+ pow( block[ i ][ j ].DCb - block[ i     ][ j + 1 ].DCb, 2 )
							
							+ pow( block[ i ][ j ].DCb - block[ i + 1 ][ j - 1 ].DCb, 2 )
							+ pow( block[ i ][ j ].DCb - block[ i + 1 ][ j     ].DCb, 2 )
							+ pow( block[ i ][ j ].DCb - block[ i + 1 ][ j + 1 ].DCb, 2 );
						
						block[ i ][ j ].WeightFinal = pow( block[ i ][ j ].WeightL * block[ i ][ j ].Weighta * block[ i ][ j ].Weightb, 0.5 );
						
						WeightTotalFinal += block[ i ][ j ].WeightFinal;
					
					}
				
				double tone_L1;		// every L of control point ( 0 ~ 100 )
				double tone_L2;
				double tone_L3;
				double tone_L4;
				
				double tone_c1x = 10;	// MacroBlock DCL weight sum accumulation ratio
				double tone_c2x = 30;
				double tone_c3x = 70;
				double tone_c4x = 90;
				
				double tone_wL1 = 0;	// accumulate every DCL weight sum of control pointªºDCL weight sum, aim at final value
				double tone_wL2 = 0;
				double tone_wL3 = 0;
				double tone_wL4 = 0;
				
				// find out four ratios of WeightFinal, calculate corresponding DCL
				for( int p = 0; p < Len_pri; p ++ )
					for( int i = 1; i < imageHeight / 16 - 1; i ++ )
						for( int j = 1; j < imageWidth / 16 - 1; j ++ )
							if( block[ i ][ j ].DCL == L_sort[ p ] )
							{
								
								if( tone_wL1 < tone_c1x / 100 )
								{
									tone_wL1 +=  block[ i ][ j ].WeightFinal / WeightTotalFinal;
									if( tone_wL1 >= tone_c1x / 100 )
										tone_L1 = block[ i ][ j ].DCL;
									tone_wL2 += block[ i ][ j ].WeightFinal / WeightTotalFinal;
									tone_wL3 += block[ i ][ j ].WeightFinal / WeightTotalFinal;							
									tone_wL4 += block[ i ][ j ].WeightFinal / WeightTotalFinal;							
								}
								else if( tone_wL1 >= tone_c1x / 100 && tone_wL2 < tone_c2x / 100 )
								{
									tone_wL2 += block[ i ][ j ].WeightFinal / WeightTotalFinal;
									if( tone_wL2 >= tone_c2x / 100 )
										tone_L2 = block[ i ][ j ].DCL;
									tone_wL3 += block[ i ][ j ].WeightFinal / WeightTotalFinal;
									tone_wL4 += block[ i ][ j ].WeightFinal / WeightTotalFinal;							
								}
								else if( tone_wL2 >= tone_c2x / 100 && tone_wL3 < tone_c3x / 100 )
								{
									tone_wL3 += block[ i ][ j ].WeightFinal / WeightTotalFinal;
									if( tone_wL3 >= tone_c3x / 100 )
										tone_L3 = block[ i ][ j ].DCL;
									tone_wL4 += block[ i ][ j ].WeightFinal / WeightTotalFinal;							
								}
								else if( tone_wL3 >= tone_c3x / 100 && tone_wL4 < tone_c4x / 100 )
								{
									tone_wL4 += block[ i ][ j ].WeightFinal / WeightTotalFinal;							
									if( tone_wL4 >= tone_c4x / 100 )
										tone_L4 = block[ i ][ j ].DCL;
								}
								
							}
				
				double tone_c1y = 20;	// every L of control point should be adjust to value( 0 ~100 )
				double tone_c2y = 40;
				double tone_c3y = 60;
				double tone_c4y = 80;
				
				// Tone Reproduction on L domain
				for( int p = 0; p < imageHeight; p ++ )
					for( int q = 0; q < ( 3 * imageWidth ); q +=3 )
					{
						
						if( Lab_buf[ p ][ q ] >= 0 && Lab_buf[ p ][ q ] < tone_L1 )
							Lab_buf[ p ][ q ] = Lab_buf[ p ][ q ] * tone_c1y / tone_L1;
						else if( Lab_buf[ p ][ q ] >= tone_L1 && Lab_buf[ p ][ q ] < tone_L2 )
							Lab_buf[ p ][ q ] = tone_c1y + ( Lab_buf[ p ][ q ] - tone_L1 ) * ( tone_c2y - tone_c1y ) / ( tone_L2 - tone_L1 );
						else if( Lab_buf[ p ][ q ] >= tone_L2 && Lab_buf[ p ][ q ] < tone_L3)
							Lab_buf[ p ][ q ] =  tone_c2y + ( Lab_buf[ p ][ q ] - tone_L2 ) * ( tone_c3y - tone_c2y ) / ( tone_L3 - tone_L2 );
						else if( Lab_buf[ p ][ q ] >= tone_L3 && Lab_buf[ p ][ q ] < tone_L4 )
							Lab_buf[ p ][ q ] =  tone_c3y + ( Lab_buf[ p ][ q ] - tone_L3 ) * ( tone_c4y - tone_c3y ) / ( tone_L4 - tone_L3 );
						else
							Lab_buf[ p ][ q ] =  tone_c4y + ( Lab_buf[ p ][ q ] - tone_L4 ) * ( 100 - tone_c4y ) / ( 100 - tone_L4 );
						
						// Lab to RGB
						Lab2RGB( Lab_buf[ p ][ q + 0 ], Lab_buf[ p ][ q + 1 ], Lab_buf[ p ][ q + 2 ],
							&ucImageOut[ p ][ q + 0 ], &ucImageOut[ p ][ q + 1 ], &ucImageOut[ p ][ q + 2 ] );
						
					}
				
				FILE *outfp = fopen( ToneOutPutFile, "wb" );
				
				fwrite( &header1, 14, 1, outfp );
				fwrite( &header2, 40, 1, outfp );
				
				for( int i = 0; i < imageHeight; i ++ )
					fwrite( ucImageOut[ i ], 3 * imageWidth, 1, outfp );
				
				fclose( outfp );
				
			}
			
			Image4 -> Picture -> LoadFromFile( ToneOutPutFile );
			TabControl1->Width=Image4->Picture->Width;
			TabControl1->Height=Image4->Picture->Height;
			
			break;
			
		}
	}
	
}
예제 #12
0
//---------------------------------------------------------------------------
UnicodeString __fastcall TConfiguration::GetIniFileStorageName(bool ReadingOnly)
{
  if (FIniFileStorageName.IsEmpty())
  {
    UnicodeString ProgramPath = ParamStr(0);

    UnicodeString ProgramIniPath = ChangeFileExt(ProgramPath, L".ini");

    UnicodeString IniPath;
    if (FileExists(ProgramIniPath))
    {
      IniPath = ProgramIniPath;
    }
    else
    {
      UnicodeString AppDataIniPath =
        IncludeTrailingBackslash(GetShellFolderPath(CSIDL_APPDATA)) +
        ExtractFileName(ProgramIniPath);
      if (FileExists(AppDataIniPath))
      {
        IniPath = AppDataIniPath;
      }
      else
      {
        // avoid expensive test if we are interested in existing files only
        if (!ReadingOnly && (FProgramIniPathWrittable < 0))
        {
          UnicodeString ProgramDir = ExtractFilePath(ProgramPath);
          FProgramIniPathWrittable = IsDirectoryWriteable(ProgramDir) ? 1 : 0;
        }

        // does not really matter what we return when < 0
        IniPath = (FProgramIniPathWrittable == 0) ? AppDataIniPath : ProgramIniPath;
      }
    }

    // BACKWARD COMPATIBILITY with 4.x
    if (FVirtualIniFileStorageName.IsEmpty() &&
        TPath::IsDriveRooted(IniPath))
    {
      UnicodeString LocalAppDataPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA);
      // virtual store for non-system drives have a different virtual store,
      // do not bother about them
      if (TPath::IsDriveRooted(LocalAppDataPath) &&
          SameText(ExtractFileDrive(IniPath), ExtractFileDrive(LocalAppDataPath)))
      {
        FVirtualIniFileStorageName =
          IncludeTrailingBackslash(LocalAppDataPath) +
          L"VirtualStore\\" +
          IniPath.SubString(4, IniPath.Length() - 3);
      }
    }

    if (!FVirtualIniFileStorageName.IsEmpty() &&
        FileExists(FVirtualIniFileStorageName))
    {
      return FVirtualIniFileStorageName;
    }
    else
    {
      return IniPath;
    }
  }
  else
  {
    return FIniFileStorageName;
  }
}
예제 #13
0
void TProfileToGui::_listToTreeView(std::vector<String> &list, const TNodeStateIndex state,
		TTreeNode* rootnode, String rootdir)
{
	rootdir = IncludeTrailingPathDelimiter(rootdir);
	TTreeNode *node, *nod;

	_removeNonExistentDirsFromList(list);

	int pos;
	bool node_exists;
	String dir, subdir;
	for (unsigned int i = 0; i < list.size(); i++)
	{
		dir = list[i];

		// Ab.0075 Change charactercase for dir into 'real' case on disk:
        // Do not call ActualPathName() if dir is a drive (like 'C:\'):
        if (dir != IncludeTrailingPathDelimiter(ExtractFileDrive(dir)))
    		dir = IncludeTrailingPathDelimiter(ecc::ActualPathName(dir));

		// Skip directories that are not below current Root Source Dir:
		if (dir.LowerCase().Pos(rootdir.LowerCase()) != 1)
			continue;

		// Strip rootdir from dir:
		dir = dir.Delete(1, rootdir.Length());

		// Add unselected subdir:
		node = rootnode;
		while (dir.Length())
		{
			pos			= dir.Pos("\\");
			subdir		= dir.SubString(1, pos-1);
			node_exists	= false;
			nod			= node->getFirstChild();
			while (nod)
			{
				if (nod->Text.AnsiCompareIC(subdir) == 0)
				{
					node_exists = true;
					break;
				}
				nod = nod->getNextSibling();
			}

/* 092RC2: Incorrect code, replaced by code below this comment block (SE 27-mar-2006)
            if (!node_exists)
			{
				if (DirectoryExists(list[i]))
				{
					node = f_Main->fr_Source->tv_Dirs->Items->AddChild(node, subdir);
					node->StateIndex = state;
				}
			}
			dir = dir.Delete(1, pos);
			if (nod) node = nod;
		}
		node->StateIndex = state; */

            if (!node_exists)
            {
                if (DirectoryExists(list[i]))
                {
                    node = f_Main->fr_Source->tv_Dirs->Items->AddChild(node, subdir);
                    node->StateIndex = state;
                }
                else
                {
                    node = NULL;
                }
            }
            else
            {
                node = nod;
            }
            if (!node) break;
            dir = dir.Delete(1, pos);
        }
        if (node) node->StateIndex = state;
	}
}
void __fastcall TForm1::TabControl1Change(TObject *Sender)
{
	
	switch( TabControl1 -> TabIndex )
	{
		case 0:
		{
			
			TabControl1 -> Tabs -> Strings[ TabControl1 -> TabIndex ] = ExtractFileName( FileListBox1 -> FileName );
			Image4 -> Picture -> LoadFromFile( FileListBox1 -> FileName );
			TabControl1->Width=Image4->Picture->Width;
			TabControl1->Height=Image4->Picture->Height;
			
			break;
		}
		
		case 1:
		case 2:
		{
			
			char histogram_file[ 100 ];
			char ec_file[ 100 ];
			char PresentWorkingDirectory[ 100 ];
			
			strcpy( histogram_file, FileListBox1 -> FileName.c_str() );
			strcpy( ec_file, FileListBox1 -> FileName.c_str() );
			
			sprintf( PresentWorkingDirectory, "%s", ExtractFileDir( FileListBox1 -> FileName ) );
			
			if( TabControl1 -> TabIndex == 1 )
			{
				
				sprintf( strrchr( histogram_file, '.' ), "_histogram.emf" );

				
				if( FileExists( histogram_file ) )
				{
					
					Image4 -> Picture -> LoadFromFile( histogram_file );
					TabControl1->Width=Image4->Picture->Width;
					TabControl1->Height=Image4->Picture->Height;
					
					break;
				}
			}
			else	// TabControl1 -> TabIndex == 2
			{
				
				sprintf( strrchr( ec_file, '.' ), "_ec.emf" );
				
				if( FileExists( ec_file ) )
				{
					Image4 -> Picture -> LoadFromFile( ec_file );
					TabControl1->Width=Image4->Picture->Width;
					TabControl1->Height=Image4->Picture->Height;
					
					break;
				}
			}
			
			FILE *fp_domain_data;
			FILE *fp_domain_script;
			
			int abDomain[ 185 ][ 203 ];
			
			unsigned int a_index;
			unsigned int b_index;
			
			double aSum = 0;
			double bSum = 0;
			
			double aMean;
			double bMean;
			double offset;
			
			double aVariance;
			double bVariance;
			double radius;
			
			double intensity;
			
			memset( abDomain, 0, sizeof( abDomain ) );
			
			ReadBMPData( FileListBox1 -> FileName.c_str() );
			
			for( int i = 0; i < imageHeight; i++ )
				for( int j = 0; j < imageWidth * 3; j += 3 )
				{
					
					RGB2Lab( ImageDataBlock[ i ][ j + 0 ], ImageDataBlock[ i ][ j + 1 ], ImageDataBlock[ i ][ j + 2 ],
							&Lab_buf[ i ][ j + 0 ], &Lab_buf[ i ][ j + 1 ], &Lab_buf[ i ][ j + 2 ] );
					
					aSum += Lab_buf[ i ][ j + 1 ];
					bSum += Lab_buf[ i ][ j + 2 ];
					
					a_index = ( int )( Lab_buf[ i ][ j + 1 ] + 0.5 ) + 86;
					b_index = ( int )( Lab_buf[ i ][ j + 2 ] + 0.5 ) + 108;
					
					abDomain[ a_index ][ b_index ]++;
					
				}
			
			fp_domain_data = fopen( "histogram.dat", "w" );
			
			// write ab domain value in data file
			for( int i = 0; i <= 184; i ++ )
				for( int j = 0; j <= 202; j ++ )
					if( abDomain[ i ][ j ] != 0 )
						fprintf( fp_domain_data, "%d %d %d\n", i - 86, j - 108, abDomain[ i ][ j ] );
			
			fclose( fp_domain_data );
			
			fp_domain_script = fopen( "histogram.dem", "w" );
			fprintf( fp_domain_script, "cd '%s'\n", PresentWorkingDirectory );
			
			fprintf( fp_domain_script, "set terminal emf color\n" );
			fprintf( fp_domain_script, "set xrange [ -86 : 98 ]\n" );
			fprintf( fp_domain_script, "set yrange [ -108 : 94 ]\n" );
			fprintf( fp_domain_script, "set xlabel 'a'\n" );
			fprintf( fp_domain_script, "set ylabel 'b'\n" );
			fprintf( fp_domain_script, "set grid\n" );
			
			if( TabControl1 -> TabIndex == 1 )
			{
				
				fprintf( fp_domain_script, "set zlabel 'intensity'\n\n" );
				
				fprintf( fp_domain_script, "set title '2D histogram in the ab plane'\n" );
				fprintf( fp_domain_script, "set ticslevel 0\n" );
				
				fprintf( fp_domain_script, "set output '%s'\n", histogram_file );
				
				fprintf( fp_domain_script, "splot 'histogram.dat' title '%s' with lines\n\n", histogram_file );

			}
			else	// TabControl1 -> TabIndex == 2
			{
				aMean = aSum / ( imageHeight * imageWidth );
				bMean = bSum / ( imageHeight * imageWidth );				
				
				offset = pow( aMean * aMean + bMean * bMean, 0.5 );
				
				aSum = 0;
				bSum = 0;
				
				for( int i = 0; i <= 184; i ++ )
					for( int j = 0; j <= 202; j ++ )
						if( abDomain[ i ][ j ] != 0 )
						{
							aSum += pow( aMean - ( i -  86 ), 2 ) * abDomain[ i ][ j ];
							bSum += pow( bMean - ( j - 108 ), 2 ) * abDomain[ i ][ j ];
						}
				
				aVariance = aSum / ( imageHeight * imageWidth );
				bVariance = bSum / ( imageHeight * imageWidth );
				
				radius = pow( aVariance + bVariance, 0.5 );
				
				intensity = ( offset - radius ) / radius;
				
				fprintf( fp_domain_script, "set parametric\n" );
				fprintf( fp_domain_script, "set output '%s'\n", ec_file );
				
				fprintf( fp_domain_script, "set arrow to %f, %f\n", aMean, bMean );
				fprintf( fp_domain_script, "set title 'Equivalent circle'\n" );
				
				if( aMean >= 0 && bMean >= 0 )		// first quadrant
				{
					fprintf( fp_domain_script, "set label 'offset = %f' at -10, -10\n", offset );
					fprintf( fp_domain_script, "set label 'radius = %f' at -10, -20\n", radius );
					fprintf( fp_domain_script, "set label 'intensity = %f' at -10, -30\n", intensity );
				}
				else if( aMean <= 0 && bMean >= 0 )	// second quadrant
				{
					fprintf( fp_domain_script, "set label 'offset = %f' at 10, -10\n", offset );
					fprintf( fp_domain_script, "set label 'radius = %f' at 10, -20\n", radius );
					fprintf( fp_domain_script, "set label 'intensity = %f' at 10, -30\n", intensity );
				}
				else if( aMean <= 0 && bMean <= 0 )	// third quadrant
				{
					fprintf( fp_domain_script, "set label 'offset = %f' at 10, 30\n", offset );
					fprintf( fp_domain_script, "set label 'radius = %f' at 10, 20\n", radius );
					fprintf( fp_domain_script, "set label 'intensity = %f' at 10, 10\n", intensity );
				}
				else					// fourth quadrant
				{
					fprintf( fp_domain_script, "set label 'offset = %f' at -10, 30\n", offset );
					fprintf( fp_domain_script, "set label 'radius = %f' at -10, 20\n", radius );
					fprintf( fp_domain_script, "set label 'intensity = %f' at -10, 10\n", intensity );
				}
				
				fprintf( fp_domain_script, "plot [ 0 : 2 * pi ] %f * sin( t ) + %f, %f * cos( t ) + %f title '%s'\n", radius, aMean, radius, bMean, ec_file );

			}
			
			fclose( fp_domain_data );
			
			char command[ 200 ];
			sprintf( command, "%s\\gnuplot\\bin\\wgnuplot.exe %s\\histogram.dem", ExtractFileDrive( FileListBox1 -> FileName ), PresentWorkingDirectory );
			system( command );
			
			if( TabControl1 -> TabIndex == 1 )
				Image4 -> Picture -> LoadFromFile( histogram_file );
			else	// TabControl1 -> TabIndex == 2
				Image4 -> Picture -> LoadFromFile( ec_file );
			
			TabControl1->Width=Image4->Picture->Width;
			TabControl1->Height=Image4->Picture->Height;
			
			remove( "histogram.dat" );
			remove( "histogram.dem" );
			
			break;
		}
		
	}
}