Skip to content

Commit

Permalink
Work around missing PKImageDecode_GetXMPMetadata_WMP in libjxr Debian…
Browse files Browse the repository at this point in the history
… package
  • Loading branch information
chausner committed Jun 12, 2017
1 parent d6fc9d4 commit 1a234f1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
25 changes: 25 additions & 0 deletions LEGAL
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
jxrlib

Copyright © Microsoft Corp.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

• Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
• Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
4 changes: 2 additions & 2 deletions src/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ static ERR jxrlib_load(const gchar* filename, Image* image, gchar** error_messag
Call(decoder->GetColorContext(decoder, image->color_context, &image->color_context_size));
}

Call(PKImageDecode_GetXMPMetadata_WMP(decoder, NULL, &image->xmp_metadata_size));
Call(_PKImageDecode_GetXMPMetadata_WMP(decoder, NULL, &image->xmp_metadata_size));
if (image->xmp_metadata_size != 0)
{
image->xmp_metadata = g_new(guchar, image->xmp_metadata_size);
Call(PKImageDecode_GetXMPMetadata_WMP(decoder, image->xmp_metadata, &image->xmp_metadata_size));
Call(_PKImageDecode_GetXMPMetadata_WMP(decoder, image->xmp_metadata, &image->xmp_metadata_size));
}

image->black_one = decoder->WMP.wmiSCP.bBlackWhite;
Expand Down
57 changes: 57 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,60 @@ gchar* get_pixel_format_mnemonic(const PKPixelFormatGUID* pixel_format)
return NULL;
}
}

// the following metadata helper functions have been copied from jxrlib as they are missing in libjxr Debian packages

ERR _PKImageDecode_GetMetadata_WMP(PKImageDecode *pID, U32 uOffset, U32 uByteCount, U8 *pbGot, U32 *pcbGot)
{
ERR err = WMP_errSuccess;

if (pbGot && uOffset)
{
struct WMPStream* pWS = pID->pStream;
size_t iCurrPos;

FailIf(*pcbGot < uByteCount, WMP_errBufferOverflow);
Call(pWS->GetPos(pWS, &iCurrPos));
Call(pWS->SetPos(pWS, uOffset));
Call(pWS->Read(pWS, pbGot, uByteCount));
Call(pWS->SetPos(pWS, iCurrPos));
}

Cleanup:
if (Failed(err))
*pcbGot = 0;
else
*pcbGot = uByteCount;

return err;
}

ERR _PKImageDecode_GetXMPMetadata_WMP(PKImageDecode *pID, U8 *pbXMPMetadata, U32 *pcbXMPMetadata)
{
return _PKImageDecode_GetMetadata_WMP(pID, pID->WMP.wmiDEMisc.uXMPMetadataOffset,
pID->WMP.wmiDEMisc.uXMPMetadataByteCount, pbXMPMetadata, pcbXMPMetadata);
}

ERR _PKImageDecode_GetEXIFMetadata_WMP(PKImageDecode *pID, U8 *pbEXIFMetadata, U32 *pcbEXIFMetadata)
{
return _PKImageDecode_GetMetadata_WMP(pID, pID->WMP.wmiDEMisc.uEXIFMetadataOffset,
pID->WMP.wmiDEMisc.uEXIFMetadataByteCount, pbEXIFMetadata, pcbEXIFMetadata);
}

ERR _PKImageDecode_GetGPSInfoMetadata_WMP(PKImageDecode *pID, U8 *pbGPSInfoMetadata, U32 *pcbGPSInfoMetadata)
{
return _PKImageDecode_GetMetadata_WMP(pID, pID->WMP.wmiDEMisc.uGPSInfoMetadataOffset,
pID->WMP.wmiDEMisc.uGPSInfoMetadataByteCount, pbGPSInfoMetadata, pcbGPSInfoMetadata);
}

ERR _PKImageDecode_GetIPTCNAAMetadata_WMP(PKImageDecode *pID, U8 *pbIPTCNAAMetadata, U32 *pcbIPTCNAAMetadata)
{
return _PKImageDecode_GetMetadata_WMP(pID, pID->WMP.wmiDEMisc.uIPTCNAAMetadataOffset,
pID->WMP.wmiDEMisc.uIPTCNAAMetadataByteCount, pbIPTCNAAMetadata, pcbIPTCNAAMetadata);
}

ERR _PKImageDecode_GetPhotoshopMetadata_WMP(PKImageDecode *pID, U8 *pbPhotoshopMetadata, U32 *pcbPhotoshopMetadata)
{
return _PKImageDecode_GetMetadata_WMP(pID, pID->WMP.wmiDEMisc.uPhotoshopMetadataOffset,
pID->WMP.wmiDEMisc.uPhotoshopMetadataByteCount, pbPhotoshopMetadata, pcbPhotoshopMetadata);
}

0 comments on commit 1a234f1

Please sign in to comment.