fast_resize 1.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bindings/ruby/ext/fastresize/extconf.rb +79 -105
- data/bindings/ruby/lib/fastresize/platform.rb +102 -56
- data/bindings/ruby/lib/fastresize/version.rb +1 -1
- data/bindings/ruby/lib/fastresize.rb +321 -6
- data/bindings/ruby/prebuilt/linux-aarch64/bin/fast_resize +0 -0
- data/bindings/ruby/prebuilt/linux-aarch64.tar.gz +0 -0
- data/bindings/ruby/prebuilt/linux-x86_64/bin/fast_resize +0 -0
- data/bindings/ruby/prebuilt/linux-x86_64/lib/libfastresize.a +0 -0
- data/bindings/ruby/prebuilt/linux-x86_64.tar.gz +0 -0
- data/bindings/ruby/prebuilt/macos-arm64/bin/fast_resize +0 -0
- data/bindings/ruby/prebuilt/macos-arm64/lib/libfastresize.a +0 -0
- data/bindings/ruby/prebuilt/macos-arm64.tar.gz +0 -0
- data/bindings/ruby/prebuilt/macos-x86_64/bin/fast_resize +0 -0
- data/bindings/ruby/prebuilt/macos-x86_64/lib/libfastresize.a +0 -0
- data/bindings/ruby/prebuilt/macos-x86_64.tar.gz +0 -0
- metadata +4 -22
- data/CMakeLists.txt +0 -311
- data/bindings/ruby/ext/fastresize/fastresize_ext.cpp +0 -377
- data/include/fastresize.h +0 -189
- data/include/stb_image.h +0 -7988
- data/include/stb_image_resize2.h +0 -10651
- data/include/stb_image_write.h +0 -1724
- data/src/cli.cpp +0 -540
- data/src/decoder.cpp +0 -647
- data/src/encoder.cpp +0 -376
- data/src/fastresize.cpp +0 -445
- data/src/internal.h +0 -108
- data/src/pipeline.cpp +0 -284
- data/src/pipeline.h +0 -175
- data/src/resizer.cpp +0 -199
- data/src/simd_resize.cpp +0 -384
- data/src/simd_resize.h +0 -72
- data/src/simd_utils.h +0 -127
- data/src/thread_pool.cpp +0 -232
data/src/fastresize.cpp
DELETED
|
@@ -1,445 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* FastResize - The Fastest Image Resizing Library On The Planet
|
|
3
|
-
* Copyright (C) 2025 Tran Huu Canh (0xTh3OKrypt) and FastResize Contributors
|
|
4
|
-
*
|
|
5
|
-
* Resize 1,000 images in 2 seconds. Up to 2.9x faster than libvips,
|
|
6
|
-
* 3.1x faster than imageflow. Uses 3-4x less RAM than alternatives.
|
|
7
|
-
*
|
|
8
|
-
* Author: Tran Huu Canh (0xTh3OKrypt)
|
|
9
|
-
* Email: tranhuucanh39@gmail.com
|
|
10
|
-
* Homepage: https://github.com/tranhuucanh/fast_resize
|
|
11
|
-
*
|
|
12
|
-
* BSD 3-Clause License
|
|
13
|
-
*
|
|
14
|
-
* Redistribution and use in source and binary forms, with or without
|
|
15
|
-
* modification, are permitted provided that the following conditions are met:
|
|
16
|
-
*
|
|
17
|
-
* 1. Redistributions of source code must retain the above copyright notice,
|
|
18
|
-
* this list of conditions and the following disclaimer.
|
|
19
|
-
*
|
|
20
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
21
|
-
* this list of conditions and the following disclaimer in the documentation
|
|
22
|
-
* and/or other materials provided with the distribution.
|
|
23
|
-
*
|
|
24
|
-
* 3. Neither the name of the copyright holder nor the names of its
|
|
25
|
-
* contributors may be used to endorse or promote products derived from
|
|
26
|
-
* this software without specific prior written permission.
|
|
27
|
-
*
|
|
28
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
29
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
30
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
31
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
32
|
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
33
|
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
34
|
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
35
|
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
36
|
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
37
|
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
38
|
-
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
#include "internal.h"
|
|
42
|
-
#include "pipeline.h"
|
|
43
|
-
#include <cstring>
|
|
44
|
-
#include <mutex>
|
|
45
|
-
|
|
46
|
-
namespace fastresize {
|
|
47
|
-
|
|
48
|
-
namespace {
|
|
49
|
-
std::mutex error_mutex;
|
|
50
|
-
ErrorCode last_error_code = OK;
|
|
51
|
-
std::string last_error_message;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
namespace internal {
|
|
55
|
-
void set_last_error(ErrorCode code, const std::string& message) {
|
|
56
|
-
std::lock_guard<std::mutex> lock(error_mutex);
|
|
57
|
-
last_error_code = code;
|
|
58
|
-
last_error_message = message;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
std::string get_last_error() {
|
|
63
|
-
std::lock_guard<std::mutex> lock(error_mutex);
|
|
64
|
-
return last_error_message;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
ErrorCode get_last_error_code() {
|
|
68
|
-
std::lock_guard<std::mutex> lock(error_mutex);
|
|
69
|
-
return last_error_code;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Validate resize options
|
|
73
|
-
static bool validate_options(const ResizeOptions& opts) {
|
|
74
|
-
switch (opts.mode) {
|
|
75
|
-
case ResizeOptions::SCALE_PERCENT:
|
|
76
|
-
if (opts.scale_percent <= 0) {
|
|
77
|
-
internal::set_last_error(RESIZE_ERROR, "Scale must be positive");
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
case ResizeOptions::FIT_WIDTH:
|
|
82
|
-
if (opts.target_width <= 0) {
|
|
83
|
-
internal::set_last_error(RESIZE_ERROR, "Width must be positive");
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
case ResizeOptions::FIT_HEIGHT:
|
|
88
|
-
if (opts.target_height <= 0) {
|
|
89
|
-
internal::set_last_error(RESIZE_ERROR, "Height must be positive");
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
break;
|
|
93
|
-
case ResizeOptions::EXACT_SIZE:
|
|
94
|
-
if (opts.target_width <= 0 || opts.target_height <= 0) {
|
|
95
|
-
internal::set_last_error(RESIZE_ERROR, "Width and height must be positive");
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (opts.quality < 1 || opts.quality > 100) {
|
|
102
|
-
internal::set_last_error(RESIZE_ERROR, "Quality must be between 1 and 100");
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
ImageInfo get_image_info(const std::string& path) {
|
|
110
|
-
ImageInfo info;
|
|
111
|
-
info.width = 0;
|
|
112
|
-
info.height = 0;
|
|
113
|
-
info.channels = 0;
|
|
114
|
-
|
|
115
|
-
internal::ImageFormat format = internal::detect_format(path);
|
|
116
|
-
if (format == internal::FORMAT_UNKNOWN) {
|
|
117
|
-
internal::set_last_error(UNSUPPORTED_FORMAT, "Unknown image format");
|
|
118
|
-
return info;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
info.format = internal::format_to_string(format);
|
|
122
|
-
|
|
123
|
-
if (!internal::get_image_dimensions(path, info.width, info.height, info.channels)) {
|
|
124
|
-
internal::set_last_error(DECODE_ERROR, "Failed to read image dimensions");
|
|
125
|
-
info.width = 0;
|
|
126
|
-
info.height = 0;
|
|
127
|
-
info.channels = 0;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return info;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
bool resize(
|
|
134
|
-
const std::string& input_path,
|
|
135
|
-
const std::string& output_path,
|
|
136
|
-
const ResizeOptions& options
|
|
137
|
-
) {
|
|
138
|
-
if (!validate_options(options)) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
internal::ImageFormat input_format = internal::detect_format(input_path);
|
|
143
|
-
if (input_format == internal::FORMAT_UNKNOWN) {
|
|
144
|
-
internal::set_last_error(UNSUPPORTED_FORMAT, "Unknown input image format");
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
internal::ImageFormat output_format = internal::detect_format(output_path);
|
|
149
|
-
if (output_format == internal::FORMAT_UNKNOWN) {
|
|
150
|
-
size_t dot_pos = output_path.find_last_of('.');
|
|
151
|
-
if (dot_pos != std::string::npos) {
|
|
152
|
-
std::string ext = output_path.substr(dot_pos + 1);
|
|
153
|
-
for (char& c : ext) {
|
|
154
|
-
if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a';
|
|
155
|
-
}
|
|
156
|
-
output_format = internal::string_to_format(ext);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (output_format == internal::FORMAT_UNKNOWN) {
|
|
160
|
-
output_format = input_format;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
internal::ImageData input_data = internal::decode_image(input_path, input_format);
|
|
165
|
-
if (!input_data.pixels) {
|
|
166
|
-
internal::set_last_error(DECODE_ERROR, "Failed to decode input image");
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
int output_w, output_h;
|
|
171
|
-
internal::calculate_dimensions(
|
|
172
|
-
input_data.width, input_data.height,
|
|
173
|
-
options,
|
|
174
|
-
output_w, output_h
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
unsigned char* output_pixels = nullptr;
|
|
178
|
-
bool resize_ok = internal::resize_image(
|
|
179
|
-
input_data.pixels,
|
|
180
|
-
input_data.width, input_data.height, input_data.channels,
|
|
181
|
-
&output_pixels,
|
|
182
|
-
output_w, output_h,
|
|
183
|
-
options
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
if (!resize_ok || !output_pixels) {
|
|
187
|
-
internal::free_image_data(input_data);
|
|
188
|
-
if (output_pixels) delete[] output_pixels;
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
internal::ImageData output_data;
|
|
193
|
-
output_data.pixels = output_pixels;
|
|
194
|
-
output_data.width = output_w;
|
|
195
|
-
output_data.height = output_h;
|
|
196
|
-
output_data.channels = input_data.channels;
|
|
197
|
-
|
|
198
|
-
bool encode_ok = internal::encode_image(output_path, output_data, output_format, options.quality);
|
|
199
|
-
|
|
200
|
-
internal::free_image_data(input_data);
|
|
201
|
-
delete[] output_pixels;
|
|
202
|
-
|
|
203
|
-
if (!encode_ok) {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
internal::set_last_error(OK, "");
|
|
208
|
-
return true;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
bool resize_with_format(
|
|
212
|
-
const std::string& input_path,
|
|
213
|
-
const std::string& output_path,
|
|
214
|
-
const std::string& output_format_str,
|
|
215
|
-
const ResizeOptions& options
|
|
216
|
-
) {
|
|
217
|
-
if (!validate_options(options)) {
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
internal::ImageFormat input_format = internal::detect_format(input_path);
|
|
222
|
-
if (input_format == internal::FORMAT_UNKNOWN) {
|
|
223
|
-
internal::set_last_error(UNSUPPORTED_FORMAT, "Unknown input image format");
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
internal::ImageFormat output_format = internal::string_to_format(output_format_str);
|
|
228
|
-
if (output_format == internal::FORMAT_UNKNOWN) {
|
|
229
|
-
internal::set_last_error(UNSUPPORTED_FORMAT, "Unknown output format: " + output_format_str);
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
internal::ImageData input_data = internal::decode_image(input_path, input_format);
|
|
234
|
-
if (!input_data.pixels) {
|
|
235
|
-
internal::set_last_error(DECODE_ERROR, "Failed to decode input image");
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
int output_w, output_h;
|
|
240
|
-
internal::calculate_dimensions(
|
|
241
|
-
input_data.width, input_data.height,
|
|
242
|
-
options,
|
|
243
|
-
output_w, output_h
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
unsigned char* output_pixels = nullptr;
|
|
247
|
-
bool resize_ok = internal::resize_image(
|
|
248
|
-
input_data.pixels,
|
|
249
|
-
input_data.width, input_data.height, input_data.channels,
|
|
250
|
-
&output_pixels,
|
|
251
|
-
output_w, output_h,
|
|
252
|
-
options
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
if (!resize_ok || !output_pixels) {
|
|
256
|
-
internal::free_image_data(input_data);
|
|
257
|
-
if (output_pixels) delete[] output_pixels;
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
internal::ImageData output_data;
|
|
262
|
-
output_data.pixels = output_pixels;
|
|
263
|
-
output_data.width = output_w;
|
|
264
|
-
output_data.height = output_h;
|
|
265
|
-
output_data.channels = input_data.channels;
|
|
266
|
-
|
|
267
|
-
bool encode_ok = internal::encode_image(output_path, output_data, output_format, options.quality);
|
|
268
|
-
|
|
269
|
-
internal::free_image_data(input_data);
|
|
270
|
-
delete[] output_pixels;
|
|
271
|
-
|
|
272
|
-
if (!encode_ok) {
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
internal::set_last_error(OK, "");
|
|
277
|
-
return true;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
namespace {
|
|
281
|
-
size_t calculate_optimal_threads(size_t batch_size, int requested_threads) {
|
|
282
|
-
if (requested_threads > 0) {
|
|
283
|
-
return static_cast<size_t>(requested_threads);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (batch_size < 5) {
|
|
287
|
-
return 1;
|
|
288
|
-
} else if (batch_size < 20) {
|
|
289
|
-
return 2;
|
|
290
|
-
} else if (batch_size < 50) {
|
|
291
|
-
return 4;
|
|
292
|
-
} else {
|
|
293
|
-
return 8;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
BatchResult batch_resize(
|
|
299
|
-
const std::vector<std::string>& input_paths,
|
|
300
|
-
const std::string& output_dir,
|
|
301
|
-
const ResizeOptions& options,
|
|
302
|
-
const BatchOptions& batch_opts
|
|
303
|
-
) {
|
|
304
|
-
BatchResult result;
|
|
305
|
-
result.total = static_cast<int>(input_paths.size());
|
|
306
|
-
result.success = 0;
|
|
307
|
-
result.failed = 0;
|
|
308
|
-
|
|
309
|
-
if (input_paths.empty()) {
|
|
310
|
-
return result;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (batch_opts.max_speed && input_paths.size() >= 20) {
|
|
314
|
-
std::vector<BatchItem> items;
|
|
315
|
-
items.reserve(input_paths.size());
|
|
316
|
-
|
|
317
|
-
for (const std::string& input_path : input_paths) {
|
|
318
|
-
BatchItem item;
|
|
319
|
-
item.input_path = input_path;
|
|
320
|
-
|
|
321
|
-
size_t last_slash = input_path.find_last_of("/\\");
|
|
322
|
-
std::string filename = (last_slash != std::string::npos)
|
|
323
|
-
? input_path.substr(last_slash + 1)
|
|
324
|
-
: input_path;
|
|
325
|
-
|
|
326
|
-
item.output_path = output_dir + "/" + filename;
|
|
327
|
-
item.options = options;
|
|
328
|
-
items.push_back(item);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return batch_resize_custom(items, batch_opts);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
size_t num_threads = calculate_optimal_threads(input_paths.size(), batch_opts.num_threads);
|
|
335
|
-
|
|
336
|
-
internal::ThreadPool* pool = internal::create_thread_pool(num_threads);
|
|
337
|
-
internal::BufferPool* buffer_pool = internal::create_buffer_pool();
|
|
338
|
-
|
|
339
|
-
std::mutex result_mutex;
|
|
340
|
-
std::atomic<bool> should_stop(false);
|
|
341
|
-
|
|
342
|
-
for (const std::string& input_path : input_paths) {
|
|
343
|
-
if (should_stop.load()) {
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
internal::thread_pool_enqueue(pool, [&, input_path]() {
|
|
348
|
-
if (should_stop.load()) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
size_t last_slash = input_path.find_last_of("/\\");
|
|
353
|
-
std::string filename = (last_slash != std::string::npos)
|
|
354
|
-
? input_path.substr(last_slash + 1)
|
|
355
|
-
: input_path;
|
|
356
|
-
|
|
357
|
-
std::string output_path = output_dir + "/" + filename;
|
|
358
|
-
|
|
359
|
-
bool success = resize(input_path, output_path, options);
|
|
360
|
-
|
|
361
|
-
{
|
|
362
|
-
std::lock_guard<std::mutex> lock(result_mutex);
|
|
363
|
-
if (success) {
|
|
364
|
-
result.success++;
|
|
365
|
-
} else {
|
|
366
|
-
result.failed++;
|
|
367
|
-
result.errors.push_back(input_path + ": " + get_last_error());
|
|
368
|
-
if (batch_opts.stop_on_error) {
|
|
369
|
-
should_stop.store(true);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
internal::thread_pool_wait(pool);
|
|
377
|
-
|
|
378
|
-
internal::destroy_buffer_pool(buffer_pool);
|
|
379
|
-
internal::destroy_thread_pool(pool);
|
|
380
|
-
|
|
381
|
-
return result;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
BatchResult batch_resize_custom(
|
|
385
|
-
const std::vector<BatchItem>& items,
|
|
386
|
-
const BatchOptions& batch_opts
|
|
387
|
-
) {
|
|
388
|
-
BatchResult result;
|
|
389
|
-
result.total = static_cast<int>(items.size());
|
|
390
|
-
result.success = 0;
|
|
391
|
-
result.failed = 0;
|
|
392
|
-
|
|
393
|
-
if (items.empty()) {
|
|
394
|
-
return result;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
if (batch_opts.max_speed && items.size() >= 20) {
|
|
398
|
-
internal::PipelineProcessor pipeline(4, 8, 4, 32);
|
|
399
|
-
return pipeline.process_batch(items);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
size_t num_threads = calculate_optimal_threads(items.size(), batch_opts.num_threads);
|
|
403
|
-
|
|
404
|
-
internal::ThreadPool* pool = internal::create_thread_pool(num_threads);
|
|
405
|
-
internal::BufferPool* buffer_pool = internal::create_buffer_pool();
|
|
406
|
-
|
|
407
|
-
std::mutex result_mutex;
|
|
408
|
-
std::atomic<bool> should_stop(false);
|
|
409
|
-
|
|
410
|
-
for (const BatchItem& item : items) {
|
|
411
|
-
if (should_stop.load()) {
|
|
412
|
-
break;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
internal::thread_pool_enqueue(pool, [&, item]() {
|
|
416
|
-
if (should_stop.load()) {
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
bool success = resize(item.input_path, item.output_path, item.options);
|
|
421
|
-
|
|
422
|
-
{
|
|
423
|
-
std::lock_guard<std::mutex> lock(result_mutex);
|
|
424
|
-
if (success) {
|
|
425
|
-
result.success++;
|
|
426
|
-
} else {
|
|
427
|
-
result.failed++;
|
|
428
|
-
result.errors.push_back(item.input_path + ": " + get_last_error());
|
|
429
|
-
if (batch_opts.stop_on_error) {
|
|
430
|
-
should_stop.store(true);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
internal::thread_pool_wait(pool);
|
|
438
|
-
|
|
439
|
-
internal::destroy_buffer_pool(buffer_pool);
|
|
440
|
-
internal::destroy_thread_pool(pool);
|
|
441
|
-
|
|
442
|
-
return result;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
}
|
data/src/internal.h
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* FastResize - The Fastest Image Resizing Library On The Planet
|
|
3
|
-
* Copyright (C) 2025 Tran Huu Canh (0xTh3OKrypt) and FastResize Contributors
|
|
4
|
-
*
|
|
5
|
-
* Resize 1,000 images in 2 seconds. Up to 2.9x faster than libvips,
|
|
6
|
-
* 3.1x faster than imageflow. Uses 3-4x less RAM than alternatives.
|
|
7
|
-
*
|
|
8
|
-
* Author: Tran Huu Canh (0xTh3OKrypt)
|
|
9
|
-
* Email: tranhuucanh39@gmail.com
|
|
10
|
-
* Homepage: https://github.com/tranhuucanh/fast_resize
|
|
11
|
-
*
|
|
12
|
-
* BSD 3-Clause License
|
|
13
|
-
*
|
|
14
|
-
* Redistribution and use in source and binary forms, with or without
|
|
15
|
-
* modification, are permitted provided that the following conditions are met:
|
|
16
|
-
*
|
|
17
|
-
* 1. Redistributions of source code must retain the above copyright notice,
|
|
18
|
-
* this list of conditions and the following disclaimer.
|
|
19
|
-
*
|
|
20
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
21
|
-
* this list of conditions and the following disclaimer in the documentation
|
|
22
|
-
* and/or other materials provided with the distribution.
|
|
23
|
-
*
|
|
24
|
-
* 3. Neither the name of the copyright holder nor the names of its
|
|
25
|
-
* contributors may be used to endorse or promote products derived from
|
|
26
|
-
* this software without specific prior written permission.
|
|
27
|
-
*
|
|
28
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
29
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
30
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
31
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
32
|
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
33
|
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
34
|
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
35
|
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
36
|
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
37
|
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
38
|
-
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
#ifndef FASTRESIZE_INTERNAL_H
|
|
42
|
-
#define FASTRESIZE_INTERNAL_H
|
|
43
|
-
|
|
44
|
-
#include <fastresize.h>
|
|
45
|
-
#include <string>
|
|
46
|
-
#include <functional>
|
|
47
|
-
|
|
48
|
-
namespace fastresize {
|
|
49
|
-
namespace internal {
|
|
50
|
-
|
|
51
|
-
class ThreadPool;
|
|
52
|
-
class BufferPool;
|
|
53
|
-
|
|
54
|
-
enum ImageFormat {
|
|
55
|
-
FORMAT_UNKNOWN,
|
|
56
|
-
FORMAT_JPEG,
|
|
57
|
-
FORMAT_PNG,
|
|
58
|
-
FORMAT_WEBP,
|
|
59
|
-
FORMAT_BMP
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
ImageFormat detect_format(const std::string& path);
|
|
63
|
-
std::string format_to_string(ImageFormat format);
|
|
64
|
-
ImageFormat string_to_format(const std::string& str);
|
|
65
|
-
|
|
66
|
-
struct ImageData {
|
|
67
|
-
unsigned char* pixels;
|
|
68
|
-
int width;
|
|
69
|
-
int height;
|
|
70
|
-
int channels;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
ImageData decode_image(const std::string& path, ImageFormat format);
|
|
74
|
-
void free_image_data(ImageData& data);
|
|
75
|
-
bool get_image_dimensions(const std::string& path, int& width, int& height, int& channels);
|
|
76
|
-
|
|
77
|
-
bool encode_image(const std::string& path, const ImageData& data, ImageFormat format, int quality, BufferPool* buffer_pool = nullptr);
|
|
78
|
-
|
|
79
|
-
void calculate_dimensions(
|
|
80
|
-
int in_w, int in_h,
|
|
81
|
-
const ResizeOptions& opts,
|
|
82
|
-
int& out_w, int& out_h
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
bool resize_image(
|
|
86
|
-
const unsigned char* input_pixels,
|
|
87
|
-
int input_w, int input_h, int channels,
|
|
88
|
-
unsigned char** output_pixels,
|
|
89
|
-
int output_w, int output_h,
|
|
90
|
-
const ResizeOptions& opts
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
void set_last_error(ErrorCode code, const std::string& message);
|
|
94
|
-
|
|
95
|
-
ThreadPool* create_thread_pool(size_t num_threads);
|
|
96
|
-
void destroy_thread_pool(ThreadPool* pool);
|
|
97
|
-
void thread_pool_enqueue(ThreadPool* pool, std::function<void()> task);
|
|
98
|
-
void thread_pool_wait(ThreadPool* pool);
|
|
99
|
-
|
|
100
|
-
BufferPool* create_buffer_pool();
|
|
101
|
-
void destroy_buffer_pool(BufferPool* pool);
|
|
102
|
-
unsigned char* buffer_pool_acquire(BufferPool* pool, size_t size);
|
|
103
|
-
void buffer_pool_release(BufferPool* pool, unsigned char* buffer, size_t capacity);
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
#endif
|