-
Notifications
You must be signed in to change notification settings - Fork 1
/
mqo.c
172 lines (155 loc) · 4.23 KB
/
mqo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* Copyright(c) 2010 Network Applied Communication Lab. All rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the software, and to permit persons to whom the software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHOR OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Note however, the ARToolKit library itself is licensed under either the GNU
* General Public License or another dedicated commercial license. The author
* of this binding did not read the latter when the author wrote this, but
* believes this binding can fit to both. This license is at least compatible
* with the GPL.
*/
/* First edition by Urabe Shyouhei <shyouhei@netlab.jp> on 11 Jul, 2010. */
/**
* @file mqo.c
* @brief very tiny GLMetaseq wrapper
*/
#include <ruby.h>
#include "extconf.h"
#ifdef HAVE_JPEGLIB_H
#include <jpeglib.h>
#define D_JPEG
#endif
#ifdef HAVE_PNG_H
#include <png.h>
#define D_PNG
#endif
#include "GLMetaseq.h"
/**
* @function
* @brief wrapper for mqoInit
* @param[in] self not used at all
* @returns self.
*/
static VALUE m_init _((VALUE self));
/**
* @function
* @brief wrapper for mqoCleanup
* @param[in] self not used at all
* @returns self.
*/
static VALUE m_cleanup _((VALUE self));
/**
* @function
* @brief allocates a new instance
* @param[in] klass the klass to associate
* @returns a newly allocated klass instance
*/
static VALUE m_alloc _((VALUE klass));
/**
* @function
* @brief deallocates an instance
* @param[in] ptr memory region to terminate
*/
static void m_dealloc _((void* ptr));
/**
* @function
* @brief wrapper for mqoCreateModel
* @param[out] self object to load into
* @param[in] path path to read file form
* @param[in] zoom zoom factor
* @returns self
*/
static VALUE m_create_model _((VALUE self, VALUE path, VALUE zoom));
/**
* @function
* @brief wrapper for mqoCallModel
* @param[in] self object to call
* @returns self
*/
static VALUE m_call_model _((VALUE self));
VALUE
m_init(self)
VALUE self;
{
mqoInit();
if(rb_block_given_p())
rb_ensure(rb_yield, self, m_cleanup, self);
return self;
}
VALUE
m_cleanup(self)
VALUE self;
{
mqoCleanup();
return self;
}
VALUE
m_alloc(klass)
VALUE klass;
{
/* Fake, because resource allocation should be done from initialize. */
return Data_Wrap_Struct(klass, 0, m_dealloc, 0);
}
void
m_dealloc(ptr)
void* ptr;
{
if(ptr)
mqoDeleteModel(ptr);
}
VALUE
m_create_model(self, path, zoom)
VALUE self, path, zoom;
{
if(DATA_PTR(self))
rb_raise(rb_eArgError, "initialize twice");
else
DATA_PTR(self) = mqoCreateModel(StringValueCStr(path), NUM2DBL(zoom));
return self;
}
VALUE
m_call_model(self)
VALUE self;
{
if(!DATA_PTR(self))
rb_raise(rb_eArgError, "unlinitialized");
mqoCallModel(DATA_PTR(self));
return self;
}
Init_mqo(void)
{
VALUE m = rb_define_class("MQO", rb_cData);
rb_define_singleton_method(m, "init", m_init, 0);
rb_define_singleton_method(m, "cleanup", m_cleanup, 0);
rb_define_alloc_func(m, m_alloc);
rb_define_method(m, "initialize", m_create_model, 2);
rb_define_method(m, "call", m_call_model, 0);
}
/*
* Local Variables:
* mode: C
* coding: utf-8-unix
* indent-tabs-mode: nil
* tab-width: 8
* fill-column: 79
* default-justification: full
* c-file-style: "Ruby"
* c-doc-comment-style: javadoc
* End:
*/