async-ruby-vips 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ #ifndef ASYNC_VIPS_TRANSFORM_H
2
+ #define ASYNC_VIPS_TRANSFORM_H
3
+
4
+ #include "async_vips.h"
5
+ #include "transform_data.h"
6
+
7
+ void init_async_vips_transform();
8
+
9
+ void* av_build_image_thread_func(void* data);
10
+
11
+ #endif
@@ -0,0 +1,74 @@
1
+ #include "transform_data.h"
2
+
3
+ /* Creates a new transform_data structure */
4
+ transform_data_t* av_make_transform_data_src(const char* src_path)
5
+ {
6
+ transform_data_t* tdata = (transform_data_t*)malloc(sizeof(transform_data_t));
7
+ if(tdata)
8
+ {
9
+ memset(tdata, 0, sizeof(transform_data_t));
10
+
11
+ // Source
12
+ tdata->src_path = (char*)malloc(strlen(src_path) + 1);
13
+ if(tdata->src_path)
14
+ {
15
+ strcpy(tdata->src_path, src_path);
16
+ }
17
+ }
18
+
19
+ return tdata;
20
+ }
21
+
22
+ /* Creates a new transform_data structure */
23
+ transform_data_t* av_make_transform_data(const char* src_path, const char* dst_path)
24
+ {
25
+ transform_data_t* tdata = (transform_data_t*)malloc(sizeof(transform_data_t));
26
+ if(tdata)
27
+ {
28
+ memset(tdata, 0, sizeof(transform_data_t));
29
+
30
+ // Source
31
+ tdata->src_path = (char*)malloc(strlen(src_path) + 1);
32
+ if(tdata->src_path)
33
+ {
34
+ strcpy(tdata->src_path, src_path);
35
+ }
36
+
37
+ // Destination
38
+ tdata->dst_path = (char*)malloc(strlen(dst_path) + 1);
39
+ if(tdata->dst_path)
40
+ {
41
+ strcpy(tdata->dst_path, dst_path);
42
+ }
43
+ }
44
+
45
+ return tdata;
46
+ }
47
+
48
+ /* Frees transform data */
49
+ void av_free_transform_data(transform_data_t* tdata)
50
+ {
51
+ if(!tdata)
52
+ return;
53
+
54
+ if(tdata->src_path)
55
+ {
56
+ free(tdata->src_path);
57
+ tdata->src_path = NULL;
58
+ }
59
+
60
+ if(tdata->dst_path)
61
+ {
62
+ free(tdata->dst_path);
63
+ tdata->dst_path = NULL;
64
+ }
65
+
66
+ if(tdata->err_str)
67
+ {
68
+ free(tdata->err_str);
69
+ tdata->err_str = NULL;
70
+ }
71
+
72
+ free(tdata);
73
+ }
74
+
@@ -0,0 +1,34 @@
1
+ #ifndef ASYNC_VIPS_TRANSFORM_DATA_H
2
+ #define ASYNC_VIPS_TRANSFORM_DATA_H
3
+
4
+ #include "ruby.h"
5
+
6
+ typedef struct _transform_data_t
7
+ {
8
+ char* src_path;
9
+ char* dst_path;
10
+
11
+ int target_width;
12
+ int target_height;
13
+
14
+ int natural_orientation;
15
+
16
+ int final_width;
17
+ int final_height;
18
+
19
+ long long final_size;
20
+
21
+ VALUE proc;
22
+ char* err_str;
23
+
24
+ struct _transform_data_t* next;
25
+
26
+ } transform_data_t;
27
+
28
+
29
+ transform_data_t* av_make_transform_data_src(const char* src_path);
30
+ transform_data_t* av_make_transform_data(const char* src_path, const char* dst_path);
31
+ void av_free_transform_data(transform_data_t* tdata);
32
+
33
+
34
+ #endif
@@ -0,0 +1,6 @@
1
+ #ifndef ASYNC_VIPS_TRANSFORM_DATA_FWD_H
2
+ #define ASYNC_VIPS_TRANSFORM_DATA_FWD_H
3
+
4
+ struct transform_data_t;
5
+
6
+ #endif
@@ -0,0 +1,96 @@
1
+ #include "writer.h"
2
+ #include "transform_data.h"
3
+ #include <memory.h>
4
+ #include <stdlib.h>
5
+ #include <pthread.h>
6
+
7
+ pthread_t av_writer_thread;
8
+ pthread_once_t av_qt_once = PTHREAD_ONCE_INIT;
9
+
10
+ typedef struct _av_write_task_t
11
+ {
12
+ transform_func_t func;
13
+ void* data;
14
+ struct _av_write_task_t* next;
15
+ } av_write_task_t;
16
+
17
+
18
+ /* Queue of tasks for processing. */
19
+ pthread_mutex_t av_writer_mutex = PTHREAD_MUTEX_INITIALIZER;
20
+ pthread_cond_t av_writer_cond = PTHREAD_COND_INITIALIZER;
21
+ av_write_task_t* av_writer_queue = NULL;
22
+
23
+
24
+ /* Push new task to front of the queue */
25
+ static void av_write_task_queue_push(av_write_task_t* wtask)
26
+ {
27
+ wtask->next = av_writer_queue;
28
+ av_writer_queue = wtask;
29
+ }
30
+
31
+ /* Pop next task from the queue; Returns NULL, when the queue is empty */
32
+ static av_write_task_t* av_write_task_queue_pop(void)
33
+ {
34
+ av_write_task_t* wtask = av_writer_queue;
35
+ if(wtask)
36
+ {
37
+ av_writer_queue = wtask->next;
38
+ }
39
+
40
+ return wtask;
41
+ }
42
+
43
+
44
+ /* Task processing queue */
45
+ static void* av_writer_thread_func(void* data)
46
+ {
47
+ int is_running = 1;
48
+ av_write_task_t* wtask = NULL;
49
+
50
+ while(is_running)
51
+ {
52
+ pthread_mutex_lock(&av_writer_mutex);
53
+ while (is_running && (wtask = av_write_task_queue_pop()) == NULL)
54
+ {
55
+ pthread_cond_wait(&av_writer_cond, &av_writer_mutex);
56
+ }
57
+ pthread_mutex_unlock(&av_writer_mutex);
58
+
59
+ if(wtask)
60
+ {
61
+ if(wtask->func)
62
+ {
63
+ wtask->func(wtask->data);
64
+ }
65
+
66
+ free(wtask);
67
+ }
68
+ }
69
+
70
+ return NULL;
71
+ }
72
+
73
+
74
+ /* Initialize the writer thread. The thread will wait for tasks to process */
75
+ static void av_init_writer_thread(void)
76
+ {
77
+ pthread_create(&av_writer_thread, NULL, av_writer_thread_func, NULL);
78
+ pthread_detach(av_writer_thread);
79
+ }
80
+
81
+ /* asynchronously invoke the func with the provided data */
82
+ void av_enqueue_task(transform_func_t func, void* data)
83
+ {
84
+ pthread_once(&av_qt_once, av_init_writer_thread);
85
+
86
+ pthread_mutex_lock(&av_writer_mutex);
87
+
88
+ av_write_task_t* wtask = (av_write_task_t*)malloc(sizeof(av_write_task_t));
89
+ memset(wtask, 0, sizeof(av_write_task_t));
90
+ wtask->func = func;
91
+ wtask->data = data;
92
+ av_write_task_queue_push(wtask);
93
+
94
+ pthread_mutex_unlock(&av_writer_mutex);
95
+ pthread_cond_signal(&av_writer_cond);
96
+ }
@@ -0,0 +1,7 @@
1
+ #ifndef ASYNC_VIPS_WRITER_H
2
+ #define ASYNC_VIPS_WRITER_H
3
+
4
+ typedef void* (*transform_func_t)(void*);
5
+ void av_enqueue_task(transform_func_t func, void* data);
6
+
7
+ #endif
@@ -0,0 +1,5 @@
1
+ # Vips will print warnings to stdout unless this is set
2
+ ENV['IM_WARNING'] = "0"
3
+
4
+ require 'async_vips_ext'
5
+ require 'async_vips/version'
@@ -0,0 +1,3 @@
1
+ module AsyncVips
2
+ VERSION = "1.2.2"
3
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: async-ruby-vips
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Grigoriy Chudnov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jeweler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ description: Non-blocking transformation and image writing in Ruby, powered by VIPS.
70
+ email: g.chudnov@gmail.com
71
+ executables: []
72
+ extensions:
73
+ - ext/extconf.rb
74
+ extra_rdoc_files:
75
+ - README.md
76
+ files:
77
+ - Gemfile.lock
78
+ - README.md
79
+ - async-ruby-vips.gemspec
80
+ - ext/LICENSE
81
+ - ext/async_vips.c
82
+ - ext/async_vips.h
83
+ - ext/callback.c
84
+ - ext/callback.h
85
+ - ext/details.c
86
+ - ext/details.h
87
+ - ext/extconf.rb
88
+ - ext/image.c
89
+ - ext/image.h
90
+ - ext/info.c
91
+ - ext/info.h
92
+ - ext/transform.c
93
+ - ext/transform.h
94
+ - ext/transform_data.c
95
+ - ext/transform_data.h
96
+ - ext/transform_data_fwd.h
97
+ - ext/writer.c
98
+ - ext/writer.h
99
+ - lib/async_vips.rb
100
+ - lib/async_vips/version.rb
101
+ homepage: https://github.com/gchudnov/async-ruby-vips
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.3
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: async-ruby-vips is a ruby extension for vips that transforms images asynchronously.
125
+ test_files: []