/usr/share/perl5/Image/ExifTool/BPG.pm is in libimage-exiftool-perl 10.40-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | #------------------------------------------------------------------------------
# File: BPG.pm
#
# Description: Read BPG meta information
#
# Revisions: 2016-07-05 - P. Harvey Created
#
# References: 1) http://bellard.org/bpg/
#------------------------------------------------------------------------------
package Image::ExifTool::BPG;
use strict;
use vars qw($VERSION);
use Image::ExifTool qw(:DataAccess :Utils);
$VERSION = '1.00';
# BPG information
%Image::ExifTool::BPG::Main = (
PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
NOTES => q{
The information listed below is extracted from BPG (Better Portable
Graphics) images. See L<http://bellard.org/bpg/> for the specification.
},
4 => {
Name => 'PixelFormat',
Format => 'int16u',
Mask => 0xe000,
PrintConv => {
0x0000 => 'Grayscale',
0x2000 => '4:2:0 (chroma at 0.5, 0.5)',
0x4000 => '4:2:2 (chroma at 0.5, 0)',
0x6000 => '4:4:4',
0x8000 => '4:2:0 (chroma at 0, 0.5)',
0xa000 => '4:2:2 (chroma at 0, 0)',
},
},
4.1 => {
Name => 'Alpha',
Format => 'int16u',
Mask => 0x1004,
PrintConv => {
0x0000 => 'No Alpha Plane',
0x1000 => 'Alpha Exists (color not premultiplied)',
0x1004 => 'Alpha Exists (color premultiplied)',
0x0004 => 'Alpha Exists (W color component)',
},
},
4.2 => {
Name => 'BitDepth',
Format => 'int16u',
Mask => 0x0f00,
ValueConv => '($val >> 8) + 8',
},
4.3 => {
Name => 'ColorSpace',
Format => 'int16u',
Mask => 0x00f0,
PrintConv => {
0x0000 => 'YCbCr (BT 601)',
0x0010 => 'RGB',
0x0020 => 'YCgCo',
0x0030 => 'YCbCr (BT 709)',
0x0040 => 'YCbCr (BT 2020)',
0x0050 => 'BT 2020 Constant Luminance',
},
},
4.4 => {
Name => 'Flags',
Format => 'int16u',
Mask => 0x000b,
PrintConv => { BITMASK => {
0 => 'Animation',
1 => 'Limited Range',
3 => 'Extension Present',
}},
},
6 => { Name => 'ImageWidth', Format => 'var_ue7' },
7 => { Name => 'ImageHeight', Format => 'var_ue7' },
# length of image data or 0 to EOF
# (must be decoded so we know where the extension data starts)
8 => { Name => 'ImageLength', Format => 'var_ue7' },
);
%Image::ExifTool::BPG::Extensions = (
GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
VARS => { ALPHA_FIRST => 1 },
1 => {
Name => 'EXIF',
SubDirectory => {
TagTable => 'Image::ExifTool::Exif::Main',
ProcessProc => \&Image::ExifTool::ProcessTIFF,
},
},
2 => {
Name => 'ICC_Profile',
SubDirectory => { TagTable => 'Image::ExifTool::ICC_Profile::Main' },
},
3 => {
Name => 'XMP',
SubDirectory => { TagTable => 'Image::ExifTool::XMP::Main' },
},
4 => {
Name => 'ThumbnailBPG',
Binary => 1,
},
5 => {
Name => 'AnimationControl',
Binary => 1,
Unknown => 1,
},
);
#------------------------------------------------------------------------------
# Get ue7 integer from binary data (max 32 bits)
# Inputs: 0) data ref, 1) location in data (undef for 0)
# Returns: 0) ue7 as integer or undef on error, 1) length of ue7 in bytes
sub Get_ue7($;$)
{
my $dataPt = shift;
my $pos = shift || 0;
my $size = length $$dataPt;
my $val = 0;
my $i;
for ($i=0; ; ) {
return() if $pos+$i >= $size or $i >= 5;
my $byte = Get8u($dataPt, $pos + $i);
$val = ($val << 7) | ($byte & 0x7f);
unless ($byte & 0x80) {
return() if $i == 4 and $byte & 0x70; # error if bits 32-34 are set
last; # this was the last byte
}
return() if $i == 0 and $byte == 0x80; # error if first byte is 0x80
++$i; # step to the next byte
}
return($val, $i+1);
}
#------------------------------------------------------------------------------
# Extract EXIF information from a BPG image
# Inputs: 0) ExifTool object reference, 1) dirInfo reference
# Returns: 1 on success, 0 if this wasn't a valid BPG file
sub ProcessBPG($$)
{
local $_;
my ($et, $dirInfo) = @_;
my $raf = $$dirInfo{RAF};
my ($buff, $size, $n, $len, $pos);
# verify this is a valid BPG file
return 0 unless $raf->Read($buff, 21) == 21; # (21 bytes is maximum header length)
return 0 unless $buff =~ /^BPG\xfb/;
$et->SetFileType(); # set the FileType tag
SetByteOrder('MM');
my %dirInfo = (
DataPt => \$buff,
DirStart => 0,
DirLen => length($buff),
VarFormatData => [ ],
);
$et->ProcessDirectory(\%dirInfo, GetTagTable('Image::ExifTool::BPG::Main'));
return 1 unless $$et{VALUE}{Flags} & 0x0008; # all done unless extension flag is set
# add varSize from last entry in VarFormatData to determine
# the current read position in the file
my $dataPos = 9 + $dirInfo{VarFormatData}[-1][1];
# read extension length
unless ($raf->Seek($dataPos, 0) and $raf->Read($buff, 5) == 5) {
$et->Warn('Missing BPG extension data');
return 1;
}
($size, $n) = Get_ue7(\$buff);
defined $size or $et->Warn('Corrupted BPG extension length'), return 1;
$dataPos += $n;
$size > 10000000 and $et->Warn('BPG extension is too large'), return 1;
unless ($raf->Seek($dataPos, 0) and $raf->Read($buff, $size) == $size) {
$et->Warn('Truncated BPG extension');
return 1;
}
my $tagTablePtr = GetTagTable('Image::ExifTool::BPG::Extensions');
# loop through the individual extensions
for ($pos=0; $pos<$size; $pos+=$len) {
my $type = Get8u(\$buff, $pos);
# get length of this extension
($len, $n) = Get_ue7(\$buff, ++$pos);
defined $len or $et->Warn('Corrupted BPG extension'), last;
$pos += $n; # point to start of data for this extension
$pos + $len > $size and $et->Warn('Invalid BPG extension size'), last;
$$tagTablePtr{$type} or $et->Warn("Unrecognized BPG extension $type ($len bytes)", 1), next;
# libbpg (in my opinion) incorrectly copies the padding byte after the
# "EXIF\0" APP1 header to the start of the BPG EXIF extension, so issue a
# minor warning and ignore the padding if we find it before the TIFF header
if ($type == 1 and $len > 3 and substr($buff,$pos,3)=~/^.(II|MM)/s) {
$et->Warn("Ignored extra byte at start of EXIF extension", 1);
++$pos;
--$len;
}
$et->HandleTag($tagTablePtr, $type, undef,
DataPt => \$buff,
DataPos => $dataPos,
Start => $pos,
Size => $len,
Parent => 'BPG',
);
}
return 1;
}
1; # end
__END__
=head1 NAME
Image::ExifTool::BPG - Read BPG meta information
=head1 SYNOPSIS
This module is used by Image::ExifTool
=head1 DESCRIPTION
This module contains definitions required by Image::ExifTool to read BPG
(Better Portable Graphics) images.
=head1 AUTHOR
Copyright 2003-2017, Phil Harvey (phil at owl.phy.queensu.ca)
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 REFERENCES
=over 4
=item L<http://bellard.org/bpg/>
=back
=head1 SEE ALSO
L<Image::ExifTool::TagNames/BPG Tags>,
L<Image::ExifTool(3pm)|Image::ExifTool>
=cut
|