Skip to content

Commit 96cf86f

Browse files
committed
add vips_header_get
1 parent dff6821 commit 96cf86f

File tree

5 files changed

+55
-18
lines changed

5 files changed

+55
-18
lines changed

src/action.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ action_proc_dot(Reduce *rc, Compile *compile,
433433
g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(pspec));
434434
g_object_get_property(gobject, p, &value);
435435

436-
if (!heap_gvalue_to_ip(&value, out)) {
436+
if (!heap_gvalue_to_ip(rc->heap, &value, out)) {
437437
g_value_unset(&value);
438438
reduce_throw(rc);
439439
}

src/builtin.c

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static BuiltinTypeSpot *header_get_typeof_args[] = {
539539
/* Get type of header field.
540540
*/
541541
static 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
*/
648687
static 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

src/heap.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,11 +1975,8 @@ heap_ip_to_gvalue(PElement *in, GValue *out)
19751975
/* Try to make a heap object from a gvalue.
19761976
*/
19771977
gboolean
1978-
heap_gvalue_to_ip(GValue *in, PElement *out)
1978+
heap_gvalue_to_ip(Heap *heap, GValue *in, PElement *out)
19791979
{
1980-
Reduce *rc = reduce_context;
1981-
Heap *heap = rc->heap;
1982-
19831980
if (G_VALUE_HOLDS_BOOLEAN(in))
19841981
PEPUTP(out, ELEMENT_BOOL, (int) g_value_get_boolean(in));
19851982
else if (G_VALUE_HOLDS_CHAR(in))

src/heap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ gboolean heap_reduce_strict(PElement *base);
498498
gboolean heap_copy(Heap *heap, Compile *compile, PElement *out);
499499

500500
gboolean heap_ip_to_gvalue(PElement *in, GValue *out);
501-
gboolean heap_gvalue_to_ip(GValue *in, PElement *out);
501+
gboolean heap_gvalue_to_ip(Heap *heap, GValue *in, PElement *out);
502502

503503
void graph_node(Heap *heap, VipsBuf *buf, HeapNode *root, gboolean fn);
504504
void graph_pelement(Heap *heap, VipsBuf *buf, PElement *root, gboolean fn);

src/vipsobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ vo_get_required_output(VipsObject *object, GParamSpec *pspec,
377377
}
378378
#endif /*DEBUG */
379379

380-
if (!heap_gvalue_to_ip(&value, &lhs)) {
380+
if (!heap_gvalue_to_ip(vo->rc->heap, &value, &lhs)) {
381381
g_value_unset(&value);
382382
return object;
383383
}
@@ -413,7 +413,7 @@ vo_get_optional_arg(const char *name, PElement *value, Vo *vo, PElement *out)
413413
return value;
414414
g_value_init(&gvalue, type);
415415
g_object_get_property(G_OBJECT(vo->object), name, &gvalue);
416-
if (!heap_gvalue_to_ip(&gvalue, &lhs)) {
416+
if (!heap_gvalue_to_ip(vo->rc->heap, &gvalue, &lhs)) {
417417
g_value_unset(&gvalue);
418418
return value;
419419
}

0 commit comments

Comments
 (0)