Repository navigation
Expand file tree
/
Copy pathrawdinal.h
More file actions
395 lines (354 loc) · 17.4 KB
/
Copy pathrawdinal.h
File metadata and controls
395 lines (354 loc) · 17.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/* SPDX-License-Identifier: GPL-3.0-only */
/* Copyright (C) 2026 Paolo SANTUCCI */
#ifndef RAWDINAL_H
#define RAWDINAL_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct rawdinal_image rawdinal_image;
typedef struct rawdinal_sensor_v1_image rawdinal_sensor_v1_image;
typedef struct rawdinal_raw_v1_image rawdinal_raw_v1_image;
#define RAWDINAL_STATUS_OK INT32_C(0)
#define RAWDINAL_STATUS_ERROR INT32_C(1)
#define RAWDINAL_STATUS_PANIC INT32_C(2)
#define RAWDINAL_STATUS_UNSUPPORTED INT32_C(3)
#define RAWDINAL_STATUS_INVALID_INPUT INT32_C(4)
#define RAWDINAL_STATUS_RESOURCE_LIMIT INT32_C(5)
#define RAWDINAL_STATUS_ALLOCATION INT32_C(6)
#define RAWDINAL_STATUS_NOT_RECOGNIZED INT32_C(7)
#define RAWDINAL_RAW_V1_INFO_VERSION UINT32_C(1)
#define RAWDINAL_RAW_V1_PROBE_INFO_VERSION UINT32_C(1)
#define RAWDINAL_RAW_V1_CAPABILITIES_VERSION UINT32_C(1)
#define RAWDINAL_CLIPPING_V1_INFO_VERSION UINT32_C(1)
#define RAWDINAL_CLIPPING_V1_THRESHOLD_UNKNOWN UINT32_C(0)
#define RAWDINAL_CLIPPING_V1_THRESHOLD_ESTIMATED_ENCODED_MAXIMUM UINT32_C(1)
#define RAWDINAL_CLIPPING_V1_THRESHOLD_CALIBRATED UINT32_C(2)
#define RAWDINAL_RAW_V1_PROCESSING_NOT_PRESENT UINT32_C(0)
#define RAWDINAL_RAW_V1_PROCESSING_APPLIED UINT32_C(1)
#define RAWDINAL_RAW_V1_PROCESSING_UNAPPLIED UINT32_C(2)
#define RAWDINAL_RAW_V1_PROCESSING_UNKNOWN UINT32_C(3)
#define RAWDINAL_RAW_V1_PROCESSING_SKIPPED_OPTIONAL UINT32_C(4)
#define RAWDINAL_RAW_V1_PROBE_NOT_RECOGNIZED UINT32_C(0)
#define RAWDINAL_RAW_V1_PROBE_SUPPORTED UINT32_C(1)
#define RAWDINAL_RAW_V1_PROBE_RECOGNIZED_UNSUPPORTED UINT32_C(2)
#define RAWDINAL_RAW_V1_CONTAINER_UNKNOWN UINT32_C(0)
#define RAWDINAL_RAW_V1_CONTAINER_DNG UINT32_C(1)
#define RAWDINAL_RAW_V1_CONTAINER_X3F UINT32_C(2)
#define RAWDINAL_RAW_V1_CODEC_UNKNOWN UINT32_C(0)
#define RAWDINAL_RAW_V1_CODEC_LOSSLESS_JPEG UINT32_C(1)
#define RAWDINAL_RAW_V1_CODEC_JPEG_XL UINT32_C(2)
#define RAWDINAL_RAW_V1_CODEC_BIT_LOSSLESS_JPEG UINT32_C(1)
#define RAWDINAL_RAW_V1_CODEC_BIT_JPEG_XL UINT32_C(2)
#define RAWDINAL_RAW_V1_TIFF_BYTE_ORDER_UNKNOWN UINT32_C(0)
#define RAWDINAL_RAW_V1_TIFF_BYTE_ORDER_LITTLE_ENDIAN UINT32_C(1)
#define RAWDINAL_RAW_V1_TIFF_BYTE_ORDER_BIG_ENDIAN UINT32_C(2)
#define RAWDINAL_RAW_V1_COLORIMETRIC_REFERENCE_SCENE_REFERRED UINT32_C(0)
#define RAWDINAL_RAW_V1_COLORIMETRIC_REFERENCE_OUTPUT_REFERRED UINT32_C(1)
#define RAWDINAL_RAW_V1_FALSE UINT32_C(0)
#define RAWDINAL_RAW_V1_TRUE UINT32_C(1)
typedef struct rawdinal_raw_v1_info
{
uint32_t version;
uint32_t reserved;
uint32_t width;
uint32_t height;
uint32_t channels;
size_t stride_samples;
size_t sample_count;
const float *samples;
const uint8_t *component_ids;
size_t component_id_count;
uint8_t dng_version[4];
uint8_t dng_backward_version[4];
uint32_t dng_backward_version_present;
uint32_t tiff_byte_order;
const uint8_t *make;
size_t make_length;
const uint8_t *model;
size_t model_length;
uint32_t active_area_top;
uint32_t active_area_left;
uint32_t active_area_bottom;
uint32_t active_area_right;
uint32_t orientation;
uint32_t orientation_present;
uint32_t default_crop_origin_x;
uint32_t default_crop_origin_y;
uint32_t default_crop_origin_present;
uint32_t default_crop_size_width;
uint32_t default_crop_size_height;
uint32_t default_crop_size_present;
uint32_t linearization;
uint32_t black_subtraction;
uint32_t white_normalization;
uint32_t white_balance;
uint32_t color_conversion;
uint32_t default_crop;
uint32_t orientation_processing;
uint32_t baseline_exposure;
uint32_t profile_tone_curve;
uint32_t demosaic;
uint32_t opcode_list_1;
uint32_t opcode_list_2;
uint32_t opcode_list_3;
uint32_t profile_gain_table_map_processing;
uint32_t semantic_masks;
const uint8_t *profile_gain_table_map;
size_t profile_gain_table_map_length;
uint32_t scene_linear;
uint32_t camera_native;
uint32_t already_demosaiced;
uint32_t colorimetric_reference;
uint32_t colorimetric_reference_present;
} rawdinal_raw_v1_info;
typedef struct rawdinal_raw_v1_probe_info
{
uint32_t version;
uint32_t reserved;
uint32_t classification;
uint32_t container;
uint32_t codec;
uint32_t width;
uint32_t height;
uint32_t channels;
} rawdinal_raw_v1_probe_info;
typedef struct rawdinal_raw_v1_capabilities
{
uint32_t version;
uint32_t reserved;
uint32_t codec_bits;
uint32_t reserved2;
} rawdinal_raw_v1_capabilities;
#define RAWDINAL_RAW_V1_CODEC_UNCOMPRESSED UINT32_C(3)
#define RAWDINAL_RAW_V1_CODEC_LOSSY_JPEG UINT32_C(4)
#define RAWDINAL_RAW_V1_CODEC_BIT_UNCOMPRESSED UINT32_C(4)
#define RAWDINAL_RAW_V1_CODEC_BIT_LOSSY_JPEG UINT32_C(8)
#define RAWDINAL_RAW_V1_PROCESSING_PARTIALLY_APPLIED UINT32_C(5)
#define RAWDINAL_RAW_V1_RETAIN_ENCODED UINT32_C(1)
#define RAWDINAL_RAW_V1_RETAIN_FLAGS UINT32_C(2)
#define RAWDINAL_RAW_V1_DECODE_MASKS UINT32_C(4)
#define RAWDINAL_RAW_V1_SAMPLE_ENCODED_MAXIMUM UINT8_C(1)
#define RAWDINAL_RAW_V1_SAMPLE_DECLARED_WHITE UINT8_C(2)
#define RAWDINAL_RAW_V1_SAMPLE_OUTSIDE_ACTIVE UINT8_C(4)
#define RAWDINAL_RAW_V1_SAMPLE_OPCODE_PROCESSED UINT8_C(8)
typedef struct rawdinal_raw_v1_metadata
{
uint32_t version;
uint32_t root_offset;
uint32_t raw_offset;
uint32_t valid_area[4];
uint32_t crop_origin_present;
uint32_t crop_size_present;
double crop_origin[2];
double crop_size[2];
size_t directory_count;
const uint16_t *encoded_samples;
size_t encoded_sample_count;
const uint8_t *sample_flags;
size_t sample_flag_count;
size_t mask_count;
} rawdinal_raw_v1_metadata;
typedef struct rawdinal_raw_v1_directory
{
uint32_t offset;
uint32_t parent_offset;
size_t tag_count;
} rawdinal_raw_v1_directory;
typedef struct rawdinal_raw_v1_tag
{
uint16_t id;
uint16_t field_type;
uint32_t count;
const uint8_t *data;
size_t byte_count;
} rawdinal_raw_v1_tag;
typedef struct rawdinal_raw_v1_mask
{
uint32_t ifd_offset;
uint32_t width;
uint32_t height;
uint32_t sub_area_present;
uint32_t sub_area[4];
const uint8_t *name;
size_t name_length;
const uint8_t *instance_id;
size_t instance_id_length;
const uint8_t *samples;
size_t sample_count;
} rawdinal_raw_v1_mask;
typedef uint32_t rawdinal_sensor_v1_plane_id;
#define RAWDINAL_SENSOR_V1_BOTTOM UINT32_C(0)
#define RAWDINAL_SENSOR_V1_MIDDLE UINT32_C(1)
#define RAWDINAL_SENSOR_V1_TOP UINT32_C(2)
typedef struct rawdinal_sensor_v1_plane
{
rawdinal_sensor_v1_plane_id identity;
uint32_t reserved;
size_t width;
size_t height;
size_t stride_samples;
size_t sample_count;
const uint16_t *samples;
} rawdinal_sensor_v1_plane;
typedef struct rawdinal_info
{
uint32_t width;
uint32_t height;
const uint8_t *exif;
size_t exif_size;
} rawdinal_info;
typedef struct rawdinal_clipping_v1_plane
{
uint32_t identity;
uint32_t threshold_code;
uint32_t threshold_provenance;
uint32_t reserved;
size_t width;
size_t height;
size_t stride_bytes;
size_t byte_count;
const uint8_t *data;
} rawdinal_clipping_v1_plane;
typedef struct rawdinal_clipping_v1_info
{
uint32_t version;
uint32_t reserved;
size_t width;
size_t height;
size_t stride_bytes;
size_t byte_count;
const uint8_t *data;
rawdinal_clipping_v1_plane planes[3];
} rawdinal_clipping_v1_info;
/** Borrow the camera JPEG for metadata or thumbnails. The returned storage belongs
* to the input mapping and expires with it. Returns zero on success. */
int32_t rawdinal_preview(const uint8_t *data, size_t length, const uint8_t **preview, size_t *preview_length);
/** Decode to experimental linear sRGB. Returns zero on success. Input storage is
* borrowed only during the call. The caller releases *output with rawdinal_free.
* All output pointers must refer to writable, nonoverlapping storage. The EXIF
* pointer in info is borrowed from the handle and expires when it is released. */
int32_t rawdinal_decode(const uint8_t *data, size_t length, rawdinal_image **output,
rawdinal_info *info, char *error, size_t error_capacity);
/** Decode to experimental linear sRGB and retain version-1 clipping provenance. Ownership,
* argument, error, and release rules are identical to rawdinal_decode. */
int32_t rawdinal_decode_with_clipping_v1(const uint8_t *data, size_t length,
rawdinal_image **output, rawdinal_info *info,
char *error, size_t error_capacity);
/** Copy to width*height*4 caller-owned floats without clipping. Alpha is one.
* The image handle must remain live and the destination must not overlap it. */
int32_t rawdinal_copy_rgba(const rawdinal_image *image, float *destination, size_t float_count);
/** Borrow version-1 estimated encoded-maximum clipping provenance from a handle returned by
* rawdinal_decode_with_clipping_v1. The combined output mask has
* one byte per output pixel and native planes are bottom, middle, top. A nonzero byte means that
* contributing source support met its layer's estimated encoded maximum; it does not indicate
* calibrated physical saturation. All pointers expire with rawdinal_free. Output must be writable
* and disjoint from the handle and its owned storage, is cleared on failure, and the handle must
* not be accessed or released concurrently. */
int32_t rawdinal_get_clipping_v1(const rawdinal_image *image,
rawdinal_clipping_v1_info *output);
/** Release exactly once after all reads. Null is accepted. */
void rawdinal_free(rawdinal_image *image);
/** Decode the observed Merrill, dp Quattro, sd Quattro and sd Quattro H sensor layouts
* without calibration, reconstruction, white balance or color conversion. Samples are
* uncalibrated. Input storage is borrowed only during the call. Output must be writable,
* disjoint from all other arguments and must not contain an unreleased handle. It is cleared
* on failure. Error may be null; otherwise it must be writable and disjoint. Returns
* RAWDINAL_STATUS_OK, RAWDINAL_STATUS_ERROR or RAWDINAL_STATUS_PANIC. The caller releases a
* successful output with rawdinal_sensor_v1_free. */
int32_t rawdinal_sensor_v1_decode(const uint8_t *data, size_t length,
rawdinal_sensor_v1_image **output,
char *error, size_t error_capacity);
/** Borrow one decoded uint16 plane from the handle. Rows contain width samples and
* stride_samples is expressed in uint16 samples. Dimensions preserve the full encoded
* layout and can exceed nominal image dimensions. The pointer expires when the handle is
* released. Output must be writable and disjoint from the handle and its owned storage; it is
* cleared on failure. The handle must not be released or accessed concurrently. */
int32_t rawdinal_sensor_v1_get_plane(const rawdinal_sensor_v1_image *image,
rawdinal_sensor_v1_plane_id identity,
rawdinal_sensor_v1_plane *output);
/** Borrow decompressed, uninterpreted CAMF bytes from the handle. The pointer
* expires when the handle is released. Data and length must be writable, disjoint from each
* other and handle storage; both are cleared on failure. The handle must not be released or
* accessed concurrently. */
int32_t rawdinal_sensor_v1_get_camf(const rawdinal_sensor_v1_image *image,
const uint8_t **data, size_t *length);
/** Borrow TIFF/EXIF bytes copied from the JPEG preview. Empty output is valid
* when no readable EXIF block exists. The pointer expires with the handle. Data and length
* must be writable, disjoint from each other and handle storage; both are cleared on failure.
* The handle must not be released or accessed concurrently. */
int32_t rawdinal_sensor_v1_get_exif(const rawdinal_sensor_v1_image *image,
const uint8_t **data, size_t *length);
/** Release exactly once after all sensor, CAMF and EXIF reads. Null is accepted. */
void rawdinal_sensor_v1_free(rawdinal_sensor_v1_image *image);
/** Decode the supported Apple ProRAW DNG tiled linear-raw layout. Input is borrowed only during
* this call. Output must be writable, must not contain a live handle, and must be disjoint from
* input and error. Error may be null; otherwise its error_capacity bytes must be writable and
* disjoint from input and output. On success, output owns decoded samples and metadata and must
* be released with rawdinal_raw_v1_free. Output is cleared and error is NUL-terminated on
* failure. Unsupported inputs return RAWDINAL_STATUS_UNSUPPORTED; malformed inputs, limits, and
* allocation failures return their respective detailed status. Arbitrary or non-DNG input returns
* RAWDINAL_STATUS_NOT_RECOGNIZED; recognized X3F and valid unsupported DNG return
* RAWDINAL_STATUS_UNSUPPORTED. */
int32_t rawdinal_raw_v1_decode(const uint8_t *data, size_t length,
rawdinal_raw_v1_image **output,
char *error, size_t error_capacity);
/** Borrow a fixed version-1 descriptor from a live decoded handle. Width, height, ActiveArea,
* and default crop values are pixels; ActiveArea is half-open stored coordinates and an absent
* ActiveArea expands to the stored image. Crop origin is relative to ActiveArea. Orientation is
* the DNG value 1 through 8. Stride and sample count are float samples in chunky, interleaved
* component_ids and calibration-channel order. Make, model, component IDs, samples, and
* ProfileGainTableMap are byte or float arrays and are not NUL-terminated unless their lengths
* include such a byte. tiff_byte_order interprets ProfileGainTableMap bytes. Presence fields make
* optional values meaningful; absent colorimetric_reference defaults to SCENE_REFERRED.
* Processing values use RAWDINAL_RAW_V1_PROCESSING_* and classification fields use
* RAWDINAL_RAW_V1_TRUE/FALSE. Scoped TIFF metadata, including calibration and EXIF fields, is
* available through rawdinal_raw_v1_get_metadata/get_directory/get_tag. Private embedded offsets
* may still require the original file. Fractional crop values are available through get_metadata;
* the integer fields are absent when a value is fractional. All borrowed pointers expire with
* the handle. The handle must not be accessed
* or released concurrently, and output must be writable and disjoint from handle-owned storage.
* Output is zeroed on failure. */
int32_t rawdinal_raw_v1_get_info(const rawdinal_raw_v1_image *image,
rawdinal_raw_v1_info *output);
/** Probe bounded input without decoding samples. Output must be writable and disjoint from input
* and error. Error may be null; otherwise it must be writable and disjoint. A successful call
* returns a RAWDINAL_RAW_V1_PROBE_* classification; malformed input and resource failures clear
* output and return their detailed statuses. */
int32_t rawdinal_raw_v1_probe(const uint8_t *data, size_t length,
rawdinal_raw_v1_probe_info *output,
char *error, size_t error_capacity);
/** Write immutable raw-v1 decoder capabilities. Output must be writable and is zeroed on failure. */
int32_t rawdinal_raw_v1_get_capabilities(rawdinal_raw_v1_capabilities *output);
/** Release a raw-v1 handle exactly once after all descriptor reads. Null is accepted. */
void rawdinal_raw_v1_free(rawdinal_raw_v1_image *image);
/** Extended decoding has the same ownership contract as rawdinal_raw_v1_decode.
* Flags are RETAIN_ENCODED, RETAIN_FLAGS and DECODE_MASKS, ORed together; other bits are invalid.
* Encoded samples precede list 1. Sample flags describe encoded maxima/declared white, never
* measured photosite saturation. OPCODE_PROCESSED conservatively marks the whole image. */
int32_t rawdinal_raw_v1_decode_extended(const uint8_t *data, size_t length, uint32_t flags,
rawdinal_raw_v1_image **output, char *error, size_t error_capacity);
/** Metadata getters borrow handle-owned arrays until rawdinal_raw_v1_free. Outputs must be
* writable and disjoint from handle storage and are zeroed on error. The handle must remain live
* and cannot be accessed or freed concurrently. Directory and tag indices are zero-based.
* Metadata root/raw offsets identify scope; fields from previews are never substituted for them.
* valid_area is half-open stored-image coordinates. Crop doubles preserve rational fractions.
* Mask sub_area is [top,left,full_width,full_height], not a bottom/right rectangle. Masks are
* untransformed uint8 weights; dividing by 255 yields unit weights, with no gamma conversion. */
int32_t rawdinal_raw_v1_get_metadata(const rawdinal_raw_v1_image *image, rawdinal_raw_v1_metadata *output);
int32_t rawdinal_raw_v1_get_directory(const rawdinal_raw_v1_image *image, size_t index,
rawdinal_raw_v1_directory *output);
int32_t rawdinal_raw_v1_get_tag(const rawdinal_raw_v1_image *image, size_t directory, size_t index,
rawdinal_raw_v1_tag *output);
int32_t rawdinal_raw_v1_get_mask(const rawdinal_raw_v1_image *image, size_t index,
rawdinal_raw_v1_mask *output);
/** Copy a numeric TIFF tag as doubles. Count must exactly match the tag's component count.
* Output must reference count writable doubles disjoint from the handle and remains untouched
* on failure. The handle must remain live and cannot be accessed or freed concurrently. */
int32_t rawdinal_raw_v1_copy_tag_numbers(const rawdinal_raw_v1_image *image, size_t directory,
size_t index, double *output, size_t count);
#ifdef __cplusplus
}
#endif
#endif