open_image 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 230ce099b778ece1f735b1d8d7e45f27dc78183f
4
+ data.tar.gz: ee95075f4bc3581d02cee7c439535fe478f2ad69
5
+ SHA512:
6
+ metadata.gz: cb366c4c4268c2dd24c1fd9300829eb94bc788aa5af6481577dee7e82ef981c791c95e6247872766a07e83a102382b61f681984b0ec2cbf15c28bbbe06132f9a
7
+ data.tar.gz: 9630a051b1ffbffbbb169c5893d4dee9977c4c9e888f41969aec044c4fe1dcf32a7a17f1cc479a220046e973aa6dbefbcf2761f7c7d1fbda15ed9a6383b96615
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
14
+ /.idea/
15
+ /.vscode/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.4
5
+ before_install: gem install bundler -v 1.16.2
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ --readme README.md
2
+ --title 'OpenImage Documentation'
3
+ --charset utf-8
4
+ --markup markdown
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at efreed09@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in open_image.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Eric Freed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # OpenImage
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/open_image`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'open_image'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install open_image
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/open_image. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the OpenImage project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/open_image/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ require 'rake/extensiontask'
11
+
12
+ task :build => :compile
13
+
14
+ Rake::ExtensionTask.new('open_image') do |ext|
15
+ ext.lib_dir = 'lib/open_image'
16
+ end
17
+
18
+ task :default => [:clobber, :compile, :test]
data/TODO.md ADDED
@@ -0,0 +1,38 @@
1
+ # TODO
2
+
3
+ ## Point
4
+
5
+ * `offset(x, y)`
6
+ * `offset!(point)`
7
+ * `offset!(x, y)`
8
+ * `move(x, y)`
9
+
10
+ ## Size
11
+
12
+ * `resize(width, height)`
13
+
14
+ ## Rect
15
+
16
+ * `inflate`
17
+ * `inflate!`
18
+ * `offset(point)`
19
+ * `offset(x, y)`
20
+ * `offset!(point)`
21
+ * `offset!(x, y)`
22
+ * `move(x, y)`
23
+ * `resize(width, height)`
24
+ * `intersect(rect)`
25
+ * `intersects?(rect)`
26
+ * `union(rect)`
27
+ * `include?(x, y)`
28
+ * `include?(point)`
29
+ * `include?(rect)`
30
+ * `alias include?, contains?`
31
+
32
+ ## Image
33
+
34
+ * `blit(point, image)`
35
+ * `blit(x, y, image)`
36
+ * `blit(rect, image)`
37
+ * `draw_rect(x, y, width, height, color, thickness)`
38
+ * `draw_rect(rect, color, thickness)`
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "open_image"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,165 @@
1
+
2
+ #include "color.h"
3
+
4
+ #define COLOR() \
5
+ Color *color; \
6
+ Data_Get_Struct(self, Color, color)
7
+
8
+ #define CLAMP(value, min, max) (value < min ? min : value > max ? max : value)
9
+
10
+ VALUE rb_cOpenImageColor;
11
+
12
+ void Init_open_image_color(VALUE module) {
13
+ rb_cOpenImageColor = rb_define_class_under(module, "Color", rb_cObject);
14
+ rb_define_alloc_func(rb_cOpenImageColor, open_image_color_alloc);
15
+ rb_define_method(rb_cOpenImageColor, "initialize", open_image_color_initialize, -1);
16
+
17
+ rb_define_method(rb_cOpenImageColor, "r", open_image_color_get_r, 0);
18
+ rb_define_method(rb_cOpenImageColor, "g", open_image_color_get_g, 0);
19
+ rb_define_method(rb_cOpenImageColor, "b", open_image_color_get_b, 0);
20
+ rb_define_method(rb_cOpenImageColor, "a", open_image_color_get_a, 0);
21
+
22
+ rb_define_method(rb_cOpenImageColor, "r=", open_image_color_set_r, 1);
23
+ rb_define_method(rb_cOpenImageColor, "g=", open_image_color_set_g, 1);
24
+ rb_define_method(rb_cOpenImageColor, "b=", open_image_color_set_b, 1);
25
+ rb_define_method(rb_cOpenImageColor, "a=", open_image_color_set_a, 1);
26
+
27
+ rb_define_alias(rb_cOpenImageColor, "red", "r");
28
+ rb_define_alias(rb_cOpenImageColor, "green", "g");
29
+ rb_define_alias(rb_cOpenImageColor, "blue", "b");
30
+ rb_define_alias(rb_cOpenImageColor, "alpha", "a");
31
+
32
+ rb_define_alias(rb_cOpenImageColor, "red=", "r=");
33
+ rb_define_alias(rb_cOpenImageColor, "green=", "g=");
34
+ rb_define_alias(rb_cOpenImageColor, "blue=", "b=");
35
+ rb_define_alias(rb_cOpenImageColor, "alpha=", "a=");
36
+
37
+ rb_define_method(rb_cOpenImageColor, "to_a", open_image_color_to_a, 0);
38
+ rb_define_method(rb_cOpenImageColor, "to_h", open_image_color_to_h, 0);
39
+ rb_define_method(rb_cOpenImageColor, "to_s", open_image_color_to_s, 0);
40
+ rb_define_method(rb_cOpenImageColor, "to_i", open_image_color_to_i, 0);
41
+
42
+ rb_define_alias(rb_cOpenImageColor, "to_str", "to_s");
43
+ rb_define_alias(rb_cOpenImageColor, "to_int", "to_i");
44
+ }
45
+
46
+ VALUE open_image_color_alloc(VALUE klass) {
47
+ Color *color = ALLOC(Color);
48
+ memset(color, 0, sizeof(Color));
49
+ return Data_Wrap_Struct(klass, NULL, RUBY_DEFAULT_FREE, color);
50
+ }
51
+
52
+ VALUE open_image_color_initialize(int argc, VALUE *argv, VALUE self) {
53
+ unsigned char *color = RDATA(self)->data;
54
+ switch (argc) {
55
+ case 0: // None
56
+ break;
57
+ case 1: {
58
+ uint argb;
59
+ if (RB_TYPE_P(argv[0], T_STRING)) // HTML
60
+ {
61
+ const char *hexstring = StringValueCStr(argv[0]);
62
+ if (hexstring[0] == '#')
63
+ hexstring++;
64
+ argb = (uint)strtoul(hexstring, NULL, 16);
65
+
66
+ printf("%u", argb);
67
+ } else // Unsigned Integer
68
+ {
69
+ argb = NUM2UINT(argv[0]);
70
+ }
71
+ color[3] = (unsigned char)((argb & 0xff000000) >> 24);
72
+ color[0] = (unsigned char)((argb & 0x00ff0000) >> 16);
73
+ color[1] = (unsigned char)((argb & 0x0000ff00) >> 8);
74
+ color[2] = (unsigned char)(argb & 0x000000ff);
75
+
76
+ // TODO: Test big-endian
77
+
78
+ break;
79
+ }
80
+ case 3: // RGB
81
+ color[3] = 255;
82
+ case 4: // RGBA
83
+ {
84
+ for (int i = 0; i < argc; i++) {
85
+ char c = NUM2CHR(argv[i]);
86
+ memcpy(&color[i], &c, 1);
87
+ }
88
+ break;
89
+ }
90
+ }
91
+ return Qnil;
92
+ }
93
+
94
+ VALUE open_image_color_get_r(VALUE self) {
95
+ COLOR();
96
+ return INT2NUM(color->r);
97
+ }
98
+
99
+ VALUE open_image_color_get_g(VALUE self) {
100
+ COLOR();
101
+ return INT2NUM(color->g);
102
+ }
103
+
104
+ VALUE open_image_color_get_b(VALUE self) {
105
+ COLOR();
106
+ return INT2NUM(color->b);
107
+ }
108
+
109
+ VALUE open_image_color_get_a(VALUE self) {
110
+ COLOR();
111
+ return INT2NUM(color->a);
112
+ }
113
+
114
+ VALUE open_image_color_set_r(VALUE self, VALUE value) {
115
+ COLOR();
116
+ color->r = (unsigned char)CLAMP(NUM2INT(value), 0, 255);
117
+ return value;
118
+ }
119
+
120
+ VALUE open_image_color_set_g(VALUE self, VALUE value) {
121
+ COLOR();
122
+ color->g = (unsigned char)CLAMP(NUM2INT(value), 0, 255);
123
+ return value;
124
+ }
125
+ VALUE open_image_color_set_b(VALUE self, VALUE value) {
126
+ COLOR();
127
+ color->b = (unsigned char)CLAMP(NUM2INT(value), 0, 255);
128
+ return value;
129
+ }
130
+
131
+ VALUE open_image_color_set_a(VALUE self, VALUE value) {
132
+ COLOR();
133
+ color->a = (unsigned char)CLAMP(NUM2INT(value), 0, 255);
134
+ return value;
135
+ }
136
+
137
+ VALUE open_image_color_to_a(VALUE self) {
138
+ COLOR();
139
+ VALUE ary = rb_ary_new_capa(4);
140
+ rb_ary_store(ary, 0, color->r);
141
+ rb_ary_store(ary, 1, color->g);
142
+ rb_ary_store(ary, 2, color->b);
143
+ rb_ary_store(ary, 3, color->a);
144
+ return ary;
145
+ }
146
+
147
+ VALUE open_image_color_to_h(VALUE self) {
148
+ COLOR();
149
+ VALUE hash = rb_hash_new();
150
+ rb_hash_aset(hash, STR2SYM("red"), color->r);
151
+ rb_hash_aset(hash, STR2SYM("green"), color->g);
152
+ rb_hash_aset(hash, STR2SYM("blue"), color->b);
153
+ rb_hash_aset(hash, STR2SYM("alpha"), color->a);
154
+ return hash;
155
+ }
156
+
157
+ VALUE open_image_color_to_s(VALUE self) {
158
+ COLOR();
159
+ return rb_sprintf("<Color: R:%d, G:%d, B:%d, A:%d>", color->r, color->g, color->b, color->a);
160
+ }
161
+
162
+ VALUE open_image_color_to_i(VALUE self) {
163
+ COLOR();
164
+ return UINT2NUM((uint)(((color->a << 24) | (color->r << 16) | (color->g << 8) | color->b) & 0xFFFFFFFFu));
165
+ }
@@ -0,0 +1,27 @@
1
+
2
+ #ifndef RB_OPEN_IMAGE_COLOR_H
3
+ #define RB_OPEN_IMAGE_COLOR_H 1
4
+
5
+ #include <string.h>
6
+ #include "common.h"
7
+
8
+ void Init_open_image_color(VALUE module);
9
+ VALUE open_image_color_alloc(VALUE klass);
10
+ VALUE open_image_color_initialize(int argc, VALUE *argv, VALUE self);
11
+
12
+ VALUE open_image_color_get_r(VALUE self);
13
+ VALUE open_image_color_get_g(VALUE self);
14
+ VALUE open_image_color_get_b(VALUE self);
15
+ VALUE open_image_color_get_a(VALUE self);
16
+
17
+ VALUE open_image_color_set_r(VALUE self, VALUE value);
18
+ VALUE open_image_color_set_g(VALUE self, VALUE value);
19
+ VALUE open_image_color_set_b(VALUE self, VALUE value);
20
+ VALUE open_image_color_set_a(VALUE self, VALUE value);
21
+
22
+ VALUE open_image_color_to_a(VALUE self);
23
+ VALUE open_image_color_to_h(VALUE self);
24
+ VALUE open_image_color_to_s(VALUE self);
25
+ VALUE open_image_color_to_i(VALUE self);
26
+
27
+ #endif /* RB_OPEN_IMAGE_COLOR_H */