@@ -539,7 +539,7 @@ static BuiltinTypeSpot *header_get_typeof_args[] = {
539539/* Get type of header field.
540540 */
541541static void
542- apply_header_get_type_call (Reduce * rc ,
542+ apply_header_typeof_call (Reduce * rc ,
543543 const char * name , HeapNode * * arg , PElement * out )
544544{
545545 Heap * heap = rc -> heap ;
@@ -580,8 +580,11 @@ apply_header_int_call(Reduce *rc,
580580 Imageinfo * ii = reduce_get_image (rc , & rhs );
581581
582582 int value ;
583- if (vips_image_get_int (ii -> image , buf , & value ) ||
584- !heap_real_new (heap , value , out ))
583+ if (vips_image_get_int (ii -> image , buf , & value )) {
584+ error_vips_all ();
585+ reduce_throw (rc );
586+ }
587+ if (!heap_real_new (heap , value , out ))
585588 reduce_throw (rc );
586589}
587590
@@ -605,8 +608,11 @@ apply_header_double_call(Reduce *rc,
605608 Imageinfo * ii = reduce_get_image (rc , & rhs );
606609
607610 double value ;
608- if (vips_image_get_double (ii -> image , buf , & value ) ||
609- !heap_real_new (heap , value , out ))
611+ if (vips_image_get_double (ii -> image , buf , & value )) {
612+ error_vips_all ();
613+ reduce_throw (rc );
614+ }
615+ if (!heap_real_new (heap , value , out ))
610616 reduce_throw (rc );
611617}
612618
@@ -632,8 +638,10 @@ apply_header_string_call(Reduce *rc,
632638 // a managedstring, since value might go away ... take a copy and control
633639 // it with our GC
634640 const char * value ;
635- if (vips_image_get_string (ii -> image , buf , & value ))
641+ if (vips_image_get_string (ii -> image , buf , & value )) {
642+ error_vips_all ();
636643 reduce_throw (rc );
644+ }
637645 if (!value ) {
638646 error_top (_ ("Null value" ));
639647 error_sub (_ ("field %s has a NULL value" ), buf );
@@ -643,6 +651,37 @@ apply_header_string_call(Reduce *rc,
643651 reduce_throw (rc );
644652}
645653
654+ /* Get any type field to a nip4 type, if possible.
655+ */
656+ static void
657+ apply_header_get_call (Reduce * rc ,
658+ const char * name , HeapNode * * arg , PElement * out )
659+ {
660+ Heap * heap = rc -> heap ;
661+
662+ PElement rhs ;
663+
664+ /* Get string.
665+ */
666+ PEPOINTRIGHT (arg [1 ], & rhs );
667+ char buf [VIPS_PATH_MAX ];
668+ (void ) reduce_get_string (rc , & rhs , buf , VIPS_PATH_MAX );
669+
670+ PEPOINTRIGHT (arg [0 ], & rhs );
671+ Imageinfo * ii = reduce_get_image (rc , & rhs );
672+
673+ GValue value_copy = { 0 };
674+ if (vips_image_get (ii -> image , buf , & value_copy )) {
675+ error_vips_all ();
676+ reduce_throw (rc );
677+ }
678+ if (!heap_gvalue_to_ip (heap , & value_copy , out )) {
679+ g_value_unset (& value_copy );
680+ reduce_throw (rc );
681+ }
682+ g_value_unset (& value_copy );
683+ }
684+
646685/* Args for "math".
647686 */
648687static BuiltinTypeSpot * math_args [] = {
@@ -1400,7 +1439,7 @@ static BuiltinInfo builtin_table[] = {
14001439
14011440 { "vips_header_typeof" , N_ ("get header field type" ),
14021441 FALSE, VIPS_NUMBER (header_get_typeof_args ),
1403- & header_get_typeof_args [0 ], apply_header_get_type_call },
1442+ & header_get_typeof_args [0 ], apply_header_typeof_call },
14041443 { "vips_header_int" , N_ ("get int valued field" ),
14051444 FALSE, VIPS_NUMBER (header_get_typeof_args ),
14061445 & header_get_typeof_args [0 ], apply_header_int_call },
@@ -1410,6 +1449,9 @@ static BuiltinInfo builtin_table[] = {
14101449 { "vips_header_string" , N_ ("get string valued field" ),
14111450 FALSE, VIPS_NUMBER (header_get_typeof_args ),
14121451 & header_get_typeof_args [0 ], apply_header_string_call },
1452+ { "vips_header_get" , N_ ("get any valued field" ),
1453+ FALSE, VIPS_NUMBER (header_get_typeof_args ),
1454+ & header_get_typeof_args [0 ], apply_header_get_call },
14131455
14141456};
14151457
@@ -1468,9 +1510,7 @@ builtin_usage(VipsBuf *buf, BuiltinInfo *builtin)
14681510 vips_buf_appends (buf , "\n" );
14691511
14701512 for (i = 0 ; i < builtin -> nargs ; i ++ )
1471- vips_buf_appendf (buf , " %d - %s\n" ,
1472- i + 1 ,
1473- builtin -> args [i ]-> name );
1513+ vips_buf_appendf (buf , " %d - %s\n" , i + 1 , builtin -> args [i ]-> name );
14741514}
14751515
14761516#ifdef DEBUG
0 commit comments