/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2016-2024 Matthias Klumpp <matthias@tenstral.net>
 *
 * Licensed under the GNU Lesser General Public License Version 2.1
 *
 * This library 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.1 of the license, or
 * (at your option) any later version.
 *
 * This library 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 library.  If not, see <http://www.gnu.org/licenses/>.
 */

#if !defined(__APPSTREAM_COMPOSE_H) && !defined(ASC_COMPILATION)
#error "Only <appstream-compose.h> can be included directly."
#endif
#pragma once

#include <glib-object.h>
#include <appstream.h>

G_BEGIN_DECLS

#define ASC_TYPE_IMAGE (asc_image_get_type ())
G_DECLARE_FINAL_TYPE (AscImage, asc_image, ASC, IMAGE, GObject)

/**
 * AscImageSaveFlags:
 * @ASC_IMAGE_SAVE_FLAG_NONE:		No special flags set
 * @ASC_IMAGE_SAVE_FLAG_OPTIMIZE:	Optimize generated PNG for size
 * @ASC_IMAGE_SAVE_FLAG_PAD_16_9:	Pad with alpha to 16:9 aspect
 * @ASC_IMAGE_SAVE_FLAG_SHARPEN:	Sharpen the image to clarify detail
 * @ASC_IMAGE_SAVE_FLAG_BLUR:		Blur the image to clear detail
 *
 * The flags used for saving images.
 **/
typedef enum {
	ASC_IMAGE_SAVE_FLAG_NONE     = 0,
	ASC_IMAGE_SAVE_FLAG_OPTIMIZE = 1 << 0,
	ASC_IMAGE_SAVE_FLAG_PAD_16_9 = 1 << 1,
	ASC_IMAGE_SAVE_FLAG_SHARPEN  = 1 << 2,
	ASC_IMAGE_SAVE_FLAG_BLUR     = 1 << 3,
	/*< private >*/
	ASC_IMAGE_SAVE_FLAG_LAST
} AscImageSaveFlags;

/**
 * AscImageLoadFlags:
 * @ASC_IMAGE_LOAD_FLAG_NONE:			No special flags set
 * @ASC_IMAGE_LOAD_FLAG_SHARPEN:		Sharpen the resulting image
 * @ASC_IMAGE_LOAD_FLAG_ALLOW_UNSUPPORTED:	Allow loading of unsupported image types.
 * @ASC_IMAGE_LOAD_FLAG_ALWAYS_RESIZE:		Always resize the source image to the perfect size
 *
 * The flags used for loading images.
 **/
typedef enum {
	ASC_IMAGE_LOAD_FLAG_NONE	      = 0,
	ASC_IMAGE_LOAD_FLAG_SHARPEN	      = 1 << 0,
	ASC_IMAGE_LOAD_FLAG_ALLOW_UNSUPPORTED = 1 << 1,
	ASC_IMAGE_LOAD_FLAG_ALWAYS_RESIZE     = 1 << 2,
	/*< private >*/
	ASC_IMAGE_LOAD_FLAG_LAST
} AscImageLoadFlags;

/**
 * AscImageFormat:
 * @ASC_IMAGE_FORMAT_UNKNOWN:	Unknown image format.
 * @ASC_IMAGE_FORMAT_PNG:	PNG format
 * @ASC_IMAGE_FORMAT_JXL:	JPEG-XL format
 * @ASC_IMAGE_FORMAT_AVIF:	AVIF format
 * @ASC_IMAGE_FORMAT_WEBP:	WebP format
 * @ASC_IMAGE_FORMAT_SVG:	SVG format
 * @ASC_IMAGE_FORMAT_SVGZ:	Compressed SVG format
 * @ASC_IMAGE_FORMAT_JPEG:	JPEG format
 * @ASC_IMAGE_FORMAT_GIF:	GIF format
 * @ASC_IMAGE_FORMAT_XPM:	XPM format
 *
 * File format of an image.
 **/
typedef enum {
	ASC_IMAGE_FORMAT_UNKNOWN,
	ASC_IMAGE_FORMAT_PNG,
	ASC_IMAGE_FORMAT_JXL,
	ASC_IMAGE_FORMAT_AVIF,
	ASC_IMAGE_FORMAT_WEBP,
	ASC_IMAGE_FORMAT_SVG,
	ASC_IMAGE_FORMAT_SVGZ,
	ASC_IMAGE_FORMAT_JPEG,
	ASC_IMAGE_FORMAT_GIF,
	ASC_IMAGE_FORMAT_XPM,
	/*< private >*/
	ASC_IMAGE_FORMAT_LAST
} AscImageFormat;

/**
 * AscImageError:
 * @ASC_IMAGE_ERROR_FAILED:	 Generic failure.
 * @ASC_IMAGE_ERROR_UNSUPPORTED: The graphic type is not supported.
 *
 * An image processing error.
 **/
typedef enum {
	ASC_IMAGE_ERROR_FAILED,
	ASC_IMAGE_ERROR_UNSUPPORTED,
	/*< private >*/
	ASC_IMAGE_ERROR_LAST
} AscImageError;

#define ASC_IMAGE_ERROR asc_image_error_quark ()
GQuark	       asc_image_error_quark (void);

const gchar   *asc_image_format_to_string (AscImageFormat format);
AscImageFormat asc_image_format_from_string (const gchar *str);
AscImageFormat asc_image_format_from_filename (const gchar *fname);

GHashTable    *asc_image_supported_format_names (void);

AscImage      *asc_image_new (void);
AscImage      *asc_image_new_from_file (const gchar	 *fname,
					gint		  dest_width,
					gint		  dest_height,
					AscImageLoadFlags flags,
					GError		**error);
AscImage      *asc_image_new_from_data (const void	 *data,
					gssize		  len,
					gint		  dest_width,
					gint		  dest_height,
					AscImageLoadFlags flags,
					AscImageFormat	  format_hint,
					GError		**error);

gboolean       asc_image_load_filename (AscImage	 *image,
					const gchar	 *filename,
					gint		  dest_width,
					gint		  dest_height,
					gint		  src_size_min,
					AscImageLoadFlags flags,
					GError		**error);

gboolean       asc_image_save_filename (AscImage	 *image,
					const gchar	 *filename,
					gint		  width,
					gint		  height,
					AscImageSaveFlags flags,
					GError		**error);

gint	       asc_image_get_width (AscImage *image);
gint	       asc_image_get_height (AscImage *image);

void	       asc_image_scale (AscImage *image, gint new_width, gint new_height);

void	       asc_image_scale_to_width (AscImage *image, gint new_width);
void	       asc_image_scale_to_height (AscImage *image, gint new_height);
void	       asc_image_scale_to_fit (AscImage *image, gint size);

gboolean       asc_render_svg_to_file (GInputStream  *stream,
				       gint	      width,
				       gint	      height,
				       AscImageFormat format,
				       const gchar   *filename,
				       GError	    **error);

G_END_DECLS
