Commit 114618ea9 for imagemagick.org
commit 114618ea91a8186554d6e4700d0cb01f63fb63ff
Author: Cristy <urban-warrior@imagemagick.org>
Date: Sun Aug 30 19:32:19 2026 -0400
c2pa decode poc
diff --git a/coders/c2pa.c b/coders/c2pa.c
index 0cb040a64..530c12f47 100644
--- a/coders/c2pa.c
+++ b/coders/c2pa.c
@@ -56,6 +56,7 @@
#include "MagickCore/monitor.h"
#include "MagickCore/monitor-private.h"
#include "MagickCore/option.h"
+#include "MagickCore/property.h"
#include "MagickCore/resource_.h"
#include "MagickCore/static.h"
#include "MagickCore/string_.h"
@@ -100,13 +101,12 @@ static MagickBooleanType
static Image *ReadC2PAImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
- ExceptionInfo
- *sans_exception;
+ char
+ *json,
+ json_filename[MagickPathExtent];
Image
- *image,
- *images,
- *next;
+ *image;
ImageInfo
*read_info;
@@ -133,47 +133,36 @@ static Image *ReadC2PAImage(const ImageInfo *image_info,
}
(void) CloseBlob(image);
/*
- Leverage delegate to decode the image provenance.
+ Leverage delegate to create the image manifest.
*/
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
read_info->temporary=MagickFalse;
- (void) CopyMagickString(read_info->filename,image_info->filename,
- MagickPathExtent);
(void) CopyMagickString(image->filename,image_info->filename,
MagickPathExtent);
status=InvokeDelegate(read_info,image,"c2pa:decode",(char *) NULL,exception);
+ (void) FormatLocaleString(json_filename,MagickPathExtent,"%s.json",
+ read_info->unique);
+ read_info=DestroyImageInfo(read_info);
image=DestroyImageList(image);
if (status == MagickFalse)
- {
- if (*read_info->unique != '\0')
- (void) RelinquishUniqueFileResource(read_info->unique);
- read_info=DestroyImageInfo(read_info);
- return((Image *) NULL);
- }
+ return((Image *) NULL);
/*
- Read the image the delegate returned in %o.
+ Read image.
*/
- (void) CopyMagickString(read_info->filename,read_info->unique,
- MagickPathExtent);
+ read_info=CloneImageInfo(image_info);
+ SetImageInfoBlob(read_info,(void *) NULL,0);
*read_info->magick='\0';
- sans_exception=AcquireExceptionInfo();
- (void) SetImageInfo(read_info,1,sans_exception);
- sans_exception=DestroyExceptionInfo(sans_exception);
- images=ReadImage(read_info,exception);
- (void) RelinquishUniqueFileResource(read_info->unique);
+ image=ReadImage(read_info,exception);
read_info=DestroyImageInfo(read_info);
- if (images == (Image *) NULL)
- return((Image *) NULL);
- for (next=images; next != (Image *) NULL; next=GetNextImageInList(next))
- {
- (void) CopyMagickString(next->filename,image_info->filename,
- MagickPathExtent);
- (void) CopyMagickString(next->magick,"C2PA",MagickPathExtent);
- (void) CopyMagickString(next->magick_filename,image_info->filename,
- MagickPathExtent);
- }
- return(GetFirstImageInList(images));
+ if (image == (Image *) NULL)
+ return(image);
+ json=FileToString(json_filename,~0UL,exception);
+ if (json == (char *) NULL)
+ return(image);
+ (void) SetImageProperty(image,"c2pa:manifest",json,exception);
+ json=DestroyString(json);
+ return(GetFirstImageInList(image));
}
/*
diff --git a/coders/url.c b/coders/url.c
index 6dbde6ca7..1a3df6975 100644
--- a/coders/url.c
+++ b/coders/url.c
@@ -94,8 +94,8 @@
*/
#if !defined(MAGICKCORE_WINDOWS_SUPPORT)
-static Image* InvokeURLDelegate(ImageInfo* read_info,Image* image,
- const char *delegate,ExceptionInfo* exception)
+static Image *InvokeURLDelegate(ImageInfo *read_info,Image *image,
+ const char *delegate,ExceptionInfo *exception)
{
Image
*images,
diff --git a/config/delegates.xml.in b/config/delegates.xml.in
index 8f7a1ae26..88386a386 100644
--- a/config/delegates.xml.in
+++ b/config/delegates.xml.in
@@ -62,7 +62,7 @@
<delegate decode="bpg" command="@SHELL_QUOTE@@BPGDecodeDelegate@@SHELL_QUOTE@ -b 16 -o @SHELL_QUOTE@%o@SHELL_QUOTE@ @SHELL_QUOTE@%i@SHELL_QUOTE@"/>
<delegate decode="png" encode="bpg" command="@SHELL_QUOTE@@BPGEncodeDelegate@@SHELL_QUOTE@ -b 12 -q @SHELL_QUOTE@%~@SHELL_QUOTE@ -o @SHELL_QUOTE@%o@SHELL_QUOTE@ @SHELL_QUOTE@%i@SHELL_QUOTE@"/>
<delegate decode="blender" command="@SHELL_QUOTE@@BlenderDecodeDelegate@@SHELL_QUOTE@ -b @SHELL_QUOTE@%i@SHELL_QUOTE@ -F PNG -o @SHELL_QUOTE@%o@SHELL_QUOTE@@SHELL_QUOTE@\n@SHELL_QUOTE@@ConvertDelegate@@SHELL_QUOTE@ -concatenate @SHELL_QUOTE@%o*.png@SHELL_QUOTE@ @SHELL_QUOTE@%o@SHELL_QUOTE@"/>
- <delegate decode="c2pa:decode" command="@SHELL_QUOTE@@C2PADecodeDelegate@@SHELL_QUOTE@ @SHELL_QUOTE@%i@SHELL_QUOTE@ --output @SHELL_QUOTE@%o@SHELL_QUOTE@"/>
+ <delegate decode="c2pa:decode" command="@SHELL_QUOTE@@C2PADecodeDelegate@@SHELL_QUOTE@ --crjson @SHELL_QUOTE@%i@SHELL_QUOTE@ > @SHELL_QUOTE@%u.json@SHELL_QUOTE@;"/>
<delegate encode="c2pa:encode" command="env C2PA_PRIVATE_KEY=%[c2pa:key] C2PA_PASSWORD=%[c2pa:password] C2PA_CERT_CHAIN=%[c2pa:cert] @SHELL_QUOTE@@C2PAEncodeDelegate@@SHELL_QUOTE@ @SHELL_QUOTE@%i@SHELL_QUOTE@ --manifest @SHELL_QUOTE@%[c2pa:manifest]@SHELL_QUOTE@ --force --output @SHELL_QUOTE@%o@SHELL_QUOTE@"/>
<delegate decode="browse" stealth="True" spawn="True" command="@SHELL_QUOTE@@BrowseDelegate@@SHELL_QUOTE@ https://imagemagick.org/; @RMDelegate@ @SHELL_QUOTE@%i@SHELL_QUOTE@"/>
<delegate decode="http:decode" command="@SHELL_QUOTE@@WWWDecodeDelegate@@SHELL_QUOTE@ -s -L -o @SHELL_QUOTE@%u.dat@SHELL_QUOTE@ @SHELL_QUOTE@http:%M@SHELL_QUOTE@"/>