Skip to content

Commit 29f1182

Browse files
committed
experiment with ppf save
argh won't work
1 parent 1364829 commit 29f1182

File tree

4 files changed

+105
-8
lines changed

4 files changed

+105
-8
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
- added restart_interval option to jpegsave [manthey]
1515
- add IIIF3 support to dzsaave [martimpassos]
1616
- add atan2 [indus]
17+
- added "string_arguments" ... buffer and target savers which support multiple
18+
formats should no longer need special cases
1719

1820
16/8/21 started 8.11.4
1921
- fix off-by-one error in new rank fast path

NOTES

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,40 @@
1616

1717
hide from introspection? eg. tag as DEPRECATED
1818

19+
- nope, also fails, since py calls
20+
21+
pointer = vips_lib.vips_filename_get_options(format_string)
22+
options = _to_string_copy(pointer)
23+
24+
pointer = vips_lib.vips_foreign_find_save_target(format_string)
25+
if pointer == ffi.NULL:
26+
raise Error('unable to write to target')
27+
name = _to_string(pointer)
28+
29+
return pyvips.Operation.call(name, self, target,
30+
string_options=options, **kwargs)
31+
32+
ie. the filename part is stripped before we see it
33+
34+
we'd need to change pyvips too, and it would need to detect older libvipses
35+
36+
- could add an extra string param to vips_lib.vips_filename_get_options()?
37+
38+
vips_lib.vips_filename_get_options("x.y[arg=val]")
39+
40+
could yield
41+
42+
[arg=val,suffix=.y]
43+
44+
ie. append a magic extra arg we make
45+
46+
how fragile and ugly!
47+
1948
- something in pytest is taking FOREVER ... find it and fix it
2049

2150
uses enough memory to kill the laptop
51+
52+
heifsave is incredibly slow
53+
54+
is it testing AVIF too?
55+

libvips/foreign/ppmsave.c

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ struct _VipsForeignSavePpm {
7575

7676
VipsSavePpmFn fn;
7777

78+
/* Our save options in string form. See target save.
79+
*/
80+
const char *string_arguments;
81+
7882
/* Deprecated.
7983
*/
8084
gboolean squash;
@@ -216,7 +220,6 @@ vips_foreign_save_ppm_build( VipsObject *object )
216220
{
217221
VipsForeignSave *save = (VipsForeignSave *) object;
218222
VipsForeignSavePpm *ppm = (VipsForeignSavePpm *) object;
219-
220223
VipsImage *image;
221224
char *magic;
222225
char *date;
@@ -238,6 +241,49 @@ vips_foreign_save_ppm_build( VipsObject *object )
238241
vips_image_pio_input( image ) )
239242
return( -1 );
240243

244+
/* ppm types. We use the suffix (if avail.) to set the defaults for
245+
* bitdepth etc.
246+
*
247+
* pbm ... 1 band 1 bit
248+
* pgm ... 1 band many bit
249+
* ppm ... 3 band many bit
250+
* pfm ... 1 or 3 bands, 32 bit
251+
*/
252+
if( ppm->string_arguments ) {
253+
VipsImage **t = (VipsImage **)
254+
vips_object_local_array( object, 2 );
255+
256+
char filename[VIPS_PATH_MAX];
257+
char option_string[VIPS_PATH_MAX];
258+
VipsBandFormat target_format;
259+
VipsInterpretation target_interpretation;
260+
261+
vips__filename_split8( ppm->string_arguments,
262+
filename, option_string );
263+
264+
target_format = image->BandFmt;
265+
target_interpretation = image->Type;
266+
267+
if( vips_iscasepostfix( filename, ".pbm" ) ||
268+
vips_iscasepostfix( filename, ".pgm" ) )
269+
target_interpretation = VIPS_INTERPRETATION_B_W;
270+
else if( vips_iscasepostfix( filename, ".ppm" ) )
271+
target_interpretation = VIPS_INTERPRETATION_sRGB;
272+
else if( vips_iscasepostfix( filename, ".pfm" ) )
273+
target_format = VIPS_FORMAT_FLOAT;
274+
275+
if( vips_cast( image, &t[0], target_format, NULL ) )
276+
return( -1 );
277+
image = t[0];
278+
279+
if( image->Type != target_interpretation ) {
280+
if( vips_colourspace( image, &t[1],
281+
target_interpretation, NULL ) )
282+
return( -1 );
283+
image = t[1];
284+
}
285+
}
286+
241287
if( ppm->ascii &&
242288
image->BandFmt == VIPS_FORMAT_FLOAT ) {
243289
g_warning( "%s",
@@ -428,6 +474,16 @@ vips_foreign_save_ppm_class_init( VipsForeignSavePpmClass *class )
428474
G_STRUCT_OFFSET( VipsForeignSavePpm, squash ),
429475
FALSE );
430476

477+
/* This isn't really deprecated, just internal. We just want to hide
478+
* it from bindings and the user.
479+
*/
480+
VIPS_ARG_STRING( class, "string_arguments", 12,
481+
_( "String arguments" ),
482+
_( "Save options in string form" ),
483+
VIPS_ARGUMENT_OPTIONAL_INPUT | VIPS_ARGUMENT_DEPRECATED,
484+
G_STRUCT_OFFSET( VipsForeignSavePpm, string_arguments ),
485+
NULL );
486+
431487
}
432488

433489
static void

libvips/iofuncs/object.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -795,23 +795,28 @@ vips_object_get_argument( VipsObject *object, const char *name,
795795
}
796796

797797
/**
798-
* vips_object_argument_has:
798+
* vips_object_argument_has: (skip)
799799
* @object: the object to fetch the args from
800800
* @name: arg name
801801
*
802802
* Convenience: true if the object has the named argument.
803803
*
804804
* Returns: %TRUE if the argument exists.
805805
*/
806-
static gboolean
806+
int
807807
vips_object_argument_has( VipsObject *object, const char *name )
808808
{
809-
GParamSpec *pspec;
810-
VipsArgumentClass *argument_class;
811-
VipsArgumentInstance *argument_instance;
809+
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
812810

813-
return( !vips_object_get_argument( object, name,
814-
&pspec, &argument_class, &argument_instance ) );
811+
GParamSpec pspec;
812+
813+
if( g_object_class_find_property( G_OBJECT_CLASS( class ), name ) )
814+
return( TRUE );
815+
816+
if( vips__argument_table_lookup( class->argument_table, &pspec ) )
817+
return( TRUE );
818+
819+
return( FALSE );
815820
}
816821

817822
/**

0 commit comments

Comments
 (0)