imagepot 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 82a218549dc582ae6da81a56efd9b7994d054a0b1d1eabb7b76bf4e10c030276
4
+ data.tar.gz: 68e22a78727b73f6de1e721d0a7b46fb7e7d15c6728f01ff112764b802f3150a
5
+ SHA512:
6
+ metadata.gz: 27333f75219632ba083f99c6979731481931df0c4e15d3fba5d32baf4598f2503840d9f397d129675662b09a79b8945dea4bf9172dfc923bdf07eef80f650ccf
7
+ data.tar.gz: e21d339f0fc3de05cca235003fbd0800484d24b8187d9b38e08d7daf8cc45ab130f711aee81b3c744a39492636d9dd2e6167656a7d105bcc349d5156727dd775
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Tommy Jeff
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,39 @@
1
+ # Imagepot
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ 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/imagepot`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
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. 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 the created tag, 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]/imagepot.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/extensiontask"
5
+
6
+ task build: :compile
7
+
8
+ GEMSPEC = Gem::Specification.load("imagepot.gemspec")
9
+
10
+ Rake::ExtensionTask.new("imagepot", GEMSPEC) do |ext|
11
+ ext.lib_dir = "lib/imagepot"
12
+ end
13
+
14
+ task default: %i[clobber compile]
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ # Makes all symbols private by default to avoid unintended conflict
6
+ # with other gems. To explicitly export symbols you can use RUBY_FUNC_EXPORTED
7
+ # selectively, or entirely remove this flag.
8
+ append_cflags("-fvisibility=hidden")
9
+
10
+ have_framework("Cocoa")
11
+
12
+ $CFLAGS << " -ObjC"
13
+
14
+ # Add Cocoa framework to linker flags
15
+ $LDFLAGS << " -framework Cocoa"
16
+
17
+ create_makefile("imagepot/imagepot")
@@ -0,0 +1,6 @@
1
+ #ifndef IMAGEPOT_H
2
+ #define IMAGEPOT_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #endif /* IMAGEPOT_H */
@@ -0,0 +1,79 @@
1
+ #include "imagepot.h"
2
+ #import <Cocoa/Cocoa.h>
3
+
4
+ NSData *CompressNSImageToJPEG(NSImage *image, CGFloat compressionFactor) {
5
+ // Make sure the image has representations we can work with
6
+ if (![image isValid]) return nil;
7
+
8
+ // Convert NSImage to bitmap representation
9
+ NSBitmapImageRep *bitmapRep = nil;
10
+ for (NSImageRep *rep in [image representations]) {
11
+ if ([rep isKindOfClass:[NSBitmapImageRep class]]) {
12
+ bitmapRep = (NSBitmapImageRep *)rep;
13
+ break;
14
+ }
15
+ }
16
+
17
+ if (!bitmapRep) {
18
+ // Create a bitmap representation if one doesn't exist
19
+ [image lockFocus];
20
+ NSBitmapImageRep *newRep = [[NSBitmapImageRep alloc]
21
+ initWithFocusedViewRect:NSMakeRect(0, 0, image.size.width, image.size.height)];
22
+ [image unlockFocus];
23
+ bitmapRep = newRep;
24
+ }
25
+
26
+ // Set compression quality
27
+ NSDictionary *properties = @{
28
+ NSImageCompressionFactor: @(compressionFactor) // value between 0.0 and 1.0
29
+ };
30
+
31
+ // Convert to JPEG data
32
+ NSData *jpegData = [bitmapRep representationUsingType:NSBitmapImageFileTypeJPEG
33
+ properties:properties];
34
+ return jpegData;
35
+ }
36
+
37
+
38
+ VALUE rb_mImagepot;
39
+ VALUE rb_mImagepotClass = Qnil;
40
+
41
+ VALUE super_initialize(VALUE self);
42
+ VALUE c_say(VALUE self, VALUE msg);
43
+ VALUE compress_jpg(VALUE self, VALUE input_path, VALUE output_path, VALUE quality);
44
+
45
+ RUBY_FUNC_EXPORTED void
46
+ Init_imagepot(void)
47
+ {
48
+ rb_mImagepot = rb_define_module("Imagepot");
49
+ rb_mImagepotClass = rb_define_class_under(rb_mImagepot, "Imagepot", rb_cObject);
50
+ rb_define_method(rb_mImagepotClass, "initialize", super_initialize, 0);
51
+ rb_define_method(rb_mImagepotClass, "c_say", c_say, 1);
52
+ rb_define_method(rb_mImagepotClass, "compress_jpg", compress_jpg, 3);
53
+ }
54
+
55
+ VALUE super_initialize(VALUE self) {
56
+ rb_iv_set(self, "@var", rb_hash_new());
57
+ return self;
58
+ }
59
+
60
+ VALUE c_say(VALUE self, VALUE msg) {
61
+ const char *cstr = StringValueCStr(msg);
62
+ printf("Hello c_say(): %s\n", cstr);
63
+ NSLog(@"Cocoa says: %s", cstr);
64
+ return Qnil;
65
+ }
66
+
67
+ VALUE compress_jpg(VALUE self, VALUE input, VALUE output, VALUE q) {
68
+ const char *input_path = StringValueCStr(input);
69
+ const char *output_path = StringValueCStr(output);
70
+ double d = NUM2DBL(q);
71
+ float quality = (float)d;
72
+ NSString *origin_path = [[NSString alloc] initWithCString:input_path encoding:NSUTF8StringEncoding];
73
+ NSString *save_path = [[NSString alloc] initWithCString:output_path encoding:NSUTF8StringEncoding];
74
+ NSImage *originalImage = [[NSImage alloc] initWithContentsOfFile:origin_path];
75
+ NSData *compressedData = CompressNSImageToJPEG(originalImage, quality);
76
+ [compressedData writeToFile:save_path atomically:YES];
77
+ return Qnil;
78
+ }
79
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Imagepot
4
+ VERSION = "0.1.0"
5
+ end
data/lib/imagepot.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "imagepot/version"
4
+ require_relative "imagepot/imagepot"
5
+
6
+ module Imagepot
7
+ class Error < StandardError; end
8
+
9
+ def self.say
10
+ puts "Hello, say"
11
+ end
12
+ end
data/sig/imagepot.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Imagepot
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imagepot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tommy Jeff
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-06-24 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Cocoa image processing
13
+ email:
14
+ - threcius@yahoo.com
15
+ executables: []
16
+ extensions:
17
+ - ext/imagepot/extconf.rb
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ - Rakefile
23
+ - ext/imagepot/extconf.rb
24
+ - ext/imagepot/imagepot.h
25
+ - ext/imagepot/imagepot.m
26
+ - lib/imagepot.rb
27
+ - lib/imagepot/version.rb
28
+ - sig/imagepot.rbs
29
+ homepage: https://github.com/orklann/imagepot
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ homepage_uri: https://github.com/orklann/imagepot
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 3.1.0
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.6.5
49
+ specification_version: 4
50
+ summary: Cocoa image processing
51
+ test_files: []