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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bindings/ruby/ext/fastresize/extconf.rb +79 -105
  4. data/bindings/ruby/lib/fastresize/platform.rb +102 -56
  5. data/bindings/ruby/lib/fastresize/version.rb +1 -1
  6. data/bindings/ruby/lib/fastresize.rb +321 -6
  7. data/bindings/ruby/prebuilt/linux-aarch64/bin/fast_resize +0 -0
  8. data/bindings/ruby/prebuilt/linux-aarch64.tar.gz +0 -0
  9. data/bindings/ruby/prebuilt/linux-x86_64/bin/fast_resize +0 -0
  10. data/bindings/ruby/prebuilt/linux-x86_64/lib/libfastresize.a +0 -0
  11. data/bindings/ruby/prebuilt/linux-x86_64.tar.gz +0 -0
  12. data/bindings/ruby/prebuilt/macos-arm64/bin/fast_resize +0 -0
  13. data/bindings/ruby/prebuilt/macos-arm64/lib/libfastresize.a +0 -0
  14. data/bindings/ruby/prebuilt/macos-arm64.tar.gz +0 -0
  15. data/bindings/ruby/prebuilt/macos-x86_64/bin/fast_resize +0 -0
  16. data/bindings/ruby/prebuilt/macos-x86_64/lib/libfastresize.a +0 -0
  17. data/bindings/ruby/prebuilt/macos-x86_64.tar.gz +0 -0
  18. metadata +4 -22
  19. data/CMakeLists.txt +0 -311
  20. data/bindings/ruby/ext/fastresize/fastresize_ext.cpp +0 -377
  21. data/include/fastresize.h +0 -189
  22. data/include/stb_image.h +0 -7988
  23. data/include/stb_image_resize2.h +0 -10651
  24. data/include/stb_image_write.h +0 -1724
  25. data/src/cli.cpp +0 -540
  26. data/src/decoder.cpp +0 -647
  27. data/src/encoder.cpp +0 -376
  28. data/src/fastresize.cpp +0 -445
  29. data/src/internal.h +0 -108
  30. data/src/pipeline.cpp +0 -284
  31. data/src/pipeline.h +0 -175
  32. data/src/resizer.cpp +0 -199
  33. data/src/simd_resize.cpp +0 -384
  34. data/src/simd_resize.h +0 -72
  35. data/src/simd_utils.h +0 -127
  36. data/src/thread_pool.cpp +0 -232
data/src/thread_pool.cpp DELETED
@@ -1,232 +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 <thread>
43
- #include <mutex>
44
- #include <condition_variable>
45
- #include <queue>
46
- #include <functional>
47
- #include <atomic>
48
- #include <vector>
49
-
50
- namespace fastresize {
51
- namespace internal {
52
-
53
- class ThreadPool {
54
- public:
55
- explicit ThreadPool(size_t num_threads);
56
- ~ThreadPool();
57
-
58
- void enqueue(std::function<void()> task);
59
-
60
- void wait();
61
-
62
- size_t get_thread_count() const { return threads_.size(); }
63
-
64
- private:
65
- std::vector<std::thread> threads_;
66
- std::queue<std::function<void()>> tasks_;
67
- std::mutex queue_mutex_;
68
- std::condition_variable condition_;
69
- std::condition_variable wait_condition_;
70
- std::atomic<bool> stop_;
71
- std::atomic<int> active_tasks_;
72
- std::atomic<int> queued_tasks_;
73
- };
74
-
75
- ThreadPool::ThreadPool(size_t num_threads)
76
- : stop_(false)
77
- , active_tasks_(0)
78
- , queued_tasks_(0)
79
- {
80
- for (size_t i = 0; i < num_threads; ++i) {
81
- threads_.emplace_back([this] {
82
- while (true) {
83
- std::function<void()> task;
84
- {
85
- std::unique_lock<std::mutex> lock(queue_mutex_);
86
- condition_.wait(lock, [this] {
87
- return stop_ || !tasks_.empty();
88
- });
89
-
90
- if (stop_ && tasks_.empty())
91
- return;
92
-
93
- task = std::move(tasks_.front());
94
- tasks_.pop();
95
- --queued_tasks_;
96
- }
97
-
98
- ++active_tasks_;
99
- task();
100
- --active_tasks_;
101
- wait_condition_.notify_all();
102
- }
103
- });
104
- }
105
- }
106
-
107
- ThreadPool::~ThreadPool() {
108
- {
109
- std::unique_lock<std::mutex> lock(queue_mutex_);
110
- stop_ = true;
111
- }
112
- condition_.notify_all();
113
- for (std::thread& thread : threads_) {
114
- if (thread.joinable()) {
115
- thread.join();
116
- }
117
- }
118
- }
119
-
120
- void ThreadPool::enqueue(std::function<void()> task) {
121
- {
122
- std::unique_lock<std::mutex> lock(queue_mutex_);
123
- tasks_.emplace(std::move(task));
124
- ++queued_tasks_;
125
- }
126
- condition_.notify_one();
127
- }
128
-
129
- void ThreadPool::wait() {
130
- std::unique_lock<std::mutex> lock(queue_mutex_);
131
- wait_condition_.wait(lock, [this] {
132
- return queued_tasks_ == 0 && active_tasks_ == 0;
133
- });
134
- }
135
-
136
- class BufferPool {
137
- public:
138
- BufferPool() = default;
139
- ~BufferPool();
140
-
141
- unsigned char* acquire(size_t size);
142
- void release(unsigned char* buffer, size_t capacity);
143
-
144
- private:
145
- struct Buffer {
146
- unsigned char* data;
147
- size_t capacity;
148
- };
149
-
150
- std::vector<Buffer> pool_;
151
- std::mutex mutex_;
152
- };
153
-
154
- BufferPool::~BufferPool() {
155
- std::lock_guard<std::mutex> lock(mutex_);
156
- for (Buffer& buf : pool_) {
157
- delete[] buf.data;
158
- }
159
- pool_.clear();
160
- }
161
-
162
- unsigned char* BufferPool::acquire(size_t size) {
163
- std::lock_guard<std::mutex> lock(mutex_);
164
-
165
- for (auto it = pool_.begin(); it != pool_.end(); ++it) {
166
- if (it->capacity >= size) {
167
- unsigned char* buffer = it->data;
168
- pool_.erase(it);
169
- return buffer;
170
- }
171
- }
172
-
173
- return new unsigned char[size];
174
- }
175
-
176
- void BufferPool::release(unsigned char* buffer, size_t capacity) {
177
- if (!buffer) return;
178
-
179
- std::lock_guard<std::mutex> lock(mutex_);
180
-
181
- if (pool_.size() < 32) {
182
- Buffer buf;
183
- buf.data = buffer;
184
- buf.capacity = capacity;
185
- pool_.push_back(buf);
186
- } else {
187
- delete[] buffer;
188
- }
189
- }
190
-
191
- ThreadPool* create_thread_pool(size_t num_threads) {
192
- return new ThreadPool(num_threads);
193
- }
194
-
195
- void destroy_thread_pool(ThreadPool* pool) {
196
- delete pool;
197
- }
198
-
199
- void thread_pool_enqueue(ThreadPool* pool, std::function<void()> task) {
200
- if (pool) {
201
- pool->enqueue(std::move(task));
202
- }
203
- }
204
-
205
- void thread_pool_wait(ThreadPool* pool) {
206
- if (pool) {
207
- pool->wait();
208
- }
209
- }
210
-
211
- BufferPool* create_buffer_pool() {
212
- return new BufferPool();
213
- }
214
-
215
- void destroy_buffer_pool(BufferPool* pool) {
216
- delete pool;
217
- }
218
-
219
- unsigned char* buffer_pool_acquire(BufferPool* pool, size_t size) {
220
- return pool ? pool->acquire(size) : new unsigned char[size];
221
- }
222
-
223
- void buffer_pool_release(BufferPool* pool, unsigned char* buffer, size_t capacity) {
224
- if (pool) {
225
- pool->release(buffer, capacity);
226
- } else {
227
- delete[] buffer;
228
- }
229
- }
230
-
231
- }
232
- }