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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: db4d679d44f55e55330bf72356fafd9bd297c3ed7ec874f9aa340efb852ae5b3
4
+ data.tar.gz: 65010fc04ff3553480cad0aef1679d1c08099a49b9cf5674ff79843640744959
5
+ SHA512:
6
+ metadata.gz: 6c75f1f8ddb58e98f1f488beb0747f4f5a5d6533438e56dc6ac6a031a73cdd9a256464c900c199fbec3fdac05a7b85fb56c58ca7bf2749efe3c475b153ddce87
7
+ data.tar.gz: f3964ea686e7888e9a46f6c169dad56a507815df96f333e3f364cb1b6ae1b45f16b1622ec84e86767ea5e0e1bd34315bb30cf2bb2793b6b3a74842fb659dd58a
data/CMakeLists.txt ADDED
@@ -0,0 +1,308 @@
1
+ cmake_minimum_required(VERSION 3.15)
2
+ project(fast_resize VERSION 1.0.0 LANGUAGES CXX C)
3
+
4
+ set(CMAKE_CXX_STANDARD 14)
5
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
6
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
7
+
8
+ # Optimization flags
9
+ if(NOT CMAKE_BUILD_TYPE)
10
+ set(CMAKE_BUILD_TYPE Release)
11
+ endif()
12
+
13
+ set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -flto")
14
+ set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG -flto")
15
+
16
+ # Option for building shared vs static libraries
17
+ option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
18
+
19
+ # Platform-specific optimizations
20
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
21
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
22
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native")
23
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|ARM64")
24
+ # ARM-specific flags
25
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
26
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
27
+ endif()
28
+
29
+ # Options
30
+ option(FASTRESIZE_STATIC "Build static library" ON)
31
+ option(FASTRESIZE_BUILD_TESTS "Build tests" ON)
32
+ option(FASTRESIZE_BUILD_EXAMPLES "Build examples" ON)
33
+ option(FASTRESIZE_BUILD_BENCHMARKS "Build benchmarks" ON)
34
+ option(FASTRESIZE_BUILD_RUBY "Build Ruby binding" ON)
35
+
36
+ # Find dependencies
37
+ find_package(PkgConfig REQUIRED)
38
+
39
+ # JPEG (libjpeg-turbo preferred)
40
+ pkg_check_modules(JPEG libjpeg)
41
+ if(NOT JPEG_FOUND)
42
+ find_package(JPEG REQUIRED)
43
+ endif()
44
+
45
+ # PNG
46
+ pkg_check_modules(PNG libpng)
47
+ if(NOT PNG_FOUND)
48
+ find_package(PNG REQUIRED)
49
+ endif()
50
+
51
+ # WebP
52
+ pkg_check_modules(WEBP libwebp libwebpdecoder libwebpdemux libsharpyuv)
53
+ if(NOT WEBP_FOUND)
54
+ message(WARNING "libwebp not found, WEBP support will be limited")
55
+ endif()
56
+
57
+ # Source files
58
+ set(FASTRESIZE_SOURCES
59
+ src/fastresize.cpp
60
+ src/decoder.cpp
61
+ src/encoder.cpp
62
+ src/resizer.cpp
63
+ src/thread_pool.cpp
64
+ src/pipeline.cpp
65
+ src/simd_resize.cpp
66
+ )
67
+
68
+ # Create library
69
+ add_library(fastresize ${FASTRESIZE_SOURCES})
70
+
71
+ target_include_directories(fastresize
72
+ PUBLIC
73
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
74
+ $<INSTALL_INTERFACE:include>
75
+ PRIVATE
76
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
77
+ ${JPEG_INCLUDE_DIRS}
78
+ ${PNG_INCLUDE_DIRS}
79
+ ${WEBP_INCLUDE_DIRS}
80
+ )
81
+
82
+ # Link with threading library
83
+ find_package(Threads REQUIRED)
84
+
85
+ # Link libraries - improved static library finding like FastQR
86
+ if(FASTRESIZE_STATIC OR NOT BUILD_SHARED_LIBS)
87
+ message(STATUS "🔧 Configuring for static linking")
88
+
89
+ # Find static libraries with explicit paths (like FastQR)
90
+ find_library(JPEG_STATIC_LIBRARY
91
+ NAMES libjpeg.a libturbojpeg.a
92
+ PATHS
93
+ /usr/local/lib
94
+ /opt/homebrew/lib
95
+ /usr/lib
96
+ /usr/lib/x86_64-linux-gnu
97
+ /usr/lib/aarch64-linux-gnu
98
+ NO_DEFAULT_PATH
99
+ )
100
+
101
+ find_library(PNG_STATIC_LIBRARY
102
+ NAMES libpng.a libpng16.a
103
+ PATHS
104
+ /usr/local/lib
105
+ /opt/homebrew/lib
106
+ /usr/lib
107
+ /usr/lib/x86_64-linux-gnu
108
+ /usr/lib/aarch64-linux-gnu
109
+ NO_DEFAULT_PATH
110
+ )
111
+
112
+ find_library(WEBP_STATIC_LIBRARY
113
+ NAMES libwebp.a
114
+ PATHS
115
+ /usr/local/lib
116
+ /opt/homebrew/lib
117
+ /usr/lib
118
+ /usr/lib/x86_64-linux-gnu
119
+ /usr/lib/aarch64-linux-gnu
120
+ NO_DEFAULT_PATH
121
+ )
122
+
123
+ find_library(SHARPYUV_STATIC_LIBRARY
124
+ NAMES libsharpyuv.a
125
+ PATHS
126
+ /usr/local/lib
127
+ /opt/homebrew/lib
128
+ /usr/lib
129
+ /usr/lib/x86_64-linux-gnu
130
+ /usr/lib/aarch64-linux-gnu
131
+ NO_DEFAULT_PATH
132
+ )
133
+
134
+ find_library(ZLIB_STATIC_LIBRARY
135
+ NAMES libz.a
136
+ PATHS
137
+ /usr/local/lib
138
+ /usr/local/opt/zlib/lib
139
+ /opt/homebrew/lib
140
+ /opt/homebrew/opt/zlib/lib
141
+ /usr/lib
142
+ /usr/lib/x86_64-linux-gnu
143
+ /usr/lib/aarch64-linux-gnu
144
+ NO_DEFAULT_PATH
145
+ )
146
+
147
+ message(STATUS "📚 Static libraries found:")
148
+ message(STATUS " JPEG: ${JPEG_STATIC_LIBRARY}")
149
+ message(STATUS " PNG: ${PNG_STATIC_LIBRARY}")
150
+ message(STATUS " WEBP: ${WEBP_STATIC_LIBRARY}")
151
+ message(STATUS " SHARPYUV: ${SHARPYUV_STATIC_LIBRARY}")
152
+ message(STATUS " ZLIB: ${ZLIB_STATIC_LIBRARY}")
153
+
154
+ # Link with required static libraries (check if they exist first)
155
+ if(JPEG_STATIC_LIBRARY AND PNG_STATIC_LIBRARY AND ZLIB_STATIC_LIBRARY)
156
+ target_link_libraries(fastresize PRIVATE
157
+ Threads::Threads
158
+ ${JPEG_STATIC_LIBRARY}
159
+ ${PNG_STATIC_LIBRARY}
160
+ ${ZLIB_STATIC_LIBRARY}
161
+ )
162
+
163
+ if(WEBP_STATIC_LIBRARY)
164
+ target_link_libraries(fastresize PRIVATE ${WEBP_STATIC_LIBRARY})
165
+ if(SHARPYUV_STATIC_LIBRARY)
166
+ target_link_libraries(fastresize PRIVATE ${SHARPYUV_STATIC_LIBRARY})
167
+ endif()
168
+ endif()
169
+ else()
170
+ message(WARNING "⚠️ Some static libraries not found, falling back to dynamic linking")
171
+ message(WARNING " JPEG: ${JPEG_STATIC_LIBRARY}")
172
+ message(WARNING " PNG: ${PNG_STATIC_LIBRARY}")
173
+ message(WARNING " ZLIB: ${ZLIB_STATIC_LIBRARY}")
174
+
175
+ target_link_libraries(fastresize PRIVATE
176
+ Threads::Threads
177
+ ${JPEG_LIBRARIES}
178
+ ${PNG_LIBRARIES}
179
+ )
180
+
181
+ if(WEBP_FOUND)
182
+ target_link_libraries(fastresize PRIVATE ${WEBP_LIBRARIES})
183
+ endif()
184
+ endif()
185
+
186
+ # On Linux: ensure full static linking
187
+ if(UNIX AND NOT APPLE)
188
+ target_link_options(fastresize PRIVATE -static-libgcc -static-libstdc++)
189
+ endif()
190
+ else()
191
+ message(STATUS "🔧 Configuring for dynamic linking")
192
+ target_link_libraries(fastresize PRIVATE
193
+ Threads::Threads
194
+ ${JPEG_LIBRARIES}
195
+ ${PNG_LIBRARIES}
196
+ )
197
+
198
+ if(WEBP_FOUND)
199
+ target_link_libraries(fastresize PRIVATE ${WEBP_LIBRARIES})
200
+ endif()
201
+ endif()
202
+
203
+ # ============================================================================
204
+ # CLI Tool
205
+ # ============================================================================
206
+
207
+ option(FASTRESIZE_BUILD_CLI "Build CLI tool" ON)
208
+
209
+ if(FASTRESIZE_BUILD_CLI)
210
+ message(STATUS "🔧 Building CLI tool")
211
+
212
+ # Read version from VERSION file
213
+ file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" FASTRESIZE_VERSION)
214
+ string(STRIP "${FASTRESIZE_VERSION}" FASTRESIZE_VERSION)
215
+
216
+ # CLI executable
217
+ add_executable(fast_resize-cli
218
+ src/cli.cpp
219
+ )
220
+
221
+ # Pass version to CLI
222
+ target_compile_definitions(fast_resize-cli PRIVATE
223
+ FASTRESIZE_VERSION="${FASTRESIZE_VERSION}"
224
+ )
225
+
226
+ # For standalone CLI binary, link statically
227
+ if(FASTRESIZE_STATIC OR NOT BUILD_SHARED_LIBS)
228
+ # Link CLI directly with library sources
229
+ target_sources(fast_resize-cli PRIVATE ${FASTRESIZE_SOURCES})
230
+
231
+ target_include_directories(fast_resize-cli PRIVATE
232
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
233
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
234
+ ${JPEG_INCLUDE_DIRS}
235
+ ${PNG_INCLUDE_DIRS}
236
+ ${WEBP_INCLUDE_DIRS}
237
+ )
238
+
239
+ # Link with static libraries
240
+ if(JPEG_STATIC_LIBRARY AND PNG_STATIC_LIBRARY AND ZLIB_STATIC_LIBRARY)
241
+ target_link_libraries(fast_resize-cli PRIVATE
242
+ Threads::Threads
243
+ ${JPEG_STATIC_LIBRARY}
244
+ ${PNG_STATIC_LIBRARY}
245
+ ${ZLIB_STATIC_LIBRARY}
246
+ )
247
+
248
+ if(WEBP_STATIC_LIBRARY)
249
+ target_link_libraries(fast_resize-cli PRIVATE ${WEBP_STATIC_LIBRARY})
250
+ if(SHARPYUV_STATIC_LIBRARY)
251
+ target_link_libraries(fast_resize-cli PRIVATE ${SHARPYUV_STATIC_LIBRARY})
252
+ endif()
253
+ endif()
254
+
255
+ # On Linux: ensure full static linking
256
+ if(UNIX AND NOT APPLE)
257
+ target_link_options(fast_resize-cli PRIVATE -static)
258
+ endif()
259
+ else()
260
+ # Fallback to library
261
+ target_link_libraries(fast_resize-cli PRIVATE fastresize)
262
+ endif()
263
+ else()
264
+ # Dynamic linking
265
+ target_link_libraries(fast_resize-cli PRIVATE fastresize)
266
+ endif()
267
+
268
+ # Set output name to fast_resize (without -cli suffix)
269
+ set_target_properties(fast_resize-cli PROPERTIES
270
+ OUTPUT_NAME fast_resize
271
+ )
272
+
273
+ # Install CLI
274
+ install(TARGETS fast_resize-cli
275
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
276
+ )
277
+ endif()
278
+
279
+ # Tests
280
+ if(FASTRESIZE_BUILD_TESTS)
281
+ enable_testing()
282
+ add_subdirectory(tests)
283
+ endif()
284
+
285
+ # Examples
286
+ if(FASTRESIZE_BUILD_EXAMPLES)
287
+ add_subdirectory(examples)
288
+ endif()
289
+
290
+ # Benchmarks
291
+ if(FASTRESIZE_BUILD_BENCHMARKS)
292
+ add_subdirectory(benchmark)
293
+ endif()
294
+
295
+ # Install
296
+ include(GNUInstallDirs)
297
+
298
+ install(TARGETS fastresize
299
+ EXPORT fastresize-targets
300
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
301
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
302
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
303
+ )
304
+
305
+ install(DIRECTORY include/
306
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
307
+ FILES_MATCHING PATTERN "*.h"
308
+ )
data/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, Tran Huu Canh <tranhuucanh39@gmail.com>
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.