#=============================================== # TkColorMap #=============================================== package TkColorMap; use TkPlotModule; @ISA = qw(TkPlotModule); #公開したいサブルーチン #@EXPORT = qw(DelSpace Reduce01 MakePath RegExpQuote); use strict; use Tk::JPEG; use Utils; use Sci::Color; use Tk; use Tk::Balloon; use MyTk::Dialog; use MyTk::MyFrame; use MyTk::MyLabel; use MyTk::MyEntry; use MyTk::MyListbox; use MyTk::MyBrowseEntry; use MyTk::MyText; use MyTk::MyButton; use MyTk::MyMenubutton; use MyTk::MyCanvas; use MyTk::MyAdjuster; use MyTk::GraphFrameArray; use GraphData; use Sci::GeneralFileFormat; #============================================================ # 変数等取得関数 #============================================================ sub FileType { return shift->{FileType}; } sub SetFileType { my ($this,$t)=@_; return $this->{FileType} = $t; } sub FileName { return shift->{FileName}; } sub SetFileName { my ($this,$f)=@_; return $this->{FileName} = $f; } sub SetDataArray { my ($this, $da)=@_; return $this->{DataArray} = $da; } sub DataArray { return shift->{DataArray}; } sub GetColor { return shift->{Color}; } sub ColorMapImage { return shift->{ColorMapImage}; } sub SetColorMapImage { my ($this,$m)=@_; return shift->{ColorMapImage} = $m; } #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module, $app) = @_; # my ($module, $app, $canvas) = @_; my $this = {}; bless $this; $this->SetApplication($app); # $this->SetCanvas($canvas); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } #============================================================ # 継承クラスで定義しなおす関数 #============================================================ sub CreateSelectFilePane { my ($this) = @_; # $this->SUPER::CreateSelectFilePane(); } sub CreateWidgets { my ($this) = @_; my $mw = $this->mw(); my $canvas = $this->Canvas(); $this->SUPER::CreateWidgets(); my $Frame = $mw->MyFrame( )->pack(-anchor => 'nw', -fill => 'x'); my $lsb = $this->{ChooseLightSourceListBox} = $Frame->MyBrowseEntry( -label => "Light Source:", -state => "readonly", # -setgrid => 1, # -height => 6, # -width => $App->{'LeftFrameWidth'}, # -scrollbars => 'e', -takefocus => 1, -browsecmd => [\&SelChangeLightSourceListBox, $this], )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $lsb->AddItem("Solar(All)"); $lsb->AddItem("Solar(Direct)"); $lsb->AddItem("HalogenLamp"); $lsb->AddItem("BlackBody"); $lsb->AddItem("Monochromatic"); $lsb->AddItem("DayLight(CIE1986c)"); $lsb->AddItem("StdLightA(CIE1986c)"); $lsb->AddItem("StdLightD65(CIE1986c)"); $lsb->AddItem("StdLightC(CIE1986c)"); $lsb->AddItem("SupplStdLightD50(CIE1986c)"); $lsb->AddItem("SupplStdLightD55(CIE1986c)"); $lsb->AddItem("SupplStdLightD75(CIE1986c)"); $lsb->AddItem("SupplStdLightB(CIE1986c)"); $lsb->SetText("Solar(Direct)"); $this->{Temperature1Label} = $Frame->MyLabel( -text => '', -takefocus => 0, )->pack(-side => 'left'); $this->{TemperatureEntry} = $Frame->MyEntry( -text => '---', -takefocus => 0, )->pack(-side => 'left'); $this->{Temperature2Label} = $Frame->MyLabel( -text => '', -takefocus => 0, )->pack(-side => 'left'); $this->{ReadLightSourceButton} = $Frame->MyButton( -text => 'Read Light Source', -takefocus => 1, -command => [ \&ReadLightSource, $this ], )->pack(-side => 'left'); $Frame = $mw->MyFrame( )->pack(-anchor => 'nw', -fill => 'x'); $this->{SpectrumFileLabel} = $Frame->MyLabel( -text => 'Spectrum:' )->pack(-side => 'left'); $this->{SpectrumFileEntry} = $Frame->MyEntry( # -width => $App->{'LeftFrameWidth'}, -takefocus => 1, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $this->{SpectrumFileEntry}->focus(); $this->{SpectrumFilePathButton} = $Frame->MyButton( -text => '&Choose', -takefocus => 1, -command => [ \&ChooseSpectrumFile, $this, $this->{SpectrumFileEntry} ], )->pack(-side => 'left'); $lsb = $this->{ChooseRTListBox} = $Frame->MyBrowseEntry( -label => "Observation:", -state => "readonly", -takefocus => 1, -width => 2, # -browsecmd => [\&SelChangeLightSourceListBox, $this], )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $lsb->AddItem("Reflection"); $lsb->AddItem("Transmission"); $lsb->SetText("Reflection"); #ツールバーのOpenボタンをスペクトル読み込みにバインドする $mw->{OpenButton}->configure( -command => [ \&ChooseSpectrumFile, $this, $this->{SpectrumFileEntry} ], ); $Frame = $mw->MyFrame( )->pack(-anchor => 'nw', -fill => 'x'); my $lsb2 = $this->{ChooseChromaticityDiagramListBox} = $Frame->MyBrowseEntry( -label => "ChromaticityDiagram:", -state => "readonly", -takefocus => 1, # -browsecmd => [\&SelChangeLightSourceListBox, $this], )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $lsb2->AddItem("XYZ(CIE1931)"); $lsb2->AddItem("X10Y10Z10(CIE1964)"); $lsb2->AddItem("ShowColorMapImage"); $lsb2->AddItem("NTSC"); $lsb2->AddItem("Adobe RGB"); $lsb2->AddItem("sRGB(D65)"); $lsb2->AddItem("sRGB(C)"); $lsb2->AddItem("HDTV"); $lsb2->AddItem("PrimaryColor (CIE RGB)"); $lsb2->SetText("XYZ(CIE1931)"); $this->{CalculateColorMapButton} = $Frame->MyButton( -text => '&Calculate ColorMap', -takefocus => 1, -command => [ \&CalculateColorMap, $this ], )->pack(-side => 'left'); $this->{CalculateColorButton} = $Frame->MyButton( -text => '&Calculate Color', -takefocus => 1, -command => [ \&CalculateColor, $this ], )->pack(-side => 'left'); $Frame = $mw->MyFrame( )->pack(-anchor => 'nw', -fill => 'x'); $this->{ReadColorMatchingFunctionButton} = $Frame->MyButton( -text => '&Read ColorMatchingFunction', -takefocus => 1, -command => [ \&ReadColorMatchingFunction, $this ], )->pack(-side => 'left'); $this->{DrawLightSourceButton} = $Frame->MyButton( -text => '&Draw Light Source', -takefocus => 1, -command => [ \&DrawLightSource, $this ], )->pack(-side => 'left'); $this->{DrawSpectrum} = $Frame->MyButton( -text => '&Draw Spectrum', -takefocus => 1, -command => [ \&DrawSpectrum, $this ], )->pack(-side => 'left'); $this->{Color} = new Color; } sub CreateGraphFrame { my ($this, $canvas, $TargetData) = @_; $canvas = $this->Canvas(); my $App = $this->App(); my $font = $App->{'GraphFrameFont'}; my @font = split(/,/, $font) if($font); my $w = $canvas->width(); my $h = $canvas->height(); my $FileType = $this->FileType(); return undef unless($FileType); my $pDataArray = $this->DataArray(); return unless($pDataArray); if($FileType =~ /(Solar|Lamp|BlackBody|Spectrum|Light|Monochro|ColorMatchingFunction|Function)/i) { my $GraphFrameArray = $this->{'GraphFrameArray'} = new GraphFrameArray($this->mw()); $GraphFrameArray->SetCanvasSize($w, $h); $GraphFrameArray->AddGraphFrame(); # $GraphFrameArray->AddGraphFrame(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $FramePosStr0 = $App->{"GraphFrame0Position"}; my $XScale0 = $GraphFrame0->GetXScale(0); my $YScale0 = $GraphFrame0->GetYScale(0); $GraphFrame0->SetPositionByStr($FramePosStr0); # my $GraphFrame1 = $GraphFrameArray->GetGraphFrame(1); # my $FramePosStr1 = $App->{"GraphFrame1Position"}; # my $XScale1 = $GraphFrame1->GetXScale(0); # my $YScale1 = $GraphFrame1->GetYScale(0); # $GraphFrame1->SetPositionByStr($FramePosStr1); $GraphFrame0->SetXCaption("lambda / nm"); $GraphFrame0->SetYCaption("Spectrum"); # $GraphFrame1->SetXCaption(""); # $GraphFrame1->SetYCaption('Spectrum'); $XScale0->SetScaleStringVisible(1); $XScale0->SetCaptionVisible(1); # $XScale1->SetScaleStringVisible(1); # $XScale1->SetCaptionVisible(0); $GraphFrame0->SetViewRange(0, 0, 1, 1); # $GraphFrame1->SetViewRange(0, 0, 1, 1); } } sub AssignGraphData { my ($this) = @_; my $GraphFrameArray = $this->GetGraphFrameArray(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $pDataArray = $this->DataArray(); my $FileType = $this->FileType(); my $TargetData = $pDataArray->{'TargetData'}; return unless($pDataArray); if($FileType =~ /(Solar|Lamp|BlackBody|Spectrum|Light|Monochro|ColorMatchingFunction|Function)/i) { my $Data0 = $pDataArray->GetGraphData(0); # my $GraphFrame1 = $GraphFrameArray->GetGraphFrame(1); # my $Data1 = $pDataArray->GetGraphData(1); # return unless($Data1); my $nData = $Data0->nData(); my $title = $Data0->Title(); for(my $i = 0 ; ; $i++) { my $pX0 = $Data0->GetDataArray("x$i"); last if(not defined $pX0); my $pY0 = $Data0->GetDataArray("y$i"); last if(not defined $pY0); my $nData0 = $GraphFrame0->AddGraphData($pX0, $pY0, 1, "auto", "", 6, "red", 0, "red", "XAutoSkip", $Data0->{"x${i}_Name"}, $Data0->{"y${i}_Name"}); } $GraphFrame0->SetYScalePlotType('x'); $GraphFrame0->CalMinMax(); $GraphFrame0->AdjustViewRange(0.05, 0.05, 0.05, 0.05); } } sub AdjustViewRange { my ($this) = @_; my $GraphFrameArray = $this->GetGraphFrameArray(); my $pGraphFrame = $GraphFrameArray->GetpGraphFrameArray(); my $FileType = $this->FileType(); if($FileType =~ /(Solar|Lamp|BlackBody|Spectrum|Light|Monochro|ColorMatchingFunction|Function)/i) { } } sub Draw { my ($this, $canvas, $TargetData) = @_; my $mw = $this->mw(); $canvas = $this->Canvas(); $mw->RefleshCanvas(); my $FileType = $this->FileType(); my $App = $this->App(); my $font = $App->{'GraphFrameFont'}; my @font = split(/,/, $font) if($font); #色度図の表示 if($this->FileType() eq '' or $this->FileType() =~ /ColorMap/i) { my $ColormapGIF = "D:\\Programs\\Perl\\Color\\data\\CIE-ColorMap.jpeg"; $mw->RefleshCanvas(); $this->mw()->WriteStatusBar("Drawing ColorMap..."); $mw->Balloon()->detach($canvas); my $image = $mw->Photo( -format => 'jpeg', -file => Color::ColorMapImagePath(), ); my $height = $image->height(); my $width = $image->width(); $App->print("image: $width x $height\n"); $canvas->createImage(0, 0, -image => $image, -anchor => 'nw'); $this->SetColorMapImage($image); my $ColorMap = $this->{ChooseChromaticityDiagramListBox}->GetText(); if($ColorMap =~ /(NTSC|HDTV|Primary|RGB|Adobe)/i) { my ($Rx,$Ry,$Gx,$Gy,$Bx,$By,$Wx,$Wy) = Color::GetDefinedxy($ColorMap); print "For $ColorMap: R=($Rx,$Ry) G=($Gx,$Gy) B=($Bx,$By) W=($Wx,$Wy)\n"; my ($rx, $ry) = Color::xyToImageCoordinate($Rx, $Ry); my $Rz = 1.0 - $Rx - $Ry; my ($gx, $gy) = Color::xyToImageCoordinate($Gx, $Gy); my $Gz = 1.0 - $Gx - $Gy; my ($bx, $by) = Color::xyToImageCoordinate($Bx, $By); my $Bz = 1.0 - $Bx - $By; my ($wx, $wy) = Color::xyToImageCoordinate($Wx, $Wy); $canvas->DrawLine($rx, $ry, $gx, $gy, 1, "black"); $canvas->DrawLine($gx, $gy, $bx, $by, 1, "black"); $canvas->DrawLine($bx, $by, $rx, $ry, 1, "black"); for(my $r = 0 ; $r < 256 ; $r += 2) { for(my $g = 0 ; $g < 256-$r ; $g += 2) { my $b = 255 - $r - $g; my $x = ($Rx*$r + $Gx*$g + $Bx*$b) / 255.0; my $y = ($Ry*$r + $Gy*$g + $By*$b) / 255.0; my $z = ($Rz*$r + $Gz*$g + $Bz*$b) / 255.0; my $T = $x + $y + $z; $x = $x / $T; $y = $y / $T; $z = $z / $T; my ($X, $Y) = Color::xyToImageCoordinate($x, $y); #print "x($x,$y) X($X,$Y)\n"; my $max = $r; $max = $b if($max < $b); $max = $g if($max < $g); my $k = 255 / $max; my $r2 = int($r * $k + 0.01); my $g2 = int($g * $k + 0.01); my $b2 = int($b * $k + 0.01); my $RGB = sprintf("#%02X%02X%02X", $r2, $g2, $b2); #print "$r,$g,$b: $RGB\n"; $canvas->DrawBox($X-1, $Y-1, $X+1, $Y+1, 0, $RGB, $RGB); } } my %TagHash; my $s = sprintf("$ColorMap R(%4.3f,%4.3f,%4.3f)", $Rx, $Ry, 1.0-$Rx-$Ry); $canvas->DrawCircle($rx, $ry, 2, 1, undef, undef, "markerR"); $TagHash{"markerR"} = $s; $s = sprintf("$ColorMap G(%4.3f,%4.3f,%4.3f)", $Gx, $Gy, 1.0-$Gx-$Gy); $canvas->DrawCircle($gx, $gy, 2, 1, undef, undef, "markerG"); $TagHash{"markerG"} = $s; $s = sprintf("$ColorMap B(%4.3f,%4.3f,%4.3f)", $Bx, $By, 1.0-$Bx-$By); $canvas->DrawCircle($bx, $by, 2, 1, undef, undef, "markerB"); $TagHash{"markerB"} = $s; $s = sprintf("$ColorMap W(%4.3f,%4.3f,%4.3f)", $Wx, $Wy, 1.0-$Wx-$Wy); if($Wx >= 0) { $canvas->DrawCircle($wx, $wy, 2, 1, undef, undef, "markerW"); $TagHash{"markerW"} = $s; } $this->mw()->Balloon()->attach($canvas, -balloonposition => 'mouse', -msg => \%TagHash); } if($this->{Colorx}) { my $vx = $this->{Colorx}; my $vy = $this->{Colory}; my ($x, $y) = Color::xyToImageCoordinate($vx, $vy); #print "(x,y)=($x,$y)\n"; my $ImageHeight = $this->ColorMapImage()->height(); my $ImageWidth = $this->ColorMapImage()->width(); my $rgb; if($x >= 0 and $x < $ImageWidth and $y >= 0 and $y < $ImageHeight) { $rgb = $this->ColorMapImage()->get($x, $y); } my $s = sprintf("xyz(%4.3f,%4.3f,%4.3f) RGB(%3d,%3d,%3d)", $vx, $vy, 1.0-$vx-$vy, $rgb->[0], $rgb->[1], $rgb->[2]); $canvas->DrawCircle($x, $y, 2, 1, undef, undef, "marker"); # my $circle = $canvas->LastDrawnObject(); #print "c: $circle\n"; my %TagHash; $TagHash{"marker"} = $s; $this->mw()->Balloon()->attach($canvas, -balloonposition => 'mouse', -msg => \%TagHash); } $mw->bind($canvas, '', [ \&ShowPopupMenu, $this, Tk::Ev('X'), Tk::Ev('Y') ]); $mw->bind($canvas, '', [ \&SelTags, $this, 'Others-LButtonDown', Tk::Ev('x'), Tk::Ev('y') ]); $mw->bind($canvas, '', [ \&SelTags, $this, 'Others-LBUttonUp', Tk::Ev('x'), Tk::Ev('y'), Tk::Ev('X'), Tk::Ev('Y') ]); $mw->bind($canvas, '', [ \&SelTags, $this, 'Others-Move', Tk::Ev('x'), Tk::Ev('y') ]); $mw->bind($canvas, '', [ \&SelTags, $this, 'Others-LButtonDouble', Tk::Ev('x'), Tk::Ev('y') ]); $mw->bind($canvas, '', sub { $this->SetCanvasSize(); } ); $this->mw()->WriteStatusBar("Finish ColorMap."); return; } #グラフの表示 else { my $GraphFrameArray = $this->GetGraphFrameArray(); if($font) { $canvas->SetFont(\@font); $GraphFrameArray->SetFont(\@font); } my $w = $canvas->width(); my $h = $canvas->height(); $GraphFrameArray->SetCanvasSize($w, $h); my $pGraphFrame = $GraphFrameArray->GetpGraphFrameArray(); my @GraphFrame = @$pGraphFrame; my $pDataArray = $this->DataArray(); my $pData = $pDataArray->GetGraphData(0); $mw->RefleshCanvas(); $mw->WriteStatusBar("Drawing Specrum..."); $mw->Balloon()->detach($canvas); $GraphFrameArray->Draw($canvas); $this->mw()->WriteStatusBar("Finish Drawing Specrum."); return; } } sub DeleteWidget { my ($this, $Frame) = @_; return undef unless($Frame); return 1; } sub AddWidget { my ($this, $Frame) = @_; return undef unless($Frame); # 左枠3列目作成: ファイルの内容を表示するセクションリストボックス # $this->mw()->CreateSectionListBox(); # 左枠4列目作成: ファイルの内容を表示するテキストボックス # $this->mw()->CreateFileContentTextBox(); return 1; } sub SetFileInfo { my ($this, $ListBox, $TextBox) = @_; return undef unless($ListBox); return undef unless($TextBox); $ListBox->ClearAll(); $TextBox->ClearText(); my $App = $this->App(); my @Font = split(/,/, $App->{"FileContentFont"}); $TextBox->configure(-font => \@Font) if(@Font > 0); my $DataArray = $App->TkData(); return undef unless($DataArray); # $TextBox->AddText("$nData\n"); return 1; } sub SelTags { my ($canvas, $this, $command, $x, $y, $X, $Y) = @_; #print "command: $command Pos: ($x, $y)\n"; if($command =~ /LButtonDown/i) { } elsif($command =~ /Move/i) { my $s = "($x,$y)"; if($this->FileType() =~ /ColorMap/i and $this->ColorMapImage()) { my $height = $this->ColorMapImage()->height(); my $width = $this->ColorMapImage()->width(); if($x >= 0 and $x < $width and $y >= 0 and $y < $height) { my $rgb = $this->ColorMapImage()->get($x, $y); my ($xx, $yy) = Color::ImageCoordinatetoXYZMapping($x, $y); my $zz = 1.0 - $xx - $yy; $s = sprintf "$s RGB(%d,%d,%d) xyz(%4.3f,%4.3f,%4.3f)", $rgb->[0], $rgb->[1], $rgb->[2], $xx, $yy, $zz; } } $this->mw()->WriteStatusBar($s); } elsif($command =~ /LButtonUp/i) { } } sub SelChangeLightSourceListBox { my ($this) = @_; my $lb = $this->{ChooseLightSourceListBox}; my $s = $lb->GetText(); #print "text: $s\n"; my $te = $this->{TemperatureEntry}; if($s =~ /Solar/i) { $this->{Temperature1Label}->SetText(""); $this->{Temperature2Label}->SetText(""); $te->SetText("---"); } elsif($s =~ /Black/i) { $this->{Temperature1Label}->SetText("T="); $this->{Temperature2Label}->SetText("K"); $te->SetText(6000); } elsif($s =~ /DayLight/i) { $this->{Temperature1Label}->SetText("T="); $this->{Temperature2Label}->SetText("K"); $te->SetText(6500); } elsif($s =~ /Monochromatic/i) { $this->{Temperature1Label}->SetText("wl="); $this->{Temperature2Label}->SetText("nm"); $te->SetText(600); } } sub ChooseSpectrumFile { my ($this, $widget) = @_; my $App = $this->App(); my $canvas = $this->Canvas(); my $mw = $this->mw(); my $dir = ''; unless($widget) { $dir = $this->App()->{'WorkDir'}; chdir($dir); } my $fmask = '*.csv'; my $defstr = ''; my $message = 'Choose file'; my $filepath = Dialog::OpenFileDialog($mw, 'open', $fmask, $defstr, $message, $dir); if($filepath) { my $DirPath = $this->SetWorkDir($filepath); if($widget) { $widget->SetText($filepath); } } $this->DrawSpectrum(); return $filepath; } sub ReadLightSource { my ($this) = @_; my $App = $this->App(); my $canvas = $this->Canvas(); my $lb = $this->{ChooseLightSourceListBox}; my $LightSource = $lb->GetText(); my $te = $this->{TemperatureEntry}; my $T = $te->GetText(); $this->SetFileType($LightSource); $App->print("Read/Calculate [$LightSource] for T=$T K.\n"); $this->mw()->WriteStatusBar("Read/Calculating [$LightSource] for T=$T K..."); my $GraphArray = $this->GetColor()->ReadLightSource($LightSource, $T); $this->SetDataArray($GraphArray); $this->mw()->WriteStatusBar("Finish reading/calculating [$LightSource] for T=$T K."); $this->CreateGraphFrame($canvas, ''); $this->AssignGraphData(); $this->Draw(); } sub ReadColorMatchingFunction { my ($this) = @_; my $App = $this->App(); my $canvas = $this->Canvas(); $this->SetFileType("ColorMatchingFunction"); $this->SetFileType("ColorMatchingFunction"); my $lsb = $this->{ChooseChromaticityDiagramListBox}; my $XYZSpec = $lsb->GetText(); $App->print("Read ColorMatchingFunctions.\n"); $this->mw()->WriteStatusBar("Reading ColorMatchingFunctions..."); my $GraphArray = $this->GetColor()->ReadColorMatchingFunctions($XYZSpec); if(!$GraphArray) { $App->print("Error in TkColorMap::ReadColorMatchingFunction: " ."Can not read ColorMatchingFunctions.\n"); $this->mw()->WriteStatusBar("Failed to read ColorMatchingFunctions."); return 0; } $this->mw()->WriteStatusBar("Finish reading ColorMatchingFunctions."); $this->SetDataArray($GraphArray); $this->CreateGraphFrame($canvas, ''); $this->AssignGraphData(); $this->Draw(); } sub CalculateColorMap { my ($this) = @_; my $App = $this->App(); my $canvas = $this->Canvas(); $this->SetFileType("ColorMatchingFunction"); my $lsb = $this->{ChooseChromaticityDiagramListBox}; my $XYZSpec = $lsb->GetText(); $App->print("Read ColorMatchingFunctions.\n"); $this->mw()->WriteStatusBar("Reading ColorMatchingFunctions..."); my $GraphArray = $this->GetColor()->ReadColorMatchingFunctions($XYZSpec); if(!$GraphArray) { $App->print("Error in TkColorMap::ReadColorMatchingFunction: " ."Can not read ColorMatchingFunctions.\n"); $this->mw()->WriteStatusBar("Failed to read ColorMatchingFunctions."); return 0; } $this->mw()->WriteStatusBar("Finish reading ColorMatchingFunctions."); my $S = $GraphArray->GetGraphData(0); my $nData = $S->nData(); $this->SetDataArray(new GraphDataArray); my $Data0 = new GraphData; $Data0->SetTitle("ColorMap"); my @x; my @y; my $i; for($i = 0 ; $i < $nData ; $i++) { my $l = $S->x(0, $i); last if($l > 730); my $X = $S->y(0, $i); my $Y = $S->y(1, $i); my $Z = $S->y(2, $i); ($x[$i], $y[$i]) = Color::XYZtoxyz($X, $Y, $Z); my ($R, $G, $B) = Color::XYZtoRGB($X, $Y, $Z); printf "%4.0f\t%6.4f\t%6.4f\t\t%6.4f\t%6.4f\t%6.4f\n", $l, $x[$i], $y[$i], $R, $G, $B; } $x[$i] = $x[0]; $y[$i] = $y[0]; $Data0->{'x0'} = \@x; $Data0->{'x0_Name'} = "x"; $Data0->{'y0'} = \@y; $Data0->{'y0_Name'} = "y"; $Data0->CalMinMax(); $this->DataArray()->AddGraphData($Data0); $this->CreateGraphFrame($canvas, ''); $this->AssignGraphData(); $this->Draw(); } sub CalculateColor { my ($this) = @_; my $App = $this->App(); my $canvas = $this->Canvas(); if($this->{ChooseChromaticityDiagramListBox}->GetText() =~ /(ShowColorMapImage|NTSC|HDTV|Primary|RGB|Adbe)/i) { delete $this->{ColorX}; delete $this->{ColorY}; delete $this->{ColorZ}; delete $this->{Colorx}; delete $this->{Colory}; delete $this->{Colorz}; $this->SetFileType("ColorMap"); $this->Draw(); return 1; } my $SpectrumPath = $this->{SpectrumFileEntry}->GetText(); my $Observation = $this->{ChooseRTListBox}->GetText(); if(!$SpectrumPath) { $this->ChooseSpectrumFile($this->{SpectrumFileEntry}); $SpectrumPath = $this->{SpectrumFileEntry}->GetText(); } my $SpectrumArray = $this->GetColor()->ReadSpectrum($SpectrumPath, $Observation); if(!$SpectrumArray) { $App->print("Error in TkColorMap::CalculateColor: Can not read [$SpectrumPath].\n"); return 0; } my $LightSource = $this->{ChooseLightSourceListBox}->GetText(); my $T = $this->{TemperatureEntry}->GetText(); my $LightSourceArray = $this->GetColor()->ReadLightSource($LightSource, $T); if(!$LightSourceArray) { $App->print("Error in TkColorMap::CalculateColor: Can not read [$LightSource].\n"); return 0; } my $XYZSpec = $this->{ChooseChromaticityDiagramListBox}->GetText(); my $ColorMatchingFunctionArray = $this->GetColor()->ReadColorMatchingFunctions($XYZSpec); if(!$ColorMatchingFunctionArray) { $App->print("Error in TkColorMap::CalculateColor: " ."Can not read Color Matching Functions [$XYZSpec].\n"); return 0; } my ($X, $Y, $Z) = $this->GetColor()->CalculateColor(); my ($x, $y, $z) = Color::XYZtoxyz($X, $Y, $Z); $App->printf("XYZ=(%6.3f,%6.3f,%6.3f) xyz=(%4.3f,%4.3f,%4.3f)\n", $X, $Y, $Z, $x, $y, $z); $this->{ColorX} = $X; $this->{ColorY} = $Y; $this->{ColorZ} = $Z; $this->{Colorx} = $x; $this->{Colory} = $y; $this->{Colorz} = $z; $this->SetFileType("ColorMap"); $this->Draw(); } sub DrawLightSource { my ($this) = @_; $this->ReadLightSource(); } sub DrawSpectrum { my ($this) = @_; my $App = $this->App(); my $canvas = $this->Canvas(); my $mw = $this->mw(); $this->SetFileType("Spectrum"); my $SpectrumPath = $this->{SpectrumFileEntry}->GetText(); my $lsb = $this->{ChooseRTListBox}; my $Observation = $lsb->GetText(); $this->mw()->WriteStatusBar("Reading [$SpectrumPath]..."); my $GraphArray = $this->GetColor()->ReadSpectrum($SpectrumPath, $Observation); $this->mw()->WriteStatusBar("Finish reading [$SpectrumPath]."); $this->SetDataArray($GraphArray); $this->CreateGraphFrame($canvas, ''); $this->AssignGraphData(); $this->Draw(); } 1;