1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00
ruby-opencv/ext/opencv/cvslice.h
2011-05-21 20:43:16 +09:00

60 lines
1.5 KiB
C

/************************************************************
cvslice.h -
$Author: lsxi $
Copyright (C) 2005-2006 Masakazu Yonekura
************************************************************/
#ifndef RUBY_OPENCV_CVSLICE_H
#define RUBY_OPENCV_CVSLICE_H
#include "opencv.h"
#define __NAMESPACE_BEGIN_CVSLICE namespace cCvSlice{
#define __NAMESPACE_END_CVSLICE }
__NAMESPACE_BEGIN_OPENCV
__NAMESPACE_BEGIN_CVSLICE
VALUE rb_class();
void define_ruby_class();
VALUE rb_allocate(VALUE klass);
VALUE rb_initialize(VALUE self, VALUE start, VALUE end);
VALUE rb_start_index_aref(VALUE self);
VALUE rb_end_index_aref(VALUE self);
VALUE rb_start_index_aset(VALUE self, VALUE index);
VALUE rb_end_index_aset(VALUE self, VALUE index);
__NAMESPACE_END_CVSLICE
inline CvSlice*
CVSLICE(VALUE object)
{
CvSlice *ptr;
Data_Get_Struct(object, CvSlice, ptr);
return ptr;
}
inline CvSlice
VALUE_TO_CVSLICE(VALUE object)
{
if (rb_obj_is_kind_of(object, cCvSlice::rb_class())) {
CvSlice* ptr = CVSLICE(object);
return *ptr;
}
else if (rb_obj_is_kind_of(object, rb_cRange)) {
return cvSlice(NUM2INT(rb_funcall(object, rb_intern("begin"), 0)),
rb_funcall(object, rb_intern("exclude_end?"), 0) ? NUM2INT(rb_funcall(object, rb_intern("end"), 0)) : NUM2INT(rb_funcall(object, rb_intern("end"), 0)) - 1);
}
else {
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvSlice::rb_class()));
}
}
__NAMESPACE_END_OPENCV
#endif // RUBY_OPENCV_CVSLICE_H