stbimage 0.1.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +116 -0
- data/dlls/stbDLL_x64.dll +0 -0
- data/dlls/stbDLL_x86.dll +0 -0
- data/lib/stbimage.rb +69 -32
- data/utils/system_check.rb +51 -0
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c7e3cbdd4dccecf5bf9a5c6ebc0365b6466fde88658ba4cc55d9b8d723217b5
|
4
|
+
data.tar.gz: 32f870bd08f340ac675e3d1a68bced77b0201b9fe7c73ea58bcee53314df131c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a1e041c4080ea9a88292ee5b5b8882a228b0a3ce485ab5eea544cca27576f8e4ccd05e2858e1b0d77b517c004658db6a5d62845b409d44dd0b7d0a4dbdaf313
|
7
|
+
data.tar.gz: 9507fa97a2455e1280d402ebe1419eca0db673e8b7c9001253d7070ddfc1be99e130a31e12eba38f26c6f68f34fe5438a07623bf8c73ae29820243029c7c986c
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# STBIMAGE
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
Ruby binding of stb-image.h
|
6
|
+
|
7
|
+
**Works well on windows!!!**
|
8
|
+
**Added support for Linux (32, 64, arm)**
|
9
|
+
|
10
|
+
* ### Supports (so far): ###
|
11
|
+
<br>
|
12
|
+
|
13
|
+
* **stbi_load** (Default image loader)
|
14
|
+
* **stbi_load_16**
|
15
|
+
* **stbi_loadf** (For `.hdr` images)
|
16
|
+
* **stbi_info**
|
17
|
+
* **stbi_image_free**
|
18
|
+
* **stbi_failure_reason**
|
19
|
+
* **stbi_set_flip_vertically_on_load**
|
20
|
+
* **stbi_set_flip_vertically_on_load_thread**
|
21
|
+
* **stbi_set_unpremultiply_on_load**
|
22
|
+
* **stbi_convert_iphone_png_to_rgb**
|
23
|
+
* **stbi_hdr_to_ldr_gamma**
|
24
|
+
* **stbi_hdr_to_ldr_scale**
|
25
|
+
* **stbi_is_16_bit**
|
26
|
+
* **stbi_is_hdr**
|
27
|
+
* **stbi_zlib_decode_buffer**
|
28
|
+
* **stbi_zlib_decode_malloc**
|
29
|
+
* **stbi_zlib_decode_malloc_guesssize**
|
30
|
+
* **stbi_zlib_decode_malloc_guesssize_headerflag**
|
31
|
+
* **stbi_zlib_decode_noheader_buffer**
|
32
|
+
* **stbi_zlib_decode_noheader_malloc**
|
33
|
+
|
34
|
+
|
35
|
+
<br>
|
36
|
+
|
37
|
+
# Installation
|
38
|
+
|
39
|
+
* Windows:\
|
40
|
+
`gem install stbimage`
|
41
|
+
|
42
|
+
* Linux/macOs:\
|
43
|
+
`gem install stbimage`
|
44
|
+
|
45
|
+
*Note: In macOs you have to compile the dynamic libary (.so) yourself. Although I planned to include it in the future*
|
46
|
+
|
47
|
+
<br>
|
48
|
+
|
49
|
+
# .dll libs
|
50
|
+
|
51
|
+
You can find it under [dlls](dlls) folder
|
52
|
+
|
53
|
+
<br>
|
54
|
+
|
55
|
+
# Usage
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require 'stbimage'
|
59
|
+
|
60
|
+
# use this to load the dll (from gem version 0.2.3 and above)! Only For windows and linux yet
|
61
|
+
STBIMAGE.load_lib()
|
62
|
+
|
63
|
+
# In macOs you have to provide a dynamic libary (.so) by yourself
|
64
|
+
# STBIMAGE.load_lib('your_name.so', 'absolute_path_to_file')
|
65
|
+
|
66
|
+
|
67
|
+
width = ' ' * 4
|
68
|
+
height = ' ' * 4
|
69
|
+
nr_channels = ' ' * 4
|
70
|
+
|
71
|
+
data = STBIMAGE.stbi_load("blue-poly.jpg", width, height, nr_channels, 0)
|
72
|
+
|
73
|
+
puts data # You can use this data in OpenGL for instance.
|
74
|
+
|
75
|
+
puts width.unpack('l')[0]
|
76
|
+
puts height.unpack('l')[0]
|
77
|
+
puts nr_channels.unpack('l')[0]
|
78
|
+
```
|
79
|
+
|
80
|
+
<br>
|
81
|
+
|
82
|
+
# Credit
|
83
|
+
|
84
|
+
* Credit to Vaiorabbit who made the bindings of opengl into ruby! This wrapper is based on his glfw wrapper.
|
85
|
+
His repo: https://github.com/vaiorabbit/ruby-opengl
|
86
|
+
|
87
|
+
* stb_image.h by Sean Barret. Repo: https://github.com/nothings/stb/blob/master/stb_image.h
|
88
|
+
|
89
|
+
|
90
|
+
<br>
|
91
|
+
|
92
|
+
# Licence
|
93
|
+
|
94
|
+
MIT License
|
95
|
+
|
96
|
+
```
|
97
|
+
Copyright (c) 2021 Samuel Keresztes
|
98
|
+
|
99
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
100
|
+
of this software and associated documentation files (the "Software"), to deal
|
101
|
+
in the Software without restriction, including without limitation the rights
|
102
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
103
|
+
copies of the Software, and to permit persons to whom the Software is
|
104
|
+
furnished to do so, subject to the following conditions:
|
105
|
+
|
106
|
+
The above copyright notice and this permission notice shall be included in all
|
107
|
+
copies or substantial portions of the Software.
|
108
|
+
|
109
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
110
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
111
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
112
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
113
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
114
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
115
|
+
SOFTWARE.
|
116
|
+
```
|
data/dlls/stbDLL_x64.dll
ADDED
Binary file
|
data/dlls/stbDLL_x86.dll
ADDED
Binary file
|
data/lib/stbimage.rb
CHANGED
@@ -29,12 +29,53 @@ module STBIMAGE
|
|
29
29
|
end
|
30
30
|
|
31
31
|
|
32
|
-
@@
|
32
|
+
@@stbi_image_import_done = false
|
33
33
|
|
34
|
-
# Load native
|
34
|
+
# Load native dll libary
|
35
35
|
def self.load_lib(lib = nil, path = nil, output_error = false)
|
36
36
|
if lib == nil && path == nil
|
37
|
-
|
37
|
+
|
38
|
+
if RUBY_PLATFORM =~ /x86/
|
39
|
+
|
40
|
+
# puts "You have a 32-bit Architecture ruby"
|
41
|
+
if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
|
42
|
+
# puts "With Windows"
|
43
|
+
lib, path = 'stbDLL_x86.dll', "#{__dir__}/../dlls"
|
44
|
+
elsif RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /cygwin/
|
45
|
+
# puts "With Linux"
|
46
|
+
lib, path = 'libstb_x86.so', "#{__dir__}/../dlls"
|
47
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
48
|
+
# puts "With macOS"
|
49
|
+
else
|
50
|
+
# puts "I have no idea what os are you using, so it's possible that stbimage wont't work"
|
51
|
+
end
|
52
|
+
|
53
|
+
elsif RUBY_PLATFORM =~ /arm/
|
54
|
+
|
55
|
+
# puts "You have a arm architecture"
|
56
|
+
lib, path = 'libstb_arm.so', "#{__dir__}/../dlls"
|
57
|
+
|
58
|
+
elsif RUBY_PLATFORM =~ /java/
|
59
|
+
|
60
|
+
# puts "You have jruby!"
|
61
|
+
|
62
|
+
else
|
63
|
+
|
64
|
+
# puts "You have a 64-bit Architecture ruby"
|
65
|
+
if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
|
66
|
+
# puts "With Windows"
|
67
|
+
lib, path = 'stbDLL_x64.dll', "#{__dir__}/../dlls"
|
68
|
+
elsif RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /cygwin/
|
69
|
+
# puts "With Linux"
|
70
|
+
lib, path = 'libstb_x64.so', "#{__dir__}/../dlls"
|
71
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
72
|
+
# puts "With macOS"
|
73
|
+
else
|
74
|
+
# puts "I have no idea what os are you using, so it's possible that stbimage wont't work"
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
38
79
|
end
|
39
80
|
|
40
81
|
if path
|
@@ -42,36 +83,31 @@ module STBIMAGE
|
|
42
83
|
else
|
43
84
|
dlload (lib)
|
44
85
|
end
|
45
|
-
import_symbols(output_error) unless @@
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.load_dll(lib = nil, path = nil)
|
49
|
-
puts "Warning STBIMAGE.load_dll is deprecated, use GLFW.load_lib instead"
|
50
|
-
self.load_lib(lib, path)
|
86
|
+
import_symbols(output_error) unless @@stbi_image_import_done
|
51
87
|
end
|
52
88
|
|
53
89
|
@@lib_signature = [
|
54
90
|
'void stbi_convert_iphone_png_to_rgb(int)',
|
55
|
-
'const char
|
91
|
+
'const char* stbi_failure_reason(void)',
|
56
92
|
'void stbi_hdr_to_ldr_gamma(float)',
|
57
93
|
'void stbi_hdr_to_ldr_scale(float)',
|
58
94
|
'void stbi_image_free(void*)',
|
59
95
|
'int stbi_info(char const* , int*, int*, int*)',
|
60
|
-
# '
|
96
|
+
# 'stbi_info_from_callbacks'
|
61
97
|
# 'stbi_info_from_file'
|
62
98
|
# 'stbi_info_from_memory'
|
63
|
-
|
99
|
+
'int stbi_is_16_bit(char const*)',
|
64
100
|
# 'stbi_is_16_bit_from_callbacks'
|
65
101
|
# 'stbi_is_16_bit_from_file'
|
66
102
|
# 'stbi_is_16_bit_from_memory'
|
67
|
-
|
103
|
+
'int stbi_is_hdr(char const*)',
|
68
104
|
# 'stbi_is_hdr_from_callbacks'
|
69
105
|
# 'stbi_is_hdr_from_file'
|
70
106
|
# 'stbi_is_hdr_from_memory'
|
71
|
-
|
72
|
-
|
107
|
+
'void stbi_ldr_to_hdr_gamma(float)',
|
108
|
+
'void stbi_ldr_to_hdr_scale(float)',
|
73
109
|
'stbi_uc* stbi_load(char const*, int*, int*, int*, int)',
|
74
|
-
|
110
|
+
'stbi_us* stbi_load_16(char const*, int*, int*, int*, int)',
|
75
111
|
# 'stbi_load_16_from_callbacks'
|
76
112
|
# 'stbi_load_16_from_memory'
|
77
113
|
# 'stbi_load_from_callbacks'
|
@@ -79,37 +115,38 @@ module STBIMAGE
|
|
79
115
|
# 'stbi_load_from_file_16'
|
80
116
|
# 'stbi_load_from_memory'
|
81
117
|
# 'stbi_load_gif_from_memory'
|
82
|
-
|
118
|
+
'float* stbi_loadf(char const*, int*, int*, int*, int)',
|
83
119
|
# 'stbi_loadf_from_callbacks'
|
84
120
|
# 'stbi_loadf_from_file'
|
85
121
|
# 'stbi_loadf_from_memory'
|
86
|
-
'void stbi_set_flip_vertically_on_load(int)'
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
122
|
+
'void stbi_set_flip_vertically_on_load(int)',
|
123
|
+
'void stbi_set_flip_vertically_on_load_thread(int)',
|
124
|
+
'void stbi_set_unpremultiply_on_load(int)',
|
125
|
+
'int stbi_zlib_decode_buffer(char*, int, const char*, int)',
|
126
|
+
'char* stbi_zlib_decode_malloc(const char*, int, int*)',
|
127
|
+
'char* stbi_zlib_decode_malloc_guesssize(const char*, int, int, int*)',
|
128
|
+
'char* stbi_zlib_decode_malloc_guesssize_headerflag(const char*, int, int, int*, int)',
|
129
|
+
'int stbi_zlib_decode_noheader_buffer(char*, int, const char*, int)',
|
130
|
+
'char* stbi_zlib_decode_noheader_malloc(const char*, int, int*)'
|
131
|
+
|
95
132
|
]
|
96
133
|
|
97
134
|
def self.import_symbols(output_error = false)
|
98
135
|
typealias 'stbi_uc', 'unsigned char'
|
99
|
-
typealias 'stbi_us', 'unsigned short'
|
100
|
-
|
136
|
+
typealias 'stbi_us', 'unsigned short'
|
101
137
|
|
102
138
|
# function
|
103
139
|
@@lib_signature.each do |sig|
|
140
|
+
|
104
141
|
begin
|
105
142
|
extern sig
|
106
143
|
rescue
|
107
144
|
$stderr.puts("[Warning] Failed to import #{sig}.") if output_error
|
108
145
|
end
|
146
|
+
|
109
147
|
end
|
110
148
|
|
111
|
-
|
149
|
+
@@stbi_image_import_done = true
|
150
|
+
|
112
151
|
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
152
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
RUBY_PLATFORM = x86-mingw32
|
2
|
+
|
3
|
+
if RUBY_PLATFORM =~ /x86/
|
4
|
+
|
5
|
+
puts "You have a 32-bit Architecture ruby"
|
6
|
+
if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
|
7
|
+
puts "With Windows"
|
8
|
+
lib, path = 'stbDLL_x86.dll', "#{__dir__}/../dlls"
|
9
|
+
elsif RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /cygwin/
|
10
|
+
puts "With Linux"
|
11
|
+
lib, path = 'libstb_x86.so', "#{__dir__}/../dlls"
|
12
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
13
|
+
puts "With macOS"
|
14
|
+
else
|
15
|
+
puts "I have no idea what os are you using, so it's possible that stbimage wont't work"
|
16
|
+
end
|
17
|
+
|
18
|
+
elsif RUBY_PLATFORM =~ /arm/
|
19
|
+
|
20
|
+
puts "You have a arm architecture"
|
21
|
+
lib, path = 'libstb_arm.so', "#{__dir__}/../dlls"
|
22
|
+
|
23
|
+
elsif RUBY_PLATFORM =~ /java/
|
24
|
+
|
25
|
+
puts "You have jruby!"
|
26
|
+
|
27
|
+
else
|
28
|
+
|
29
|
+
puts "You have a 64-bit Architecture ruby"
|
30
|
+
if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
|
31
|
+
puts "With Windows"
|
32
|
+
lib, path = 'stbDLL_x64.dll', "#{__dir__}/../dlls"
|
33
|
+
elsif RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /cygwin/
|
34
|
+
puts "With Linux"
|
35
|
+
lib, path = 'libstb_x64.so', "#{__dir__}/../dlls"
|
36
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
37
|
+
puts "With macOS"
|
38
|
+
else
|
39
|
+
puts "I have no idea what os are you using, so it's possible that stbimage wont't work"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# if RUBY_PLATFORM == "x64-mswin64_140" || RUBY_PLATFORM == "x64-mingw32"
|
46
|
+
# lib, path = 'stbDLL_x64.dll', "#{__dir__}/../dlls"
|
47
|
+
# elsif RUBY_PLATFORM == "x86-mingw32"
|
48
|
+
# lib, path = 'stbDLL_x86.dll', "#{__dir__}/../dlls"
|
49
|
+
# elsif RUBY_PLATFORM =~ /x86_linux/
|
50
|
+
# lib, path = 'libstd_x86.so', "#{__dir__}/../dlls"
|
51
|
+
# else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stbimage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Keresztes
|
@@ -10,15 +10,21 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2021-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
|
13
|
+
description: "!Beta Version! A practical image importer/loader. It wraps stb_image.h
|
14
|
+
(ver:2.26 -2020.07.13-). Supported image formats are: JPEG, PNG, TGA, BMP, PSD,
|
15
|
+
GIF(not animation), HDR, PIC, PNM. Only works well with windows (win32/win64) and
|
16
|
+
with linux so far, but for macOS, users have to include . Checkout the Homepage
|
17
|
+
for more info (installation, usage and other information)"
|
16
18
|
email: ''
|
17
19
|
executables: []
|
18
20
|
extensions: []
|
19
21
|
extra_rdoc_files: []
|
20
22
|
files:
|
23
|
+
- README.md
|
24
|
+
- dlls/stbDLL_x64.dll
|
25
|
+
- dlls/stbDLL_x86.dll
|
21
26
|
- lib/stbimage.rb
|
27
|
+
- utils/system_check.rb
|
22
28
|
homepage: https://github.com/fellowchap-samuel/stbimage-ruby
|
23
29
|
licenses:
|
24
30
|
- MIT
|