2019-01-29 11:27:00 +01:00
|
|
|
/* save to heif
|
|
|
|
*
|
|
|
|
* 5/7/18
|
|
|
|
* - from niftisave.c
|
2019-07-03 16:04:58 +02:00
|
|
|
* 3/7/19 [lovell]
|
|
|
|
* - add "compression" option
|
2019-09-01 17:58:50 +02:00
|
|
|
* 1/9/19 [meyermarcel]
|
|
|
|
* - save alpha when necessary
|
2020-03-15 19:17:08 +01:00
|
|
|
* 15/3/20
|
|
|
|
* - revise for new VipsTarget API
|
2021-02-14 13:55:45 +01:00
|
|
|
* 14/2/21 kleisauke
|
|
|
|
* - move GObject part to vips2heif.c
|
2019-01-29 11:27:00 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This file is part of VIPS.
|
|
|
|
|
|
|
|
VIPS is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
02110-1301 USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
#define DEBUG_VERBOSE
|
|
|
|
#define DEBUG
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
#include <vips/intl.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <vips/vips.h>
|
2019-01-29 17:40:34 +01:00
|
|
|
#include <vips/internal.h>
|
2019-01-29 11:27:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* vips_heifsave: (method)
|
|
|
|
* @in: image to save
|
|
|
|
* @filename: file to write to
|
|
|
|
* @...: %NULL-terminated list of optional named arguments
|
|
|
|
*
|
2019-01-29 17:40:34 +01:00
|
|
|
* Optional arguments:
|
|
|
|
*
|
|
|
|
* * @Q: %gint, quality factor
|
|
|
|
* * @lossless: %gboolean, enable lossless encoding
|
2019-07-03 16:04:58 +02:00
|
|
|
* * @compression: #VipsForeignHeifCompression, write with this compression
|
2021-05-01 15:48:06 +02:00
|
|
|
* * @speed: %gint, encoding speed
|
2021-01-11 21:40:13 +01:00
|
|
|
* * @subsample_mode: #VipsForeignSubsample, chroma subsampling mode
|
2019-01-29 17:40:34 +01:00
|
|
|
*
|
2019-01-29 11:27:00 +01:00
|
|
|
* Write a VIPS image to a file in HEIF format.
|
|
|
|
*
|
2019-01-29 18:21:13 +01:00
|
|
|
* Use @Q to set the compression factor. Default 50, which seems to be roughly
|
|
|
|
* what the iphone uses. Q 30 gives about the same quality as JPEG Q 75.
|
2019-01-29 17:40:34 +01:00
|
|
|
*
|
|
|
|
* Set @lossless %TRUE to switch to lossless compression.
|
|
|
|
*
|
2021-03-26 10:50:17 +01:00
|
|
|
* Use @compression to set the encoder e.g. HEVC, AVC, AV1. It defaults to AV1
|
|
|
|
* if the target filename ends with ".avif", otherwise HEVC.
|
2019-07-03 14:07:55 +02:00
|
|
|
*
|
2020-09-16 20:22:45 +02:00
|
|
|
* Use @speed to control the CPU effort spent improving compression.
|
2021-05-01 15:48:06 +02:00
|
|
|
* This is currently only applicable to AV1 encoders. Defaults to 5, 0 is
|
|
|
|
* slowest, 9 is fastest.
|
2020-09-16 20:22:45 +02:00
|
|
|
*
|
2021-03-27 16:16:38 +01:00
|
|
|
* Chroma subsampling is normally automatically disabled for Q >= 90. You can
|
2021-01-11 21:40:13 +01:00
|
|
|
* force the subsampling mode with @subsample_mode.
|
|
|
|
*
|
2019-01-29 11:27:00 +01:00
|
|
|
* See also: vips_image_write_to_file(), vips_heifload().
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, -1 on error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vips_heifsave( VipsImage *in, const char *filename, ... )
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
va_start( ap, filename );
|
|
|
|
result = vips_call_split( "heifsave", ap, in, filename );
|
|
|
|
va_end( ap );
|
|
|
|
|
|
|
|
return( result );
|
|
|
|
}
|
2019-01-29 18:21:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* vips_heifsave_buffer: (method)
|
|
|
|
* @in: image to save
|
|
|
|
* @buf: (array length=len) (element-type guint8): return output buffer here
|
|
|
|
* @len: (type gsize): return output length here
|
|
|
|
* @...: %NULL-terminated list of optional named arguments
|
|
|
|
*
|
|
|
|
* Optional arguments:
|
|
|
|
*
|
|
|
|
* * @Q: %gint, quality factor
|
|
|
|
* * @lossless: %gboolean, enable lossless encoding
|
2019-07-03 16:04:58 +02:00
|
|
|
* * @compression: #VipsForeignHeifCompression, write with this compression
|
2021-05-01 15:48:06 +02:00
|
|
|
* * @speed: %gint, encoding speed
|
2021-01-11 21:40:13 +01:00
|
|
|
* * @subsample_mode: #VipsForeignSubsample, chroma subsampling mode
|
2019-01-29 18:21:13 +01:00
|
|
|
*
|
|
|
|
* As vips_heifsave(), but save to a memory buffer.
|
|
|
|
*
|
|
|
|
* The address of the buffer is returned in @obuf, the length of the buffer in
|
|
|
|
* @olen. You are responsible for freeing the buffer with g_free() when you
|
|
|
|
* are done with it.
|
|
|
|
*
|
|
|
|
* See also: vips_heifsave(), vips_image_write_to_file().
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, -1 on error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vips_heifsave_buffer( VipsImage *in, void **buf, size_t *len, ... )
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
VipsArea *area;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
area = NULL;
|
|
|
|
|
|
|
|
va_start( ap, len );
|
|
|
|
result = vips_call_split( "heifsave_buffer", ap, in, &area );
|
|
|
|
va_end( ap );
|
|
|
|
|
|
|
|
if( !result &&
|
|
|
|
area ) {
|
|
|
|
if( buf ) {
|
|
|
|
*buf = area->data;
|
|
|
|
area->free_fn = NULL;
|
|
|
|
}
|
|
|
|
if( len )
|
|
|
|
*len = area->length;
|
|
|
|
|
|
|
|
vips_area_unref( area );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( result );
|
|
|
|
}
|
2020-03-15 19:17:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* vips_heifsave_target: (method)
|
|
|
|
* @in: image to save
|
|
|
|
* @target: save image to this target
|
|
|
|
* @...: %NULL-terminated list of optional named arguments
|
|
|
|
*
|
|
|
|
* Optional arguments:
|
|
|
|
*
|
|
|
|
* * @Q: %gint, quality factor
|
|
|
|
* * @lossless: %gboolean, enable lossless encoding
|
|
|
|
* * @compression: #VipsForeignHeifCompression, write with this compression
|
2021-05-01 15:48:06 +02:00
|
|
|
* * @speed: %gint, encoding speed
|
2021-01-11 21:40:13 +01:00
|
|
|
* * @subsample_mode: #VipsForeignSubsample, chroma subsampling mode
|
2020-03-15 19:17:08 +01:00
|
|
|
*
|
|
|
|
* As vips_heifsave(), but save to a target.
|
|
|
|
*
|
|
|
|
* See also: vips_heifsave(), vips_image_write_to_target().
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, -1 on error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vips_heifsave_target( VipsImage *in, VipsTarget *target, ... )
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
va_start( ap, target );
|
|
|
|
result = vips_call_split( "heifsave_target", ap, in, target );
|
|
|
|
va_end( ap );
|
|
|
|
|
|
|
|
return( result );
|
|
|
|
}
|