contrek 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 (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +84 -0
  6. data/LICENSE.md +9 -0
  7. data/README.md +118 -0
  8. data/Rakefile +19 -0
  9. data/contrek.gemspec +23 -0
  10. data/contrek.png +0 -0
  11. data/ext/cpp_polygon_finder/PolygonFinder/.cproject +136 -0
  12. data/ext/cpp_polygon_finder/PolygonFinder/.project +27 -0
  13. data/ext/cpp_polygon_finder/PolygonFinder/.settings/org.eclipse.ltk.core.refactoring.prefs +2 -0
  14. data/ext/cpp_polygon_finder/PolygonFinder/images/labyrinth.png +0 -0
  15. data/ext/cpp_polygon_finder/PolygonFinder/src/Main.cpp +41 -0
  16. data/ext/cpp_polygon_finder/PolygonFinder/src/Tests.cpp +69 -0
  17. data/ext/cpp_polygon_finder/PolygonFinder/src/Tests.h +19 -0
  18. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/Bitmap.cpp +52 -0
  19. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/Bitmap.h +32 -0
  20. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.cpp +656 -0
  21. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.h +42 -0
  22. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/PngBitmap.cpp +48 -0
  23. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/PngBitmap.h +32 -0
  24. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/RemoteFastPngBitmap.cpp +30 -0
  25. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/RemoteFastPngBitmap.h +26 -0
  26. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/X_picopng.cpp +576 -0
  27. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.cpp +120 -0
  28. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.h +40 -0
  29. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.cpp +36 -0
  30. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.h +30 -0
  31. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.cpp +111 -0
  32. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.h +80 -0
  33. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.cpp +325 -0
  34. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.h +59 -0
  35. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.cpp +206 -0
  36. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.h +69 -0
  37. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/optionparser.h +2858 -0
  38. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/Matcher.cpp +23 -0
  39. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/Matcher.h +23 -0
  40. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBMatcher.cpp +20 -0
  41. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBMatcher.h +23 -0
  42. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBNotMatcher.cpp +20 -0
  43. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBNotMatcher.h +23 -0
  44. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/ValueNotMatcher.cpp +20 -0
  45. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/ValueNotMatcher.h +21 -0
  46. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/LinearReducer.cpp +40 -0
  47. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/LinearReducer.h +23 -0
  48. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/Reducer.cpp +19 -0
  49. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/Reducer.h +25 -0
  50. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/UniqReducer.cpp +30 -0
  51. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/UniqReducer.h +21 -0
  52. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/VisvalingamReducer.cpp +50 -0
  53. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/VisvalingamReducer.h +121 -0
  54. data/ext/cpp_polygon_finder/cpp_polygon_finder.cpp +260 -0
  55. data/ext/cpp_polygon_finder/extconf.rb +2 -0
  56. data/lib/contrek/bitmaps/bitmap.rb +21 -0
  57. data/lib/contrek/bitmaps/chunky_bitmap.rb +33 -0
  58. data/lib/contrek/bitmaps/painting.rb +40 -0
  59. data/lib/contrek/bitmaps/png_bitmap.rb +62 -0
  60. data/lib/contrek/bitmaps/rgb_color.rb +25 -0
  61. data/lib/contrek/finder/list.rb +132 -0
  62. data/lib/contrek/finder/list_entry.rb +11 -0
  63. data/lib/contrek/finder/listable.rb +8 -0
  64. data/lib/contrek/finder/lists.rb +25 -0
  65. data/lib/contrek/finder/node.rb +126 -0
  66. data/lib/contrek/finder/node_cluster.rb +294 -0
  67. data/lib/contrek/finder/polygon_finder.rb +121 -0
  68. data/lib/contrek/map/mercator_projection.rb +76 -0
  69. data/lib/contrek/matchers/matcher.rb +20 -0
  70. data/lib/contrek/matchers/matcher_hsb.rb +24 -0
  71. data/lib/contrek/matchers/value_not_matcher.rb +9 -0
  72. data/lib/contrek/reducers/linear_reducer.rb +25 -0
  73. data/lib/contrek/reducers/reducer.rb +14 -0
  74. data/lib/contrek/reducers/uniq_reducer.rb +9 -0
  75. data/lib/contrek/reducers/visvalingam_reducer.rb +139 -0
  76. data/lib/contrek/version.rb +3 -0
  77. data/lib/contrek.rb +58 -0
  78. metadata +175 -0
@@ -0,0 +1,42 @@
1
+ /*
2
+ * FastPngBitmap.h
3
+ *
4
+ * Created on: 17 gen 2019
5
+ * Author: ema
6
+ */
7
+
8
+ #ifndef POLYGON_BITMAPS_FASTPNGBITMAP_H_
9
+ #define POLYGON_BITMAPS_FASTPNGBITMAP_H_
10
+
11
+ #include "Bitmap.h"
12
+ #include <vector>
13
+ #include <cstddef>
14
+ class RGBMatcher;
15
+
16
+ static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
17
+
18
+ class FastPngBitmap : public Bitmap {
19
+ public:
20
+ FastPngBitmap(std::string filename);
21
+ virtual ~FastPngBitmap();
22
+ bool pixel_match(int x,int y,Matcher *matcher);
23
+ int h();
24
+ int w();
25
+ virtual int error();
26
+ char value_at(int x,int y);
27
+ unsigned int rgb_value_at(int x,int y);
28
+ protected:
29
+ std::vector<unsigned char> buffer;
30
+ std::vector<unsigned char> base64_decode(std::string &encoded_string);
31
+ std::vector<unsigned char> image;
32
+ unsigned long width,height;
33
+ unsigned char *last_red = nullptr;
34
+ int png_error;
35
+ int decodePNG(std::vector<unsigned char>& out_image, unsigned long& image_width, unsigned long& image_height, const unsigned char* in_png, size_t in_size, bool convert_to_rgba32 = true);
36
+
37
+ private:
38
+ void loadFile(std::vector<unsigned char>& buffer, const std::string& filename);
39
+
40
+ };
41
+
42
+ #endif /* POLYGON_BITMAPS_FASTPNGBITMAP_H_ */
@@ -0,0 +1,48 @@
1
+ /*
2
+ * PngBitmap.cpp
3
+ *
4
+ * Created on: 03 dic 2018
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+ // http://www.piko3d.net/tutorials/libpng-tutorial-loading-png-files-from-streams/
9
+ #include "PngBitmap.h"
10
+ #include <stdlib.h>
11
+ #include <stdio.h>
12
+ #include <string>
13
+ #include <iostream>
14
+ #include <typeinfo>
15
+ #include "../matchers/RGBMatcher.h"
16
+ #include "../matchers/RGBNotMatcher.h"
17
+ #include "png++/png.hpp"
18
+
19
+ PngBitmap::PngBitmap(std::string filename) : Bitmap("", 0) {
20
+ this->image = png::image< png::rgb_pixel >(filename);
21
+ this->width = image.get_width();
22
+ this->height = image.get_height();
23
+ }
24
+
25
+ bool PngBitmap::pixel_match(int x, int y, Matcher *matcher)
26
+ { png::basic_rgb_pixel<unsigned char> pixel = image.get_pixel(x, y);
27
+ unsigned int color = pixel.blue + (pixel.green << 8) + (pixel.red << 16);
28
+
29
+ if (typeid(*matcher) == typeid(RGBMatcher)) return(((RGBMatcher*) matcher)->match(color));
30
+ if (typeid(*matcher) == typeid(RGBNotMatcher)) return(((RGBNotMatcher*) matcher)->match(color));
31
+ return(false);
32
+ }
33
+
34
+
35
+ PngBitmap::~PngBitmap() {
36
+ }
37
+
38
+ int PngBitmap::w() {
39
+ return this->width;
40
+ }
41
+ int PngBitmap::h() {
42
+ return this->height;
43
+ }
44
+ char PngBitmap::value_at(int x, int y) {
45
+ png::basic_rgb_pixel<unsigned char> pixel = image.get_pixel(x, y);
46
+ char color = pixel.blue | pixel.green | pixel.red;
47
+ return(color);
48
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ * PngBitmap.h
3
+ *
4
+ * Created on: 03 dic 2018
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #ifndef POLYGON_BITMAPS_PNGBITMAP_H_
10
+ #define POLYGON_BITMAPS_PNGBITMAP_H_
11
+
12
+ #include "Bitmap.h"
13
+ #include <string>
14
+ #include "png++/png.hpp"
15
+
16
+ class RGBMatcher;
17
+
18
+ class PngBitmap : public Bitmap {
19
+ public:
20
+ PngBitmap(std::string filename);
21
+ virtual ~PngBitmap();
22
+ bool pixel_match(int x, int y, Matcher *matcher);
23
+ int h();
24
+ int w();
25
+ char value_at(int x, int y);
26
+ private:
27
+ unsigned int width;
28
+ unsigned int height;
29
+ png::image< png::rgb_pixel> image;
30
+ };
31
+
32
+ #endif /* POLYGON_BITMAPS_PNGBITMAP_H_ */
@@ -0,0 +1,30 @@
1
+ /*
2
+ * RemoteFastPngBitmap.cpp
3
+ *
4
+ * Created on: 01 mag 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #include "RemoteFastPngBitmap.h"
10
+ #include <cstring>
11
+ #include <iostream>
12
+ #include <vector>
13
+ #include <fstream>
14
+ #include <cstddef>
15
+ #include <typeinfo>
16
+ #include <string>
17
+ #include "../matchers/RGBMatcher.h"
18
+ #include "../matchers/RGBNotMatcher.h"
19
+
20
+ RemoteFastPngBitmap::RemoteFastPngBitmap(std::string *dataurl) : FastPngBitmap("") {
21
+ buffer = base64_decode(*dataurl);
22
+ int error = decodePNG(image, width, height, buffer.empty() ? 0 : &buffer[0], (unsigned long) buffer.size(), true);
23
+ if (error != 0) std::cout << "error: " << error << std::endl;
24
+ this->last_red = &image[0];
25
+ this->png_error = error;
26
+ }
27
+
28
+ RemoteFastPngBitmap::~RemoteFastPngBitmap() {
29
+ }
30
+
@@ -0,0 +1,26 @@
1
+ /*
2
+ * RemoteFastPngBitmap.h
3
+ *
4
+ * Created on: 01 mag 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #ifndef POLYGON_BITMAPS_REMOTEFASTPNGBITMAP_H_
10
+ #define POLYGON_BITMAPS_REMOTEFASTPNGBITMAP_H_
11
+
12
+ #include "FastPngBitmap.h"
13
+ #include "Bitmap.h"
14
+ #include <vector>
15
+ #include <string>
16
+ #include <cstddef>
17
+
18
+ class RGBMatcher;
19
+
20
+ class RemoteFastPngBitmap: public FastPngBitmap {
21
+ public:
22
+ RemoteFastPngBitmap(std::string *dataurl);
23
+ virtual ~RemoteFastPngBitmap();
24
+ };
25
+
26
+ #endif /* POLYGON_BITMAPS_REMOTEFASTPNGBITMAP_H_ */