| 1 | #------------------------------------------------------------------------------ | ||||||||||
| 2 | # File: ZISRAW.pm | ||||||||||
| 3 | # | ||||||||||
| 4 | # Description: Read ZISRAW (CZI) meta information | ||||||||||
| 5 | # | ||||||||||
| 6 | # Revisions: 2020-08-07 - P. Harvey Created | ||||||||||
| 7 | # | ||||||||||
| 8 | # References: 1) https://www.zeiss.com/microscopy/us/products/microscope-software/zen/czi.html | ||||||||||
| 9 | #------------------------------------------------------------------------------ | ||||||||||
| 10 | |||||||||||
| 11 | package Image::ExifTool::ZISRAW; | ||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use Image::ExifTool qw(:DataAccess :Utils); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | $VERSION = '1.01'; | |||||||||
| 18 | |||||||||||
| 19 | 1 | %Image::ExifTool::ZISRAW::Main = ( | |||||||||
| 20 | PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData, | ||||||||||
| 21 | GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' }, | ||||||||||
| 22 | NOTES => q{ | ||||||||||
| 23 | As well as the header information listed below, ExifTool also extracts the | ||||||||||
| 24 | top-level XML-based metadata from Zeiss Integrated Software RAW (ZISRAW) CZI | ||||||||||
| 25 | files. | ||||||||||
| 26 | }, | ||||||||||
| 27 | 0x20 => { | ||||||||||
| 28 | Name => 'ZISRAWVersion', | ||||||||||
| 29 | Format => 'int32u[2]', | ||||||||||
| 30 | PrintConv => '$val =~ tr/ /./; $val', | ||||||||||
| 31 | }, | ||||||||||
| 32 | 0x30 => { | ||||||||||
| 33 | Name => 'PrimaryFileGUID', | ||||||||||
| 34 | Format => 'undef[16]', | ||||||||||
| 35 | ValueConv => 'unpack("H*",$val)', | ||||||||||
| 36 | }, | ||||||||||
| 37 | 0x40 => { | ||||||||||
| 38 | Name => 'FileGUID', | ||||||||||
| 39 | Format => 'undef[16]', | ||||||||||
| 40 | ValueConv => 'unpack("H*",$val)', | ||||||||||
| 41 | }, | ||||||||||
| 42 | ); | ||||||||||
| 43 | |||||||||||
| 44 | #------------------------------------------------------------------------------ | ||||||||||
| 45 | # Shorten obscenely long CZI tag names | ||||||||||
| 46 | # Inputs: Tag name | ||||||||||
| 47 | # Returns: Shortened tag name | ||||||||||
| 48 | sub ShortenTagNames($) | ||||||||||
| 49 | 27 | ▶ | { | ||||||||
|
Subroutine
ShortenTagNames: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 50 | 27 | local $_; | |||||||||
| 51 | 27 | $_ = shift; | |||||||||
| 52 | 27 | s/^HardwareSetting//; | |||||||||
| 53 | 27 | s/^DevicesDevice/Device/; | |||||||||
| 54 | 27 | s/LightPathNode//g; | |||||||||
| 55 | 27 | s/Successors//g; | |||||||||
| 56 | 27 | s/ExperimentExperiment/Experiment/g; | |||||||||
| 57 | 27 | s/ObjectivesObjective/Objective/; | |||||||||
| 58 | 27 | s/ChannelsChannel/Channel/; | |||||||||
| 59 | 27 | s/TubeLensesTubeLens/TubeLens/; | |||||||||
| 60 | 27 | s/^ExperimentHardwareSettingsPoolHardwareSetting/HardwareSetting/; | |||||||||
| 61 | 27 | s/SharpnessMeasureSetSharpnessMeasure/Sharpness/; | |||||||||
| 62 | 27 | s/FocusSetupAutofocusSetup/Autofocus/; | |||||||||
| 63 | 27 | s/TracksTrack/Track/; | |||||||||
| 64 | 27 | s/ChannelRefsChannelRef/ChannelRef/; | |||||||||
| 65 | 27 | s/ChangerChanger/Changer/; | |||||||||
| 66 | 27 | s/ElementsChangerElement/Changer/; | |||||||||
| 67 | 27 | s/ChangerElements/Changer/; | |||||||||
| 68 | 27 | s/ContrastChangerContrast/Contrast/; | |||||||||
| 69 | 27 | s/KeyFunctionsKeyFunction/KeyFunction/; | |||||||||
| 70 | 27 | s/ManagerContrastManager(Contrast)?/ManagerContrast/; | |||||||||
| 71 | 27 | s/ObjectiveChangerObjective/ObjectiveChanger/; | |||||||||
| 72 | 27 | s/ManagerLightManager/ManagerLight/; | |||||||||
| 73 | 27 | s/WavelengthAreasWavelengthArea/WavelengthArea/; | |||||||||
| 74 | 27 | s/ReflectorChangerReflector/ReflectorChanger/; | |||||||||
| 75 | 27 | s/^StageStageAxesStageAxis/StageAxis/; | |||||||||
| 76 | 27 | s/ShutterChangerShutter/ShutterChanger/; | |||||||||
| 77 | 27 | s/OnOffChangerOnOff/OnOffChanger/; | |||||||||
| 78 | 27 | s/UnsharpMaskStateUnsharpMask/UnsharpMask/; | |||||||||
| 79 | 27 | s/Acquisition/Acq/; | |||||||||
| 80 | 27 | s/Continuous/Cont/; | |||||||||
| 81 | 27 | s/Resolution/Res/; | |||||||||
| 82 | 27 | s/Experiment/Expt/g; | |||||||||
| 83 | 27 | s/Threshold/Thresh/; | |||||||||
| 84 | 27 | s/Reference/Ref/; | |||||||||
| 85 | 27 | s/Magnification/Mag/; | |||||||||
| 86 | 27 | s/Original/Orig/; | |||||||||
| 87 | 27 | s/FocusSetupFocusStrategySetup/Focus/; | |||||||||
| 88 | 27 | s/ParametersParameter/Parameter/; | |||||||||
| 89 | 27 | s/IntervalInfo/Interval/; | |||||||||
| 90 | 27 | s/ExptBlocksAcqBlock/AcqBlock/; | |||||||||
| 91 | 27 | s/MicroscopesMicroscope/Microscope/; | |||||||||
| 92 | 27 | s/TimeSeriesInterval/TimeSeries/; | |||||||||
| 93 | 27 | s/Interval(.*Interval)/$1/; | |||||||||
| 94 | 27 | s/SingleTileRegionsSingleTileRegion/SingleTileRegion/; | |||||||||
| 95 | 27 | s/AcquisitionMode//; | |||||||||
| 96 | 27 | s/DetectorsDetector/Detector/; | |||||||||
| 97 | 27 | s/Setup//; | |||||||||
| 98 | 27 | s/Setting//; | |||||||||
| 99 | 27 | s/TrackTrack/Track/; | |||||||||
| 100 | 27 | s/AnalogOutMaximumsAnalogOutMaximum/AnalogOutMaximum/; | |||||||||
| 101 | 27 | s/AnalogOutMinimumsAnalogOutMinimum/AnalogOutMinimum/; | |||||||||
| 102 | 27 | s/DigitalOutLabelsDigitalOutLabelLabel/DigitalOutLabelLabel/; | |||||||||
| 103 | 27 | s/(VivaTomeOpticalSectionInformation)+VivaTomeOpticalSectionInformation/VivaTomeOpticalSectionInformation/; | |||||||||
| 104 | 27 | s/FocusDefiniteFocus/FocusDefinite/; | |||||||||
| 105 | 27 | s/ChangerChanger/Changer/; | |||||||||
| 106 | 27 | s/Calibration/Cal/; | |||||||||
| 107 | 27 | s/LightSwitchChangerRLTLSwitch/LightSwitchChangerRLTL/; | |||||||||
| 108 | 27 | s/Parameters//; | |||||||||
| 109 | 27 | s/Fluorescence/Fluor/; | |||||||||
| 110 | 27 | s/CameraGeometryCameraGeometry/CameraGeometry/; | |||||||||
| 111 | 27 | s/CameraCamera/Camera/; | |||||||||
| 112 | 27 | s/DetectorsCamera/Camera/; | |||||||||
| 113 | 27 | s/FilterChangerLeftChangerEmissionFilter/LeftChangerEmissionFilter/; | |||||||||
| 114 | 27 | s/SwitchingStatesSwitchingState/SwitchingState/; | |||||||||
| 115 | 27 | s/Information/Info/; | |||||||||
| 116 | 27 | s/SubDimensions?//g; | |||||||||
| 117 | 27 | s/Setups?//; | |||||||||
| 118 | 27 | s/Parameters?//; | |||||||||
| 119 | 27 | s/Calculate/Calc/; | |||||||||
| 120 | 27 | s/Visibility/Vis/; | |||||||||
| 121 | 27 | s/Orientation/Orient/; | |||||||||
| 122 | 27 | s/ListItems/Items/; | |||||||||
| 123 | 27 | s/Increment/Incr/; | |||||||||
| 124 | 27 | s/Parameter/Param/; | |||||||||
| 125 | 27 | s/(ParfocalParcentralValues)+ParfocalParcentralValue/Parcentral/; | |||||||||
| 126 | 27 | s/ParcentralParcentral/Parcentral/; | |||||||||
| 127 | 27 | s/CorrFocusCorrection/FocusCorr/; | |||||||||
| 128 | 27 | s/(ApoTomeDepthInfo)+Element/ApoTomeDepth/; | |||||||||
| 129 | 27 | s/(ApoTomeClickStopInfo)+Element/ApoTomeClickStop/; | |||||||||
| 130 | 27 | s/DepthDepth/Depth/; | |||||||||
| 131 | 27 | s/(Devices?)+Device/Device/; | |||||||||
| 132 | 27 | s/(BeamPathNode)+/BeamPathNode/; | |||||||||
| 133 | 27 | s/BeamPathsBeamPath/BeamPath/g; | |||||||||
| 134 | 27 | s/BeamPathBeamPath/BeamPath/g; | |||||||||
| 135 | 27 | s/Configuration/Config/; | |||||||||
| 136 | 27 | s/StageAxesStageAxis/StageAxis/; | |||||||||
| 137 | 27 | s/RangesRange/Range/; | |||||||||
| 138 | 27 | s/DataGridDatasGridData(Grid)?/DataGrid/; | |||||||||
| 139 | 27 | s/DataMicroscopeDatasMicroscopeData(Microscope)?/DataMicroscope/; | |||||||||
| 140 | 27 | s/DataWegaDatasWegaData/DataWega/; | |||||||||
| 141 | 27 | s/ClickStopPositionsClickStopPosition/ClickStopPosition/; | |||||||||
| 142 | 27 | s/LightSourcess?LightSource(Settings)?(LightSource)?/LightSource/; | |||||||||
| 143 | 27 | s/FilterSetsFilterSet/FilterSet/; | |||||||||
| 144 | 27 | s/EmissionFiltersEmissionFilter/EmissionFilter/; | |||||||||
| 145 | 27 | s/ExcitationFiltersExcitationFilter/ExcitationFilter/; | |||||||||
| 146 | 27 | s/FiltersFilter/Filter/; | |||||||||
| 147 | 27 | s/DichroicsDichroic/Dichronic/; | |||||||||
| 148 | 27 | s/WavelengthsWavelength/Wavelength/; | |||||||||
| 149 | 27 | s/MultiTrackSetup/MultiTrack/; | |||||||||
| 150 | 27 | s/TrackTrack/Track/; | |||||||||
| 151 | 27 | s/DataGrabberSetup/DataGrabber/; | |||||||||
| 152 | 27 | s/CameraFrameSetup/CameraFrame/; | |||||||||
| 153 | 27 | s/TimeSeries(TimeSeries|Setups)/TimeSeries/; | |||||||||
| 154 | 27 | s/FocusFocus/Focus/; | |||||||||
| 155 | 27 | s/FocusAutofocus/Autofocus/; | |||||||||
| 156 | 27 | s/Focus(Hardware|Software)(Autofocus)+/Autofocus$1/; | |||||||||
| 157 | 27 | s/AutofocusAutofocus/Autofocus/; | |||||||||
| 158 | 27 | return $_; | |||||||||
| 159 | } | ||||||||||
| 160 | |||||||||||
| 161 | #------------------------------------------------------------------------------ | ||||||||||
| 162 | # Extract metadata from a ZISRAW (CZI) image | ||||||||||
| 163 | # Inputs: 0) ExifTool object reference, 1) dirInfo reference | ||||||||||
| 164 | # Returns: 1 on success, 0 if this wasn't a valid CZI file | ||||||||||
| 165 | sub ProcessCZI($$) | ||||||||||
| 166 | 1 | ▶ | { | ||||||||
|
Subroutine
ProcessCZI: called CC=9 SCAR=22.7
Pod
undocumented
| |||||||||||
| 167 | 1 | my ($et, $dirInfo) = @_; | |||||||||
| 168 | 1 | my $raf = $$dirInfo{RAF}; | |||||||||
| 169 | 1 | my ($buff, $tagTablePtr); | |||||||||
| 170 | |||||||||||
| 171 | # verify this is a valid CZI file | ||||||||||
| 172 | 1 | ▶ | return 0 unless $raf->Read($buff, 100) == 100; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 173 | 1 | ▶ | return 0 unless $buff =~ /^ZISRAWFILE\0{6}/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 174 | 1 | $et->SetFileType(); | |||||||||
| 175 | 1 | SetByteOrder('II'); | |||||||||
| 176 | 1 | my %dirInfo = ( | |||||||||
| 177 | DataPt => \$buff, | ||||||||||
| 178 | DirStart => 0, | ||||||||||
| 179 | DirLen => length($buff), | ||||||||||
| 180 | ); | ||||||||||
| 181 | 1 | $tagTablePtr = GetTagTable('Image::ExifTool::ZISRAW::Main'); | |||||||||
| 182 | 1 | $et->ProcessDirectory(\%dirInfo, $tagTablePtr); | |||||||||
| 183 | |||||||||||
| 184 | # read the metadata section | ||||||||||
| 185 | 1 | ▶ | my $pos = Get64u(\$buff, 92) or return 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 186 | 1 | ▶ | $raf->Seek($pos, 0) or $et->Warn('Error seeking to metadata'), return 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 187 | 1 | ▶ | $raf->Read($buff, 288) == 288 or $et->Warn('Error reading metadata header'), return 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 188 | 1 | ▶ | $buff =~ /^ZISRAWMETADATA\0\0/ or $et->Warn('Invalid metadata header'), return 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 189 | 1 | my $len = Get32u(\$buff, 32); | |||||||||
| 190 | 1 | ▶ | $len < 200000000 or $et->Warn('Metadata section too large. Ignoring'), return 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 191 | 1 | ▶ | $raf->Read($buff, $len) or $et->Warn('Error reading XML metadata'), return 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 192 | 1 | $et->FoundTag('XML', $buff); # extract as a block | |||||||||
| 193 | 1 | $tagTablePtr = GetTagTable('Image::ExifTool::XMP::XML'); | |||||||||
| 194 | 1 | $dirInfo{DirLen} = length $buff; | |||||||||
| 195 | # shorten tag names somewhat by removing 'ImageDocumentMetadata' prefix from all | ||||||||||
| 196 | 1 | $$et{XmpIgnoreProps} = [ 'ImageDocument', 'Metadata', 'Information' ]; | |||||||||
| 197 | 1 | $$et{ShortenXmpTags} = \&ShortenTagNames; | |||||||||
| 198 | |||||||||||
| 199 | 1 | $et->ProcessDirectory(\%dirInfo, $tagTablePtr); | |||||||||
| 200 | |||||||||||
| 201 | 1 | return 1; | |||||||||
| 202 | } | ||||||||||
| 203 | |||||||||||
| 204 | 1 | 1; # end | |||||||||
| 205 | |||||||||||
| 206 | __END__ | ||||||||||