stbimage 0.5.0 → 1.0.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 +4 -4
- data/README.md +120 -31
- data/{dlls → lib/dlls}/libstb_arm.so +0 -0
- data/{dlls → lib/dlls}/libstb_x64.so +0 -0
- data/{dlls → lib/dlls}/libstb_x86.so +0 -0
- data/{dlls → lib/dlls}/stbDLL_x64.dll +0 -0
- data/{dlls → lib/dlls}/stbDLL_x86.dll +0 -0
- data/lib/stbimage.rb +10 -10
- data/stb-source/stb_image.c +7250 -0
- data/stb-source/stb_image.h +7739 -0
- data/utils/system_check.rb +9 -9
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69de01a0ee15b7dc3ce3827d250b061b62d56a3348d49b4cf01f53773439c9ab
|
4
|
+
data.tar.gz: bd2e49f16a3aad172a99645012af9cab9e8cde0a6cb0eef7bb8250ddd888183d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbac49f49b65b30ff3340a8d3d8e2dbb7fb551dae3286255e8fac24282766e8fbc2d3fc9dd43c5082ef9020a0f8aded035064f884cee4e2e7618d115ab85af6c
|
7
|
+
data.tar.gz: 8c31f5a515a4ea94524dfcdbcee97821792655ee8c227f97dab2663ac89527d3fe8820f899aaeaafdf67253c417dee306686914527cc09256fa0220b12fcab7f
|
data/README.md
CHANGED
@@ -1,35 +1,18 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# stb-image ruby bindings
|
4
2
|
|
5
3
|
Ruby binding of stb-image.h
|
6
4
|
|
7
|
-
|
8
|
-
**Added support for Linux (32, 64, arm)**
|
9
|
-
|
10
|
-
* ### Supports (so far): ###
|
5
|
+
* ### Supports: ###
|
11
6
|
<br>
|
12
7
|
|
13
8
|
* **stbi_load** (Default image loader)
|
9
|
+
* **stbi_load_from_memory**
|
14
10
|
* **stbi_load_16**
|
15
11
|
* **stbi_loadf** (For `.hdr` images)
|
16
12
|
* **stbi_info**
|
17
13
|
* **stbi_image_free**
|
18
|
-
* **stbi_failure_reason**
|
19
14
|
* **stbi_set_flip_vertically_on_load**
|
20
|
-
*
|
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**
|
15
|
+
* and more...
|
33
16
|
|
34
17
|
|
35
18
|
<br>
|
@@ -42,13 +25,30 @@ Ruby binding of stb-image.h
|
|
42
25
|
* Linux/macOs:\
|
43
26
|
`gem install stbimage`
|
44
27
|
|
45
|
-
*Note: In macOs you have to compile the dynamic libary (.so) yourself
|
28
|
+
*Note: In Windows and in Linux the gem should work immadiately 'cause we using precompiled libs (see [Usage](#Usage)). In macOs you have to compile the dynamic libary (.so) yourself (see [Compilation](#Compilation)).*
|
29
|
+
|
30
|
+
<br>
|
31
|
+
|
32
|
+
# Compilation
|
33
|
+
|
34
|
+
If you want to compile the shared libary yourself, Use the instruction below (otherwise if the gem works for you than this step is unnecessary):
|
35
|
+
|
36
|
+
1. Download sources: [stb-source](stb-source) (stb_image.h, stb_image.c)
|
37
|
+
|
38
|
+
2. Navigate to the files in terminal with `cd`
|
39
|
+
|
40
|
+
3. Run the command in terminal (works with macOs, linux, and linux arm):
|
41
|
+
`gcc -shared -o libstb.so -fPIC stb_image.c`
|
42
|
+
|
43
|
+
4. If nothing shows up than finally you got your own `libstb.so` file what is fully compatible with your system.
|
44
|
+
|
45
|
+
5. See [Usage](#Usage) to properly load it to your program.
|
46
46
|
|
47
47
|
<br>
|
48
48
|
|
49
|
-
# .dll
|
49
|
+
# Precompiled shared libs (.dll, .so)
|
50
50
|
|
51
|
-
You can find it under [dlls](dlls) folder
|
51
|
+
You can find it under [dlls](lib/dlls) folder, but they are also included in the gem
|
52
52
|
|
53
53
|
<br>
|
54
54
|
|
@@ -57,11 +57,21 @@ You can find it under [dlls](dlls) folder
|
|
57
57
|
```ruby
|
58
58
|
require 'stbimage'
|
59
59
|
|
60
|
-
#
|
60
|
+
# When you using the precompiled shared libs. Only works with linux, arm, Windows (in macOs it doesn't work)
|
61
61
|
STBIMAGE.load_lib()
|
62
62
|
|
63
|
-
#
|
64
|
-
|
63
|
+
# Although when the above function doesn't work for you for some reason (or you are using macOs), please specify arguments in .load_lib function
|
64
|
+
|
65
|
+
# 1. When your own .dll, or .so libary is at the same folder as your program. Or you wanna specify relative_path to file
|
66
|
+
|
67
|
+
# STBIMAGE.load_lib('your_name.so')
|
68
|
+
# or
|
69
|
+
# STBIMAGE.load_lib('your_folder/your_name.so')
|
70
|
+
|
71
|
+
# 2. When your own .dll or .so file is somewhere in your storage, please specify absolute path
|
72
|
+
|
73
|
+
# Example:
|
74
|
+
# STBIMAGE.load_lib('your_name.so', '/home/user/documents/ruby_proj/dll')
|
65
75
|
|
66
76
|
|
67
77
|
width = ' ' * 4
|
@@ -70,13 +80,92 @@ nr_channels = ' ' * 4
|
|
70
80
|
|
71
81
|
data = STBIMAGE.stbi_load("blue-poly.jpg", width, height, nr_channels, 0)
|
72
82
|
|
73
|
-
|
83
|
+
data # the retrieved image data
|
84
|
+
|
85
|
+
width = width.unpack1('L')
|
86
|
+
height height.unpack1('L')
|
87
|
+
nr_channels = nr_channels.unpack1('L')
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
# The retrieved data can be used in OpenGL for instance.
|
92
|
+
# glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data)
|
93
|
+
|
94
|
+
stbi_image_free(data)
|
95
|
+
```
|
96
|
+
|
97
|
+
<br>
|
98
|
+
|
99
|
+
# Function list and examples:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
include STBIMAGE
|
103
|
+
|
104
|
+
# 1. stbi_load(path_to_file, width_ptr, height_ptr, num_channels_ptr, desired_channels)
|
105
|
+
|
106
|
+
width = ' ' * 4 # width_ptr
|
107
|
+
height = ' ' * 4 # height_ptr
|
108
|
+
nr_channels = ' ' * 4 # num_channels_ptr
|
109
|
+
|
110
|
+
data = stbi_load("blue-poly.jpg", width, height, nr_channels, 0)
|
111
|
+
|
112
|
+
# retrieve the values from the pointers
|
113
|
+
width = width.unpack1('L')
|
114
|
+
height = height.unpack1('L')
|
115
|
+
nr_channels = nr_channels.unpack1('L')
|
116
|
+
```
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
include STBIMAGE
|
120
|
+
|
121
|
+
# 2. stbi_load_from_memory(ptr_to_image_data_array, image_array_size_in_bytes, width_ptr, height_ptr, num_channels_ptr, desired_channels)
|
122
|
+
|
123
|
+
white_texture_raw = [
|
124
|
+
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
|
125
|
+
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x08, 0x06, 0x00, 0x00, 0x00, 0x73, 0x7A, 0x7A,
|
126
|
+
0xF4, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, 0x00,
|
127
|
+
0x00, 0x2F, 0x49, 0x44, 0x41, 0x54, 0x58, 0x47, 0xED, 0xD0, 0x41, 0x11, 0x00, 0x00, 0x0C, 0xC2,
|
128
|
+
0xB0, 0xE1, 0x5F, 0x34, 0x93, 0xC1, 0x27, 0x55, 0xD0, 0x4B, 0xDA, 0xF6, 0x86, 0xC5, 0x00, 0x01,
|
129
|
+
0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0xB0, 0x16,
|
130
|
+
0x78, 0x31, 0x4C, 0x7F, 0xA1, 0xF9, 0xB6, 0x23, 0xF9, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E,
|
131
|
+
0x44, 0xAE, 0x42, 0x60, 0x82
|
132
|
+
]
|
133
|
+
|
134
|
+
texture_size = white_texture_raw.size
|
135
|
+
texture_ptr = Fiddle::Pointer.to_ptr(white_texture_raw.pack('C*'))
|
136
|
+
|
137
|
+
width = ' ' * 4 # width_ptr
|
138
|
+
height = ' ' * 4 # height_ptr
|
139
|
+
nr_channels = ' ' * 4 # num_channels_ptr
|
140
|
+
|
141
|
+
data = stbi_load_from_file(texture_ptr, texture_size, width, height, nr_channels, 0)
|
142
|
+
|
143
|
+
# retrieve the values from the pointers
|
144
|
+
width = width.unpack1('L')
|
145
|
+
height = height.unpack1('L')
|
146
|
+
nr_channels = nr_channels.unpack1('L')
|
147
|
+
```
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
include STBIMAGE
|
151
|
+
|
152
|
+
# 3. stbi_set_flip_vertically_on_load(value)
|
153
|
+
# before getting reading the image:
|
74
154
|
|
75
|
-
|
76
|
-
|
77
|
-
puts nr_channels.unpack('l')[0]
|
155
|
+
stbi_set_flip_vertically_on_load(1) # flips the image vertically on load
|
156
|
+
stbi_set_flip_vertically_on_load(0) # disable flipping
|
78
157
|
```
|
79
158
|
|
159
|
+
```ruby
|
160
|
+
include STBIMAGE
|
161
|
+
|
162
|
+
# 4. stbi_image_free(img_data)
|
163
|
+
# freeing up the image in memory after we loaded the image. It's essential in order to avoid big memory usage.
|
164
|
+
|
165
|
+
stbi_image_free(data)
|
166
|
+
```
|
167
|
+
|
168
|
+
|
80
169
|
<br>
|
81
170
|
|
82
171
|
# Credit
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/stbimage.rb
CHANGED
@@ -35,15 +35,15 @@ module STBIMAGE
|
|
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 =~ /
|
38
|
+
if RUBY_PLATFORM =~ /64/
|
39
39
|
|
40
|
-
# puts "You have a
|
40
|
+
# puts "You have a 64-bit Architecture ruby"
|
41
41
|
if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
|
42
42
|
# puts "With Windows"
|
43
|
-
lib, path = '
|
43
|
+
lib, path = 'stbDLL_x64.dll', "#{__dir__}/dlls"
|
44
44
|
elsif RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /cygwin/
|
45
45
|
# puts "With Linux"
|
46
|
-
lib, path = '
|
46
|
+
lib, path = 'libstb_x64.so', "#{__dir__}/dlls"
|
47
47
|
elsif RUBY_PLATFORM =~ /darwin/
|
48
48
|
# puts "With macOS"
|
49
49
|
else
|
@@ -53,7 +53,7 @@ module STBIMAGE
|
|
53
53
|
elsif RUBY_PLATFORM =~ /arm/
|
54
54
|
|
55
55
|
# puts "You have a arm architecture"
|
56
|
-
lib, path = 'libstb_arm.so', "#{__dir__}
|
56
|
+
lib, path = 'libstb_arm.so', "#{__dir__}/dlls"
|
57
57
|
|
58
58
|
elsif RUBY_PLATFORM =~ /java/
|
59
59
|
|
@@ -61,13 +61,13 @@ module STBIMAGE
|
|
61
61
|
|
62
62
|
else
|
63
63
|
|
64
|
-
# puts "You have a
|
64
|
+
# puts "You have a 32-bit Architecture ruby"
|
65
65
|
if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
|
66
66
|
# puts "With Windows"
|
67
|
-
lib, path = '
|
67
|
+
lib, path = 'stbDLL_x86.dll', "#{__dir__}/dlls"
|
68
68
|
elsif RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /cygwin/
|
69
69
|
# puts "With Linux"
|
70
|
-
lib, path = '
|
70
|
+
lib, path = 'libstb_x86.so', "#{__dir__}/dlls"
|
71
71
|
elsif RUBY_PLATFORM =~ /darwin/
|
72
72
|
# puts "With macOS"
|
73
73
|
else
|
@@ -81,7 +81,7 @@ module STBIMAGE
|
|
81
81
|
if path
|
82
82
|
dlload (path + '/' + lib)
|
83
83
|
else
|
84
|
-
dlload (lib)
|
84
|
+
dlload ("#{__dir__}/#{lib}")
|
85
85
|
end
|
86
86
|
import_symbols(output_error) unless @@stbi_image_import_done
|
87
87
|
end
|
@@ -113,7 +113,7 @@ module STBIMAGE
|
|
113
113
|
# 'stbi_load_from_callbacks'
|
114
114
|
# 'stbi_load_from_file'
|
115
115
|
# 'stbi_load_from_file_16'
|
116
|
-
|
116
|
+
'stbi_uc const* stbi_load_from_memory(stbi_uc const*, int, int*, int*, int*, int)',
|
117
117
|
# 'stbi_load_gif_from_memory'
|
118
118
|
'float* stbi_loadf(char const*, int*, int*, int*, int)',
|
119
119
|
# 'stbi_loadf_from_callbacks'
|