add ".pnm" save

see https://github.com/libvips/libvips/issues/3016
This commit is contained in:
John Cupitt 2022-08-30 12:31:47 +01:00
parent 2e5e9fb755
commit 6a154ac9f2
5 changed files with 51 additions and 2 deletions

View File

@ -10,6 +10,7 @@ master
- require libjxl 0.7+
- add "interlace" option to GIF save [dloebl]
- magick load sets "magick-format" metadata [aksdb]
- add ".pnm", save as image format [ewelot]
24/7/22 started 8.13.1
- fix im7 feature detection in meson

View File

@ -131,6 +131,7 @@ extern const char *vips__save_pbm_suffs[];
extern const char *vips__save_pgm_suffs[];
extern const char *vips__save_ppm_suffs[];
extern const char *vips__save_pfm_suffs[];
extern const char *vips__save_pnm_suffs[];
int vips__ppm_save_target( VipsImage *in, VipsTarget *target,
gboolean ascii, gboolean squash );

View File

@ -141,11 +141,14 @@ static char *magic_names[] = {
/* Shared with ppmsave.
*/
const char *vips__ppm_suffs[] = { ".pbm", ".pgm", ".ppm", ".pfm", NULL };
const char *vips__ppm_suffs[] = {
".pbm", ".pgm", ".ppm", ".pfm", ".pnm", NULL
};
const char *vips__save_pbm_suffs[] = { ".pbm", NULL };
const char *vips__save_pgm_suffs[] = { ".pgm", NULL };
const char *vips__save_ppm_suffs[] = { ".ppm", NULL };
const char *vips__save_pfm_suffs[] = { ".pfm", NULL };
const char *vips__save_pnm_suffs[] = { ".pnm", NULL };
static gboolean
vips_foreign_load_ppm_is_a_source( VipsSource *source )

View File

@ -14,6 +14,8 @@
* - don't add date with @strip [ewelot]
* 28/10/21
* - add @format, default type by filename
* 30/8/22
* - add ".pnm", save as image format [ewelot]
*/
/*
@ -239,6 +241,7 @@ vips_foreign_save_ppm_build( VipsObject *object )
* pgm ... 1 band many bit
* ppm ... 3 band many bit
* pfm ... 1 or 3 bands, 32 bit
* pnm ... pick from input
*/
switch( ppm->format ) {
case VIPS_FOREIGN_PPM_FORMAT_PBM:
@ -265,8 +268,9 @@ vips_foreign_save_ppm_build( VipsObject *object )
target_format = VIPS_FORMAT_FLOAT;
break;
case VIPS_FOREIGN_PPM_FORMAT_PNM:
default:
/* Harmless.
/* Just use the input format and interpretation.
*/
break;
}
@ -527,6 +531,8 @@ vips_foreign_save_ppm_file_build( VipsObject *object )
ppm->format = VIPS_FOREIGN_PPM_FORMAT_PGM;
else if( vips_iscasepostfix( file->filename, ".pfm" ) )
ppm->format = VIPS_FOREIGN_PPM_FORMAT_PFM;
else if( vips_iscasepostfix( file->filename, ".pnm" ) )
ppm->format = VIPS_FOREIGN_PPM_FORMAT_PNM;
return( VIPS_OBJECT_CLASS( vips_foreign_save_ppm_file_parent_class )->
build( object ) );
@ -716,6 +722,38 @@ vips_foreign_save_pfm_target_init( VipsForeignSavePfmTarget *target )
ppm->format = VIPS_FOREIGN_PPM_FORMAT_PFM;
}
typedef VipsForeignSavePpmTarget VipsForeignSavePnmTarget;
typedef VipsForeignSavePpmTargetClass VipsForeignSavePnmTargetClass;
G_DEFINE_TYPE( VipsForeignSavePnmTarget, vips_foreign_save_pnm_target,
vips_foreign_save_ppm_target_get_type() );
static void
vips_foreign_save_pnm_target_class_init(
VipsForeignSavePfmTargetClass *class )
{
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsForeignClass *foreign_class = (VipsForeignClass *) class;
VipsOperationClass *operation_class = (VipsOperationClass *) class;
object_class->nickname = "pnmsave_target";
object_class->description = _( "save image in pnm format" );
foreign_class->suffs = vips__save_pnm_suffs;
/* Hide from UI.
*/
operation_class->flags |= VIPS_OPERATION_DEPRECATED;
}
static void
vips_foreign_save_pnm_target_init( VipsForeignSavePfmTarget *target )
{
VipsForeignSavePpm *ppm = (VipsForeignSavePpm *) target;
ppm->format = VIPS_FOREIGN_PPM_FORMAT_PNM;
}
#endif /*HAVE_PPM*/
/**

View File

@ -715,6 +715,7 @@ int vips_pngsave_buffer( VipsImage *in, void **buf, size_t *len, ... )
* @VIPS_FOREIGN_PPM_FORMAT_PGM: portable greymap
* @VIPS_FOREIGN_PPM_FORMAT_PPM: portable pixmap
* @VIPS_FOREIGN_PPM_FORMAT_PFM: portable float map
* @VIPS_FOREIGN_PPM_FORMAT_PNM: portable anymap
*
* The netpbm file format to save as.
*
@ -725,12 +726,17 @@ int vips_pngsave_buffer( VipsImage *in, void **buf, size_t *len, ... )
* #VIPS_FOREIGN_PPM_FORMAT_PPM images are 8, 16, or 32-bits, three bands.
*
* #VIPS_FOREIGN_PPM_FORMAT_PFM images are 32-bit float pixels.
*
* #VIPS_FOREIGN_PPM_FORMAT_PNM images are anymap images -- the image format
* is used to pick the saver.
*
*/
typedef enum {
VIPS_FOREIGN_PPM_FORMAT_PBM,
VIPS_FOREIGN_PPM_FORMAT_PGM,
VIPS_FOREIGN_PPM_FORMAT_PPM,
VIPS_FOREIGN_PPM_FORMAT_PFM,
VIPS_FOREIGN_PPM_FORMAT_PNM,
VIPS_FOREIGN_PPM_FORMAT_LAST
} VipsForeignPpmFormat;