@g9tm/lynxcontrols-native 2.6.19 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -1
- package/android/build.gradle.kts +7 -0
- package/android/src/main/java/com/g9lynx/g9native/G9NativeImages.kt +16 -0
- package/android/src/main/java/com/g9lynx/g9native/canvas/G9CanvasModel.kt +2 -2
- package/android/src/main/java/com/g9lynx/g9native/canvas/G9CanvasPaths.kt +7 -26
- package/android/src/main/java/com/g9lynx/g9native/canvas/G9CanvasView.kt +9 -4
- package/android/src/main/java/com/g9lynx/g9native/generated/G9ImageModuleSpec.java +27 -0
- package/android/src/main/java/com/g9lynx/g9native/image/G9HostTypeface.kt +49 -0
- package/android/src/main/java/com/g9lynx/g9native/image/G9ImageDraw.kt +222 -0
- package/android/src/main/java/com/g9lynx/g9native/image/G9ImageModule.kt +54 -0
- package/android/src/main/java/com/g9lynx/g9native/image/G9ImageProcessor.kt +464 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9HostFont.kt +28 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageBudget.kt +54 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageColor.kt +48 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageError.kt +19 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageExifTags.kt +61 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageFiles.kt +99 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageGeometry.kt +150 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageJson.kt +200 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageQuality.kt +65 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageRedaction.kt +77 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageService.kt +102 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageSniff.kt +63 -0
- package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageSpec.kt +237 -0
- package/catalog/catalog.json +161 -1
- package/catalog/index.md +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/image.d.ts +219 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +116 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/protocol.d.ts +12 -0
- package/dist/protocol.d.ts.map +1 -1
- package/generated/G9ImageModule.ts +64 -0
- package/ios/Tests/G9NativeTestSuite.h +8 -0
- package/ios/Tests/G9NativeTestSuite.m +350 -0
- package/ios/Tests/G9NativeTests.m +16 -0
- package/ios/g9lynx-native-swift.podspec +1 -1
- package/ios/g9lynx-native.podspec +5 -4
- package/ios/src/G9ImageModule.h +30 -0
- package/ios/src/G9ImageModule.m +986 -0
- package/ios/src/core/G9ImageCore.h +201 -0
- package/ios/src/core/G9ImageCore.m +1039 -0
- package/ios/src/generated/G9ImageModuleSpec.h +16 -0
- package/ios/src/generated/G9ImageModuleSpec.m +2 -0
- package/ios/swift/canvas/G9LCCanvasCore.swift +3 -2
- package/ios/swift/canvas/G9LCCanvasView.swift +15 -4
- package/ios/swift/shared/G9LCFonts.swift +18 -2
- package/package.json +4 -4
- package/types/platform-native-module.d.ts +18 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// The platform-free decisions of G9ImageModule on iOS (the G9PhotoEditor native contract, 2.7.0): the EXIF orientation
|
|
2
|
+
// and box math, the subsample, the quality search, unique names, colours, SVG path data, the metadata filter and the
|
|
3
|
+
// validation of every method's JSON. Foundation only (no blocks, no literals, explicit ivars), so the Linux harness
|
|
4
|
+
// (`npm run test:ios-core`) runs it; ImageIO, Core Graphics, Core Image and Core Text live in G9ImageModule.m.
|
|
5
|
+
// TWIN: the Android core of G9ImageModule.
|
|
6
|
+
#import <Foundation/Foundation.h>
|
|
7
|
+
|
|
8
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
9
|
+
|
|
10
|
+
/** x' = a·x + c·y + e, y' = b·x + d·y + f (the contract's `matrix` and CGAffineTransform's order). */
|
|
11
|
+
typedef struct {
|
|
12
|
+
double a, b, c, d, e, f;
|
|
13
|
+
} G9ImageAffine;
|
|
14
|
+
|
|
15
|
+
/** A pixel box: origin and size, top-left origin. Empty when width or height is 0. */
|
|
16
|
+
typedef struct {
|
|
17
|
+
double x, y, width, height;
|
|
18
|
+
} G9ImageBox;
|
|
19
|
+
|
|
20
|
+
/** One SVG path segment, absolute: move (p0,p1), line (p0,p1), cubic (c1, c2, end), quad (c, end), close. */
|
|
21
|
+
typedef enum { G9PathMove = 0, G9PathLine = 1, G9PathCubic = 2, G9PathQuad = 3, G9PathClose = 4 } G9PathOp;
|
|
22
|
+
|
|
23
|
+
typedef struct {
|
|
24
|
+
int op;
|
|
25
|
+
double p[6];
|
|
26
|
+
} G9PathSegment;
|
|
27
|
+
|
|
28
|
+
extern NSString *const G9ImageErrorInvalidArgument; // invalid-argument
|
|
29
|
+
extern NSString *const G9ImageErrorNotFound; // not-found
|
|
30
|
+
extern NSString *const G9ImageErrorDecode; // decode
|
|
31
|
+
extern NSString *const G9ImageErrorMemory; // memory
|
|
32
|
+
extern NSString *const G9ImageErrorIO; // io
|
|
33
|
+
extern NSString *const G9ImageErrorCancelled; // cancelled
|
|
34
|
+
extern NSString *const G9ImageErrorUnsupported; // unsupported
|
|
35
|
+
|
|
36
|
+
G9ImageAffine G9ImageAffineIdentity(void);
|
|
37
|
+
/** `outer ∘ inner`: first `inner`, then `outer`. */
|
|
38
|
+
G9ImageAffine G9ImageAffineConcat(G9ImageAffine outer, G9ImageAffine inner);
|
|
39
|
+
/** The inverse, or `ok = NO` (and the identity) when singular. */
|
|
40
|
+
G9ImageAffine G9ImageAffineInvert(G9ImageAffine m, BOOL *_Nullable ok);
|
|
41
|
+
void G9ImageAffineApply(G9ImageAffine m, double x, double y, double *outX, double *outY);
|
|
42
|
+
|
|
43
|
+
/** Answers the quality search's question: the encoded size at a quality (0..100), or < 0 when encoding failed. */
|
|
44
|
+
@protocol G9ImageQualityEncoder <NSObject>
|
|
45
|
+
- (long long)byteCountAtQuality:(NSInteger)quality;
|
|
46
|
+
@end
|
|
47
|
+
|
|
48
|
+
@interface G9ImageCore : NSObject
|
|
49
|
+
|
|
50
|
+
// ---- orientation and boxes ----
|
|
51
|
+
/** 1..8; anything else is 1. */
|
|
52
|
+
+ (NSInteger)normalizedOrientation:(NSInteger)orientation;
|
|
53
|
+
/** YES for 5..8 (the picture is turned a quarter: width and height swap). */
|
|
54
|
+
+ (BOOL)orientationSwapsAxes:(NSInteger)orientation;
|
|
55
|
+
/** The size a person sees: the raw size with the axes swapped for orientations 5..8. */
|
|
56
|
+
+ (void)orientedSizeForRawWidth:(double)rawWidth
|
|
57
|
+
rawHeight:(double)rawHeight
|
|
58
|
+
orientation:(NSInteger)orientation
|
|
59
|
+
width:(double *)width
|
|
60
|
+
height:(double *)height;
|
|
61
|
+
/** Oriented (displayed) source px → raw (stored) px for an EXIF orientation of a raw `rawWidth` × `rawHeight` file. */
|
|
62
|
+
+ (G9ImageAffine)orientedToRawForOrientation:(NSInteger)orientation rawWidth:(double)rawWidth rawHeight:(double)rawHeight;
|
|
63
|
+
/**
|
|
64
|
+
* Pipeline step 2: the four output corners through `matrix` (output px → oriented px), their bounding box plus `margin`
|
|
65
|
+
* px clamped to the oriented picture, then the same box in the RAW file through the orientation, whole pixels, clamped
|
|
66
|
+
* to the raw size. Empty when the output does not touch the picture.
|
|
67
|
+
*/
|
|
68
|
+
+ (G9ImageBox)rawBoxForOutputWidth:(double)width
|
|
69
|
+
height:(double)height
|
|
70
|
+
matrix:(G9ImageAffine)matrix
|
|
71
|
+
orientation:(NSInteger)orientation
|
|
72
|
+
rawWidth:(double)rawWidth
|
|
73
|
+
rawHeight:(double)rawHeight
|
|
74
|
+
margin:(double)margin;
|
|
75
|
+
/** Source px per output px along the matrix's tighter axis (min of its column lengths). */
|
|
76
|
+
+ (double)sourcePixelsPerOutputPixel:(G9ImageAffine)matrix;
|
|
77
|
+
/** The ImageIO subsample: the largest of 1, 2, 4, 8 that is ≤ `sourcePerOutput` (whole source px per output px). */
|
|
78
|
+
+ (NSInteger)subsampleForSourcePerOutput:(double)sourcePerOutput;
|
|
79
|
+
/** Preview: the thumbnail's longest side, `maxSide` but never above the picture's own longest side (no upscale). */
|
|
80
|
+
+ (NSInteger)previewMaxPixelForMaxSide:(NSInteger)maxSide width:(double)width height:(double)height;
|
|
81
|
+
|
|
82
|
+
// ---- encoding ----
|
|
83
|
+
/** The quality floor of the maxBytes search: 30, or the asked quality when it is lower. */
|
|
84
|
+
+ (NSInteger)qualityFloorForQuality:(NSInteger)quality;
|
|
85
|
+
/**
|
|
86
|
+
* The highest quality in [floor, start] whose encoding fits `maxBytes` (start is tried first, then a binary search
|
|
87
|
+
* below it), or -1 when even the floor is too big (the caller scales the output by 0.85 and searches again).
|
|
88
|
+
* `attempts` (optional) receives the number of encodings asked for.
|
|
89
|
+
*/
|
|
90
|
+
+ (NSInteger)qualityForMaxBytes:(long long)maxBytes
|
|
91
|
+
start:(NSInteger)start
|
|
92
|
+
floor:(NSInteger)floor
|
|
93
|
+
encoder:(id<G9ImageQualityEncoder>)encoder
|
|
94
|
+
attempts:(NSInteger *_Nullable)attempts;
|
|
95
|
+
/** One maxBytes scale step: round(value · 0.85), at least 1. */
|
|
96
|
+
+ (NSInteger)scaledDimension:(NSInteger)value;
|
|
97
|
+
/**
|
|
98
|
+
* Another maxBytes scale step is allowed: the shorter side stays at 16 px or more after it. When it is not, the limit
|
|
99
|
+
* cannot be met: process answers `invalid-argument` and writes no file.
|
|
100
|
+
*/
|
|
101
|
+
+ (BOOL)canScaleWidth:(NSInteger)width height:(NSInteger)height;
|
|
102
|
+
/** A text overlay's line height: 1.25 × its size. */
|
|
103
|
+
+ (double)lineHeightForSize:(double)size;
|
|
104
|
+
/**
|
|
105
|
+
* What is written for a requested format (`jpeg`, `png`, `webp`, `source`) and the source's mime: `jpeg`, `png` or
|
|
106
|
+
* `webp`. `webp` only when the device can encode it (iOS has no WebP encoder: JPEG); `source` keeps JPEG and PNG, a
|
|
107
|
+
* HEIC (and any other) source becomes JPEG, or PNG when it has alpha.
|
|
108
|
+
*/
|
|
109
|
+
+ (NSString *)outputFormatForRequested:(NSString *)requested
|
|
110
|
+
sourceMime:(nullable NSString *)sourceMime
|
|
111
|
+
hasAlpha:(BOOL)hasAlpha
|
|
112
|
+
webpEncodable:(BOOL)webpEncodable;
|
|
113
|
+
/** YES for `png` and `webp` (formats with transparency). */
|
|
114
|
+
+ (BOOL)formatHasAlpha:(NSString *)format;
|
|
115
|
+
+ (NSString *)mimeForFormat:(NSString *)format;
|
|
116
|
+
/** File extension without the dot: jpg, png, webp, heic, gif, tiff, bmp; `img` for anything unknown. */
|
|
117
|
+
+ (NSString *)extensionForFormat:(NSString *)format;
|
|
118
|
+
/** ImageIO type identifier (`public.jpeg`, …) → mime; `application/octet-stream` when unknown. */
|
|
119
|
+
+ (NSString *)mimeForTypeIdentifier:(nullable NSString *)typeIdentifier;
|
|
120
|
+
/** mime → the contract's format word (`jpeg`, `png`, `webp`, `heic`, `gif`, `tiff`, `bmp`), nil when unknown. */
|
|
121
|
+
+ (nullable NSString *)formatForMime:(nullable NSString *)mime;
|
|
122
|
+
|
|
123
|
+
// ---- redactions and text ----
|
|
124
|
+
/** pixelate block = max(4, strength·0.08·min(W,H)) px, strength clamped to 0..1. */
|
|
125
|
+
+ (double)pixelateBlockForStrength:(double)strength width:(double)width height:(double)height;
|
|
126
|
+
/** blur radius = max(2, strength·0.05·min(W,H)) px, strength clamped to 0..1. */
|
|
127
|
+
+ (double)blurRadiusForStrength:(double)strength width:(double)width height:(double)height;
|
|
128
|
+
/** CSS weight 100..900 → Core Text's weight trait (-1..1, the UIFontWeight values). */
|
|
129
|
+
+ (double)fontWeightTraitForWeight:(double)weight;
|
|
130
|
+
|
|
131
|
+
// ---- names and paths ----
|
|
132
|
+
/** `g9photo-<epoch ms>-<4 hex>` from the low 16 bits of `random`. */
|
|
133
|
+
+ (NSString *)defaultNameForEpochMs:(long long)epochMs random:(uint32_t)random;
|
|
134
|
+
/** A base name the caller gave is usable: non-empty, no `/`, `\`, NUL, not `.` or `..`. */
|
|
135
|
+
+ (BOOL)isUsableName:(NSString *)name;
|
|
136
|
+
/** `<dir>/<base>.<ext>`, or `<dir>/<base>-1.<ext>`, `-2`, … the first that does not exist yet. */
|
|
137
|
+
+ (NSString *)uniquePathInDirectory:(NSString *)directory base:(NSString *)base extension:(NSString *)extension;
|
|
138
|
+
/** A plain path or a `file://` URI (percent-decoded) → a path; nil for other schemes (`content://`) and empty input. */
|
|
139
|
+
+ (nullable NSString *)filePathFromString:(nullable NSString *)value;
|
|
140
|
+
|
|
141
|
+
// ---- colours ----
|
|
142
|
+
/**
|
|
143
|
+
* CSS colour → RGBA 0..1 (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb()`/`rgba()` with commas or spaces and `/`,
|
|
144
|
+
* percentages, `transparent`, `black`, `white`). NO for anything else (`rgba` untouched).
|
|
145
|
+
*/
|
|
146
|
+
+ (BOOL)parseColor:(nullable NSString *)value rgba:(double *)rgba;
|
|
147
|
+
|
|
148
|
+
// ---- SVG path data ----
|
|
149
|
+
/** `d` (M L H V C S Q T Z, absolute or relative, implicit repeats) → absolute segments (NSData of G9PathSegment). */
|
|
150
|
+
+ (NSData *)pathSegmentsFromData:(nullable NSString *)d;
|
|
151
|
+
|
|
152
|
+
// ---- metadata ----
|
|
153
|
+
/**
|
|
154
|
+
* keepMetadata: the source's ImageIO properties for the output: the EXIF, EXIF aux, GPS, TIFF and IPTC dictionaries
|
|
155
|
+
* and the DPI kept (GPS, dates, camera, description), Orientation = 1 (top level and TIFF), the pixel dimensions, the
|
|
156
|
+
* subject area and every other top-level key (thumbnails, JFIF, colour model, profile) dropped.
|
|
157
|
+
*/
|
|
158
|
+
+ (NSDictionary *)outputMetadataFromSourceProperties:(nullable NSDictionary *)properties;
|
|
159
|
+
|
|
160
|
+
// ---- JSON ----
|
|
161
|
+
/** The JSON text → an object, or nil (the caller answers invalid-argument). */
|
|
162
|
+
+ (nullable id)objectFromJSON:(nullable NSString *)json;
|
|
163
|
+
/** `{"ok":true,"value":value}` as JSON text (nil value → `{}`). */
|
|
164
|
+
+ (NSString *)okReply:(nullable id)value;
|
|
165
|
+
/** `{"ok":false,"error":{"code","message"}}` as JSON text. */
|
|
166
|
+
+ (NSString *)failReply:(NSString *)code message:(nullable NSString *)message;
|
|
167
|
+
/** probe/preview/cancel arguments: the path (or `token`) checked; nil + `message` on a bad argument. */
|
|
168
|
+
+ (nullable NSDictionary *)validateProbeArguments:(nullable id)args message:(NSString *_Nullable *_Nullable)message;
|
|
169
|
+
+ (nullable NSDictionary *)validatePreviewArguments:(nullable id)args message:(NSString *_Nullable *_Nullable)message;
|
|
170
|
+
+ (nullable NSDictionary *)validateCancelArguments:(nullable id)args message:(NSString *_Nullable *_Nullable)message;
|
|
171
|
+
/**
|
|
172
|
+
* process: the spec with its defaults filled in and every field checked (types, ranges, colours, modes); nil +
|
|
173
|
+
* `message` on the first problem. Keys: token (string or absent), path, width, height (integers ≥ 1), matrix (6
|
|
174
|
+
* numbers; identity when absent; width and height 1..20000), background (string or absent), circle, redact (normalized regions), overlay
|
|
175
|
+
* (normalized ops), format, quality, maxBytes (0 = none), keepMetadata (default NO), passthrough, dir, name.
|
|
176
|
+
*/
|
|
177
|
+
+ (nullable NSDictionary *)validateProcessSpec:(nullable id)spec message:(NSString *_Nullable *_Nullable)message;
|
|
178
|
+
/** The spec's matrix as an affine. */
|
|
179
|
+
+ (G9ImageAffine)affineFromArray:(nullable NSArray *)values;
|
|
180
|
+
|
|
181
|
+
@end
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The tokens of the queued and running process calls. `cancel` marks a pending token; the work checks between steps.
|
|
185
|
+
* Thread-safe.
|
|
186
|
+
*/
|
|
187
|
+
@interface G9ImageCancelRegistry : NSObject {
|
|
188
|
+
@private
|
|
189
|
+
NSMutableSet *_pending;
|
|
190
|
+
NSMutableSet *_cancelled;
|
|
191
|
+
}
|
|
192
|
+
/** A process with this token was queued (nil / empty tokens are not tracked). */
|
|
193
|
+
- (void)begin:(nullable NSString *)token;
|
|
194
|
+
/** Marks a pending token cancelled; NO when no queued or running process has it. */
|
|
195
|
+
- (BOOL)cancel:(nullable NSString *)token;
|
|
196
|
+
- (BOOL)isCancelled:(nullable NSString *)token;
|
|
197
|
+
/** The process ended (either way): forget the token. */
|
|
198
|
+
- (void)end:(nullable NSString *)token;
|
|
199
|
+
@end
|
|
200
|
+
|
|
201
|
+
NS_ASSUME_NONNULL_END
|