Skip to content

Commit 4ed3ce8

Browse files
authored
feat: Add set_intent APIs (#194)
* fix: Version bump * fix: New bindings * fix: Initial bindings * fix: Few more tests * fix: Add a test * fix: Renamings * chore: c2pa-v0.71.1 * chore: c2pa-v0.71.1 * fix: Update tests * fix: Clean up logs * fix: Clean up logs from native lib
1 parent e141978 commit 4ed3ce8

File tree

4 files changed

+402
-12
lines changed

4 files changed

+402
-12
lines changed

c2pa-native-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c2pa-v0.71.0
1+
c2pa-v0.71.2

src/c2pa/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
C2paError,
2323
Reader,
2424
C2paSigningAlg,
25+
C2paDigitalSourceType,
26+
C2paBuilderIntent,
2527
C2paSignerInfo,
2628
Signer,
2729
Stream,
@@ -35,6 +37,8 @@
3537
'C2paError',
3638
'Reader',
3739
'C2paSigningAlg',
40+
'C2paDigitalSourceType',
41+
'C2paBuilderIntent',
3842
'C2paSignerInfo',
3943
'Signer',
4044
'Stream',

src/c2pa/c2pa.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
'c2pa_builder_free',
4949
'c2pa_builder_set_no_embed',
5050
'c2pa_builder_set_remote_url',
51+
'c2pa_builder_set_intent',
5152
'c2pa_builder_add_resource',
5253
'c2pa_builder_add_ingredient_from_stream',
5354
'c2pa_builder_add_action',
@@ -158,6 +159,37 @@ class C2paSigningAlg(enum.IntEnum):
158159
ED25519 = 6
159160

160161

162+
class C2paDigitalSourceType(enum.IntEnum):
163+
"""List of possible digital source types."""
164+
EMPTY = 0
165+
TRAINED_ALGORITHMIC_DATA = 1
166+
DIGITAL_CAPTURE = 2
167+
COMPUTATIONAL_CAPTURE = 3
168+
NEGATIVE_FILM = 4
169+
POSITIVE_FILM = 5
170+
PRINT = 6
171+
HUMAN_EDITS = 7
172+
COMPOSITE_WITH_TRAINED_ALGORITHMIC_MEDIA = 8
173+
ALGORITHMICALLY_ENHANCED = 9
174+
DIGITAL_CREATION = 10
175+
DATA_DRIVEN_MEDIA = 11
176+
TRAINED_ALGORITHMIC_MEDIA = 12
177+
ALGORITHMIC_MEDIA = 13
178+
SCREEN_CAPTURE = 14
179+
VIRTUAL_RECORDING = 15
180+
COMPOSITE = 16
181+
COMPOSITE_CAPTURE = 17
182+
COMPOSITE_SYNTHETIC = 18
183+
184+
185+
class C2paBuilderIntent(enum.IntEnum):
186+
"""Builder intent enumeration.
187+
"""
188+
CREATE = 0 # New digital creation with specified digital source type
189+
EDIT = 1 # Edit of a pre-existing parent asset
190+
UPDATE = 2 # Restricted version of Edit for non-editorial changes
191+
192+
161193
# Mapping from C2paSigningAlg enum to string representation,
162194
# as the enum value currently maps by default to an integer value.
163195
_ALG_TO_STRING_BYTES_MAPPING = {
@@ -258,6 +290,7 @@ def _clear_error_state():
258290
# Free the error to clear the state
259291
_lib.c2pa_string_free(error)
260292

293+
261294
class C2paSignerInfo(ctypes.Structure):
262295
"""Configuration for a Signer."""
263296
_fields_ = [
@@ -414,6 +447,10 @@ def _setup_function(func, argtypes, restype=None):
414447
_setup_function(
415448
_lib.c2pa_builder_set_remote_url, [
416449
ctypes.POINTER(C2paBuilder), ctypes.c_char_p], ctypes.c_int)
450+
_setup_function(
451+
_lib.c2pa_builder_set_intent,
452+
[ctypes.POINTER(C2paBuilder), ctypes.c_uint, ctypes.c_uint],
453+
ctypes.c_int)
417454
_setup_function(_lib.c2pa_builder_add_resource, [ctypes.POINTER(
418455
C2paBuilder), ctypes.c_char_p, ctypes.POINTER(C2paStream)], ctypes.c_int)
419456
_setup_function(_lib.c2pa_builder_add_ingredient_from_stream,
@@ -2570,6 +2607,46 @@ def set_remote_url(self, remote_url: str):
25702607
raise C2paError(
25712608
Builder._ERROR_MESSAGES['url_error'].format("Unknown error"))
25722609

2610+
def set_intent(
2611+
self,
2612+
intent: C2paBuilderIntent,
2613+
digital_source_type: C2paDigitalSourceType = (
2614+
C2paDigitalSourceType.EMPTY
2615+
)
2616+
):
2617+
"""Set the intent for the manifest.
2618+
2619+
The intent specifies what kind of manifest to create:
2620+
- CREATE: New with specified digital source type.
2621+
Must not have a parent ingredient.
2622+
- EDIT: Edit of a pre-existing parent asset.
2623+
Must have a parent ingredient.
2624+
- UPDATE: Restricted version of Edit for non-editorial changes.
2625+
Must have only one ingredient as a parent.
2626+
2627+
Args:
2628+
intent: The builder intent (C2paBuilderIntent enum value)
2629+
digital_source_type: The digital source type (required
2630+
for CREATE intent). Defaults to C2paDigitalSourceType.EMPTY
2631+
(for all other cases).
2632+
2633+
Raises:
2634+
C2paError: If there was an error setting the intent
2635+
"""
2636+
self._ensure_valid_state()
2637+
2638+
result = _lib.c2pa_builder_set_intent(
2639+
self._builder,
2640+
ctypes.c_uint(intent),
2641+
ctypes.c_uint(digital_source_type),
2642+
)
2643+
2644+
if result != 0:
2645+
error = _parse_operation_result_for_error(_lib.c2pa_error())
2646+
if error:
2647+
raise C2paError(error)
2648+
raise C2paError("Error setting intent for Builder: Unknown error")
2649+
25732650
def add_resource(self, uri: str, stream: Any):
25742651
"""Add a resource to the builder.
25752652

0 commit comments

Comments
 (0)