hexapdf-cext 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +21 -0
- data/Rakefile +7 -0
- data/ext/hexapdf_cext/extconf.rb +3 -0
- data/ext/hexapdf_cext/hexapdf_cext.c +37 -0
- data/lib/hexapdf/cext.rb +2 -0
- data/lib/hexapdf/cext/image_loader_png.rb +46 -0
- data/lib/hexapdf/cext/version.rb +8 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7947c3aceca18962fee8b94606e67c190c1413817473096cd23cda6086a59af6
|
4
|
+
data.tar.gz: 3e344aa71bd3b5cdee212593f82dd2ba7bf0560907174f315131998c885e6df8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ea9745ea3af00a150858f3845781a392a861bb39798f129ad6bf50e9da5dfe8561c683103a0b1981e90bf200b491f5d8b19fd75e148618b1a1277eaf1640e50
|
7
|
+
data.tar.gz: 7658d7700e433461a9c251df1c6e813cf3ab906ddaff3ea014384bc4770b0c7808425c5dcddb0fb4dc61cd12e2e0d026bcaf80109a0b2bc580ee9b3f83589b5e
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
hexapdf-cext - HexaPDF extension for making slower parts faster
|
2
|
+
Copyright (C) 2020 Thomas Leitner <t_leitner@gmx.at>
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
5
|
+
copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included
|
13
|
+
in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
16
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# hexapdf-cext
|
2
|
+
|
3
|
+
This library provides implementations of some HexaPDF algorithms in C so as to make HexaPDF still faster.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Install the library via Rubygems `gem install hexapdf-cext`. Current versions of HexaPDF automatically look for this gem and activate it if it is found.
|
8
|
+
|
9
|
+
To manually activate the library use `require 'hexapdf/cext'`.
|
10
|
+
|
11
|
+
## Implemented Algorithms
|
12
|
+
|
13
|
+
* Separation of alpha channel from image data for PNG images.
|
14
|
+
|
15
|
+
## License
|
16
|
+
|
17
|
+
MIT - see LICENSE file.
|
18
|
+
|
19
|
+
## Author
|
20
|
+
|
21
|
+
Thomas Leitner <t_leitner@gmx.at>
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#include <errno.h>
|
2
|
+
#include "ruby/ruby.h"
|
3
|
+
#include "string.h"
|
4
|
+
|
5
|
+
VALUE HexaPDFCExt = Qnil;
|
6
|
+
|
7
|
+
void Init_hexapdf_cext();
|
8
|
+
|
9
|
+
VALUE separate_alpha_channel_loop(VALUE self, VALUE data, VALUE bytes_per_row, VALUE bytes_per_colors,
|
10
|
+
VALUE bytes_per_alpha, VALUE image_data, VALUE mask_data) {
|
11
|
+
long bpr = NUM2LONG(bytes_per_row);
|
12
|
+
long bpc = NUM2LONG(bytes_per_colors);
|
13
|
+
long bpa = NUM2LONG(bytes_per_alpha);
|
14
|
+
char* data_ptr = RSTRING_PTR(data);
|
15
|
+
long data_length = RSTRING_LEN(data);
|
16
|
+
char* current;
|
17
|
+
|
18
|
+
for (current = data_ptr; current - data_ptr + bpr <= data_length;) {
|
19
|
+
char* end = current + bpr;
|
20
|
+
rb_str_cat(image_data, current, 1);
|
21
|
+
rb_str_cat(mask_data, current, 1);
|
22
|
+
current++;
|
23
|
+
while (current < end) {
|
24
|
+
rb_str_cat(image_data, current, bpc);
|
25
|
+
current += bpc;
|
26
|
+
rb_str_cat(mask_data, current, bpa);
|
27
|
+
current += bpa;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
return rb_str_drop_bytes(data, current - data_ptr);
|
32
|
+
}
|
33
|
+
|
34
|
+
void Init_hexapdf_cext() {
|
35
|
+
HexaPDFCExt = rb_define_module("HexaPDFCExt");
|
36
|
+
rb_define_module_function(HexaPDFCExt, "separate_alpha_channel_loop", separate_alpha_channel_loop, 6);
|
37
|
+
}
|
data/lib/hexapdf/cext.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'hexapdf/image_loader/png'
|
2
|
+
|
3
|
+
module HexaPDF
|
4
|
+
module CExt
|
5
|
+
module ImageLoaderPNG
|
6
|
+
|
7
|
+
# Faster version of this method by moving the inner loop to C.
|
8
|
+
def separate_alpha_channel(offset, decode_parms)
|
9
|
+
bytes_per_colors = (decode_parms[:BitsPerComponent] * decode_parms[:Colors] + 7) / 8
|
10
|
+
bytes_per_alpha = (decode_parms[:BitsPerComponent] + 7) / 8
|
11
|
+
bytes_per_row = (decode_parms[:Columns] * decode_parms[:BitsPerComponent] *
|
12
|
+
(decode_parms[:Colors] + 1) + 7) / 8 + 1
|
13
|
+
image_data = ''.b
|
14
|
+
mask_data = ''.b
|
15
|
+
|
16
|
+
flate_decode = @document.config.constantize('filter.map', :FlateDecode)
|
17
|
+
source = flate_decode.decoder(Fiber.new(&image_data_proc(offset)))
|
18
|
+
image_deflate = Zlib::Deflate.new(HexaPDF::GlobalConfiguration['filter.flate_compression'],
|
19
|
+
Zlib::MAX_WBITS,
|
20
|
+
HexaPDF::GlobalConfiguration['filter.flate_memory'])
|
21
|
+
mask_deflate = Zlib::Deflate.new(HexaPDF::GlobalConfiguration['filter.flate_compression'],
|
22
|
+
Zlib::MAX_WBITS,
|
23
|
+
HexaPDF::GlobalConfiguration['filter.flate_memory'])
|
24
|
+
data = ''.b
|
25
|
+
image_temp = ''.b
|
26
|
+
mask_temp = ''.b
|
27
|
+
while source.alive? && (new_data = source.resume)
|
28
|
+
data << new_data
|
29
|
+
image_temp.clear
|
30
|
+
mask_temp.clear
|
31
|
+
HexaPDFCExt.separate_alpha_channel_loop(data, bytes_per_row, bytes_per_colors,
|
32
|
+
bytes_per_alpha, image_temp, mask_temp)
|
33
|
+
image_data << image_deflate.deflate(image_temp)
|
34
|
+
mask_data << mask_deflate.deflate(mask_temp)
|
35
|
+
end
|
36
|
+
image_data << image_deflate.finish
|
37
|
+
mask_data << mask_deflate.finish
|
38
|
+
|
39
|
+
return [image_data, mask_data]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
HexaPDF::ImageLoader::PNG.prepend(HexaPDF::CExt::ImageLoaderPNG)
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hexapdf-cext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Leitner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hexapdf
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email: t_leitner@gmx.at
|
43
|
+
executables: []
|
44
|
+
extensions:
|
45
|
+
- ext/hexapdf_cext/extconf.rb
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- ext/hexapdf_cext/extconf.rb
|
52
|
+
- ext/hexapdf_cext/hexapdf_cext.c
|
53
|
+
- lib/hexapdf/cext.rb
|
54
|
+
- lib/hexapdf/cext/image_loader_png.rb
|
55
|
+
- lib/hexapdf/cext/version.rb
|
56
|
+
homepage: https://hexapdf.gettalong.org
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.4'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.1.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Faster implementation of some HexaPDF algorithms in C for still more performance
|
79
|
+
test_files: []
|