Open Source Faster Image Processing Library for C++
Create, Manipulate, Draw, Divide, Copy & Convert Popular Image Formats; Apply Filters, Divide Two Images, Grid an Image via Free C++ Library.
What is libvips?
The libvips open source image processing library is engineered for exceptional speedy operations with very low memory consumption. It excels at handling large images and supports an extensive range of image file formats, including JPEG, TIFF, PNG, WebP, HEIC, PDF, SVG, and GIF. Its compatibility extends via ImageMagick or GraphicsMagick, enabling support for specialized formats like DICOM. This powerful combination of broad format support and efficient resource use establishes libvips as a premier choice for demanding applications.
This library delivers better performance than many alternatives, particularly on machines with multiple CPUs, due to its intelligent architecture that automatically divides the image workflows. It supports a huge range of numeric types from 8-bit to 128-bit precision. Unlike other libraries that use standard threaded operations, libvips innovatively embeds threading within its image IO system, assigning a copy of the entire image pipeline to each thread. This horizontal threading style optimizes processor caches and minimizes locking. The library provides comprehensive support for essential image processing features, such as drawing images, copying an image, dividing two images, applying gaussian filters, and performing operations like add two images or save the image to JPEG file, making it uniquely capable and efficient.
Getting Started with libvips
Clone the latest sources using the following command.
Install libvips via git command
git clone git://github.com/libvips/libvips.git Building from git needs more packages, you’ll need at least gtk-doc and gobject-introspection.
Install libvips packages via git command
./autogen.sh
make
sudo make install Faster Images Rendering via C++ API
The libvips library has provided functionality for faster image creation and manipulation on all the leading platforms. Some of the leading image processing libraries like ImageMagick and GD libraries are very powerful and provide advanced features for working with images but need a large amount of memory for processing images. On the other hand, libvips can do virtually the same actives as ImageMagick, but much faster and with a comparatively small memory footprint
Save Image to Other supported Formats
The open source libvips library has provided a set of operations that load and save images in a variety of formats. The library has included built-in support for saving images in popular formats like TIFF, JPEG, PNG, Analyze, PPM, OpenEXR, CSV, Matlab, Radiance, RAW, FITS, WebP, SVG, PDF, GIF, and VIPS. The VipsForeign can be used to load and save images in a variety of formats.
How to Read and write Images to Memory via C++ API?
int
main( int argc, char **argv )
{
gchar *buf;
gsize len;
int i;
if( VIPS_INIT( argv[0] ) )
vips_error_exit( NULL );
if( argc != 2 )
vips_error_exit( "usage: %s FILENAME", argv[0] );
if( !g_file_get_contents( argv[1], &buf, &len, NULL ) )
vips_error_exit( NULL );
for( i = 0; i < 10; i++ ) {
VipsImage *image;
void *new_buf;
size_t new_len;
printf( "loop %d ...\n", i );
if( !(image = vips_image_new_from_buffer( buf, len, "",
"access", VIPS_ACCESS_SEQUENTIAL,
NULL )) )
vips_error_exit( NULL );
if( vips_image_write_to_buffer( image,
".jpg", &new_buf, &new_len,
"Q", 95,
NULL ) )
vips_error_exit( NULL );
g_object_unref( image );
g_free( new_buf );
}
g_free( buf );
vips_shutdown();
return( 0 );
}
Faster Image Resizing
The open source libvips library gives software developers the power to resize images on the fly inside their own apps. First, you need to load the image from the images repository by providing an image name and complete address. After that, you can resize it to the specified width and height according to your needs. After that, you can save it the location of your choice with the new size.
How to Resize Image via C++ API?
int
vips_resize( VipsImage *in, VipsImage **out,
double scale, ... )
{
va_list ap;
int result;
va_start( ap, scale );
result = vips_call_split( "resize", ap, in, out, scale );
va_end( ap );
return( result );
}
Image Filtering via C++ API
Image filtering is a valuable feature that is used in various image processing and computer vision applications across the globe. The libvips library provides complete support for Image filtering via C++ commands. Features like smoothing, sharpening, and edge enhancement are some examples of Image processing operations implemented with filtering. The library also included PNG filters like difference to the left, an average of left and up, adaptive, pick best neighbor predictor automatically, and no filtering. It also includes import filters that can load with libMagick and with OpenSlide.