| 1 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # File: XISF.pm | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Description: Read Extensible Image Serialization Format metadata | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Revisions: 2023-10-10 - P. Harvey Created | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # References: 1) https://pixinsight.com/doc/docs/XISF-1.0-spec/XISF-1.0-spec.html | ||||||||||||||||||||||||||||||||||||||||||
| 9 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | package Image::ExifTool::XISF; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use Image::ExifTool::XMP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | $VERSION = '1.00'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # XISF tags (ref 1) | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | %Image::ExifTool::XISF::Main = ( | |||||||||||||||||||||||||||||||||||||||||
| 22 | GROUPS => { 0 => 'XML', 1 => 'XML', 2 => 'Image' }, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | VARS => { LONG_TAGS => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | NOTES => q{ | ||||||||||||||||||||||||||||||||||||||||||
| 25 | This table lists some standard Extensible Image Serialization Format (XISF) | ||||||||||||||||||||||||||||||||||||||||||
| 26 | tags, but ExifTool will extract any other tags found. See | ||||||||||||||||||||||||||||||||||||||||||
| 27 | L<https://pixinsight.com/xisf/> for the specification. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ImageGeometry => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ImageSampleFormat => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | ImageBounds => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ImageImageType => { Name => 'ImageType' }, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ImageColorSpace => { Name => 'ColorSpace' }, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ImageLocation => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ImageResolutionHorizontal => 'XResolution', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ImageResolutionVertical => 'YResolution', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ImageResolutionUnit => 'ResolutionUnit', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | ImageICCProfile => { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | Name => 'ICC_Profile', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | ValueConv => 'Image::ExifTool::XMP::DecodeBase64($val)', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | Binary => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ImageICCProfileLocation => { Name => 'ICCProfileLocation' }, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | ImagePixelStorage => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ImageOffset => { Name => 'ImagePixelOffset' }, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | ImageOrientation => { Name => 'Orientation' }, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ImageId => { Name => 'ImageID' }, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ImageUuid => { Name => 'UUID' }, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ImageData => { Binary => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 'CreationTime' => { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | Name => 'CreateDate', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | Shift => 'Time', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | Groups => { 2 => 'Time' }, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ValueConv => 'Image::ExifTool::XMP::ConvertXMPDate($val)', | ||||||||||||||||||||||||||||||||||||||||||
| 55 | PrintConv => '$self->ConvertDateTime($val)', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | CreatorApplication => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | Abstract => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | AccessRights => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | Authors => { Groups => { 2 => 'Author' } }, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | BibliographicReferences => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | BriefDescription => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | CompressionLevel => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | CompressionCodecs => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | Contributors => { Groups => { 2 => 'Author' } }, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | Copyright => { Groups => { 2 => 'Author' } }, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | CreatorModule => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | CreatorOS => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | Description => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | Keywords => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | Languages => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | License => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | OriginalCreationTime => { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | Name => 'DateTimeOriginal', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | Description => 'Date/Time Original', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | Shift => 'Time', | ||||||||||||||||||||||||||||||||||||||||||
| 77 | Groups => { 2 => 'Time' }, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ValueConv => 'Image::ExifTool::XMP::ConvertXMPDate($val)', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | PrintConv => '$self->ConvertDateTime($val)', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | RelatedResources => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | Title => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # Handle properties in XISF metadata structures | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # Inputs: 0) attribute list ref, 1) attr hash ref, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # 2) property name ref, 3) property value ref | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # Returns: true if value was changed | ||||||||||||||||||||||||||||||||||||||||||
| 90 | sub HandleXISFAttrs($$$$) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
HandleXISFAttrs: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 11 | my ($attrList, $attrs, $prop, $valPt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 11 | ▶ | return 0 unless defined $$attrs{id}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | my ($changed, $a); | |||||||||||||||||||||||||||||||||||||||||
| 95 | # use "id" as the tag name, "value" as the value, and ignore "type" | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | $$prop = $$attrs{id}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | $$prop =~ s/^XISF://; # remove XISF namespace | |||||||||||||||||||||||||||||||||||||||||
| 98 | 6 | ▶ | if (defined $$attrs{value}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | $$valPt = $$attrs{value}; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $changed = 1; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | my @attrs = @$attrList; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | @$attrList = ( ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | foreach $a (@attrs) { | |||||||||||||||||||||||||||||||||||||||||
| 105 | 13 | ▶ | if ($a eq 'id' or $a eq 'value' or $a eq 'type') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$a eq "id" or $a eq "value" or $a eq "type"
$a eq "id" or $a eq "value"
MC/DC0%0/3
$a eq "id" or $a eq "value" or $a eq "type"
$a eq "id"
$a eq "value"
$a eq "type"
Truth table75%3/4
A or B or C
A= $a eq "id"B= $a eq "value"C= $a eq "type"
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 13 | delete $$attrs{$a}; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | push @$attrList, $a; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | return $changed; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # Read information in a XISF document | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # Inputs: 0) ExifTool ref, 1) dirInfo ref | ||||||||||||||||||||||||||||||||||||||||||
| 117 | # Returns: 1 on success, 0 if this wasn't a valid XISF file | ||||||||||||||||||||||||||||||||||||||||||
| 118 | sub ProcessXISF($$) | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ProcessXISF: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | my ($et, $dirInfo) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | my $raf = $$dirInfo{RAF}; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | my $buff; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | return 0 unless $raf->Read($buff, 16) == 16 and $buff =~ /^XISF0100/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$raf->Read($buff, 16) == 16 and $buff =~ /^XISF0100/
MC/DC0%0/2
$raf->Read($buff, 16) == 16 and $buff =~ /^XISF0100/
$raf->Read($buff, 16) == 16
$buff =~ /^XISF0100/
Truth table33%1/3
A and B
A= $raf->Read($buff, 16) == 16B= $buff =~ /^XISF0100/
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | $et->SetFileType(); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | SetByteOrder('II'); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my $tagTablePtr = GetTagTable('Image::ExifTool::XISF::Main'); | |||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | my $hdrLen = Get32u(\$buff, 8); | |||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | $raf->Read($buff, $hdrLen) == $hdrLen or $et->Warn('Error reading XISF header'), return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | $et->FoundTag(XML => $buff); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | my %dirInfo = ( | |||||||||||||||||||||||||||||||||||||||||
| 132 | DataPt => \$buff, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | IgnoreProp => { xisf => 1, Metadata => 1, Property => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | XMPParseOpts => { AttrProc => \&HandleXISFAttrs }, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | Image::ExifTool::XMP::ProcessXMP($et, \%dirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | my $geo = $$et{VALUE}{ImageGeometry}; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | ▶ | if ($geo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | my ($w, $h, $n) = split /:/, $geo; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | $et->FoundTag(ImageWidth => $w); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | $et->FoundTag(ImageHeight => $h); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | $et->FoundTag(NumPlanes => $n); | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | 1; # end | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | __END__ | ||||||||||||||||||||||||||||||||||||||||||