fast_resize 1.0.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.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/CMakeLists.txt +308 -0
  3. data/LICENSE +29 -0
  4. data/README.md +426 -0
  5. data/VERSION +1 -0
  6. data/bindings/ruby/ext/fastresize/extconf.rb +152 -0
  7. data/bindings/ruby/ext/fastresize/fastresize_ext.cpp +377 -0
  8. data/bindings/ruby/lib/fastresize/platform.rb +106 -0
  9. data/bindings/ruby/lib/fastresize/version.rb +5 -0
  10. data/bindings/ruby/lib/fastresize.rb +13 -0
  11. data/bindings/ruby/prebuilt/linux-aarch64/bin/fast_resize +0 -0
  12. data/bindings/ruby/prebuilt/linux-aarch64/include/fastresize.h +189 -0
  13. data/bindings/ruby/prebuilt/linux-aarch64/include/stb_image.h +7988 -0
  14. data/bindings/ruby/prebuilt/linux-aarch64/include/stb_image_resize2.h +10651 -0
  15. data/bindings/ruby/prebuilt/linux-aarch64/include/stb_image_write.h +1724 -0
  16. data/bindings/ruby/prebuilt/linux-aarch64/lib/libfastresize.a +0 -0
  17. data/bindings/ruby/prebuilt/linux-aarch64.tar.gz +0 -0
  18. data/bindings/ruby/prebuilt/linux-x86_64/bin/fast_resize +0 -0
  19. data/bindings/ruby/prebuilt/linux-x86_64/include/fastresize.h +189 -0
  20. data/bindings/ruby/prebuilt/linux-x86_64/include/stb_image.h +7988 -0
  21. data/bindings/ruby/prebuilt/linux-x86_64/include/stb_image_resize2.h +10651 -0
  22. data/bindings/ruby/prebuilt/linux-x86_64/include/stb_image_write.h +1724 -0
  23. data/bindings/ruby/prebuilt/linux-x86_64/lib/libfastresize.a +0 -0
  24. data/bindings/ruby/prebuilt/linux-x86_64.tar.gz +0 -0
  25. data/bindings/ruby/prebuilt/macos-arm64/bin/fast_resize +0 -0
  26. data/bindings/ruby/prebuilt/macos-arm64/include/fastresize.h +189 -0
  27. data/bindings/ruby/prebuilt/macos-arm64/include/stb_image.h +7988 -0
  28. data/bindings/ruby/prebuilt/macos-arm64/include/stb_image_resize2.h +10651 -0
  29. data/bindings/ruby/prebuilt/macos-arm64/include/stb_image_write.h +1724 -0
  30. data/bindings/ruby/prebuilt/macos-arm64/lib/libfastresize.a +0 -0
  31. data/bindings/ruby/prebuilt/macos-arm64.tar.gz +0 -0
  32. data/bindings/ruby/prebuilt/macos-x86_64/bin/fast_resize +0 -0
  33. data/bindings/ruby/prebuilt/macos-x86_64/include/fastresize.h +189 -0
  34. data/bindings/ruby/prebuilt/macos-x86_64/include/stb_image.h +7988 -0
  35. data/bindings/ruby/prebuilt/macos-x86_64/include/stb_image_resize2.h +10651 -0
  36. data/bindings/ruby/prebuilt/macos-x86_64/include/stb_image_write.h +1724 -0
  37. data/bindings/ruby/prebuilt/macos-x86_64/lib/libfastresize.a +0 -0
  38. data/bindings/ruby/prebuilt/macos-x86_64.tar.gz +0 -0
  39. data/include/fastresize.h +189 -0
  40. data/include/stb_image.h +7988 -0
  41. data/include/stb_image_resize2.h +10651 -0
  42. data/include/stb_image_write.h +1724 -0
  43. data/src/cli.cpp +540 -0
  44. data/src/decoder.cpp +647 -0
  45. data/src/encoder.cpp +376 -0
  46. data/src/fastresize.cpp +445 -0
  47. data/src/internal.h +108 -0
  48. data/src/pipeline.cpp +284 -0
  49. data/src/pipeline.h +175 -0
  50. data/src/resizer.cpp +199 -0
  51. data/src/simd_resize.cpp +384 -0
  52. data/src/simd_resize.h +72 -0
  53. data/src/simd_utils.h +127 -0
  54. data/src/thread_pool.cpp +232 -0
  55. metadata +158 -0
@@ -0,0 +1,189 @@
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_H
42
+ #define FASTRESIZE_H
43
+
44
+ #include <string>
45
+ #include <vector>
46
+
47
+ namespace fastresize {
48
+
49
+ // ============================================
50
+ // Core Structures
51
+ // ============================================
52
+
53
+ struct ResizeOptions {
54
+ // Resize mode
55
+ enum Mode {
56
+ SCALE_PERCENT, // Scale by percentage
57
+ FIT_WIDTH, // Fixed width, height auto
58
+ FIT_HEIGHT, // Fixed height, width auto
59
+ EXACT_SIZE // Exact width & height
60
+ } mode;
61
+
62
+ // Dimensions
63
+ int target_width; // Target width (pixels)
64
+ int target_height; // Target height (pixels)
65
+ float scale_percent; // Scale percentage (0.0-1.0)
66
+
67
+ // Options
68
+ bool keep_aspect_ratio; // Preserve aspect ratio (default: true)
69
+ bool overwrite_input; // Overwrite input file (default: false)
70
+
71
+ // Quality
72
+ int quality; // JPEG/WEBP quality 1-100 (default: 85)
73
+
74
+ // Filter
75
+ enum Filter {
76
+ MITCHELL, // Default, good balance
77
+ CATMULL_ROM, // Sharp edges
78
+ BOX, // Fast, lower quality
79
+ TRIANGLE // Bilinear
80
+ } filter;
81
+
82
+ // Constructor with defaults
83
+ ResizeOptions()
84
+ : mode(EXACT_SIZE)
85
+ , target_width(0)
86
+ , target_height(0)
87
+ , scale_percent(1.0f)
88
+ , keep_aspect_ratio(true)
89
+ , overwrite_input(false)
90
+ , quality(85)
91
+ , filter(MITCHELL)
92
+ {}
93
+ };
94
+
95
+ struct ImageInfo {
96
+ int width;
97
+ int height;
98
+ int channels; // 1=Gray, 3=RGB, 4=RGBA
99
+ std::string format; // "jpg", "png", "webp", "bmp"
100
+ };
101
+
102
+ // ============================================
103
+ // Single Image Resize
104
+ // ============================================
105
+
106
+ // Resize single image (auto-detect format)
107
+ bool resize(
108
+ const std::string& input_path,
109
+ const std::string& output_path,
110
+ const ResizeOptions& options
111
+ );
112
+
113
+ // Resize with explicit format
114
+ bool resize_with_format(
115
+ const std::string& input_path,
116
+ const std::string& output_path,
117
+ const std::string& output_format, // "jpg", "png", "webp", "bmp"
118
+ const ResizeOptions& options
119
+ );
120
+
121
+ // Get image info without loading
122
+ ImageInfo get_image_info(const std::string& path);
123
+
124
+ // ============================================
125
+ // Batch Processing
126
+ // ============================================
127
+
128
+ struct BatchItem {
129
+ std::string input_path;
130
+ std::string output_path;
131
+ ResizeOptions options; // Per-image options
132
+ };
133
+
134
+ struct BatchOptions {
135
+ int num_threads; // Thread pool size (0 = auto-detect, default: 0)
136
+ bool stop_on_error; // Stop if any image fails (default: false)
137
+ bool max_speed; // Enable Phase C pipeline (faster but uses more RAM, default: false)
138
+
139
+ BatchOptions()
140
+ : num_threads(0) // Phase A Optimization #7: Auto-detect thread count
141
+ , stop_on_error(false)
142
+ , max_speed(false) // Phase C: Default to balanced mode (no extra RAM)
143
+ {}
144
+ };
145
+
146
+ struct BatchResult {
147
+ int total; // Total images
148
+ int success; // Successfully processed
149
+ int failed; // Failed to process
150
+ std::vector<std::string> errors; // Error messages
151
+ };
152
+
153
+ // Batch resize - same options for all images
154
+ BatchResult batch_resize(
155
+ const std::vector<std::string>& input_paths,
156
+ const std::string& output_dir,
157
+ const ResizeOptions& options,
158
+ const BatchOptions& batch_opts = BatchOptions()
159
+ );
160
+
161
+ // Batch resize - individual options per image
162
+ BatchResult batch_resize_custom(
163
+ const std::vector<BatchItem>& items,
164
+ const BatchOptions& batch_opts = BatchOptions()
165
+ );
166
+
167
+ // ============================================
168
+ // Error Handling
169
+ // ============================================
170
+
171
+ // Get last error message
172
+ std::string get_last_error();
173
+
174
+ // Error codes
175
+ enum ErrorCode {
176
+ OK = 0,
177
+ FILE_NOT_FOUND,
178
+ UNSUPPORTED_FORMAT,
179
+ DECODE_ERROR,
180
+ RESIZE_ERROR,
181
+ ENCODE_ERROR,
182
+ WRITE_ERROR
183
+ };
184
+
185
+ ErrorCode get_last_error_code();
186
+
187
+ } // namespace fastresize
188
+
189
+ #endif // FASTRESIZE_H