Skip to content

Commit b0045f1

Browse files
committed
add vector output types
1 parent 91dadd6 commit b0045f1

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/heap.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,33 @@ heap_intvec_new(Heap *heap, int n, int *vec, PElement *out)
11901190
return TRUE;
11911191
}
11921192

1193+
gboolean
1194+
heap_imagevec_new(Heap *heap, int n, VipsImage **vec, PElement *out)
1195+
{
1196+
PElement list = *out;
1197+
1198+
/* Make first RHS ... the end of the list.
1199+
*/
1200+
heap_list_init(&list);
1201+
1202+
/* Build a CONS node for each element.
1203+
*/
1204+
for (int i = 0; i < n; i++) {
1205+
PElement t;
1206+
if (!heap_list_add(heap, &list, &t))
1207+
return FALSE;
1208+
1209+
g_object_ref(vec[i]);
1210+
Managed *managed = MANAGED(imageinfo_new(main_imageinfogroup,
1211+
heap, vec[i], vec[i]->filename));
1212+
PEPUTP(&t, ELEMENT_MANAGED, managed);
1213+
1214+
(void) heap_list_next(&list);
1215+
}
1216+
1217+
return TRUE;
1218+
}
1219+
11931220
/* Make a matrix.
11941221
*/
11951222
gboolean
@@ -2033,6 +2060,36 @@ heap_gvalue_to_ip(Heap *heap, GValue *in, PElement *out)
20332060
if (!heap_managedstring_new(heap, g_value_get_string(in), out))
20342061
return FALSE;
20352062
}
2063+
else if (G_VALUE_HOLDS_BOXED(in)) {
2064+
if (G_VALUE_TYPE(in) == VIPS_TYPE_ARRAY_INT) {
2065+
int n;
2066+
int *array = vips_value_get_array_int(in, &n);
2067+
2068+
if (!heap_intvec_new(heap, n, array, out))
2069+
return FALSE;
2070+
}
2071+
else if (G_VALUE_TYPE(in) == VIPS_TYPE_ARRAY_DOUBLE) {
2072+
int n;
2073+
double *array = vips_value_get_array_double(in, &n);
2074+
2075+
if (!heap_realvec_new(heap, n, array, out))
2076+
return FALSE;
2077+
}
2078+
else if (G_VALUE_TYPE(in) == VIPS_TYPE_ARRAY_IMAGE) {
2079+
int n;
2080+
VipsImage **array = vips_value_get_array_image(in, &n);
2081+
2082+
if (!heap_imagevec_new(heap, n, array, out))
2083+
return FALSE;
2084+
}
2085+
else {
2086+
error_top(_("Unimplemented type"));
2087+
error_sub(_("unable to convert boxed type %s to a nip type"),
2088+
G_VALUE_TYPE_NAME(in));
2089+
2090+
return FALSE;
2091+
}
2092+
}
20362093
else if (G_VALUE_HOLDS_OBJECT(in)) {
20372094
GObject *object;
20382095
Managed *managed;

src/heap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ gboolean heap_list_next(PElement *list);
452452
gboolean heap_list_cat(Reduce *rc, PElement *a, PElement *b, PElement *out);
453453
void heap_appl_init(PElement *base, PElement *func);
454454
gboolean heap_appl_add(Heap *heap, PElement *base, PElement *parm);
455+
gboolean heap_imagevec_new(Heap *heap, int n, VipsImage **vec, PElement *out);
455456
gboolean heap_matrix_new(Heap *heap,
456457
int xsize, int ysize, double *vec, PElement *out);
457458
gboolean heap_string_new(Heap *heap, const char *str, PElement *out);

0 commit comments

Comments
 (0)