magro 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8bfcf8b7886c7fa5d89556642be97b077f6bf96d7a1725fd2cb8cf1b15c0aef
4
- data.tar.gz: b0ab5bff6959f1264ed584dcefc25fb7a64fc866164f73dcf11b1556e7cf6377
3
+ metadata.gz: bfa8a730f370ebbdf54c3bbbe2248046ec82e0dc759e14f974637d79d437e254
4
+ data.tar.gz: c907656b0d0732f095d103e0c2bfa76eca70859831c19426ebe517c7560d6592
5
5
  SHA512:
6
- metadata.gz: f40b650588ec98b33aa8d88bd5c0fb11d4dc8b14faaa197751275f478c2c316e7348b5bd1ff4cc55d33e451036b6b6411fc4f60d9d374c787c91d30ff661abc4
7
- data.tar.gz: 7df4bfc3e747f2e8d8fb2dad307df3a0b6370fae1b6c53df66797252629851cf57ab256fdcc64088950ce9177ee2d6ca3a694e498588dc3b4baeef17c771d928
6
+ metadata.gz: 8943d964496a118ee778532cfc5fe9cdf8ef4a9731b9217453c98f09ec5ef05be77a5d205ef7e6172e9e3d18475b4dcb336d0626ec458a74b957b1504e3f6e36
7
+ data.tar.gz: 14ef03b1c882e6d0c2502edce3a93b8bf805588e8ee319652bae5b39cb4d6f682df8387268b646e1e1c1b751db5b944247eec96ad7f7152813af97c3afadf74a
data/.clang-format ADDED
@@ -0,0 +1,149 @@
1
+ ---
2
+ Language: Cpp
3
+ # BasedOnStyle: LLVM
4
+ AccessModifierOffset: -2
5
+ AlignAfterOpenBracket: Align
6
+ AlignConsecutiveMacros: false
7
+ AlignConsecutiveAssignments: false
8
+ AlignConsecutiveBitFields: false
9
+ AlignConsecutiveDeclarations: false
10
+ AlignEscapedNewlines: Right
11
+ AlignOperands: Align
12
+ AlignTrailingComments: true
13
+ AllowAllArgumentsOnNextLine: true
14
+ AllowAllConstructorInitializersOnNextLine: true
15
+ AllowAllParametersOfDeclarationOnNextLine: true
16
+ AllowShortEnumsOnASingleLine: true
17
+ AllowShortBlocksOnASingleLine: Never
18
+ AllowShortCaseLabelsOnASingleLine: false
19
+ AllowShortFunctionsOnASingleLine: All
20
+ AllowShortLambdasOnASingleLine: All
21
+ AllowShortIfStatementsOnASingleLine: Never
22
+ AllowShortLoopsOnASingleLine: false
23
+ AlwaysBreakAfterDefinitionReturnType: None
24
+ AlwaysBreakAfterReturnType: None
25
+ AlwaysBreakBeforeMultilineStrings: false
26
+ AlwaysBreakTemplateDeclarations: MultiLine
27
+ BinPackArguments: true
28
+ BinPackParameters: true
29
+ BraceWrapping:
30
+ AfterCaseLabel: false
31
+ AfterClass: false
32
+ AfterControlStatement: Never
33
+ AfterEnum: false
34
+ AfterFunction: false
35
+ AfterNamespace: false
36
+ AfterObjCDeclaration: false
37
+ AfterStruct: false
38
+ AfterUnion: false
39
+ AfterExternBlock: false
40
+ BeforeCatch: false
41
+ BeforeElse: false
42
+ BeforeLambdaBody: false
43
+ BeforeWhile: false
44
+ IndentBraces: false
45
+ SplitEmptyFunction: true
46
+ SplitEmptyRecord: true
47
+ SplitEmptyNamespace: true
48
+ BreakBeforeBinaryOperators: None
49
+ BreakBeforeBraces: Attach
50
+ BreakBeforeInheritanceComma: false
51
+ BreakInheritanceList: BeforeColon
52
+ BreakBeforeTernaryOperators: true
53
+ BreakConstructorInitializersBeforeComma: false
54
+ BreakConstructorInitializers: BeforeColon
55
+ BreakAfterJavaFieldAnnotations: false
56
+ BreakStringLiterals: true
57
+ ColumnLimit: 128
58
+ CommentPragmas: '^ IWYU pragma:'
59
+ CompactNamespaces: false
60
+ ConstructorInitializerAllOnOneLineOrOnePerLine: false
61
+ ConstructorInitializerIndentWidth: 4
62
+ ContinuationIndentWidth: 4
63
+ Cpp11BracedListStyle: true
64
+ DeriveLineEnding: true
65
+ DerivePointerAlignment: false
66
+ DisableFormat: false
67
+ ExperimentalAutoDetectBinPacking: false
68
+ FixNamespaceComments: true
69
+ ForEachMacros:
70
+ - foreach
71
+ - Q_FOREACH
72
+ - BOOST_FOREACH
73
+ IncludeBlocks: Preserve
74
+ IncludeCategories:
75
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
76
+ Priority: 2
77
+ SortPriority: 0
78
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
79
+ Priority: 3
80
+ SortPriority: 0
81
+ - Regex: '.*'
82
+ Priority: 1
83
+ SortPriority: 0
84
+ IncludeIsMainRegex: '(Test)?$'
85
+ IncludeIsMainSourceRegex: ''
86
+ IndentCaseLabels: false
87
+ IndentCaseBlocks: false
88
+ IndentGotoLabels: true
89
+ IndentPPDirectives: None
90
+ IndentExternBlock: AfterExternBlock
91
+ IndentWidth: 2
92
+ IndentWrappedFunctionNames: false
93
+ InsertTrailingCommas: None
94
+ JavaScriptQuotes: Leave
95
+ JavaScriptWrapImports: true
96
+ KeepEmptyLinesAtTheStartOfBlocks: true
97
+ MacroBlockBegin: ''
98
+ MacroBlockEnd: ''
99
+ MaxEmptyLinesToKeep: 1
100
+ NamespaceIndentation: None
101
+ ObjCBinPackProtocolList: Auto
102
+ ObjCBlockIndentWidth: 2
103
+ ObjCBreakBeforeNestedBlockParam: true
104
+ ObjCSpaceAfterProperty: false
105
+ ObjCSpaceBeforeProtocolList: true
106
+ PenaltyBreakAssignment: 2
107
+ PenaltyBreakBeforeFirstCallParameter: 19
108
+ PenaltyBreakComment: 300
109
+ PenaltyBreakFirstLessLess: 120
110
+ PenaltyBreakString: 1000
111
+ PenaltyBreakTemplateDeclaration: 10
112
+ PenaltyExcessCharacter: 1000000
113
+ PenaltyReturnTypeOnItsOwnLine: 60
114
+ PointerAlignment: Left
115
+ ReflowComments: true
116
+ SortIncludes: true
117
+ SortUsingDeclarations: true
118
+ SpaceAfterCStyleCast: false
119
+ SpaceAfterLogicalNot: false
120
+ SpaceAfterTemplateKeyword: true
121
+ SpaceBeforeAssignmentOperators: true
122
+ SpaceBeforeCpp11BracedList: false
123
+ SpaceBeforeCtorInitializerColon: true
124
+ SpaceBeforeInheritanceColon: true
125
+ SpaceBeforeParens: ControlStatements
126
+ SpaceBeforeRangeBasedForLoopColon: true
127
+ SpaceInEmptyBlock: false
128
+ SpaceInEmptyParentheses: false
129
+ SpacesBeforeTrailingComments: 1
130
+ SpacesInAngles: false
131
+ SpacesInConditionalStatement: false
132
+ SpacesInContainerLiterals: true
133
+ SpacesInCStyleCastParentheses: false
134
+ SpacesInParentheses: false
135
+ SpacesInSquareBrackets: false
136
+ SpaceBeforeSquareBrackets: false
137
+ Standard: Latest
138
+ StatementMacros:
139
+ - Q_UNUSED
140
+ - QT_REQUIRE_VERSION
141
+ TabWidth: 8
142
+ UseCRLF: false
143
+ UseTab: Never
144
+ WhitespaceSensitiveMacros:
145
+ - STRINGIZE
146
+ - PP_STRINGIZE
147
+ - BOOST_PP_STRINGIZE
148
+ ...
149
+
data/.coveralls.yml CHANGED
@@ -1 +1 @@
1
- service_name: travis-ci
1
+ service_name: github-ci
@@ -0,0 +1,23 @@
1
+ name: build
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-20.04
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '2.6', '2.7', '3.0' ]
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Install libpng and libjpeg
14
+ run: sudo apt-get install -y libpng-dev libjpeg-dev
15
+ - name: Set up Ruby ${{ matrix.ruby }}
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: Build and test with Rake
20
+ run: |
21
+ gem install --no-document bundler
22
+ bundle install --jobs 4 --retry 3
23
+ bundle exec rake
@@ -0,0 +1,29 @@
1
+ name: coverage
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ coverage:
11
+ runs-on: ubuntu-20.04
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Install libpng and libjpeg
15
+ run: sudo apt-get install -y libpng-dev libjpeg-dev
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby 2.7
18
+ uses: actions/setup-ruby@v1
19
+ with:
20
+ ruby-version: '2.7'
21
+ - name: Build and test with Rake
22
+ run: |
23
+ gem install bundler
24
+ bundle install
25
+ bundle exec rake
26
+ - name: Coveralls GitHub Action
27
+ uses: coverallsapp/github-action@v1.1.2
28
+ with:
29
+ github-token: ${{ secrets.GITHUB_TOKEN }}
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ # 0.5.1
2
+ - Fix version specifier of runtime dependencies.
3
+
4
+ # 0.5.0
5
+ - Add type declaration files.
6
+ - Refactor some codes.
7
+
8
+ # 0.4.3
9
+ - Fix imread method to read image from URL.
10
+ - Fix some configulation files.
11
+
12
+ # 0.4.2
13
+ - Add GC guard to reading and writing image methods.
14
+
15
+ # 0.4.1
16
+ - Add GC guard to narray given to native extension method.
17
+ - Fix some configulation files.
18
+
1
19
  # 0.4.0
2
20
  - Rename extension file for reading and writing image file.
3
21
  - Update documentations.
data/Gemfile CHANGED
@@ -3,8 +3,11 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in magro.gemspec
4
4
  gemspec
5
5
 
6
- gem 'coveralls', '~> 0.8'
7
6
  gem 'bundler', '~> 2.0'
8
- gem 'rake', '~> 12.0'
7
+ gem 'rake', '~> 13.0'
9
8
  gem 'rake-compiler', '~> 1.0'
10
9
  gem 'rspec', '~> 3.0'
10
+ gem 'simplecov', '~> 0.19'
11
+ gem 'simplecov-lcov', '~> 0.8'
12
+ gem 'rbs', '~> 1.2'
13
+ gem 'steep', '~> 0.44'
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2019-2020 Atsushi Tatsuma
1
+ Copyright (c) 2019-2021 Atsushi Tatsuma
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Magro
2
2
 
3
- [![Build Status](https://travis-ci.org/yoshoku/magro.svg?branch=master)](https://travis-ci.org/yoshoku/magro)
4
- [![Coverage Status](https://coveralls.io/repos/github/yoshoku/magro/badge.svg?branch=master)](https://coveralls.io/github/yoshoku/magro?branch=master)
3
+ [![Build Status](https://github.com/yoshoku/magro/workflows/build/badge.svg)](https://github.com/yoshoku/magro/actions?query=workflow%3Abuild)
4
+ [![Coverage Status](https://coveralls.io/repos/github/yoshoku/magro/badge.svg?branch=main)](https://coveralls.io/github/yoshoku/magro?branch=main)
5
5
  [![Gem Version](https://badge.fury.io/rb/magro.svg)](https://badge.fury.io/rb/magro)
6
- [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-liblinear/blob/master/LICENSE.txt)
6
+ [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-liblinear/blob/main/LICENSE.txt)
7
7
  [![Documentation](http://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/magro/doc/)
8
8
 
9
9
  Magro is a minimal image processing library in Ruby.
@@ -63,4 +63,4 @@ This project is intended to be a safe, welcoming space for collaboration, and co
63
63
 
64
64
  ## Code of Conduct
65
65
 
66
- Everyone interacting in the Magro project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/magro/blob/master/CODE_OF_CONDUCT.md).
66
+ Everyone interacting in the Magro project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/magro/blob/main/CODE_OF_CONDUCT.md).
data/Steepfile ADDED
@@ -0,0 +1,20 @@
1
+ target :lib do
2
+ signature "sig"
3
+ #
4
+ check "lib" # Directory name
5
+ # check "Gemfile" # File name
6
+ # check "app/models/**/*.rb" # Glob
7
+ # # ignore "lib/templates/*.rb"
8
+ #
9
+ # # library "pathname", "set" # Standard libraries
10
+ # # library "strong_json" # Gems
11
+ end
12
+
13
+ # target :spec do
14
+ # signature "sig", "sig-private"
15
+ #
16
+ # check "spec"
17
+ #
18
+ # # library "pathname", "set" # Standard libraries
19
+ # # library "rspec"
20
+ # end
data/ext/magro/imgrw.c CHANGED
@@ -5,9 +5,7 @@ RUBY_EXTERN VALUE mMagro;
5
5
  /**
6
6
  * @!visibility private
7
7
  */
8
- static
9
- VALUE magro_io_read_png(VALUE self, VALUE filename_)
10
- {
8
+ static VALUE magro_io_read_png(VALUE self, VALUE filename_) {
11
9
  char* filename = StringValuePtr(filename_);
12
10
  FILE* file_ptr = fopen(filename, "rb");
13
11
  unsigned char header[8];
@@ -21,7 +19,7 @@ VALUE magro_io_read_png(VALUE self, VALUE filename_)
21
19
  png_uint_32 y;
22
20
  int n_dims = 0;
23
21
  int n_ch;
24
- size_t shape[3] = { 0 };
22
+ size_t shape[3] = {0};
25
23
  VALUE nary;
26
24
  uint8_t* nary_ptr;
27
25
 
@@ -76,36 +74,36 @@ VALUE magro_io_read_png(VALUE self, VALUE filename_)
76
74
  }
77
75
 
78
76
  switch (color_type) {
79
- case PNG_COLOR_TYPE_GRAY:
80
- n_ch = 1;
81
- n_dims = 2;
82
- shape[0] = height;
83
- shape[1] = width;
84
- break;
85
- case PNG_COLOR_TYPE_GRAY_ALPHA:
86
- n_ch = 2;
87
- n_dims = 3;
88
- shape[0] = height;
89
- shape[1] = width;
90
- shape[2] = 2;
91
- break;
92
- case PNG_COLOR_TYPE_RGB:
93
- n_ch = 3;
94
- n_dims = 3;
95
- shape[0] = height;
96
- shape[1] = width;
97
- shape[2] = 3;
98
- break;
99
- case PNG_COLOR_TYPE_RGB_ALPHA:
100
- n_ch = 4;
101
- n_dims = 3;
102
- shape[0] = height;
103
- shape[1] = width;
104
- shape[2] = 4;
105
- break;
106
- default:
107
- n_dims = 0;
108
- break;
77
+ case PNG_COLOR_TYPE_GRAY:
78
+ n_ch = 1;
79
+ n_dims = 2;
80
+ shape[0] = height;
81
+ shape[1] = width;
82
+ break;
83
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
84
+ n_ch = 2;
85
+ n_dims = 3;
86
+ shape[0] = height;
87
+ shape[1] = width;
88
+ shape[2] = 2;
89
+ break;
90
+ case PNG_COLOR_TYPE_RGB:
91
+ n_ch = 3;
92
+ n_dims = 3;
93
+ shape[0] = height;
94
+ shape[1] = width;
95
+ shape[2] = 3;
96
+ break;
97
+ case PNG_COLOR_TYPE_RGB_ALPHA:
98
+ n_ch = 4;
99
+ n_dims = 3;
100
+ shape[0] = height;
101
+ shape[1] = width;
102
+ shape[2] = 4;
103
+ break;
104
+ default:
105
+ n_dims = 0;
106
+ break;
109
107
  }
110
108
 
111
109
  if (n_dims == 0) {
@@ -126,15 +124,15 @@ VALUE magro_io_read_png(VALUE self, VALUE filename_)
126
124
  fclose(file_ptr);
127
125
  png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
128
126
 
127
+ RB_GC_GUARD(filename_);
128
+
129
129
  return nary;
130
130
  }
131
131
 
132
132
  /**
133
133
  * @!visibility private
134
134
  */
135
- static
136
- VALUE magro_io_save_png(VALUE self, VALUE filename_, VALUE image)
137
- {
135
+ static VALUE magro_io_save_png(VALUE self, VALUE filename_, VALUE image) {
138
136
  char* filename = StringValuePtr(filename_);
139
137
  FILE* file_ptr = fopen(filename, "wb");
140
138
  png_structp png_ptr;
@@ -173,18 +171,18 @@ VALUE magro_io_save_png(VALUE self, VALUE filename_, VALUE image)
173
171
  }
174
172
 
175
173
  switch (n_ch) {
176
- case 4:
177
- color_type = PNG_COLOR_TYPE_RGBA;
178
- break;
179
- case 3:
180
- color_type = PNG_COLOR_TYPE_RGB;
181
- break;
182
- case 2:
183
- color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
184
- break;
185
- default:
186
- color_type = PNG_COLOR_TYPE_GRAY;
187
- break;
174
+ case 4:
175
+ color_type = PNG_COLOR_TYPE_RGBA;
176
+ break;
177
+ case 3:
178
+ color_type = PNG_COLOR_TYPE_RGB;
179
+ break;
180
+ case 2:
181
+ color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
182
+ break;
183
+ default:
184
+ color_type = PNG_COLOR_TYPE_GRAY;
185
+ break;
188
186
  }
189
187
 
190
188
  png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
@@ -206,8 +204,8 @@ VALUE magro_io_save_png(VALUE self, VALUE filename_, VALUE image)
206
204
  return Qfalse;
207
205
  }
208
206
 
209
- png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type,
210
- PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
207
+ png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
208
+ PNG_FILTER_TYPE_DEFAULT);
211
209
 
212
210
  row_ptr_ptr = png_malloc(png_ptr, height * sizeof(png_bytep));
213
211
  for (y = 0; y < height; y++) {
@@ -226,6 +224,9 @@ VALUE magro_io_save_png(VALUE self, VALUE filename_, VALUE image)
226
224
  png_free(png_ptr, row_ptr_ptr);
227
225
  png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
228
226
 
227
+ RB_GC_GUARD(image);
228
+ RB_GC_GUARD(filename_);
229
+
229
230
  return Qtrue;
230
231
  }
231
232
 
@@ -234,9 +235,7 @@ struct my_error_mgr {
234
235
  jmp_buf setjmp_buffer;
235
236
  };
236
237
 
237
- static void
238
- my_error_exit(j_common_ptr cinfo)
239
- {
238
+ static void my_error_exit(j_common_ptr cinfo) {
240
239
  struct my_error_mgr* my_err = (struct my_error_mgr*)cinfo->err;
241
240
  (*cinfo->err->output_message)(cinfo);
242
241
  longjmp(my_err->setjmp_buffer, 1);
@@ -245,16 +244,14 @@ my_error_exit(j_common_ptr cinfo)
245
244
  /**
246
245
  * @!visibility private
247
246
  */
248
- static
249
- VALUE magro_io_read_jpg(VALUE self, VALUE filename_)
250
- {
247
+ static VALUE magro_io_read_jpg(VALUE self, VALUE filename_) {
251
248
  char* filename = StringValuePtr(filename_);
252
249
  FILE* file_ptr = fopen(filename, "rb");
253
250
  struct jpeg_decompress_struct jpeg;
254
251
  struct my_error_mgr err;
255
252
  unsigned int width, height;
256
253
  int n_colors;
257
- size_t shape[3] = { 0 };
254
+ size_t shape[3] = {0};
258
255
  int n_dims;
259
256
  unsigned int y;
260
257
  VALUE nary;
@@ -298,15 +295,15 @@ VALUE magro_io_read_jpg(VALUE self, VALUE filename_)
298
295
  jpeg_finish_decompress(&jpeg);
299
296
  jpeg_destroy_decompress(&jpeg);
300
297
 
298
+ RB_GC_GUARD(filename_);
299
+
301
300
  return nary;
302
301
  }
303
302
 
304
303
  /**
305
304
  * @!visibility private
306
305
  */
307
- static
308
- VALUE magro_io_save_jpg(int argc, VALUE* argv, VALUE self)
309
- {
306
+ static VALUE magro_io_save_jpg(int argc, VALUE* argv, VALUE self) {
310
307
  VALUE filename_;
311
308
  VALUE image;
312
309
  VALUE quality_;
@@ -371,15 +368,15 @@ VALUE magro_io_save_jpg(int argc, VALUE* argv, VALUE self)
371
368
  jpeg.input_components = n_ch;
372
369
 
373
370
  switch (n_ch) {
374
- case 3:
375
- jpeg.in_color_space = JCS_RGB;
376
- break;
377
- case 1:
378
- jpeg.in_color_space = JCS_GRAYSCALE;
379
- break;
380
- default:
381
- jpeg.in_color_space = JCS_UNKNOWN;
382
- break;
371
+ case 3:
372
+ jpeg.in_color_space = JCS_RGB;
373
+ break;
374
+ case 1:
375
+ jpeg.in_color_space = JCS_GRAYSCALE;
376
+ break;
377
+ default:
378
+ jpeg.in_color_space = JCS_UNKNOWN;
379
+ break;
383
380
  }
384
381
 
385
382
  jpeg_set_defaults(&jpeg);
@@ -398,11 +395,13 @@ VALUE magro_io_save_jpg(int argc, VALUE* argv, VALUE self)
398
395
 
399
396
  fclose(file_ptr);
400
397
 
398
+ RB_GC_GUARD(image);
399
+ RB_GC_GUARD(filename_);
400
+
401
401
  return Qtrue;
402
402
  }
403
403
 
404
- void init_io_module()
405
- {
404
+ void init_io_module() {
406
405
  VALUE mIO = rb_define_module_under(mMagro, "IO");
407
406
  rb_define_module_function(mIO, "read_png", magro_io_read_png, 1);
408
407
  rb_define_module_function(mIO, "save_png", magro_io_save_png, 2);
data/ext/magro/imgrw.h CHANGED
@@ -6,10 +6,12 @@
6
6
  #include <string.h>
7
7
 
8
8
  #include <setjmp.h>
9
- #include <png.h>
9
+
10
10
  #include <jpeglib.h>
11
+ #include <png.h>
11
12
 
12
13
  #include <ruby.h>
14
+
13
15
  #include <numo/narray.h>
14
16
  #include <numo/template.h>
15
17
 
data/ext/magro/magro.c CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  VALUE mMagro;
4
4
 
5
- void Init_magro()
6
- {
5
+ void Init_magro() {
7
6
  mMagro = rb_define_module("Magro");
8
7
 
9
8
  init_io_module();
data/lib/magro/filter.rb CHANGED
@@ -32,7 +32,7 @@ module Magro
32
32
  if n_channels.nil?
33
33
  filter1ch(padded, kernel, scale, offset)
34
34
  else
35
- image.class.zeros(*image.shape).tap do |filtered|
35
+ image.class.zeros(image.shape).tap do |filtered|
36
36
  n_channels.times do |c|
37
37
  filtered[true, true, c] = filter1ch(padded[true, true, c], kernel, scale, offset)
38
38
  end
data/lib/magro/io.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'open-uri'
4
+ require 'tempfile'
5
+
3
6
  module Magro
4
7
  # IO module provides functions for input and output of image file.
5
8
  module IO
6
9
  module_function
7
10
 
8
11
  # Loads an image from file.
9
- # @param filename [String] Path to image file to be loaded.
12
+ # @param filename [String] File path or URL of image file to be loaded.
10
13
  # Currently, the following file formats are support:
11
14
  # Portbale Network Graphics (*.png) and JPEG files (*.jpeg, *.jpg, *jpe).
12
15
  # @raise [ArgumentError] This error is raised when filename is not String.
@@ -15,8 +18,27 @@ module Magro
15
18
  # @return [Numo::UInt8] (shape: [height, width, n_channels]) Loaded image.
16
19
  def imread(filename)
17
20
  raise ArgumentError, 'Expect class of filename to be String.' unless filename.is_a?(String)
18
- return read_jpg(filename) if filename.downcase =~ /\.(jpeg|jpg|jpe)$/
19
- return read_png(filename) if filename.downcase =~ /\.png$/
21
+
22
+ unless url?(filename)
23
+ return case filename.downcase
24
+ when /\.(jpeg|jpg|jpe)$/
25
+ read_jpg(filename)
26
+ when /\.png$/
27
+ read_png(filename)
28
+ end
29
+ end
30
+
31
+ uri = URI.parse(filename)
32
+ ext = File.extname(uri.path).downcase
33
+ raise IOError, 'Failed to detect file extension from given URL.' unless ext =~ /\.(jpeg|jpg|jpe|png)$/
34
+
35
+ uri.open do |file|
36
+ temp = Tempfile.new(['magro_', ext])
37
+ temp.binmode
38
+ temp.write(file.read)
39
+ temp.rewind
40
+ imread(temp.path)
41
+ end
20
42
  end
21
43
 
22
44
  # Saves an image to file.
@@ -46,6 +68,11 @@ module Magro
46
68
  false
47
69
  end
48
70
 
49
- private_class_method :read_jpg, :read_png, :save_jpg, :save_png
71
+ def url?(str)
72
+ uri = URI.parse(str)
73
+ uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
74
+ end
75
+
76
+ private_class_method :read_jpg, :read_png, :save_jpg, :save_png, :url?
50
77
  end
51
78
  end
data/lib/magro/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # Magro is an image processing library in Ruby.
4
4
  module Magro
5
5
  # The version of Magro you are using.
6
- VERSION = '0.4.0'
6
+ VERSION = '0.5.1'
7
7
  end
data/magro.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.metadata['homepage_uri'] = spec.homepage
23
23
  spec.metadata['source_code_uri'] = 'https://github.com/yoshoku/magro'
24
- spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/magro/blob/master/CHANGELOG.md'
24
+ spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/magro/blob/main/CHANGELOG.md'
25
25
  spec.metadata['documentation_uri'] = 'https://yoshoku.github.io/magro/doc/'
26
26
 
27
27
  # Specify which files should be added to the gem when it is released.
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.require_paths = ['lib']
36
36
  spec.extensions = ['ext/magro/extconf.rb']
37
37
 
38
- spec.add_runtime_dependency 'numo-narray', '~> 0.9.1'
38
+ spec.add_runtime_dependency 'numo-narray', '>= 0.9.1'
39
39
  end
data/sig/magro.rbs ADDED
@@ -0,0 +1,9 @@
1
+ module Magro
2
+ VERSION: String
3
+
4
+ type magro_image_narray = (
5
+ Numo::Int8 | Numo::Int16 | Numo::Int32 | Numo::Int64 |
6
+ Numo::UInt8 | Numo::UInt16 | Numo::UInt32 | Numo::UInt64 |
7
+ Numo::SFloat | Numo::DFloat
8
+ )
9
+ end
@@ -0,0 +1,20 @@
1
+ module Magro
2
+ module Filter
3
+ def self?.filter2d: (Numo::UInt8 image, Numo::DFloat kernel, ?scale: Float? scale, ?offset: Integer offset) -> Numo::UInt8
4
+ def self?.convolve2d: (magro_image_narray arr1, magro_image_narray arr2) -> magro_image_narray
5
+
6
+ private
7
+
8
+ INTEGER_NARRAY: Array[String]
9
+
10
+ #def self?.zero_padding: (magro_image_narray image, Integer filter_h, Integer filter_w) -> magro_image_narray
11
+ #def self?.filter1ch: (magro_image_narray image, Numo::DFloat kernel, Float? scale, Integer offset) -> magro_image_narray
12
+ #def self?.im2col: (magro_image_narray image, Integer filter_h, Integer filter_w) -> magro_image_narray
13
+ #def self?.integer_narray?: (Numo::NArray image) -> bool
14
+
15
+ def self?.zero_padding: (untyped image, Integer filter_h, Integer filter_w) -> untyped
16
+ def self?.filter1ch: (untyped image, Numo::DFloat kernel, Float? scale, Integer offset) -> untyped
17
+ def self?.im2col: (untyped image, Integer filter_h, Integer filter_w) -> untyped
18
+ def self?.integer_narray?: (Numo::NArray image) -> bool
19
+ end
20
+ end
data/sig/magro/io.rbs ADDED
@@ -0,0 +1,14 @@
1
+ module Magro
2
+ module IO
3
+ def self?.imread: (String filename) -> Numo::UInt8?
4
+ def self?.imsave: (String filename, Numo::UInt8 image, ?quality: Integer) -> bool
5
+
6
+ private
7
+
8
+ def self?.read_jpg: (String filename) -> Numo::UInt8
9
+ def self?.read_png: (String filename) -> Numo::UInt8
10
+ def self?.save_jpg: (String filename, Numo::UInt8 image, Integer? quality) -> bool
11
+ def self?.save_png: (String filename, Numo::UInt8 image) -> bool
12
+ def self?.url?: (String str) -> bool
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Magro
2
+ module Transform
3
+ def self?.resize: (Numo::UInt8 image, height: Integer height, width: Integer width) -> Numo::UInt8
4
+
5
+ private
6
+
7
+ INTEGER_NARRAY: Array[String]
8
+
9
+ def self?.bilinear_resize: (Numo::UInt8 image, Integer new_height, Integer new_width) -> Numo::UInt8
10
+ def self?.integer_narray?: (Numo::NArray image) -> bool
11
+ end
12
+ end
data/sig/patch.rbs ADDED
@@ -0,0 +1,90 @@
1
+ module Numo
2
+ class NArray
3
+ def self.cast: (untyped a) -> untyped
4
+ def self.zeros: (*Integer) -> untyped
5
+ def self.[]: (*untyped) -> untyped
6
+ def []: () -> untyped
7
+ def []=: () -> untyped
8
+ def +: (untyped) -> untyped
9
+ def empty?: () -> bool
10
+ def flatten: () -> untyped
11
+ def initialize: (*untyped) -> untyped
12
+ def ndim: () -> Integer
13
+ def shape: () -> [Integer, Integer]
14
+ def swapaxes: (Integer, Integer) -> untyped
15
+ def transpose: (*untyped) -> untyped
16
+ end
17
+
18
+ class Int8 < NArray
19
+ def *: (untyped) -> untyped
20
+ def +: (untyped) -> untyped
21
+ def []: (*untyped) -> untyped
22
+ def []=: (*untyped) -> untyped
23
+ end
24
+
25
+ class Int16 < NArray
26
+ def *: (untyped) -> untyped
27
+ def +: (untyped) -> untyped
28
+ def []: (*untyped) -> untyped
29
+ def []=: (*untyped) -> untyped
30
+ end
31
+
32
+ class Int32 < NArray
33
+ def *: (untyped) -> untyped
34
+ def +: (untyped) -> untyped
35
+ def []: (*untyped) -> untyped
36
+ def []=: (*untyped) -> untyped
37
+ def seq: (*untyped) -> untyped
38
+ end
39
+
40
+ class Int64 < NArray
41
+ def *: (untyped) -> untyped
42
+ def +: (untyped) -> untyped
43
+ def []: (*untyped) -> untyped
44
+ def []=: (*untyped) -> untyped
45
+ end
46
+
47
+ class UInt8 < NArray
48
+ def *: (untyped) -> untyped
49
+ def +: (untyped) -> untyped
50
+ def []: (*untyped) -> untyped
51
+ def []=: (*untyped) -> untyped
52
+ end
53
+
54
+ class UInt16 < NArray
55
+ def *: (untyped) -> untyped
56
+ def +: (untyped) -> untyped
57
+ def []: (*untyped) -> untyped
58
+ def []=: (*untyped) -> untyped
59
+ end
60
+
61
+ class UInt32 < NArray
62
+ def *: (untyped) -> untyped
63
+ def +: (untyped) -> untyped
64
+ def []: (*untyped) -> untyped
65
+ def []=: (*untyped) -> untyped
66
+ end
67
+
68
+ class UInt64 < NArray
69
+ def *: (untyped) -> untyped
70
+ def +: (untyped) -> untyped
71
+ def []: (*untyped) -> untyped
72
+ def []=: (*untyped) -> untyped
73
+ end
74
+
75
+ class SFloat < NArray
76
+ def sum: (*untyped) -> untyped
77
+ def *: (untyped) -> untyped
78
+ def +: (untyped) -> untyped
79
+ def []: (*untyped) -> untyped
80
+ def []=: (*untyped) -> untyped
81
+ end
82
+
83
+ class DFloat < NArray
84
+ def sum: (*untyped) -> untyped
85
+ def *: (untyped) -> untyped
86
+ def +: (untyped) -> untyped
87
+ def []: (*untyped) -> untyped
88
+ def []=: (*untyped) -> untyped
89
+ end
90
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-25 00:00:00.000000000 Z
11
+ date: 2021-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.9.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.1
27
27
  description: |
@@ -36,16 +36,19 @@ extensions:
36
36
  - ext/magro/extconf.rb
37
37
  extra_rdoc_files: []
38
38
  files:
39
+ - ".clang-format"
39
40
  - ".coveralls.yml"
41
+ - ".github/workflows/build.yml"
42
+ - ".github/workflows/coverage.yml"
40
43
  - ".gitignore"
41
44
  - ".rspec"
42
- - ".travis.yml"
43
45
  - CHANGELOG.md
44
46
  - CODE_OF_CONDUCT.md
45
47
  - Gemfile
46
48
  - LICENSE.txt
47
49
  - README.md
48
50
  - Rakefile
51
+ - Steepfile
49
52
  - bin/console
50
53
  - bin/setup
51
54
  - ext/magro/extconf.rb
@@ -59,15 +62,20 @@ files:
59
62
  - lib/magro/transform.rb
60
63
  - lib/magro/version.rb
61
64
  - magro.gemspec
65
+ - sig/magro.rbs
66
+ - sig/magro/filter.rbs
67
+ - sig/magro/io.rbs
68
+ - sig/magro/transform.rbs
69
+ - sig/patch.rbs
62
70
  homepage: https://github.com/yoshoku/magro
63
71
  licenses:
64
72
  - BSD-3-Clause
65
73
  metadata:
66
74
  homepage_uri: https://github.com/yoshoku/magro
67
75
  source_code_uri: https://github.com/yoshoku/magro
68
- changelog_uri: https://github.com/yoshoku/magro/blob/master/CHANGELOG.md
76
+ changelog_uri: https://github.com/yoshoku/magro/blob/main/CHANGELOG.md
69
77
  documentation_uri: https://yoshoku.github.io/magro/doc/
70
- post_install_message:
78
+ post_install_message:
71
79
  rdoc_options: []
72
80
  require_paths:
73
81
  - lib
@@ -82,8 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
90
  - !ruby/object:Gem::Version
83
91
  version: '0'
84
92
  requirements: []
85
- rubygems_version: 3.1.2
86
- signing_key:
93
+ rubygems_version: 3.2.21
94
+ signing_key:
87
95
  specification_version: 4
88
96
  summary: Magro is a minimal image processing library for Ruby.
89
97
  test_files: []
data/.travis.yml DELETED
@@ -1,19 +0,0 @@
1
- ---
2
- os: linux
3
- dist: bionic
4
- language: ruby
5
- cache: bundler
6
- rvm:
7
- - '2.4'
8
- - '2.5'
9
- - '2.6'
10
- - '2.7'
11
-
12
- addons:
13
- apt:
14
- packages:
15
- - libpng-dev
16
- - libjpeg-dev
17
-
18
- before_install:
19
- - gem install bundler -v 2.1.4