Skip to content

Commit

Permalink
flag to save bmp with bitdepth 1 (libvips#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasbarton authored and dloebl committed May 20, 2022
1 parent c5ea747 commit 34971b1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -624,7 +624,7 @@ if test x"$magick6" = x"yes"; then
LIBS="$LIBS $MAGICK_LIBS"
CFLAGS="$CFLAGS $MAGICK_CFLAGS"

AC_CHECK_FUNCS([InheritException AcquireExceptionInfo SetImageProperty SetImageExtent AcquireImage GetVirtualPixels ResetImageProfileIterator ResetImageAttributeIterator ResetImagePropertyIterator MagickCoreGenesis SetImageOption BlobToStringInfo OptimizePlusImageLayers OptimizeImageTransparency])
AC_CHECK_FUNCS([InheritException AcquireExceptionInfo SetImageProperty SetImageExtent AcquireImage GetVirtualPixels ResetImageProfileIterator ResetImageAttributeIterator ResetImagePropertyIterator MagickCoreGenesis SetImageOption BlobToStringInfo OptimizePlusImageLayers OptimizeImageTransparency SetImageType])

LIBS="$save_LIBS"
CFLAGS="$save_CFLAGS"
Expand Down
10 changes: 10 additions & 0 deletions libvips/foreign/magick.c
Expand Up @@ -846,4 +846,14 @@ magick_set_magick_profile( Image *image,
return( 0 );
}

int
magick_set_image_type( Image *images,
ImageType image_type, ExceptionInfo *exception )
{
// SetImageDepth( images, 1, exception);
SetImageType( images, image_type, exception );

return( exception->severity == UndefinedException );
}

#endif /*defined(HAVE_MAGICK6) || defined(HAVE_MAGICK7)*/
2 changes: 2 additions & 0 deletions libvips/foreign/magick.h
Expand Up @@ -88,6 +88,8 @@ int magick_optimize_image_layers( Image **images, ExceptionInfo *exception );
int magick_optimize_image_transparency( const Image *images,
ExceptionInfo *exception );

int magick_set_image_type( Image *images, ImageType image_type, ExceptionInfo *exception );

gboolean magick_ismagick( const unsigned char *bytes, size_t length );

#endif /*HAVE_MAGICK6*/
19 changes: 19 additions & 0 deletions libvips/foreign/vips2magick.c
Expand Up @@ -69,6 +69,7 @@ typedef struct _VipsForeignSaveMagick {
char *filename; /* NULL during buffer output */
char *format;
int quality;
gboolean bmp_bitdepth_1;
gboolean optimize_gif_frames;
gboolean optimize_gif_transparency;

Expand Down Expand Up @@ -406,6 +407,17 @@ vips_foreign_save_magick_build( VipsObject *object )
return( -1 );
}
}

if( magick->bmp_bitdepth_1 ) {
if( !magick_set_image_type( magick->images,
BilevelType, magick->exception ) ) {
magick_inherit_exception( magick->exception,
magick->images );
magick_vips_error( class->nickname, magick->exception );

return( -1 );
}
}

return( 0 );
}
Expand Down Expand Up @@ -493,6 +505,13 @@ vips_foreign_save_magick_class_init( VipsForeignSaveMagickClass *class )
G_STRUCT_OFFSET( VipsForeignSaveMagick,
optimize_gif_transparency ),
FALSE );

VIPS_ARG_BOOL( class, "bmp_bitdepth_1", 6,
_( "BMP bithdepth 1" ),
_( "BMP file bitdepth 1`" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignSaveMagick, bmp_bitdepth_1 ),
FALSE );
}

static void
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Expand Up @@ -186,7 +186,7 @@ if not get_option('magick').disabled() and magick_dep.found()
if cc.has_member('struct _ImageInfo', 'number_scenes', prefix: '#include <magick/api.h>', dependencies: magick_dep)
cfg_var.set('HAVE_NUMBER_SCENES', '1')
endif
func_names = [ 'InheritException', 'AcquireExceptionInfo', 'SetImageProperty', 'SetImageExtent', 'AcquireImage', 'GetVirtualPixels', 'ResetImageProfileIterator', 'ResetImageAttributeIterator', 'ResetImagePropertyIterator', 'MagickCoreGenesis', 'SetImageOption', 'BlobToStringInfo', 'OptimizePlusImageLayers', 'OptimizeImageTransparency' ]
func_names = [ 'InheritException', 'AcquireExceptionInfo', 'SetImageProperty', 'SetImageExtent', 'AcquireImage', 'GetVirtualPixels', 'ResetImageProfileIterator', 'ResetImageAttributeIterator', 'ResetImagePropertyIterator', 'MagickCoreGenesis', 'SetImageOption', 'BlobToStringInfo', 'OptimizePlusImageLayers', 'OptimizeImageTransparency', 'SetImageType' ]
foreach func_name : func_names
if cc.has_function(func_name, prefix: '#include <magick/api.h>', dependencies: magick_dep)
cfg_var.set('HAVE_' + func_name.to_upper(), '1')
Expand Down

0 comments on commit 34971b1

Please sign in to comment.