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
//! OxiGDAL Mobile SDK - FFI bindings for iOS and Android
//!
//! This crate provides C-compatible FFI bindings that enable OxiGDAL to be used
//! from iOS (Swift/Objective-C) and Android (Kotlin/Java) applications.
//!
//! # Architecture
//!
//! The mobile SDK is organized into several layers:
//!
//! - **FFI Layer** (`ffi` module): C-compatible types and functions
//! - **Platform Layer** (`ios`/`android` modules): Platform-specific utilities
//! - **Language Bindings** (Swift/Kotlin): High-level wrappers (in `bindings/` directory)
//!
//! # Safety
//!
//! While this crate uses `unsafe` extensively due to FFI requirements, it provides
//! safety guarantees through:
//!
//! - Extensive null pointer validation
//! - Bounds checking on all array operations
//! - UTF-8 validation on string conversions
//! - Proper resource lifecycle management
//! - Thread-safe error handling
//!
//! # Memory Management
//!
//! The FFI layer follows these conventions:
//!
//! - **Handles**: Created by `*_open` or `*_create`, freed by `*_close` or `*_free`
//! - **Strings**: Returned strings must be freed with `oxigdal_string_free`
//! - **Buffers**: Caller-allocated, OxiGDAL only writes to them
//! - **Opaque Types**: Must not be dereferenced on the foreign side
//!
//! # Error Handling
//!
//! All FFI functions return `OxiGdalErrorCode`:
//! - `Success` (0) indicates success
//! - Non-zero values indicate specific error types
//! - Detailed messages available via `oxigdal_get_last_error()`
//!
//! # Example (C API)
//!
//! ```c
//! // Initialize
//! oxigdal_init();
//!
//! // Open dataset
//! OxiGdalDataset* dataset;
//! if (oxigdal_dataset_open("/path/to/file.tif", &dataset) != Success) {
//! char* error = oxigdal_get_last_error();
//! printf("Error: %s\n", error);
//! oxigdal_string_free(error);
//! return;
//! }
//!
//! // Get metadata
//! OxiGdalMetadata metadata;
//! oxigdal_dataset_get_metadata(dataset, &metadata);
//! printf("Size: %d x %d\n", metadata.width, metadata.height);
//!
//! // Read region
//! OxiGdalBuffer* buffer = oxigdal_buffer_alloc(256, 256, 3);
//! oxigdal_dataset_read_region(dataset, 0, 0, 256, 256, 1, buffer);
//!
//! // Cleanup
//! oxigdal_buffer_free(buffer);
//! oxigdal_dataset_close(dataset);
//! oxigdal_cleanup();
//! ```
//!
//! # Features
//!
//! - `std` (default): Enable standard library support
//! - `ios`: Enable iOS-specific bindings
//! - `android`: Enable Android JNI bindings
//! - `offline`: Enable offline COG reading
//! - `filters`: Enable image enhancement filters
//! - `tiles`: Enable map tile generation
//!
//! # Platform Support
//!
//! ## iOS
//! - Target: `aarch64-apple-ios`, `x86_64-apple-ios` (simulator)
//! - Swift bindings available in `bindings/ios/`
//! - Integration: CocoaPods, Swift Package Manager
//!
//! ## Android
//! - Targets: `aarch64-linux-android`, `armv7-linux-androideabi`, `x86_64-linux-android`
//! - Kotlin bindings available in `bindings/android/`
//! - Integration: Gradle, AAR library
//!
//! # COOLJAPAN Policies
//!
//! This crate adheres to COOLJAPAN ecosystem policies:
//! - **Pure Rust**: No C/C++ dependencies by default
//! - **No Unwrap**: All error cases explicitly handled
//! - **Workspace**: Version management via workspace
//! - **Latest Crates**: Always use latest stable dependencies
// FFI code requires unsafe functions, unsafe blocks, and no_mangle symbols
// FFI code requires no_mangle for C symbol export
// FFI code uses expect() for internal invariant checks
// Allow unnecessary unsafe blocks (wrapped in outer unsafe fn)
// Allow unused variables in FFI (may be used conditionally)
// Allow unused imports in platform-specific code
// Allow manual div_ceil for compatibility
// Allow complex types in FFI interfaces
// Allow match collapsing warnings - explicit matches preferred in FFI
// Allow first element access with get(0)
// Allow too many arguments for complex FFI operations
// Allow unexpected cfg for conditional compilation
extern crate alloc;
// Re-export main types for convenience
pub use *;
pub use ;