Ignore:
Timestamp:
2011-06-01T12:33:42+12:00 (13 years ago)
Author:
sjm84
Message:

Updating the ExifTool perl modules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/cpan/Image/ExifTool/PNG.pm

    r16842 r24107  
    1212#               3) http://www.libpng.org/pub/mng/
    1313#               4) http://www.libpng.org/pub/png/spec/register/
    14 #
    15 # Notes:        I haven't found a sample PNG image with a 'iTXt' chunk, so
    16 #               this part of the code is still untested.
    17 #
    18 #               Writing meta information in PNG images is a pain in the butt
     14#               5) ftp://ftp.simplesystems.org/pub/png/documents/pngext-1.4.0-pdg.html
     15#
     16# Notes:        Writing meta information in PNG images is a pain in the butt
    1917#               for a number of reasons:  One biggie is that you have to
    2018#               decompress then decode the ASCII/hex profile information before
     
    2927use Image::ExifTool qw(:DataAccess :Utils);
    3028
    31 $VERSION = '1.15';
     29$VERSION = '1.24';
    3230
    3331sub ProcessPNG_tEXt($$$);
     
    3836sub AddChunks($$);
    3937sub Add_iCCP($$);
     38sub GetLangInfo($$);
     39sub BuildTextChunk($$$$$);
    4040
    4141my $noCompressLib;
     
    4848);
    4949
     50# map for directories in PNG images
     51my %pngMap = (
     52    IFD1         => 'IFD0',
     53    EXIF         => 'IFD0', # to write EXIF as a block
     54    ExifIFD      => 'IFD0',
     55    GPS          => 'IFD0',
     56    SubIFD       => 'IFD0',
     57    GlobParamIFD => 'IFD0',
     58    PrintIM      => 'IFD0',
     59    InteropIFD   => 'ExifIFD',
     60    MakerNotes   => 'ExifIFD',
     61    IFD0         => 'PNG',
     62    XMP          => 'PNG',
     63    ICC_Profile  => 'PNG',
     64    Photoshop    => 'PNG',
     65    IPTC         => 'Photoshop',
     66    MakerNotes   => 'ExifIFD',
     67);
     68
    5069# color type of current image
    5170$Image::ExifTool::PNG::colorType = -1;
     
    5574    WRITE_PROC => \&Image::ExifTool::DummyWriteProc,
    5675    GROUPS => { 2 => 'Image' },
     76    PREFERRED => 1, # always add these tags when writing
     77    NOTES => q{
     78        Tags extracted from PNG images.  See
     79        L<http://www.libpng.org/pub/png/spec/1.2/> for the official PNG 1.2
     80        specification.
     81    },
    5782    bKGD => {
    5883        Name => 'BackgroundColor',
     
    6287        Name => 'PrimaryChromaticities',
    6388        SubDirectory => { TagTable => 'Image::ExifTool::PNG::PrimaryChromaticities' },
     89    },
     90    dSIG => {
     91        Name => 'DigitalSignature',
     92        Binary => 1,
    6493    },
    6594    fRAc => {
     
    130159        Name => 'SignificantBits',
    131160        ValueConv => 'join(" ",unpack("C*",$val))',
     161    },
     162    sCAL => { # png 1.4.0
     163        Name => 'SubjectScale',
     164        SubDirectory => { TagTable => 'Image::ExifTool::PNG::SubjectScale' },
    132165    },
    133166    sPLT => {
     
    145178            3 => 'Absolute Colorimetric',
    146179        },
     180    },
     181    sTER => { # png 1.4.0
     182        Name => 'StereoImage',
     183        SubDirectory => { TagTable => 'Image::ExifTool::PNG::StereoImage' },
    147184    },
    148185    tEXt => {
     
    162199        },
    163200        PrintConv => '$self->ConvertDateTime($val)',
    164         PrintConvInv => '$val',
     201        PrintConvInv => '$self->InverseDateTime($val)',
    165202    },
    166203    tRNS => {
     
    175212        Notes => 'obsolete location specified by older XMP draft',
    176213        SubDirectory => { TagTable => 'Image::ExifTool::XMP::Main' },
     214    },
     215    vpAg => { # private imagemagick chunk
     216        Name => 'VirtualPage',
     217        SubDirectory => { TagTable => 'Image::ExifTool::PNG::VirtualPage' },
    177218    },
    178219    zTXt => {
     
    256297);
    257298
     299# PNG sCAL chunk
     300%Image::ExifTool::PNG::SubjectScale = (
     301    PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
     302    GROUPS => { 2 => 'Image' },
     303    0 => {
     304        Name => 'SubjectUnits',
     305        PrintConv => { 1 => 'Meters', 2 => 'Radians' },
     306    },
     307    1 => {
     308        Name => 'SubjectPixelWidth',
     309        Format => 'var_string',
     310    },
     311    2 => {
     312        Name => 'SubjectPixelHeight',
     313        Format => 'var_string',
     314    },
     315);
     316
     317# PNG vpAg chunk
     318%Image::ExifTool::PNG::VirtualPage = (
     319    PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
     320    GROUPS => { 2 => 'Image' },
     321    FORMAT => 'int32u',
     322    0 => 'VirtualImageWidth',
     323    1 => 'VirtualImageHeight',
     324    2 => {
     325        Name => 'VirtualPageUnits',
     326        Format => 'int8u',
     327        # what is the conversion for this?
     328    },
     329);
     330
     331# PNG sTER chunk
     332%Image::ExifTool::PNG::StereoImage = (
     333    PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
     334    GROUPS => { 2 => 'Image' },
     335    0 => {
     336        Name => 'StereoMode',
     337        PrintConv => {
     338            0 => 'Cross-fuse Layout',
     339            1 => 'Diverging-fuse Layout',
     340        },
     341    },
     342);
     343
    258344my %unreg = ( Notes => 'unregistered' );
    259345
     
    266352    PREFERRED => 1, # always add these tags when writing
    267353    GROUPS => { 2 => 'Image' },
     354    LANG_INFO => \&GetLangInfo,
    268355    NOTES => q{
    269 The PNG TextualData format allows aribrary tag names to be used.  The tags
    270 listed below are the only ones that can be written (unless new user-defined
    271 tags are added via the configuration file), however ExifTool will extract
    272 any other TextualData tags that are found.
    273 
    274 The information for the TextualData tags may be stored as tEXt, zTXt or iTXt
    275 chunks in the PNG image.  ExifTool will read and edit tags in their original
    276 form, but tEXt chunks are written by default when creating new tags.
    277 Compressed zTXt chunks are written only if Compress::Zlib is available, and
    278 only for profile information or when the -z (Compress) option is specified.
    279 
    280 Some of the tags below are not registered as part of the PNG specification,
    281 but are included here because they are generated by other software such as
    282 ImageMagick.
     356        The PNG TextualData format allows arbitrary tag names to be used.  The tags
     357        listed below are the only ones that can be written (unless new user-defined
     358        tags are added via the configuration file), however ExifTool will extract
     359        any other TextualData tags that are found.
     360       
     361        These tags may be stored as tEXt, zTXt or iTXt chunks in the PNG image.  By
     362        default ExifTool writes new string-value tags as as uncompressed tEXt, or
     363        compressed zTXt if the Compress (-z) option is used and Compress::Zlib is
     364        available.  Alternate language tags and values containing special characters
     365        (unless the Latin character set is used) are written as iTXt, and compressed
     366        if the Compress option is used and Compress::Zlib is available.  Raw profile
     367        information is always created as compressed zTXt if Compress::Zlib is
     368        available, or tEXt otherwise.  Standard XMP is written as uncompressed iTXt.
     369
     370        Alternate languages are accessed by suffixing the tag name with a '-',
     371        followed by an RFC 3066 language code (ie. "PNG:Comment-fr", or
     372        "Title-en-US").  See L<http://www.ietf.org/rfc/rfc3066.txt> for the RFC 3066
     373        specification.
     374
     375        Some of the tags below are not registered as part of the PNG specification,
     376        but are included here because they are generated by other software such as
     377        ImageMagick.
    283378    },
    284379    Title       => { },
     
    306401    Make        => { %unreg, Groups => { 2 => 'Camera' } },
    307402    Model       => { %unreg, Groups => { 2 => 'Camera' } },
     403   'create-date'=> {
     404        Name => 'CreateDate',
     405        Groups => { 2 => 'Time' },
     406        Shift => 'Time',
     407        %unreg,
     408        ValueConv => 'require Image::ExifTool::XMP; Image::ExifTool::XMP::ConvertXMPDate($val)',
     409        ValueConvInv => 'require Image::ExifTool::XMP; Image::ExifTool::XMP::FormatXMPDate($val)',
     410        PrintConv => '$self->ConvertDateTime($val)',
     411        PrintConvInv => '$self->InverseDateTime($val,undef,1)',
     412    },
     413   'modify-date'=> {
     414        Name => 'ModDate', # (to distinguish from tIME chunk "ModifyDate")
     415        Groups => { 2 => 'Time' },
     416        Shift => 'Time',
     417        %unreg,
     418        ValueConv => 'require Image::ExifTool::XMP; Image::ExifTool::XMP::ConvertXMPDate($val)',
     419        ValueConvInv => 'require Image::ExifTool::XMP; Image::ExifTool::XMP::FormatXMPDate($val)',
     420        PrintConv => '$self->ConvertDateTime($val)',
     421        PrintConvInv => '$self->InverseDateTime($val,undef,1)',
     422    },
    308423    TimeStamp   => { %unreg, Groups => { 2 => 'Time' }, Shift => 'Time' },
    309424    URL         => { %unreg },
     
    311426        Name => 'XMP',
    312427        Notes => q{
    313             location according to the XMP specification -- this is where ExifTool will
    314             add a new XMP chunk if the image didn't already contain XMP
     428            unregistered, but this is the location according to the XMP specification,
     429            and is where ExifTool will add a new XMP chunk if the image didn't already
     430            contain XMP
    315431        },
    316432        SubDirectory => {
     
    323439            # (No condition because this is just for BuildTagLookup)
    324440            Name => 'APP1_Profile',
     441            %unreg,
    325442            SubDirectory => {
    326443                TagTable=>'Image::ExifTool::Exif::Main',
     
    338455   'Raw profile type exif' => {
    339456        Name => 'EXIF_Profile',
     457        %unreg,
    340458        SubDirectory => {
    341459            TagTable=>'Image::ExifTool::Exif::Main',
     
    345463   'Raw profile type icc' => {
    346464        Name => 'ICC_Profile',
     465        %unreg,
    347466        SubDirectory => {
    348467            TagTable => 'Image::ExifTool::ICC_Profile::Main',
     
    352471   'Raw profile type icm' => {
    353472        Name => 'ICC_Profile',
     473        %unreg,
    354474        SubDirectory => {
    355475            TagTable => 'Image::ExifTool::ICC_Profile::Main',
     
    359479   'Raw profile type iptc' => {
    360480        Name => 'IPTC_Profile',
     481        %unreg,
    361482        SubDirectory => {
    362483            TagTable => 'Image::ExifTool::Photoshop::Main',
     
    366487   'Raw profile type xmp' => {
    367488        Name => 'XMP_Profile',
     489        %unreg,
    368490        SubDirectory => {
    369491            TagTable => 'Image::ExifTool::XMP::Main',
     
    379501{
    380502    return Image::ExifTool::DoAutoLoad($AUTOLOAD, @_);
     503}
     504
     505#------------------------------------------------------------------------------
     506# Get standard case for language code (this routine copied from XMP.pm)
     507# Inputs: 0) Language code
     508# Returns: Language code in standard case
     509sub StandardLangCase($)
     510{
     511    my $lang = shift;
     512    # make 2nd subtag uppercase only if it is 2 letters
     513    return lc($1) . uc($2) . lc($3) if $lang =~ /^([a-z]{2,3}|[xi])(-[a-z]{2})\b(.*)/i;
     514    return lc($lang);
     515}
     516
     517#------------------------------------------------------------------------------
     518# Get localized version of tagInfo hash
     519# Inputs: 0) tagInfo hash ref, 1) language code (ie. "x-default")
     520# Returns: new tagInfo hash ref, or undef if invalid
     521sub GetLangInfo($$)
     522{
     523    my ($tagInfo, $lang) = @_;
     524    $lang =~ tr/_/-/;   # RFC 3066 specifies '-' as a separator
     525    # no alternate languages for XMP or raw profile directories
     526    return undef if $$tagInfo{SubDirectory};
     527    # language code must normalized for use in tag ID
     528    return Image::ExifTool::GetLangInfo($tagInfo, StandardLangCase($lang));
    381529}
    382530
     
    386534#         2) Tag ID, 3) Tag value, 4) [optional] compressed data flag:
    387535#            0=not compressed, 1=unknown compression, 2-N=compression with type N-2
    388 #         5) optional output buffer reference
     536#         5) optional output buffer ref, 6) character encoding (tEXt/zTXt/iTXt only)
     537#         6) optional language code
    389538# Returns: 1 on success
    390 sub FoundPNG($$$$;$$)
     539sub FoundPNG($$$$;$$$$)
    391540{
    392     my ($exifTool, $tagTablePtr, $tag, $val, $compressed, $outBuff) = @_;
     541    my ($exifTool, $tagTablePtr, $tag, $val, $compressed, $outBuff, $enc, $lang) = @_;
     542    return 0 unless defined $val;
     543    my $verbose = $exifTool->Options('Verbose');
     544    my $id = $tag;  # generate tag ID which include language code
     545    if ($lang) {
     546        # case of language code must be normalized since they are case insensitive
     547        $lang = StandardLangCase($lang);
     548        $id .= '-' . $lang;
     549    }
     550    my $tagInfo = $exifTool->GetTagInfo($tagTablePtr, $id) ||
     551                  # (some software forgets to capitalize first letter)
     552                  $exifTool->GetTagInfo($tagTablePtr, ucfirst($id));
     553    # create alternate language tag if necessary
     554    if (not $tagInfo and $lang) {
     555        $tagInfo = $exifTool->GetTagInfo($tagTablePtr, $tag) ||
     556                   $exifTool->GetTagInfo($tagTablePtr, ucfirst($tag));
     557        $tagInfo = GetLangInfo($tagInfo, $lang) if $tagInfo;
     558    }
     559#
     560# uncompress data if necessary
     561#
    393562    my ($wasCompressed, $deflateErr);
    394     return 0 unless defined $val;
    395 #
    396 # First, uncompress data if requested
    397 #
    398     my $verbose = $exifTool->Options('Verbose');
    399     my $out = $exifTool->Options('TextOut');
    400     my $tagInfo = $exifTool->GetTagInfo($tagTablePtr, $tag) ||
    401                   # (some software forgets to capitalize first letter)
    402                   $exifTool->GetTagInfo($tagTablePtr, ucfirst($tag));
    403 
    404563    if ($compressed and $compressed > 1) {
    405564        if ($compressed == 2) { # Inflate/Deflate compression
     
    416575                }
    417576            } elsif (not $noCompressLib) {
    418                 $noCompressLib = 1;
    419                 my $verb = $outBuff ? 'write' : 'decode';
    420                 $deflateErr = "Install Compress::Zlib to $verb compressed information";
     577                $deflateErr = "Install Compress::Zlib to read compressed information";
    421578            } else {
    422579                $deflateErr = '';   # flag deflate error but no warning
     
    429586            $exifTool->VerboseDir("Unable to decompress $$tagInfo{Name}", 0, length($val));
    430587        }
    431         $exifTool->Warn($deflateErr) if $deflateErr and not $outBuff;
     588        # issue warning if relevant
     589        if ($deflateErr and (not $outBuff or
     590            ($tagInfo and $$tagInfo{SubDirectory} and $$exifTool{EDIT_DIRS}{$$tagInfo{Name}})))
     591        {
     592            $exifTool->Warn($deflateErr);
     593            $noCompressLib = 1 if $deflateErr =~ /^Install/;
     594        }
     595    }
     596    # translate character encoding if necessary (tEXt/zTXt/iTXt string values only)
     597    if ($enc and not $compressed and not ($tagInfo and $$tagInfo{SubDirectory})) {
     598        $val = $exifTool->Decode($val, $enc);
    432599    }
    433600#
     
    444611                    $wasCompressed and $name = "Decompressed $name";
    445612                    $exifTool->VerboseDir($name, 0, $len);
    446                     my %parms = ( Prefix => $exifTool->{INDENT}, Out => $out );
    447                     $parms{MaxLen} = 96 unless $verbose > 3;
    448                     Image::ExifTool::HexDump(\$val, undef, %parms);
     613                    $exifTool->VerboseDump(\$val);
    449614                }
    450615                # don't indent next directory (since it is really the same data)
     
    457622            return 1 if $outBuff and not $$subTable{WRITE_PROC};
    458623            my %subdirInfo = (
    459                 DataPt => \$val,
     624                DataPt   => \$val,
    460625                DirStart => 0,
    461                 DataLen => $len,
    462                 DirLen => $len,
    463                 DirName => $tagName,
    464                 TagInfo => $tagInfo,
     626                DataLen  => $len,
     627                DirLen   => $len,
     628                DirName  => $tagName,
     629                TagInfo  => $tagInfo,
    465630                ReadOnly => 1, # (only used by WriteXMP)
    466                 OutBuff => $outBuff,
     631                OutBuff  => $outBuff,
    467632            );
    468633            # no need to re-decompress if already done
     
    482647        if ($outBuff) {
    483648            my $writable = $tagInfo->{Writable};
     649            my $isOverwriting;
    484650            if ($writable or ($$tagTablePtr{WRITABLE} and
    485651                not defined $writable and not $$tagInfo{SubDirectory}))
    486652            {
    487653                # write new value for this tag if necessary
    488                 my ($isOverwriting, $newVal);
     654                my $newVal;
    489655                if ($exifTool->{DEL_GROUP}->{PNG}) {
    490656                    # remove this tag now, but keep in ADD_PNG list to add back later
     
    492658                } else {
    493659                    # remove this from the list of PNG tags to add
    494                     delete $exifTool->{ADD_PNG}->{$tag};
     660                    delete $exifTool->{ADD_PNG}->{$id};
    495661                    # (also handle case of tEXt tags written with lowercase first letter)
    496                     delete $exifTool->{ADD_PNG}->{ucfirst($tag)};
    497                     my $newValueHash = $exifTool->GetNewValueHash($tagInfo);
    498                     $isOverwriting = Image::ExifTool::IsOverwriting($newValueHash);
     662                    delete $exifTool->{ADD_PNG}->{ucfirst($id)};
     663                    my $nvHash = $exifTool->GetNewValueHash($tagInfo);
     664                    $isOverwriting = Image::ExifTool::IsOverwriting($nvHash);
    499665                    if (defined $deflateErr) {
    500                         $newVal = Image::ExifTool::GetNewValues($newValueHash);
    501                         # can only write tag now if unconditionally deleting it
    502                         if ($isOverwriting > 0 and not defined $newVal) {
     666                        $newVal = Image::ExifTool::GetNewValues($nvHash);
     667                        # can only write tag now if always overwriting
     668                        if ($isOverwriting > 0) {
    503669                            $val = '<deflate error>';
    504                         } else {
    505                             $isOverwriting = 0; # can't rewrite this compressed text
     670                        } elsif ($isOverwriting) {
     671                            $isOverwriting = 0; # can't overwrite
    506672                            $exifTool->Warn($deflateErr) if $deflateErr;
    507673                        }
    508674                    } else {
    509675                        if ($isOverwriting < 0) {
    510                             $isOverwriting = Image::ExifTool::IsOverwriting($newValueHash, $val);
     676                            $isOverwriting = Image::ExifTool::IsOverwriting($nvHash, $val);
    511677                        }
    512678                        # (must get new value after IsOverwriting() in case it was shifted)
    513                         $newVal = Image::ExifTool::GetNewValues($newValueHash);
     679                        $newVal = Image::ExifTool::GetNewValues($nvHash);
    514680                    }
    515681                }
    516682                if ($isOverwriting) {
    517                     $$outBuff =  (defined $newVal) ? $newVal : '';
     683                    $$outBuff = (defined $newVal) ? $newVal : '';
    518684                    ++$exifTool->{CHANGED};
    519                     if ($verbose > 1) {
    520                         print $out "    - PNG:$tagName = '",$exifTool->Printable($val),"'\n";
    521                         print $out "    + PNG:$tagName = '",$exifTool->Printable($newVal),"'\n" if defined $newVal;
    522                     }
     685                    $exifTool->VerboseValue("- PNG:$tagName", $val);
     686                    $exifTool->VerboseValue("+ PNG:$tagName", $newVal) if defined $newVal;
    523687                }
    524688            }
    525             if ($$outBuff) {
    526                 if ($wasCompressed) {
     689            if (defined $$outBuff and length $$outBuff) {
     690                if ($enc) { # must be tEXt/zTXt/iTXt if $enc is set
     691                    $$outBuff = BuildTextChunk($exifTool, $tag, $tagInfo, $$outBuff, $lang);
     692                } elsif ($wasCompressed) {
    527693                    # re-compress the output data
    528694                    my $deflate;
     
    537703                    }
    538704                    $$outBuff or $exifTool->Warn("PNG:$tagName not written (compress error)");
    539                 } elsif ($exifTool->Options('Compress')) {
    540                     $exifTool->Warn("PNG:$tagName not compressed (uncompressed tag existed)", 1);
    541705                }
    542706            }
     
    548712        ($name = $tag) =~ s/\s+(.)/\u$1/g;   # remove white space from tag name
    549713        $tagInfo = { Name => $name };
     714        $$tagInfo{LangCode} = $lang if $lang;
    550715        # make unknown profiles binary data type
    551         $$tagInfo{ValueConv} = '\$val' if $tag =~ /^Raw profile type /;
     716        $$tagInfo{Binary} = 1 if $tag =~ /^Raw profile type /;
    552717        Image::ExifTool::AddTagToTable($tagTablePtr, $tag, $tagInfo);
    553718    }
     
    605770        if ($verbose > 2) {
    606771            $exifTool->VerboseDir("Decoded $tagName", 0, $len);
    607             my %parms = (
    608                 Prefix => $exifTool->{INDENT},
    609                 Out => $exifTool->Options('TextOut'),
    610             );
    611             $parms{MaxLen} = 96 unless $verbose > 3;
    612             Image::ExifTool::HexDump(\$buff, undef, %parms);
     772            $exifTool->VerboseDump(\$buff);
    613773        }
    614774        # don't indent next directory (since it is really the same data)
     
    647807        $dirInfo{DirStart} += $hdrLen;
    648808        $dirInfo{DirLen} -= $hdrLen;
    649         $processed = $exifTool->ProcessTIFF(\%dirInfo);
    650809        if ($outBuff) {
    651             if ($$outBuff) {
    652                 $$outBuff = $Image::ExifTool::exifAPP1hdr . $$outBuff if $$outBuff;
    653             } else {
    654                 $$outBuff = '' if $processed;
    655             }
     810            $$outBuff = $exifTool->WriteDirectory(\%dirInfo, $tagTablePtr,
     811                                                  \&Image::ExifTool::WriteTIFF);
     812            $$outBuff = $Image::ExifTool::exifAPP1hdr . $$outBuff if $$outBuff;
    656813            delete $$addDirs{IFD0};
     814        } else {
     815            $processed = $exifTool->ProcessTIFF(\%dirInfo);
    657816        }
    658817    } elsif ($buff =~ /^$Image::ExifTool::xmpAPP1hdr/) {
     
    673832        # TIFF information (haven't seen this, but what the heck...)
    674833        return 1 if $outBuff and not $$editDirs{IFD0};
    675         $processed = $exifTool->ProcessTIFF(\%dirInfo);
    676834        if ($outBuff) {
    677             if ($$outBuff) {
    678                 $$outBuff = $Image::ExifTool::exifAPP1hdr . $$outBuff if $$outBuff;
    679             } else {
    680                 $$outBuff = '' if $processed;
    681             }
     835            $$outBuff = $exifTool->WriteDirectory(\%dirInfo, $tagTablePtr,
     836                                                  \&Image::ExifTool::WriteTIFF);
     837            $$outBuff = $Image::ExifTool::exifAPP1hdr . $$outBuff if $$outBuff;
    682838            delete $$addDirs{IFD0};
     839        } else {
     840            $processed = $exifTool->ProcessTIFF(\%dirInfo);
    683841        }
    684842    } else {
     
    687845        $exifTool->Warn("Unknown raw profile '$profName'");
    688846    }
    689     if ($outBuff and $$outBuff) {
     847    if ($outBuff and defined $$outBuff and length $$outBuff) {
    690848        if ($exifTool->{CHANGED} != $oldChanged) {
    691849            my $hdr = sprintf("\n%s\n%8d\n", $profileType, length($$outBuff));
     
    703861# Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) Pointer to tag table
    704862# Returns: 1 on success
     863# Notes: writes new chunk data to ${$$dirInfo{OutBuff}} if writing tag
    705864sub ProcessPNG_Compressed($$$)
    706865{
     
    712871    my $hdr = $tag . "\0" . substr($val, 0, 1);
    713872    $val = substr($val, 1); # remove compression method byte
     873    my $success;
     874    my $outBuff = $$dirInfo{OutBuff};
    714875    # use the PNG chunk tag instead of the embedded tag name for iCCP chunks
    715876    if ($$dirInfo{TagInfo} and $$dirInfo{TagInfo}->{Name} eq 'ICC_Profile') {
    716877        $tag = 'iCCP';
    717878        $tagTablePtr = \%Image::ExifTool::PNG::Main;
    718     }
    719     my $outBuff = $$dirInfo{OutBuff};
    720     my $rtnVal = FoundPNG($exifTool, $tagTablePtr, $tag, $val, $compressed, $outBuff);
    721     # add header back onto this chunk if we are writing
    722     $$outBuff = $hdr . $$outBuff if $outBuff and $$outBuff;
    723     return $rtnVal;
     879        $success = FoundPNG($exifTool, $tagTablePtr, $tag, $val, $compressed, $outBuff);
     880        $$outBuff = $hdr . $$outBuff if $outBuff and $$outBuff;
     881    } else {
     882        $success = FoundPNG($exifTool, $tagTablePtr, $tag, $val, $compressed, $outBuff, 'Latin');
     883    }
     884    return $success;
    724885}
    725886
     
    728889# Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) Pointer to tag table
    729890# Returns: 1 on success
     891# Notes: writes new chunk data to ${$$dirInfo{OutBuff}} if writing tag
    730892sub ProcessPNG_tEXt($$$)
    731893{
     
    733895    my ($tag, $val) = split /\0/, ${$$dirInfo{DataPt}}, 2;
    734896    my $outBuff = $$dirInfo{OutBuff};
    735     my $rtnVal = FoundPNG($exifTool, $tagTablePtr, $tag, $val, undef, $outBuff);
    736     # add header back onto this chunk if we are writing
    737     $$outBuff = $tag . "\0" . $$outBuff if $outBuff and $$outBuff;
    738     return $rtnVal;
     897    return FoundPNG($exifTool, $tagTablePtr, $tag, $val, undef, $outBuff, 'Latin');
    739898}
    740899
     
    743902# Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) Pointer to tag table
    744903# Returns: 1 on success
     904# Notes: writes new chunk data to ${$$dirInfo{OutBuff}} if writing tag
    745905sub ProcessPNG_iTXt($$$)
    746906{
     
    753913    $compressed and $compressed = 2 + $meth;
    754914    my $outBuff = $$dirInfo{OutBuff};
    755     my $rtnVal = FoundPNG($exifTool, $tagTablePtr, $tag, $val, $compressed, $outBuff);
    756     if ($outBuff and $$outBuff) {
    757         $$outBuff = $tag . "\0" . substr($dat, 0, 2) . "$lang\0$trans\0" . $$outBuff;
    758     }
    759     return $rtnVal;
     915    return FoundPNG($exifTool, $tagTablePtr, $tag, $val, $compressed, $outBuff, 'UTF8', $lang);
    760916}
    761917
     
    777933    return 0 unless $raf->Read($sig,8) == 8 and $pngLookup{$sig};
    778934    if ($outfile) {
     935        delete $$exifTool{TextChunkType};
    779936        Write($outfile, $sig) or $err = 1 if $outfile;
    780937        # can only add tags in Main and TextualData tables
     
    782939            \%Image::ExifTool::PNG::Main,
    783940            \%Image::ExifTool::PNG::TextualData);
    784         # initialize with same directories as JPEG, but PNG tags take priority
    785         $exifTool->InitWriteDirs('JPEG','PNG');
     941        # initialize with same directories, with PNG tags taking priority
     942        $exifTool->InitWriteDirs(\%pngMap,'PNG');
    786943    }
    787944    my ($fileType, $hdrChunk, $endChunk) = @{$pngLookup{$sig}};
     
    8471004            if ($chunk eq $hdrChunk) {
    8481005                $foundHdr = 1;
     1006            } elsif ($hdrChunk eq 'IHDR' and $chunk eq 'CgBI') {
     1007                $exifTool->Warn('Non-standard PNG image (Apple iPhone format)');
    8491008            } else {
    8501009                $exifTool->Warn("$fileType image did not start with $hdrChunk");
     
    8621021            }
    8631022            print $out "$fileType $chunk ($len bytes):\n";
    864             if ($verbose > 2) {
    865                 my %dumpParms = ( Out => $out );
    866                 $dumpParms{MaxLen} = 96 if $verbose <= 4;
    867                 Image::ExifTool::HexDump(\$dbuf, undef, %dumpParms);
    868             }
     1023            $exifTool->VerboseDump(\$dbuf, Addr => $raf->Tell() - $len - 4) if $verbose > 2;
    8691024        }
    8701025        # only extract information from chunks in our tables
     
    8771032        }
    8781033        if ($outfile) {
    879             if ($theBuff) {
    880                 $hbuf = pack('Na4',length($theBuff), $chunk);
     1034            if (defined $theBuff) {
     1035                next unless length $theBuff; # empty if we deleted the information
     1036                # change chunk type if necessary
     1037                if ($$exifTool{TextChunkType}) {
     1038                    $chunk = $$exifTool{TextChunkType};
     1039                    delete $$exifTool{TextChunkType};
     1040                }
     1041                $hbuf = pack('Na4', length($theBuff), $chunk);
    8811042                $dbuf = $theBuff;
    8821043                my $crc = CalculateCRC(\$hbuf, undef, 4);
    8831044                $crc = CalculateCRC(\$dbuf, $crc);
    8841045                $cbuf = pack('N', $crc);
    885             } elsif (defined $theBuff) {
    886                 next;   # empty if we deleted the information
    8871046            }
    8881047            Write($outfile, $hbuf, $dbuf, $cbuf) or $err = 1;
     
    9131072=head1 AUTHOR
    9141073
    915 Copyright 2003-2007, Phil Harvey (phil at owl.phy.queensu.ca)
     1074Copyright 2003-2011, Phil Harvey (phil at owl.phy.queensu.ca)
    9161075
    9171076This library is free software; you can redistribute it and/or modify it
Note: See TracChangeset for help on using the changeset viewer.