mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-10-06 01:12:40 +02:00
plug-ins: Use original DDS format on export
This patch adds a parasite on load that retains the original compression format of a DDS texture. This parasite is then checked on export, and if it exists, we default the compression format to the original to reduce the chance the user will choose the wrong format for the game they're creating the texture for.
This commit is contained in:
@@ -134,6 +134,7 @@ read_dds (GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
GimpImage *image = NULL;
|
||||
GimpParasite *parasite = NULL;
|
||||
guint layer_index = 0;
|
||||
guchar *buf, *pixels;
|
||||
FILE *fp;
|
||||
@@ -743,6 +744,16 @@ read_dds (GFile *file,
|
||||
if (flip_import)
|
||||
gimp_image_flip (image, GIMP_ORIENTATION_VERTICAL);
|
||||
|
||||
/* Store original format to use as a default for export */
|
||||
if (load_info.comp_format)
|
||||
{
|
||||
parasite = gimp_parasite_new ("dds-compression-format",
|
||||
GIMP_PARASITE_PERSISTENT,
|
||||
1, (gpointer) &load_info.comp_format);
|
||||
gimp_image_attach_parasite (image, parasite);
|
||||
gimp_parasite_free (parasite);
|
||||
}
|
||||
|
||||
*ret_image = image;
|
||||
|
||||
return GIMP_PDB_SUCCESS;
|
||||
|
@@ -44,15 +44,16 @@
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
static gboolean write_image (FILE *fp,
|
||||
GimpImage *image,
|
||||
GimpDrawable *drawable,
|
||||
GimpProcedureConfig *config);
|
||||
static gboolean save_dialog (GimpImage *image,
|
||||
GimpDrawable *drawable,
|
||||
GimpProcedure *procedure,
|
||||
GimpProcedureConfig *config);
|
||||
static gboolean write_image (FILE *fp,
|
||||
GimpImage *image,
|
||||
GimpDrawable *drawable,
|
||||
GimpProcedureConfig *config);
|
||||
static gboolean save_dialog (GimpImage *image,
|
||||
GimpDrawable *drawable,
|
||||
GimpProcedure *procedure,
|
||||
GimpProcedureConfig *config);
|
||||
|
||||
static const gchar * find_comp_format (guint32 format);
|
||||
|
||||
static const gchar *cubemap_face_names[4][6] =
|
||||
{
|
||||
@@ -497,11 +498,12 @@ write_dds (GFile *file,
|
||||
GimpProcedureConfig *config,
|
||||
gboolean is_duplicate_image)
|
||||
{
|
||||
FILE *fp;
|
||||
gint rc = 0;
|
||||
gint compression;
|
||||
gint mipmaps;
|
||||
gint savetype;
|
||||
FILE *fp;
|
||||
GimpParasite *parasite = NULL;
|
||||
gint rc = 0;
|
||||
gint compression;
|
||||
gint mipmaps;
|
||||
gint savetype;
|
||||
|
||||
savetype = gimp_procedure_config_get_choice_id (config, "save-type");
|
||||
compression = gimp_procedure_config_get_choice_id (config, "compression-format");
|
||||
@@ -515,6 +517,23 @@ write_dds (GFile *file,
|
||||
is_volume = check_volume (image);
|
||||
is_array = check_array (image);
|
||||
|
||||
parasite = gimp_image_get_parasite (image, "dds-compression-format");
|
||||
if (parasite)
|
||||
{
|
||||
const guint8 *comp_format;
|
||||
guint32 parasite_size;
|
||||
const gchar *config_comp_format;
|
||||
|
||||
comp_format = (const guint8 *) gimp_parasite_get_data (parasite,
|
||||
¶site_size);
|
||||
|
||||
config_comp_format = find_comp_format (*comp_format);
|
||||
|
||||
g_object_set (config, "compression-format", config_comp_format, NULL);
|
||||
gimp_image_detach_parasite (image, "dds-compression-format");
|
||||
g_free (parasite);
|
||||
}
|
||||
|
||||
if (interactive)
|
||||
{
|
||||
if (! is_mipmap_chain_valid &&
|
||||
@@ -2006,3 +2025,29 @@ save_dialog (GimpImage *image,
|
||||
|
||||
return run;
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
find_comp_format (guint32 format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case DDS_COMPRESS_BC1:
|
||||
return "bc1";
|
||||
|
||||
case DDS_COMPRESS_BC2:
|
||||
return "bc2";
|
||||
|
||||
case DDS_COMPRESS_BC3:
|
||||
return "bc3";
|
||||
|
||||
case DDS_COMPRESS_BC4:
|
||||
return "bc4";
|
||||
|
||||
case DDS_COMPRESS_BC5:
|
||||
return "bc5";
|
||||
|
||||
/* TODO: Update when we have BC7 export */
|
||||
default:
|
||||
return "none";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user