contrek 1.1.2 → 1.1.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +6 -1
  4. data/Gemfile.lock +1 -1
  5. data/LICENSE-MIT.md +9 -0
  6. data/README.md +41 -1
  7. data/contrek.gemspec +0 -1
  8. data/ext/cpp_polygon_finder/PolygonFinder/CMakeLists.txt +14 -2
  9. data/ext/cpp_polygon_finder/PolygonFinder/LICENSE_AGPL.txt +661 -0
  10. data/ext/cpp_polygon_finder/PolygonFinder/examples/example.cpp +9 -7
  11. data/ext/cpp_polygon_finder/PolygonFinder/src/ContrekApi.h +9 -0
  12. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.cpp +2 -0
  13. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/FinderUtils.cpp +13 -2
  14. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.cpp +74 -82
  15. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.h +12 -4
  16. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.cpp +0 -10
  17. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.h +0 -7
  18. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.cpp +39 -39
  19. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.h +10 -10
  20. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.cpp +24 -39
  21. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.h +5 -7
  22. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.cpp +6 -4
  23. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.h +4 -3
  24. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.cpp +9 -3
  25. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Finder.cpp +1 -0
  26. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.cpp +33 -0
  27. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.h +5 -1
  28. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.cpp +8 -8
  29. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.h +2 -1
  30. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.cpp +13 -0
  31. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.h +2 -0
  32. data/ext/cpp_polygon_finder/extconf.rb +12 -2
  33. data/lib/contrek/bitmaps/painting.rb +1 -0
  34. data/lib/contrek/finder/concurrent/cursor.rb +5 -5
  35. data/lib/contrek/finder/concurrent/finder.rb +2 -1
  36. data/lib/contrek/finder/concurrent/part.rb +12 -3
  37. data/lib/contrek/finder/concurrent/partitionable.rb +7 -5
  38. data/lib/contrek/finder/node.rb +41 -29
  39. data/lib/contrek/finder/node_cluster.rb +18 -12
  40. data/lib/contrek/finder/polygon_finder.rb +4 -3
  41. data/lib/contrek/version.rb +1 -1
  42. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8abb44d773af1b51fdc2221f9e50ff2afb46d6bc4bd42b71eaa9700da1ac9577
4
- data.tar.gz: 1b71d411f6bc37881eb1c39c6b4ccbe893406beffb94075e1f79c2ff1efe38ed
3
+ metadata.gz: 60fae59ed14c24cedd7dadfdc33dea05188b1131ee6443b59591e5243cb4710b
4
+ data.tar.gz: b565f7a0e9713a9389329cf1cc44f9c2da36908d75c538af625afdb6e1d9d71a
5
5
  SHA512:
6
- metadata.gz: 34caa00be7af90a31e9aad3b8f345cff66a55cd8ccc876aa45b5fa8f4893ef004d446abd41b18f8905124a4ceecf08cdaf2d3e7c5446d8d1dbcc1b07b0483b81
7
- data.tar.gz: c029a220fdafe602153d31ec9962313449b706e55e99b483e1b8cabc20037438938768ebba39c1bb22b081ffd53296eb831da677949de3f5406948c699a8752d
6
+ metadata.gz: 86ece9b65041fae9aec64173f5e3bb719971852a6327953b78dc6567f94018db544cc8b7e062d57aad3a859f8142982406e1d9301716f2a49eaa8a05a586ddfc
7
+ data.tar.gz: 87a22df67016a3249a069cec0bee1746ddb92c1103f9a98e0a8e85b2240ae7d4be735123cfa72443432b30a91be333c4d195b384b194f5703a075b4832e07bd6
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  /pkg/
2
2
 
3
+ .ruby-version
3
4
  # rspec failure tracking
4
5
  .rspec_status
5
6
 
data/CHANGELOG.md CHANGED
@@ -47,4 +47,9 @@ All notable changes to this project will be documented in this file.
47
47
 
48
48
  ## [1.1.2] - 2026-02-09
49
49
  ### Changed
50
- - Transitioned to an Open Core licensing model: Ruby Gem (MIT) and C++ Core Engine (AGPLv3).
50
+ - Transitioned to an Open Core licensing model: Ruby Gem (MIT) and C++ Core Engine (AGPLv3).
51
+
52
+ ## [1.1.3] - 2026-02-21
53
+ ### Changed
54
+ - Added support for 8-way pixel connectivity (omnidirectional) in addition to the standard 4-way mode.
55
+ - Optimized C++ and Ruby algorithms for initial spatial pixel tracking to improve performance.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- contrek (1.1.0)
4
+ contrek (1.1.3)
5
5
  chunky_png (~> 1.4)
6
6
  concurrent-ruby (~> 1.3.5)
7
7
  rice (= 4.5.0)
data/LICENSE-MIT.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License
2
+
3
+ Copyright 2018 -- 2026 by Emanuele Cesaroni.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,12 +1,25 @@
1
1
  # Contrek
2
2
  Contrek is a Ruby gem powered by a <u>standalone C++17 core library</u> for fast contour tracing and edge detection in PNG images. It employs a **topological approach** to extract polygonal contours, representing shapes as a connected graph of shared endpoints. This ensures perfect adjacency and structural integrity for shape analysis and raster-to-vector workflows, such as PNG to SVG conversion, managed via libspng (0.7.4) with multithreading support.
3
3
 
4
+
4
5
  ## About Contrek library
6
+
5
7
  Contrek (**con**tour **trek**king) simply scans your png bitmap and returns shape contour as close polygonal lines, both for the external and internal sides. It can compute the nesting level of the polygons found with a tree structure. It supports various levels and modes of compression and approximation of the found coordinates. It is capable of multithreaded processing, splitting the image into vertical strips and recombining the coordinates in pairs.
6
8
 
7
9
  In the following image all the non-white pixels have been examined and the result is the red polygon for the outer contour and the green one for the inner one
8
10
  ![alt text](contrek.png "Contour tracing")
9
11
 
12
+
13
+ ## Prerequisites
14
+
15
+ For optimal performance and efficient memory management with large images (20k+), it is highly recommended to install **tcmalloc**.
16
+
17
+ **Ubuntu / Debian:**
18
+ ```bash
19
+ sudo apt-get install libgoogle-perftools-dev
20
+ ```
21
+
22
+
10
23
  ## Install
11
24
 
12
25
  Add this line to your application's Gemfile:
@@ -122,6 +135,33 @@ puts result.metadata[:benchmarks].inspect
122
135
 
123
136
  ```
124
137
 
138
+ ### Connectivity Modes
139
+
140
+ Contrek supports different pixel connectivity rules to define how polygons are traced and merged. This is controlled by the `:connectivity` option.
141
+
142
+ | Value | Name | Type | Description |
143
+ | :--- | :--- | :--- | :--- |
144
+ | `4` | **Orthogonal** | Default | Only pixels sharing an edge (N, S, E, W) are connected. |
145
+ | `8` | **Omnidirectional** | Extended | Includes diagonal neighbors (sharing a corner). |
146
+
147
+
148
+ To enable **Omnidirectional** (8-way) connectivity, pass `connectivity: 8` in the options hash:
149
+
150
+ ```ruby
151
+ result = Contrek.contour!(
152
+ png_file_path: "./spec/files/images/sample_10240x10240.png",
153
+ options: {
154
+ number_of_threads: 4,
155
+ class: "value_not_matcher",
156
+ color: {r: 255, g: 255, b: 255, a: 255},
157
+ finder: {
158
+ number_of_tiles: 4,
159
+ connectivity: 8, # 8 for Omnidirectional, 4 for Orthogonal
160
+ compress: {uniq: true}}
161
+ }
162
+ )
163
+ ```
164
+
125
165
  ## Result
126
166
 
127
167
  The result structure contains polygon coordinates and a set of metadata. Polygon coordinates can be accessed via:
@@ -338,7 +378,7 @@ int main() {
338
378
 
339
379
  ## License
340
380
 
341
- This project is licensed under the terms of the MIT license.
381
+ This project is licensed under the terms of a dual-license.
342
382
 
343
383
  See [LICENSE.md](LICENSE.md).
344
384
 
data/contrek.gemspec CHANGED
@@ -15,7 +15,6 @@ Gem::Specification.new do |s|
15
15
  end
16
16
  s.metadata = {
17
17
  "homepage_uri" => "https://github.com/runout77/contrek",
18
- "source_code_uri" => "https://github.com/runout77/contrek",
19
18
  "documentation_uri" => "https://github.com/runout77/contrek#readme",
20
19
  "changelog_uri" => "https://github.com/runout77/contrek/blob/main/CHANGELOG.md"
21
20
  }
@@ -3,11 +3,19 @@ project(ContrekCore C CXX)
3
3
 
4
4
  set(CMAKE_CXX_STANDARD 17)
5
5
  set(CMAKE_C_STANDARD 11)
6
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread -g -march=native -DNDEBUG -Ofast -flto")
6
+
7
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread -march=native -DNDEBUG -Ofast -flto")
7
8
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -march=native -fPIC -DNDEBUG")
8
9
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread -flto=auto -Wl,--no-as-needed")
9
10
 
10
11
  find_package(ZLIB REQUIRED)
12
+ find_library(TCMALLOC_LIB tcmalloc) # <--- Cerca tcmalloc nel sistema
13
+
14
+ if(TCMALLOC_LIB)
15
+ message(STATUS "Contrek: tcmalloc found in ${TCMALLOC_LIB}")
16
+ else()
17
+ message(WARNING "Contrek: tcmalloc not found; standard one will be used.")
18
+ endif()
11
19
 
12
20
  file(GLOB_RECURSE CPP_SOURCES "*.cpp")
13
21
  file(GLOB_RECURSE C_SOURCES "*.c")
@@ -32,7 +40,11 @@ if(BUILD_EXAMPLES)
32
40
  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/example.cpp")
33
41
  message(STATUS "Contrek: Compiling example option ON")
34
42
  add_executable(contrek_test examples/example.cpp)
35
- target_link_libraries(contrek_test PRIVATE ContrekLib)
43
+ if(TCMALLOC_LIB)
44
+ target_link_libraries(contrek_test PRIVATE ContrekLib ${TCMALLOC_LIB})
45
+ else()
46
+ target_link_libraries(contrek_test PRIVATE ContrekLib)
47
+ endif()
36
48
  else()
37
49
  message(WARNING "Contrek: examples/example.cpp not found!")
38
50
  endif()