#include "php_sixel.h"
#if HAVE_SIXEL
static zend_class_entry * SixelEncoder_ce_ptr = NULL;
PHP_METHOD(SixelEncoder, __construct)
{
zend_class_entry * _this_ce;
zval * _this_zval;
if (ZEND_NUM_ARGS()>0) {
WRONG_PARAM_COUNT;
}
do {
SIXELSTATUS status;
sixel_encoder_t *encoder;
zval *value;
status = sixel_encoder_new(&encoder, NULL);
if (SIXEL_FAILED(status)) {
#if 0#endif
} else {
value = emalloc(sizeof(zval));
ZVAL_RESOURCE(value, (long)encoder);
zend_update_property(_this_ce, getThis(),
"encoder", sizeof("encoder") - 1, value);
}
} while (0);
}
PHP_METHOD(SixelEncoder, __destruct)
{
zend_class_entry * _this_ce;
zval * _this_zval = NULL;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, SixelEncoder_ce_ptr) == FAILURE) {
return;
}
_this_ce = Z_OBJCE_P(_this_zval);
do {
zval *encoder;
encoder = zend_read_property(_this_ce, getThis(),
"encoder", sizeof("encoder") - 1, 1);
sixel_encoder_unref((sixel_encoder_t *)Z_RESVAL_P(encoder));
efree(encoder);
} while (0);
}
PHP_METHOD(SixelEncoder, setopt)
{
zend_class_entry * _this_ce;
zval * _this_zval = NULL;
const char * opt = NULL;
int opt_len = 0;
const char * arg = NULL;
int arg_len = 0;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s", &_this_zval, SixelEncoder_ce_ptr, &opt, &opt_len, &arg, &arg_len) == FAILURE) {
return;
}
_this_ce = Z_OBJCE_P(_this_zval);
do {
SIXELSTATUS status;
zval *encoder;
encoder = zend_read_property(_this_ce, getThis(),
"encoder", sizeof("encoder") - 1, 1);
status = sixel_encoder_setopt((sixel_encoder_t *)Z_RESVAL_P(encoder), *opt, arg);
#if 0#endif
} while (0);
}
PHP_METHOD(SixelEncoder, encode)
{
zend_class_entry * _this_ce;
zval * _this_zval = NULL;
const char * filename = NULL;
int filename_len = 0;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &_this_zval, SixelEncoder_ce_ptr, &filename, &filename_len) == FAILURE) {
return;
}
_this_ce = Z_OBJCE_P(_this_zval);
do {
SIXELSTATUS status;
zval *encoder;
encoder = zend_read_property(_this_ce, getThis(),
"encoder", sizeof("encoder") - 1, 1);
status = sixel_encoder_encode((sixel_encoder_t *)Z_RESVAL_P(encoder), filename);
#if 0#endif
} while (0);
}
static zend_function_entry SixelEncoder_methods[] = {
PHP_ME(SixelEncoder, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(SixelEncoder, __destruct, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SixelEncoder, setopt, SixelEncoder__setopt_args, ZEND_ACC_PUBLIC)
PHP_ME(SixelEncoder, encode, SixelEncoder__encode_args, ZEND_ACC_PUBLIC)
{ NULL, NULL, NULL }
};
static void class_init_SixelEncoder(void)
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "SixelEncoder", SixelEncoder_methods);
SixelEncoder_ce_ptr = zend_register_internal_class(&ce);
}
zend_function_entry sixel_functions[] = {
{ NULL, NULL, NULL }
};
zend_module_entry sixel_module_entry = {
STANDARD_MODULE_HEADER,
"sixel",
sixel_functions,
PHP_MINIT(sixel),
PHP_MSHUTDOWN(sixel),
PHP_RINIT(sixel),
PHP_RSHUTDOWN(sixel),
PHP_MINFO(sixel),
PHP_SIXEL_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_SIXEL
ZEND_GET_MODULE(sixel)
#endif
PHP_MINIT_FUNCTION(sixel)
{
class_init_SixelEncoder();
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(sixel)
{
return SUCCESS;
}
PHP_RINIT_FUNCTION(sixel)
{
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION(sixel)
{
return SUCCESS;
}
PHP_MINFO_FUNCTION(sixel)
{
php_printf("PHP interface to libsixel\n");
php_info_print_table_start();
php_info_print_table_row(2, "Version",PHP_SIXEL_VERSION " (alpha)");
php_info_print_table_row(2, "Released", "2015-06-23");
php_info_print_table_row(2, "CVS Revision", "$Id: $");
php_info_print_table_row(2, "Authors", "Hayaki Saito 'saitoha@me.com' (developer)\n");
php_info_print_table_end();
}
#endif