@@ -1461,6 +1461,91 @@ PHP_FUNCTION(vips_image_write_to_memory)
1461
1461
}
1462
1462
/* }}} */
1463
1463
1464
+ #define ADD_ELEMENTS (TYPE , APPEND , N ) { \
1465
+ TYPE *p = arr; \
1466
+ size_t i; \
1467
+ \
1468
+ for (i = 0; i < (N); i++) \
1469
+ APPEND(return_value, p[i]); \
1470
+ }
1471
+
1472
+ /* {{{ proto array vips_image_write_to_array(resource image)
1473
+ Write an image to a PHP array. */
1474
+ PHP_FUNCTION (vips_image_write_to_array )
1475
+ {
1476
+ zval * IM ;
1477
+ VipsImage * image ;
1478
+ size_t arr_len ;
1479
+ uint8_t * arr ;
1480
+ size_t n ;
1481
+
1482
+ VIPS_DEBUG_MSG ("vips_image_write_to_array:\n" );
1483
+
1484
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "r" , & IM ) == FAILURE ) {
1485
+ RETURN_LONG (-1 );
1486
+ }
1487
+
1488
+ if ((image = (VipsImage * )zend_fetch_resource (Z_RES_P (IM ),
1489
+ "GObject" , le_gobject )) == NULL ) {
1490
+ RETURN_LONG (-1 );
1491
+ }
1492
+
1493
+ if (!(arr = vips_image_write_to_memory (image , & arr_len ))) {
1494
+ RETURN_LONG (-1 );
1495
+ }
1496
+
1497
+ array_init (return_value );
1498
+ n = arr_len / vips_format_sizeof (image -> BandFmt );
1499
+ g_assert (arr_len % vips_format_sizeof (image -> BandFmt ) == 0 );
1500
+ switch (image -> BandFmt ) {
1501
+ case VIPS_FORMAT_UCHAR :
1502
+ ADD_ELEMENTS (unsigned char , add_next_index_long , n );
1503
+ break ;
1504
+
1505
+ case VIPS_FORMAT_CHAR :
1506
+ ADD_ELEMENTS (signed char , add_next_index_long , n );
1507
+ break ;
1508
+
1509
+ case VIPS_FORMAT_USHORT :
1510
+ ADD_ELEMENTS (unsigned short, add_next_index_long , n );
1511
+ break ;
1512
+
1513
+ case VIPS_FORMAT_SHORT :
1514
+ ADD_ELEMENTS (signed short, add_next_index_long , n );
1515
+ break ;
1516
+
1517
+ case VIPS_FORMAT_UINT :
1518
+ ADD_ELEMENTS (unsigned int , add_next_index_long , n );
1519
+ break ;
1520
+
1521
+ case VIPS_FORMAT_INT :
1522
+ ADD_ELEMENTS (signed int , add_next_index_long , n );
1523
+ break ;
1524
+
1525
+ case VIPS_FORMAT_FLOAT :
1526
+ ADD_ELEMENTS (float , add_next_index_double , n );
1527
+ break ;
1528
+
1529
+ case VIPS_FORMAT_DOUBLE :
1530
+ ADD_ELEMENTS (double , add_next_index_double , n );
1531
+ break ;
1532
+
1533
+ case VIPS_FORMAT_COMPLEX :
1534
+ ADD_ELEMENTS (float , add_next_index_double , n * 2 );
1535
+ break ;
1536
+
1537
+ case VIPS_FORMAT_DPCOMPLEX :
1538
+ ADD_ELEMENTS (double , add_next_index_double , n * 2 );
1539
+ break ;
1540
+
1541
+ default :
1542
+ break ;
1543
+ }
1544
+
1545
+ g_free (arr );
1546
+ }
1547
+ /* }}} */
1548
+
1464
1549
/* {{{ proto string|long vips_foreign_find_load(string filename)
1465
1550
Find a loader for a file */
1466
1551
PHP_FUNCTION (vips_foreign_find_load )
@@ -2075,6 +2160,10 @@ ZEND_BEGIN_ARG_INFO(arginfo_vips_image_write_to_memory, 0)
2075
2160
ZEND_ARG_INFO (0 , image )
2076
2161
ZEND_END_ARG_INFO ()
2077
2162
2163
+ ZEND_BEGIN_ARG_INFO (arginfo_vips_image_write_to_array , 0 )
2164
+ ZEND_ARG_INFO (0 , image )
2165
+ ZEND_END_ARG_INFO ()
2166
+
2078
2167
ZEND_BEGIN_ARG_INFO (arginfo_vips_foreign_find_load , 0 )
2079
2168
ZEND_ARG_INFO (0 , filename )
2080
2169
ZEND_END_ARG_INFO ()
@@ -2162,6 +2251,7 @@ const zend_function_entry vips_functions[] = {
2162
2251
PHP_FE (vips_image_copy_memory , arginfo_vips_image_copy_memory )
2163
2252
PHP_FE (vips_image_new_from_memory , arginfo_vips_image_new_from_memory )
2164
2253
PHP_FE (vips_image_write_to_memory , arginfo_vips_image_write_to_memory )
2254
+ PHP_FE (vips_image_write_to_array , arginfo_vips_image_write_to_array )
2165
2255
PHP_FE (vips_foreign_find_load , arginfo_vips_foreign_find_load )
2166
2256
PHP_FE (vips_foreign_find_load_buffer , arginfo_vips_foreign_find_load_buffer )
2167
2257
PHP_FE (vips_interpolate_new , arginfo_vips_interpolate_new )
0 commit comments