<?php
-if ($argc < 4) {
- fprintf(STDERR, "Usage: swfreplacebitmapdata <swf_file> <image_id> <bitmap_file>\n");
+if ($argc < 5) {
+ fprintf(STDERR, "Usage: swfreplacebitmapdata2 <swf_file> <image_id> <bitmap_file> <opts[:opts2[:...]]>\n");
+ fprintf(STDERR, "ex) swfreplacebitmapdata2 test.swf 1 test.png without_converting\n");
+ fprintf(STDERR, "ex) swfreplacebitmapdata2 test.swf 1 test.png rgb15\n");
exit(1);
}
-if ($argc > 3) {
+if ($argc > 4) {
$swf_filename = $argv[1];
$image_id = $argv[2];
$bitmap_filename = $argv[3];
+ $opts = array();
+ foreach (explode(':', $argv[4]) as $key) {
+ $opts[$key] = true;
+ }
}
$swfdata = file_get_contents($swf_filename);
$bitmapdata = file_get_contents($bitmap_filename);
-
$obj = new SWFEditor();
$obj->setShapeAdjustMode(SWFEditor::SHAPE_BITMAP_RECT_RESIZE);
exit(1);
}
-
-$result = $obj->replaceBitmapData($image_id, $bitmapdata, null, true);
-
+if ((count($opts) === 1) && (! empty($opts['without_converting']))) {
+ $result = $obj->replaceBitmapData($image_id, $bitmapdata, null, true);
+} else {
+ $result = $obj->replaceBitmapData($image_id, $bitmapdata, null, $opts);
+}
if ($result == false) {
fprintf(STDERR, "replaceBitmapData($image_id, ...) failed\n");
WRONG_PARAM_COUNT;
RETURN_FALSE; /* XXX */
case 2:
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &image_id, &data, &data_len) == FAILURE) {
- RETURN_FALSE;
-
- }
- break;
case 3:
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsa", &image_id, &data, &data_len, &opts) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|a", &image_id, &data, &data_len, &opts) == FAILURE) {
RETURN_FALSE;
}
break;
}
if (opts) {
opts_table = Z_ARRVAL_P(opts);
- get_zend_hash_value_long(opts_table, "rgb15", rgb15);
+ get_zend_hash_value_boolean(opts_table, "rgb15", rgb15);
}
swf = get_swf_object(getThis() TSRMLS_CC);
#endif /* HAVE_GIF */
}
-
#define get_zend_hash_value_long(table, key, value) do { \
zval **tmp = NULL; \
if (zend_hash_find(table, key, sizeof(key), (void**)&tmp) == SUCCESS) { \
} \
} while (0);
+#define get_zend_hash_value_boolean(table, key, value) do { \
+ zval **tmp = NULL; \
+ if (zend_hash_find(table, key, sizeof(key), (void**)&tmp) == SUCCESS) { \
+ convert_to_boolean_ex(tmp); \
+ value = Z_LVAL_PP(tmp); \
+ } \
+ } while (0);
+
PHP_METHOD(swfed, replaceBitmapData) {
char *data = NULL, *alpha_data = NULL;
int data_len = 0 , alpha_data_len = 0;
+ zval *arg1 = NULL, *arg4 = NULL;
int image_id = 0;
- zval *image_info = NULL;
HashTable *image_info_table = NULL;
- swf_object_t *swf = NULL;
- int result = 0;
- int bitmap_format;
int width = -1, height = -1;
int red = -1, green = -1, blue = -1;
- int rgb15 = -1;
+ HashTable *opts_table = NULL;
int without_converting = 0;
+ int rgb15 = -1;
+ swf_object_t *swf = NULL;
+ int result = 0;
+ int bitmap_format;
switch (ZEND_NUM_ARGS()) {
default:
WRONG_PARAM_COUNT;
RETURN_FALSE; /* XXX */
case 2:
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "ls", &image_id, &data, &data_len) == SUCCESS) {
- ; // OK
- } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "as", &image_info, &data, &data_len) == SUCCESS) {
- ; // OK
- } else {
- php_error(E_WARNING, "%s() expects parameter 1 to be long or array given", get_active_function_name(TSRMLS_C));
-
- RETURN_FALSE;
- }
- break;
- case 3:
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "lss", &image_id, &data, &data_len, &alpha_data, &alpha_data_len) == SUCCESS) {
- ; // OK
- } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "ass", &image_info, &data, &data_len, &alpha_data, &alpha_data_len) == SUCCESS) {
- ; // OK
- } else {
- php_error(E_WARNING, "%s() expects parameter 1 to be long or array given", get_active_function_name(TSRMLS_C));
- RETURN_FALSE;
- }
- break;
- case 4:
+ case 3:
+ case 4:
+ case 5:
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "lssb", &image_id, &data, &data_len, &alpha_data, &alpha_data_len, &without_converting) == SUCCESS) {
- ; // OK
- } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "assb", &image_info, &data, &data_len, &alpha_data, &alpha_data_len, &without_converting) == SUCCESS) {
+ ZEND_NUM_ARGS() TSRMLS_CC, "zs|sz", &arg1, &data, &data_len, &alpha_data, &alpha_data_len, &arg4) == SUCCESS) {
; // OK
} else {
- php_error(E_WARNING, "%s() expects parameter 1 to be long or array given", get_active_function_name(TSRMLS_C));
+ php_error(E_WARNING, "%s() expects parameter 2 to be string given", get_active_function_name(TSRMLS_C));
RETURN_FALSE;
}
break;
}
swf = get_swf_object(getThis() TSRMLS_CC);
-
- if (image_info) {
- image_info_table = Z_ARRVAL_P(image_info);
+
+ if (Z_TYPE_P(arg1) != IS_ARRAY) { // image_id (integer)
+ if (Z_TYPE_P(arg1) != IS_LONG) {
+ convert_to_long(arg1);
+ }
+ image_id = (int) Z_LVAL_P(arg1);
+ } else { // or image_info (array)
+ image_info_table = Z_ARRVAL_P(arg1);
get_zend_hash_value_long(image_info_table, "width", width);
get_zend_hash_value_long(image_info_table, "height", height);
get_zend_hash_value_long(image_info_table, "red", red);
get_zend_hash_value_long(image_info_table, "green", green);
get_zend_hash_value_long(image_info_table, "blue", blue);
- get_zend_hash_value_long(image_info_table, "rgb15", rgb15);
image_id = swf_object_search_cid_by_bitmap_condition(swf, width, height,
red, green, blue);
if (image_id <= 0) {
RETURN_FALSE;
}
}
-
+ if (Z_TYPE_P(arg4) != IS_ARRAY) { // without_converting (boolean)
+ if (Z_TYPE_P(arg4) != IS_BOOL) {
+ convert_to_boolean(arg4);
+ }
+ without_converting = (int) Z_LVAL_P(arg4);
+ } else { // or opts (array)
+ opts_table = Z_ARRVAL_P(arg4);
+ get_zend_hash_value_boolean(opts_table, "without_converting", without_converting);
+ get_zend_hash_value_boolean(opts_table, "rgb15", rgb15);
+ }
bitmap_format = detect_bitmap_format((unsigned char*) data, data_len);
if (without_converting) { // for v8 JPEG Tag
switch (bitmap_format) {