Module: DNN::Stb

Defined in:
ext/rb_stb_image/rb_stb_image.c

Constant Summary collapse

STBIR_ALPHA_CHANNEL_NONE =
INT2FIX(STBIR_ALPHA_CHANNEL_NONE)
STBIR_FLAG_ALPHA_PREMULTIPLIED =
INT2FIX(STBIR_FLAG_ALPHA_PREMULTIPLIED)
STBIR_FLAG_ALPHA_USES_COLORSPACE =
INT2FIX(STBIR_FLAG_ALPHA_USES_COLORSPACE)
STBIR_EDGE_CLAMP =
INT2FIX(STBIR_EDGE_CLAMP)
STBIR_EDGE_REFLECT =
INT2FIX(STBIR_EDGE_REFLECT)
STBIR_EDGE_WRAP =
INT2FIX(STBIR_EDGE_WRAP)
STBIR_EDGE_ZERO =
INT2FIX(STBIR_EDGE_ZERO)

Class Method Summary collapse

Class Method Details

.stbi_load(rb_filename, rb_req_comp) ⇒ Object

STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp);



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'ext/rb_stb_image/rb_stb_image.c', line 13

static VALUE rb_stbi_load(VALUE self, VALUE rb_filename, VALUE rb_req_comp) {
  char* filename = StringValuePtr(rb_filename);
  int32_t x, y, n;
  int32_t req_comp = FIX2INT(rb_req_comp);
  uint8_t* data;
  int32_t ch;
  VALUE rb_x, rb_y, rb_n;
  VALUE rb_data;

  data = stbi_load(filename, &x, &y, &n, req_comp);
  rb_x = INT2FIX(x);
  rb_y = INT2FIX(y);
  rb_n = INT2FIX(n);
  ch = req_comp == 0 ? n : req_comp;
  rb_data = rb_str_new((char*)data, y * x * ch);
  stbi_image_free(data);
  return rb_ary_new3(4, rb_data, rb_x, rb_y, rb_n);
}

.stbi_write_bmp(rb_filename, rb_w, rb_h, rb_comp, rb_data) ⇒ Object

STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);



47
48
49
50
51
52
53
54
55
56
57
# File 'ext/rb_stb_image/rb_stb_image.c', line 47

static VALUE rb_stbi_write_bmp(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
  char* filename = StringValuePtr(rb_filename);
  int32_t w = FIX2INT(rb_w);
  int32_t h = FIX2INT(rb_h);
  int32_t comp = FIX2INT(rb_comp);
  uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
  int32_t result;

  result = stbi_write_bmp(filename, w, h, comp, data);
  return INT2FIX(result);
}

.stbi_write_hdr(rb_filename, rb_w, rb_h, rb_comp, rb_data) ⇒ Object

STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);



73
74
75
76
77
78
79
80
81
82
83
# File 'ext/rb_stb_image/rb_stb_image.c', line 73

static VALUE rb_stbi_write_hdr(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
  char* filename = StringValuePtr(rb_filename);
  int32_t w = FIX2INT(rb_w);
  int32_t h = FIX2INT(rb_h);
  int32_t comp = FIX2INT(rb_comp);
  float* data = (float*)StringValuePtr(rb_data);
  int32_t result;

  result = stbi_write_hdr(filename, w, h, comp, data);
  return INT2FIX(result);
}

.stbi_write_jpg(rb_filename, rb_w, rb_h, rb_comp, rb_data, rb_quality) ⇒ Object

STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);



86
87
88
89
90
91
92
93
94
95
96
97
# File 'ext/rb_stb_image/rb_stb_image.c', line 86

static VALUE rb_stbi_write_jpg(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data, VALUE rb_quality) {
  char* filename = StringValuePtr(rb_filename);
  int32_t w = FIX2INT(rb_w);
  int32_t h = FIX2INT(rb_h);
  int32_t comp = FIX2INT(rb_comp);
  uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
  int32_t quality = FIX2INT(rb_quality);
  int32_t result;

  result = stbi_write_jpg(filename, w, h, comp, data, quality);
  return INT2FIX(result);
}

.stbi_write_png(rb_filename, rb_w, rb_h, rb_comp, rb_data, rb_stride_in_bytes) ⇒ Object

STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);



33
34
35
36
37
38
39
40
41
42
43
44
# File 'ext/rb_stb_image/rb_stb_image.c', line 33

static VALUE rb_stbi_write_png(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data, VALUE rb_stride_in_bytes) {
  char* filename = StringValuePtr(rb_filename);
  int32_t w = FIX2INT(rb_w);
  int32_t h = FIX2INT(rb_h);
  int32_t comp = FIX2INT(rb_comp);
  uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
  int32_t stride_in_bytes = FIX2INT(rb_stride_in_bytes);
  int32_t result;

  result = stbi_write_png(filename, w, h, comp, data, stride_in_bytes);
  return INT2FIX(result);
}

.stbi_write_tga(rb_filename, rb_w, rb_h, rb_comp, rb_data) ⇒ Object

STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);



60
61
62
63
64
65
66
67
68
69
70
# File 'ext/rb_stb_image/rb_stb_image.c', line 60

static VALUE rb_stbi_write_tga(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
  char* filename = StringValuePtr(rb_filename);
  int32_t w = FIX2INT(rb_w);
  int32_t h = FIX2INT(rb_h);
  int32_t comp = FIX2INT(rb_comp);
  uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
  int32_t result;

  result = stbi_write_tga(filename, w, h, comp, data);
  return INT2FIX(result);
}

.stbir_resize_uint8(rb_input_pixels, rb_input_w, rb_input_h, rb_input_stride_in_bytes, rb_output_w, rb_output_h, rb_output_stride_in_bytes, rb_num_channels) ⇒ Object

int num_channels);



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'ext/rb_stb_image/rb_stb_image.c', line 102

static VALUE rb_stbir_resize_uint8(VALUE self, VALUE rb_input_pixels, VALUE rb_input_w, VALUE rb_input_h, VALUE rb_input_stride_in_bytes,
                                   VALUE rb_output_w, VALUE rb_output_h, VALUE rb_output_stride_in_bytes, VALUE rb_num_channels) {
  uint8_t* input_pixels = (uint8_t*)StringValuePtr(rb_input_pixels);
  int32_t input_w = FIX2INT(rb_input_w);
  int32_t input_h = FIX2INT(rb_input_h);
  int32_t input_stride_in_bytes = FIX2INT(rb_input_stride_in_bytes);
  int32_t output_w = FIX2INT(rb_output_w);
  int32_t output_h = FIX2INT(rb_output_h);
  int32_t output_stride_in_bytes = FIX2INT(rb_output_stride_in_bytes);
  int32_t num_channels = FIX2INT(rb_num_channels);
  uint8_t* output_pixels;
  VALUE rb_output_pixels;
  int32_t result;
  const int32_t output_size = output_h * output_w * num_channels;

  output_pixels = (uint8_t*)malloc(output_size);
  result = stbir_resize_uint8(input_pixels, input_w, input_h, input_stride_in_bytes,
                              output_pixels, output_w, output_h, output_stride_in_bytes, num_channels);
  rb_output_pixels = rb_str_new((char*)output_pixels, output_size);
  free(output_pixels);
  return rb_ary_new3(2, rb_output_pixels, INT2FIX(result));
}

.stbir_resize_uint8_srgb(rb_input_pixels, rb_input_w, rb_input_h, rb_input_stride_in_bytes, rb_output_w, rb_output_h, rb_output_stride_in_bytes, rb_num_channels, rb_alpha_channel, rb_flags) ⇒ Object

int num_channels, int alpha_channel, int flags);



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'ext/rb_stb_image/rb_stb_image.c', line 128

static VALUE rb_stbir_resize_uint8_srgb(VALUE self, VALUE rb_input_pixels, VALUE rb_input_w, VALUE rb_input_h, VALUE rb_input_stride_in_bytes,
                                   VALUE rb_output_w, VALUE rb_output_h, VALUE rb_output_stride_in_bytes, VALUE rb_num_channels,
                                   VALUE rb_alpha_channel, VALUE rb_flags) {
  uint8_t* input_pixels = (uint8_t*)StringValuePtr(rb_input_pixels);
  int32_t input_w = FIX2INT(rb_input_w);
  int32_t input_h = FIX2INT(rb_input_h);
  int32_t input_stride_in_bytes = FIX2INT(rb_input_stride_in_bytes);
  int32_t output_w = FIX2INT(rb_output_w);
  int32_t output_h = FIX2INT(rb_output_h);
  int32_t output_stride_in_bytes = FIX2INT(rb_output_stride_in_bytes);
  int32_t num_channels = FIX2INT(rb_num_channels);
  int32_t alpha_channel = FIX2INT(rb_alpha_channel);
  int32_t flags = FIX2INT(rb_flags);
  uint8_t* output_pixels;
  VALUE rb_output_pixels;
  int32_t result;
  const int32_t output_size = output_h * output_w * num_channels;

  output_pixels = (uint8_t*)malloc(output_size);
  result = stbir_resize_uint8_srgb(input_pixels, input_w, input_h, input_stride_in_bytes,
                                   output_pixels, output_w, output_h, output_stride_in_bytes,
                                   num_channels, alpha_channel, flags);
  rb_output_pixels = rb_str_new((char*)output_pixels, output_size);
  free(output_pixels);
  return rb_ary_new3(2, rb_output_pixels, INT2FIX(result));
}

.stbir_resize_uint8_srgb_edgemode(rb_input_pixels, rb_input_w, rb_input_h, rb_input_stride_in_bytes, rb_output_w, rb_output_h, rb_output_stride_in_bytes, rb_num_channels, rb_alpha_channel, rb_flags, rb_edge_wrap_mode) ⇒ Object

stbir_edge edge_wrap_mode);



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'ext/rb_stb_image/rb_stb_image.c', line 159

static VALUE rb_stbir_resize_uint8_srgb_edgemode(VALUE self, VALUE rb_input_pixels, VALUE rb_input_w, VALUE rb_input_h, VALUE rb_input_stride_in_bytes,
                                   VALUE rb_output_w, VALUE rb_output_h, VALUE rb_output_stride_in_bytes, VALUE rb_num_channels,
                                   VALUE rb_alpha_channel, VALUE rb_flags, VALUE rb_edge_wrap_mode) {
  uint8_t* input_pixels = (uint8_t*)StringValuePtr(rb_input_pixels);
  int32_t input_w = FIX2INT(rb_input_w);
  int32_t input_h = FIX2INT(rb_input_h);
  int32_t input_stride_in_bytes = FIX2INT(rb_input_stride_in_bytes);
  int32_t output_w = FIX2INT(rb_output_w);
  int32_t output_h = FIX2INT(rb_output_h);
  int32_t output_stride_in_bytes = FIX2INT(rb_output_stride_in_bytes);
  int32_t num_channels = FIX2INT(rb_num_channels);
  int32_t alpha_channel = FIX2INT(rb_alpha_channel);
  int32_t flags = FIX2INT(rb_flags);
  stbir_edge edge_wrap_mode = (stbir_edge)FIX2INT(rb_edge_wrap_mode);
  uint8_t* output_pixels;
  VALUE rb_output_pixels;
  int32_t result;
  const int32_t output_size = output_h * output_w * num_channels;

  output_pixels = (uint8_t*)malloc(output_size);
  result = stbir_resize_uint8_srgb_edgemode(input_pixels, input_w, input_h, input_stride_in_bytes,
                                            output_pixels, output_w, output_h, output_stride_in_bytes,
                                            num_channels, alpha_channel, flags, edge_wrap_mode);
  rb_output_pixels = rb_str_new((char*)output_pixels, output_size);
  free(output_pixels);
  return rb_ary_new3(2, rb_output_pixels, INT2FIX(result));
}