|
48 | 48 | 'c2pa_builder_free', |
49 | 49 | 'c2pa_builder_set_no_embed', |
50 | 50 | 'c2pa_builder_set_remote_url', |
| 51 | + 'c2pa_builder_set_intent', |
51 | 52 | 'c2pa_builder_add_resource', |
52 | 53 | 'c2pa_builder_add_ingredient_from_stream', |
53 | 54 | 'c2pa_builder_add_action', |
@@ -158,6 +159,37 @@ class C2paSigningAlg(enum.IntEnum): |
158 | 159 | ED25519 = 6 |
159 | 160 |
|
160 | 161 |
|
| 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 | + |
161 | 193 | # Mapping from C2paSigningAlg enum to string representation, |
162 | 194 | # as the enum value currently maps by default to an integer value. |
163 | 195 | _ALG_TO_STRING_BYTES_MAPPING = { |
@@ -258,6 +290,7 @@ def _clear_error_state(): |
258 | 290 | # Free the error to clear the state |
259 | 291 | _lib.c2pa_string_free(error) |
260 | 292 |
|
| 293 | + |
261 | 294 | class C2paSignerInfo(ctypes.Structure): |
262 | 295 | """Configuration for a Signer.""" |
263 | 296 | _fields_ = [ |
@@ -414,6 +447,10 @@ def _setup_function(func, argtypes, restype=None): |
414 | 447 | _setup_function( |
415 | 448 | _lib.c2pa_builder_set_remote_url, [ |
416 | 449 | 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) |
417 | 454 | _setup_function(_lib.c2pa_builder_add_resource, [ctypes.POINTER( |
418 | 455 | C2paBuilder), ctypes.c_char_p, ctypes.POINTER(C2paStream)], ctypes.c_int) |
419 | 456 | _setup_function(_lib.c2pa_builder_add_ingredient_from_stream, |
@@ -2570,6 +2607,46 @@ def set_remote_url(self, remote_url: str): |
2570 | 2607 | raise C2paError( |
2571 | 2608 | Builder._ERROR_MESSAGES['url_error'].format("Unknown error")) |
2572 | 2609 |
|
| 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 | + |
2573 | 2650 | def add_resource(self, uri: str, stream: Any): |
2574 | 2651 | """Add a resource to the builder. |
2575 | 2652 |
|
|
0 commit comments