Module: DNN::Stb

Defined in:
ext/rb_stb_image/rb_stb_image.c

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);



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

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);



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

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);



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

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);



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

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);



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

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);



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

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);
}