Updated with upstream update
This commit is contained in:
@ -62,35 +62,38 @@ struct _DdsClass
|
||||
|
||||
|
||||
#define DDS_TYPE (dds_get_type ())
|
||||
#define DDS (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DDS_TYPE, Dds))
|
||||
#define DDS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DDS_TYPE, Dds))
|
||||
|
||||
GType dds_get_type (void) G_GNUC_CONST;
|
||||
|
||||
static GList * dds_query_procedures (PikaPlugIn *plug_in);
|
||||
static PikaProcedure * dds_create_procedure (PikaPlugIn *plug_in,
|
||||
const gchar *name);
|
||||
static GList * dds_query_procedures (PikaPlugIn *plug_in);
|
||||
static PikaProcedure * dds_create_procedure (PikaPlugIn *plug_in,
|
||||
const gchar *name);
|
||||
|
||||
static PikaValueArray * dds_load (PikaProcedure *procedure,
|
||||
PikaRunMode run_mode,
|
||||
GFile *file,
|
||||
const PikaValueArray *args,
|
||||
gpointer run_data);
|
||||
static PikaValueArray * dds_save (PikaProcedure *procedure,
|
||||
PikaRunMode run_mode,
|
||||
PikaImage *image,
|
||||
gint n_drawables,
|
||||
PikaDrawable **drawables,
|
||||
GFile *file,
|
||||
const PikaValueArray *args,
|
||||
gpointer run_data);
|
||||
static PikaValueArray * dds_load (PikaProcedure *procedure,
|
||||
PikaRunMode run_mode,
|
||||
GFile *file,
|
||||
PikaMetadata *metadata,
|
||||
PikaMetadataLoadFlags *flags,
|
||||
PikaProcedureConfig *config,
|
||||
gpointer run_data);
|
||||
static PikaValueArray * dds_save (PikaProcedure *procedure,
|
||||
PikaRunMode run_mode,
|
||||
PikaImage *image,
|
||||
gint n_drawables,
|
||||
PikaDrawable **drawables,
|
||||
GFile *file,
|
||||
PikaMetadata *metadata,
|
||||
PikaProcedureConfig *config,
|
||||
gpointer run_data);
|
||||
#if 0
|
||||
static PikaValueArray * dds_decode (PikaProcedure *procedure,
|
||||
PikaRunMode run_mode,
|
||||
PikaImage *image,
|
||||
gint n_drawables,
|
||||
PikaDrawable **drawables,
|
||||
const PikaValueArray *args,
|
||||
gpointer run_data);
|
||||
static PikaValueArray * dds_decode (PikaProcedure *procedure,
|
||||
PikaRunMode run_mode,
|
||||
PikaImage *image,
|
||||
gint n_drawables,
|
||||
PikaDrawable **drawables,
|
||||
PikaProcedureConfig *config,
|
||||
gpointer run_data);
|
||||
#endif
|
||||
|
||||
|
||||
@ -177,15 +180,18 @@ dds_create_procedure (PikaPlugIn *plug_in,
|
||||
{
|
||||
procedure = pika_save_procedure_new (plug_in, name,
|
||||
PIKA_PDB_PROC_TYPE_PLUGIN,
|
||||
dds_save, NULL, NULL);
|
||||
FALSE, dds_save, NULL, NULL);
|
||||
|
||||
pika_procedure_set_image_types (procedure, "INDEXED, GRAY, RGB");
|
||||
|
||||
pika_procedure_set_menu_label (procedure, _("DDS image"));
|
||||
pika_file_procedure_set_format_name (PIKA_FILE_PROCEDURE (procedure),
|
||||
_("DDS"));
|
||||
|
||||
|
||||
pika_procedure_set_documentation (procedure,
|
||||
"Saves files in DDS image format",
|
||||
"Saves files in DDS image format",
|
||||
_("Saves files in DDS image format"),
|
||||
_("Saves files in DDS image format"),
|
||||
name);
|
||||
pika_procedure_set_attribution (procedure,
|
||||
"Shawn Kirst",
|
||||
@ -197,14 +203,77 @@ dds_create_procedure (PikaPlugIn *plug_in,
|
||||
pika_file_procedure_set_extensions (PIKA_FILE_PROCEDURE (procedure),
|
||||
"dds");
|
||||
|
||||
PIKA_PROC_ARG_INT (procedure, "compression-format",
|
||||
"Compression format",
|
||||
"Compression format (0 = None, 1 = BC1/DXT1, "
|
||||
"2 = BC2/DXT3, 3 = BC3/DXT5, 4 = BC3n/DXT5nm, "
|
||||
"5 = BC4/ATI1N, 6 = BC5/ATI2N, 7 = RXGB (DXT5), "
|
||||
"8 = Alpha Exponent (DXT5), 9 = YCoCg (DXT5), "
|
||||
"10 = YCoCg scaled (DXT5))",
|
||||
0, 10, DDS_COMPRESS_NONE,
|
||||
PIKA_PROC_ARG_CHOICE (procedure, "compression-format",
|
||||
_("Compressio_n"),
|
||||
_("Compression format"),
|
||||
pika_choice_new_with_values ("none", DDS_COMPRESS_NONE, _("None"), NULL,
|
||||
"bc1", DDS_COMPRESS_BC1, _("BC1 / DXT1"), NULL,
|
||||
"bc2", DDS_COMPRESS_BC2, _("BC2 / DXT3"), NULL,
|
||||
"bc3, ", DDS_COMPRESS_BC3, _("BC3 / DXT5"), NULL,
|
||||
"bc3n", DDS_COMPRESS_BC3N, _("BC3nm / DXT5nm"), NULL,
|
||||
"bc4", DDS_COMPRESS_BC4, _("BC4 / ATI1 (3Dc+)"), NULL,
|
||||
"bc5", DDS_COMPRESS_BC5, _("BC5 / ATI2 (3Dc)"), NULL,
|
||||
"rxgb", DDS_COMPRESS_RXGB, _("RXGB (DXT5)"), NULL,
|
||||
"aexp", DDS_COMPRESS_AEXP, _("Alpha Exponent (DXT5)"), NULL,
|
||||
"ycocg", DDS_COMPRESS_YCOCG, _("YCoCg (DXT5)"), NULL,
|
||||
"ycocgs", DDS_COMPRESS_YCOCGS, _("YCoCg scaled (DXT5)"), NULL,
|
||||
NULL),
|
||||
"none",
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_BOOLEAN (procedure, "perceptual-metric",
|
||||
_("Use percept_ual error metric"),
|
||||
_("Use a perceptual error metric during compression"),
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_CHOICE (procedure, "format",
|
||||
_("_Format"),
|
||||
_("Pixel format"),
|
||||
pika_choice_new_with_values ("default", DDS_FORMAT_DEFAULT, _("Default"), NULL,
|
||||
"rgb8", DDS_FORMAT_RGB8, _("RGB8"), NULL,
|
||||
"rgba8", DDS_FORMAT_RGBA8, _("RGBA8"), NULL,
|
||||
"bgr8", DDS_FORMAT_BGR8, _("BGR8"), NULL,
|
||||
"abgr8, ", DDS_FORMAT_ABGR8, _("ABGR8"), NULL,
|
||||
"r5g6b5", DDS_FORMAT_R5G6B5, _("R5G6B5"), NULL,
|
||||
"rgba4", DDS_FORMAT_RGBA4, _("RGBA4"), NULL,
|
||||
"rgb5a1", DDS_FORMAT_RGB5A1, _("RGB5A1"), NULL,
|
||||
"rgb10a2", DDS_FORMAT_RGB10A2, _("RGB10A2"), NULL,
|
||||
"r3g3b2", DDS_FORMAT_R3G3B2, _("R3G3B2"), NULL,
|
||||
"a8", DDS_FORMAT_A8, _("A8"), NULL,
|
||||
"l8", DDS_FORMAT_L8, _("L8"), NULL,
|
||||
"l8a8", DDS_FORMAT_L8A8, _("L8A8"), NULL,
|
||||
"aexp", DDS_FORMAT_AEXP, _("AEXP"), NULL,
|
||||
"ycocg", DDS_FORMAT_YCOCG, _("YCOCG"), NULL,
|
||||
NULL),
|
||||
"default",
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_INT (procedure, "save-type",
|
||||
"Save type",
|
||||
"How to save the image (0 = selected layer, "
|
||||
"1 = cube map, 2 = volume map, 3 = texture array, "
|
||||
"4 = all visible layers)",
|
||||
0, 4, DDS_SAVE_SELECTED_LAYER,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_BOOLEAN (procedure, "flip-image",
|
||||
_("Flip image _vertically on export"),
|
||||
_("Flip the image vertically on export"),
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_BOOLEAN (procedure, "transparent-color",
|
||||
_("Set _transparent color"),
|
||||
_("Make an indexed color transparent"),
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_INT (procedure, "transparent-index",
|
||||
_("Transparent inde_x"),
|
||||
_("Index of transparent color or -1 to disable "
|
||||
"(for indexed images only)."),
|
||||
0, 255, 0,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_INT (procedure, "mipmaps",
|
||||
@ -215,97 +284,62 @@ dds_create_procedure (PikaPlugIn *plug_in,
|
||||
0, 2, DDS_MIPMAP_NONE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_INT (procedure, "save-type",
|
||||
"Save type",
|
||||
"How to save the image (0 = selected layer, "
|
||||
"1 = cube map, 2 = volume map, 3 = texture array, "
|
||||
"4 = all visible layers)",
|
||||
0, 4, DDS_SAVE_SELECTED_LAYER,
|
||||
G_PARAM_READWRITE);
|
||||
PIKA_PROC_ARG_CHOICE (procedure, "mipmap-filter",
|
||||
_("F_ilter"),
|
||||
_("Filtering to use when generating mipmaps"),
|
||||
pika_choice_new_with_values ("default", DDS_MIPMAP_FILTER_DEFAULT, _("Default"), NULL,
|
||||
"nearest", DDS_MIPMAP_FILTER_NEAREST, _("Nearest"), NULL,
|
||||
"box", DDS_MIPMAP_FILTER_BOX, _("Box"), NULL,
|
||||
"triangle", DDS_MIPMAP_FILTER_TRIANGLE, _("Triangle"), NULL,
|
||||
"quadratic", DDS_MIPMAP_FILTER_QUADRATIC, _("Quadratic"), NULL,
|
||||
"bspline", DDS_MIPMAP_FILTER_BSPLINE, _("B-Spline"), NULL,
|
||||
"mitchell", DDS_MIPMAP_FILTER_MITCHELL, _("Mitchell"), NULL,
|
||||
"lanczos", DDS_MIPMAP_FILTER_LANCZOS, _("Lanczos"), NULL,
|
||||
"kaiser", DDS_MIPMAP_FILTER_KAISER, _("Kaiser"), NULL,
|
||||
NULL),
|
||||
"default",
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_INT (procedure, "format",
|
||||
"Format",
|
||||
"Pixel format (0 = default, 1 = DDS_FORMAT_RGB8, "
|
||||
"2 = DDS_FORMAT_RGBA8, 3 = DDS_FORMAT_BGR8, "
|
||||
"4 = DDS_FORMAT_ABGR8, 5 = DDS_FORMAT_R5G6B5, "
|
||||
"6 = DDS_FORMAT_RGBA4, 7 = DDS_FORMAT_RGB5A1, "
|
||||
"8 = DDS_FORMAT_RGB10A2, 9 = DDS_FORMAT_R3G3B2, "
|
||||
"10 = DDS_FORMAT_A8, 11 = DDS_FORMAT_L8, "
|
||||
"12 = DDS_FORMAT_L8A8, 13 = DDS_FORMAT_AEXP, "
|
||||
"14 = DDS_FORMAT_YCOCG)",
|
||||
0, 14, DDS_FORMAT_DEFAULT,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_BOOLEAN (procedure, "flip-image",
|
||||
"Flip image vertically",
|
||||
"Flip the image vertically on export",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_BOOLEAN (procedure, "transparent-color",
|
||||
"Transparent color",
|
||||
"Make an indexed color transparent",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_INT (procedure, "transparent-index",
|
||||
"Transparent index",
|
||||
"Index of transparent color or -1 to disable "
|
||||
"(for indexed images only).",
|
||||
0, 255, 0,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_INT (procedure, "mipmap-filter",
|
||||
"Mipmap filter",
|
||||
"Filtering to use when generating mipmaps "
|
||||
"(0 = default, 1 = nearest, 2 = box, 3 = triangle, "
|
||||
"4 = quadratic, 5 = bspline, 6 = mitchell, "
|
||||
"7 = lanczos, 8 = kaiser)",
|
||||
0, 8, DDS_MIPMAP_FILTER_DEFAULT,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_INT (procedure, "mipmap-wrap",
|
||||
"Mipmap wrap",
|
||||
"Wrap mode to use when generating mipmaps "
|
||||
"(0 = default, 1 = mirror, 2 = repeat, 3 = clamp)",
|
||||
0, 3, DDS_MIPMAP_WRAP_DEFAULT,
|
||||
G_PARAM_READWRITE);
|
||||
PIKA_PROC_ARG_CHOICE (procedure, "mipmap-wrap",
|
||||
_("_Wrap mode"),
|
||||
_("Wrap mode to use when generating mipmaps"),
|
||||
pika_choice_new_with_values ("default", DDS_MIPMAP_WRAP_DEFAULT, _("Default"), NULL,
|
||||
"mirror", DDS_MIPMAP_WRAP_MIRROR, _("Mirror"), NULL,
|
||||
"repeat", DDS_MIPMAP_WRAP_REPEAT, _("Repeat"), NULL,
|
||||
"clamp", DDS_MIPMAP_WRAP_CLAMP, _("Clamp"), NULL,
|
||||
NULL),
|
||||
"default",
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_BOOLEAN (procedure, "gamma-correct",
|
||||
"Gamma correct",
|
||||
"Use gamma correct mipmap filtering",
|
||||
_("Appl_y gamma correction"),
|
||||
_("Use gamma correct mipmap filtering"),
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_BOOLEAN (procedure, "srgb",
|
||||
"sRGB",
|
||||
"Use sRGB colorspace for gamma correction",
|
||||
_("Use sRG_B colorspace"),
|
||||
_("Use sRGB colorspace for gamma correction"),
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_DOUBLE (procedure, "gamma",
|
||||
"Gamma",
|
||||
"Gamma value to use for gamma correction (i.e. 2.2)",
|
||||
_("_Gamma"),
|
||||
_("Gamma value to use for gamma correction (e.g. 2.2)"),
|
||||
0.0, 10.0, 0.0,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_BOOLEAN (procedure, "perceptual-metric",
|
||||
"Perceptual metric",
|
||||
"Use a perceptual error metric during compression",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_BOOLEAN (procedure, "preserve-alpha-coverage",
|
||||
"Preserve alpha coverage",
|
||||
"Preserve alpha test converage for alpha "
|
||||
"channel maps",
|
||||
_("Preserve al_pha test coverage"),
|
||||
_("Preserve alpha test coverage for alpha "
|
||||
"channel maps"),
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
PIKA_PROC_ARG_DOUBLE (procedure, "alpha-test-threshold",
|
||||
"Alpha test threshold",
|
||||
"Alpha test threshold value for which alpha test "
|
||||
"converage should be preserved",
|
||||
_("Alp_ha test threshold"),
|
||||
_("Alpha test threshold value for which alpha test "
|
||||
"coverage should be preserved"),
|
||||
0.0, 1.0, 0.5,
|
||||
G_PARAM_READWRITE);
|
||||
}
|
||||
@ -386,13 +420,14 @@ dds_create_procedure (PikaPlugIn *plug_in,
|
||||
}
|
||||
|
||||
static PikaValueArray *
|
||||
dds_load (PikaProcedure *procedure,
|
||||
PikaRunMode run_mode,
|
||||
GFile *file,
|
||||
const PikaValueArray *args,
|
||||
gpointer run_data)
|
||||
dds_load (PikaProcedure *procedure,
|
||||
PikaRunMode run_mode,
|
||||
GFile *file,
|
||||
PikaMetadata *metadata,
|
||||
PikaMetadataLoadFlags *flags,
|
||||
PikaProcedureConfig *config,
|
||||
gpointer run_data)
|
||||
{
|
||||
PikaProcedureConfig *config;
|
||||
PikaValueArray *return_vals;
|
||||
PikaPDBStatusType status;
|
||||
PikaImage *image;
|
||||
@ -400,15 +435,9 @@ dds_load (PikaProcedure *procedure,
|
||||
|
||||
gegl_init (NULL, NULL);
|
||||
|
||||
config = pika_procedure_create_config (procedure);
|
||||
pika_procedure_config_begin_run (config, NULL, run_mode, args);
|
||||
|
||||
status = read_dds (file, &image, run_mode == PIKA_RUN_INTERACTIVE,
|
||||
procedure, G_OBJECT (config), &error);
|
||||
|
||||
pika_procedure_config_end_run (config, status);
|
||||
g_object_unref (config);
|
||||
|
||||
if (status != PIKA_PDB_SUCCESS)
|
||||
return pika_procedure_new_return_values (procedure, status, error);
|
||||
|
||||
@ -428,20 +457,17 @@ dds_save (PikaProcedure *procedure,
|
||||
gint n_drawables,
|
||||
PikaDrawable **drawables,
|
||||
GFile *file,
|
||||
const PikaValueArray *args,
|
||||
PikaMetadata *metadata,
|
||||
PikaProcedureConfig *config,
|
||||
gpointer run_data)
|
||||
{
|
||||
PikaProcedureConfig *config;
|
||||
PikaPDBStatusType status = PIKA_PDB_SUCCESS;
|
||||
PikaExportReturn export = PIKA_EXPORT_CANCEL;
|
||||
GError *error = NULL;
|
||||
gdouble gamma;
|
||||
PikaPDBStatusType status = PIKA_PDB_SUCCESS;
|
||||
PikaExportReturn export = PIKA_EXPORT_CANCEL;
|
||||
GError *error = NULL;
|
||||
gdouble gamma;
|
||||
|
||||
gegl_init (NULL, NULL);
|
||||
|
||||
config = pika_procedure_create_config (procedure);
|
||||
pika_procedure_config_begin_run (config, NULL, run_mode, args);
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
case PIKA_RUN_INTERACTIVE:
|
||||
@ -483,7 +509,7 @@ dds_save (PikaProcedure *procedure,
|
||||
*/
|
||||
status = write_dds (file, image, drawables[0],
|
||||
run_mode == PIKA_RUN_INTERACTIVE,
|
||||
procedure, G_OBJECT (config),
|
||||
procedure, config,
|
||||
export == PIKA_EXPORT_EXPORT);
|
||||
|
||||
if (export == PIKA_EXPORT_EXPORT)
|
||||
@ -492,9 +518,6 @@ dds_save (PikaProcedure *procedure,
|
||||
g_free (drawables);
|
||||
}
|
||||
|
||||
pika_procedure_config_end_run (config, status);
|
||||
g_object_unref (config);
|
||||
|
||||
return pika_procedure_new_return_values (procedure, status, error);
|
||||
}
|
||||
|
||||
@ -505,7 +528,7 @@ dds_decode (PikaProcedure *procedure,
|
||||
PikaImage *image,
|
||||
gint n_drawables,
|
||||
PikaDrawable **drawables,
|
||||
const PikaValueArray *args,
|
||||
PikaProcedureConfig *config,
|
||||
gpointer run_data)
|
||||
{
|
||||
const gchar *name = pika_procedure_get_name (procedure);
|
||||
|
@ -124,6 +124,7 @@ read_dds (GFile *file,
|
||||
guint l = 0;
|
||||
guchar *pixels;
|
||||
FILE *fp;
|
||||
gsize file_size;
|
||||
dds_header_t hdr;
|
||||
dds_header_dx10_t dx10hdr;
|
||||
dds_load_info_t d;
|
||||
@ -157,6 +158,10 @@ read_dds (GFile *file,
|
||||
return PIKA_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
|
||||
fseek (fp, 0L, SEEK_END);
|
||||
file_size = ftell (fp);
|
||||
fseek (fp, 0, SEEK_SET);
|
||||
|
||||
pika_progress_init_printf ("Loading %s:", pika_file_get_utf8_name (file));
|
||||
|
||||
/* read header */
|
||||
@ -358,6 +363,16 @@ read_dds (GFile *file,
|
||||
precision = PIKA_PRECISION_U8_NON_LINEAR;
|
||||
}
|
||||
|
||||
/* verify header information is accurate */
|
||||
if (d.bpp < 1 ||
|
||||
(hdr.pitch_or_linsize > (file_size - sizeof (hdr))))
|
||||
{
|
||||
fclose (fp);
|
||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Invalid or corrupted DDS header"));
|
||||
return PIKA_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
|
||||
image = pika_image_new_with_precision (hdr.width, hdr.height, type, precision);
|
||||
|
||||
if (! image)
|
||||
@ -1012,6 +1027,13 @@ load_layer (FILE *fp,
|
||||
guint size = hdr->pitch_or_linsize >> (2 * level);
|
||||
guint layerw;
|
||||
gint format = DDS_COMPRESS_NONE;
|
||||
gsize file_size;
|
||||
gsize current_position;
|
||||
|
||||
current_position = ftell (fp);
|
||||
fseek (fp, 0L, SEEK_END);
|
||||
file_size = ftell (fp);
|
||||
fseek (fp, current_position, SEEK_SET);
|
||||
|
||||
if (width < 1) width = 1;
|
||||
if (height < 1) height = 1;
|
||||
@ -1128,6 +1150,14 @@ load_layer (FILE *fp,
|
||||
size *= 16;
|
||||
}
|
||||
|
||||
if (size > (file_size - current_position) ||
|
||||
size > hdr->pitch_or_linsize)
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
_("Requested data exceeds size of file.\n"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((hdr->flags & DDSD_LINEARSIZE) &&
|
||||
!fread (buf, size, 1, fp))
|
||||
{
|
||||
@ -1167,6 +1197,16 @@ load_layer (FILE *fp,
|
||||
pika_progress_update ((double) y / (double) hdr->height);
|
||||
}
|
||||
|
||||
current_position = ftell (fp);
|
||||
if ((hdr->flags & DDSD_PITCH) &&
|
||||
((width * d->bpp) > (file_size - current_position) ||
|
||||
(width * d->bpp) > hdr->pitch_or_linsize))
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
_("Requested data exceeds size of file.\n"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((hdr->flags & DDSD_PITCH) &&
|
||||
! fread (buf, width * d->bpp, 1, fp))
|
||||
{
|
||||
|
@ -44,14 +44,14 @@
|
||||
#include "color.h"
|
||||
|
||||
|
||||
static gboolean write_image (FILE *fp,
|
||||
PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
GObject *config);
|
||||
static gboolean save_dialog (PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
PikaProcedure *procedure,
|
||||
GObject *config);
|
||||
static gboolean write_image (FILE *fp,
|
||||
PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
PikaProcedureConfig *config);
|
||||
static gboolean save_dialog (PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
PikaProcedure *procedure,
|
||||
PikaProcedureConfig *config);
|
||||
|
||||
|
||||
static const char *cubemap_face_names[4][6] =
|
||||
@ -78,25 +78,14 @@ static const char *cubemap_face_names[4][6] =
|
||||
}
|
||||
};
|
||||
|
||||
static PikaImage *global_image = NULL;
|
||||
static PikaLayer *cubemap_faces[6];
|
||||
static gboolean is_cubemap = FALSE;
|
||||
static gboolean is_volume = FALSE;
|
||||
static gboolean is_array = FALSE;
|
||||
static gboolean is_mipmap_chain_valid = FALSE;
|
||||
|
||||
static GtkWidget *compress_opt;
|
||||
static GtkWidget *format_opt;
|
||||
static GtkWidget *mipmap_opt;
|
||||
static GtkWidget *mipmap_filter_opt;
|
||||
static GtkWidget *mipmap_wrap_opt;
|
||||
static GtkWidget *transparent_spin;
|
||||
static GtkWidget *srgb_check;
|
||||
static GtkWidget *flip_check;
|
||||
static GtkWidget *gamma_check;
|
||||
static GtkWidget *gamma_spin;
|
||||
static GtkWidget *pm_check;
|
||||
static GtkWidget *alpha_coverage_check;
|
||||
static GtkWidget *alpha_test_threshold_spin;
|
||||
static GtkWidget *transparent_check;
|
||||
|
||||
static struct
|
||||
{
|
||||
@ -128,8 +117,7 @@ static struct
|
||||
|
||||
|
||||
static gboolean
|
||||
check_mipmaps (PikaImage *image,
|
||||
gint savetype)
|
||||
check_mipmaps (gint savetype)
|
||||
{
|
||||
GList *layers;
|
||||
GList *list;
|
||||
@ -159,11 +147,11 @@ check_mipmaps (PikaImage *image,
|
||||
max_surfaces = INT_MAX;
|
||||
}
|
||||
|
||||
layers = pika_image_list_layers (image);
|
||||
layers = pika_image_list_layers (global_image);
|
||||
num_layers = g_list_length (layers);
|
||||
|
||||
w = pika_image_get_width (image);
|
||||
h = pika_image_get_height (image);
|
||||
w = pika_image_get_width (global_image);
|
||||
h = pika_image_get_height (global_image);
|
||||
|
||||
num_mipmaps = get_num_mipmaps (w, h);
|
||||
|
||||
@ -237,7 +225,7 @@ check_cubemap (PikaImage *image)
|
||||
if (num_layers > 6)
|
||||
{
|
||||
/* check that mipmap layers are in order for a cubemap */
|
||||
if (! check_mipmaps (image, DDS_SAVE_CUBEMAP))
|
||||
if (! check_mipmaps (DDS_SAVE_CUBEMAP))
|
||||
return FALSE;
|
||||
|
||||
/* invalidate cubemap faces */
|
||||
@ -425,7 +413,7 @@ check_array (PikaImage *image)
|
||||
gint w, h;
|
||||
PikaImageType type;
|
||||
|
||||
if (check_mipmaps (image, DDS_SAVE_ARRAY))
|
||||
if (check_mipmaps (DDS_SAVE_ARRAY))
|
||||
return 1;
|
||||
|
||||
layers = pika_image_list_layers (image);
|
||||
@ -506,13 +494,13 @@ get_array_size (PikaImage *image)
|
||||
}
|
||||
|
||||
PikaPDBStatusType
|
||||
write_dds (GFile *file,
|
||||
PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
gboolean interactive,
|
||||
PikaProcedure *procedure,
|
||||
GObject *config,
|
||||
gboolean is_duplicate_image)
|
||||
write_dds (GFile *file,
|
||||
PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
gboolean interactive,
|
||||
PikaProcedure *procedure,
|
||||
PikaProcedureConfig *config,
|
||||
gboolean is_duplicate_image)
|
||||
{
|
||||
FILE *fp;
|
||||
gint rc = 0;
|
||||
@ -520,13 +508,16 @@ write_dds (GFile *file,
|
||||
gint mipmaps;
|
||||
gint savetype;
|
||||
|
||||
compression = pika_procedure_config_get_choice_id (config,
|
||||
"compression-format");
|
||||
g_object_get (config,
|
||||
"compression-format", &compression,
|
||||
"mipmaps", &mipmaps,
|
||||
"save-type", &savetype,
|
||||
"save-type", &savetype,
|
||||
"mipmaps", &mipmaps,
|
||||
NULL);
|
||||
|
||||
is_mipmap_chain_valid = check_mipmaps (image, savetype);
|
||||
global_image = image;
|
||||
|
||||
is_mipmap_chain_valid = check_mipmaps (savetype);
|
||||
|
||||
is_cubemap = check_cubemap (image);
|
||||
is_volume = check_volume (image);
|
||||
@ -850,15 +841,15 @@ get_mipmap_chain (unsigned char *dst,
|
||||
}
|
||||
|
||||
static void
|
||||
write_layer (FILE *fp,
|
||||
PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
GObject *config,
|
||||
int w,
|
||||
int h,
|
||||
int bpp,
|
||||
int fmtbpp,
|
||||
int num_mipmaps)
|
||||
write_layer (FILE *fp,
|
||||
PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
PikaProcedureConfig *config,
|
||||
int w,
|
||||
int h,
|
||||
int bpp,
|
||||
int fmtbpp,
|
||||
int num_mipmaps)
|
||||
{
|
||||
GeglBuffer *buffer;
|
||||
const Babl *format;
|
||||
@ -882,11 +873,12 @@ write_layer (FILE *fp,
|
||||
gint flags = 0;
|
||||
|
||||
g_object_get (config,
|
||||
"compression-format", &compression,
|
||||
"mipmaps", &mipmaps,
|
||||
"format", &pixel_format,
|
||||
"perceptual-metric", &perceptual_metric,
|
||||
"mipmaps", &mipmaps,
|
||||
NULL);
|
||||
compression = pika_procedure_config_get_choice_id (config,
|
||||
"compression-format");
|
||||
pixel_format = pika_procedure_config_get_choice_id (config, "format");
|
||||
|
||||
basetype = pika_image_get_base_type (image);
|
||||
type = pika_drawable_type (drawable);
|
||||
@ -1037,14 +1029,16 @@ write_layer (FILE *fp,
|
||||
gdouble alpha_test_threshold;
|
||||
|
||||
g_object_get (config,
|
||||
"mipmap-filter", &mipmap_filter,
|
||||
"mipmap-wrap", &mipmap_wrap,
|
||||
"gamma-correct", &gamma_correct,
|
||||
"srgb", &srgb,
|
||||
"gamma", &gamma,
|
||||
"preserve-alpha-coverage", &preserve_alpha_coverage,
|
||||
"alpha-test-threshold", &alpha_test_threshold,
|
||||
NULL);
|
||||
mipmap_filter = pika_procedure_config_get_choice_id (config,
|
||||
"mipmap-filter");
|
||||
mipmap_wrap = pika_procedure_config_get_choice_id (config,
|
||||
"mipmap-wrap");
|
||||
|
||||
generate_mipmaps (dst, src, w, h, bpp, palette != NULL,
|
||||
num_mipmaps,
|
||||
@ -1135,14 +1129,16 @@ write_layer (FILE *fp,
|
||||
gdouble alpha_test_threshold;
|
||||
|
||||
g_object_get (config,
|
||||
"mipmap-filter", &mipmap_filter,
|
||||
"mipmap-wrap", &mipmap_wrap,
|
||||
"gamma-correct", &gamma_correct,
|
||||
"srgb", &srgb,
|
||||
"gamma", &gamma,
|
||||
"preserve-alpha-coverage", &preserve_alpha_coverage,
|
||||
"alpha-test-threshold", &alpha_test_threshold,
|
||||
NULL);
|
||||
mipmap_filter = pika_procedure_config_get_choice_id (config,
|
||||
"mipmap-filter");
|
||||
mipmap_wrap = pika_procedure_config_get_choice_id (config,
|
||||
"mipmap-wrap");
|
||||
|
||||
generate_mipmaps (fmtdst, src, w, h, bpp, 0, num_mipmaps,
|
||||
mipmap_filter,
|
||||
@ -1179,16 +1175,16 @@ write_layer (FILE *fp,
|
||||
}
|
||||
|
||||
static void
|
||||
write_volume_mipmaps (FILE *fp,
|
||||
PikaImage *image,
|
||||
GObject *config,
|
||||
GList *layers,
|
||||
int w,
|
||||
int h,
|
||||
int d,
|
||||
int bpp,
|
||||
int fmtbpp,
|
||||
int num_mipmaps)
|
||||
write_volume_mipmaps (FILE *fp,
|
||||
PikaImage *image,
|
||||
PikaProcedureConfig *config,
|
||||
GList *layers,
|
||||
int w,
|
||||
int h,
|
||||
int d,
|
||||
int bpp,
|
||||
int fmtbpp,
|
||||
int num_mipmaps)
|
||||
{
|
||||
GList *list;
|
||||
gint i;
|
||||
@ -1212,14 +1208,16 @@ write_volume_mipmaps (FILE *fp,
|
||||
gdouble gamma;
|
||||
|
||||
g_object_get (config,
|
||||
"compression-format", &compression,
|
||||
"format", &pixel_format,
|
||||
"mipmap-filter", &mipmap_filter,
|
||||
"mipmap-wrap", &mipmap_wrap,
|
||||
"gamma-correct", &gamma_correct,
|
||||
"srgb", &srgb,
|
||||
"gamma", &gamma,
|
||||
NULL);
|
||||
compression = pika_procedure_config_get_choice_id (config,
|
||||
"compression-format");
|
||||
pixel_format = pika_procedure_config_get_choice_id (config, "format");
|
||||
mipmap_filter = pika_procedure_config_get_choice_id (config,
|
||||
"mipmap-filter");
|
||||
mipmap_wrap = pika_procedure_config_get_choice_id (config, "mipmap-wrap");
|
||||
|
||||
type = pika_image_get_base_type (image);
|
||||
|
||||
@ -1317,10 +1315,10 @@ write_volume_mipmaps (FILE *fp,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
write_image (FILE *fp,
|
||||
PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
GObject *config)
|
||||
write_image (FILE *fp,
|
||||
PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
PikaProcedureConfig *config)
|
||||
{
|
||||
PikaImageType drawable_type;
|
||||
PikaImageBaseType basetype;
|
||||
@ -1351,13 +1349,14 @@ write_image (FILE *fp,
|
||||
gboolean flip_export;
|
||||
|
||||
g_object_get (config,
|
||||
"compression-format", &compression,
|
||||
"mipmaps", &mipmaps,
|
||||
"save-type", &savetype,
|
||||
"format", &pixel_format,
|
||||
"transparent-index", &transindex,
|
||||
"flip-image", &flip_export,
|
||||
"mipmaps", &mipmaps,
|
||||
"save-type", &savetype,
|
||||
NULL);
|
||||
compression = pika_procedure_config_get_choice_id (config,
|
||||
"compression-format");
|
||||
pixel_format = pika_procedure_config_get_choice_id (config, "format");
|
||||
|
||||
if (flip_export)
|
||||
pika_image_flip (image, PIKA_ORIENTATION_VERTICAL);
|
||||
@ -1804,29 +1803,32 @@ combo_set_item_sensitive (GtkWidget *widget,
|
||||
}
|
||||
|
||||
static void
|
||||
config_notify (GObject *config,
|
||||
const GParamSpec *pspec,
|
||||
PikaImage *image)
|
||||
config_notify (PikaProcedureConfig *config,
|
||||
const GParamSpec *pspec,
|
||||
PikaProcedureDialog *dialog)
|
||||
{
|
||||
if (! strcmp (pspec->name, "compression-format"))
|
||||
{
|
||||
gint compression;
|
||||
|
||||
g_object_get (config,
|
||||
"compression-format", &compression,
|
||||
NULL);
|
||||
compression = pika_procedure_config_get_choice_id (config,
|
||||
"compression-format");
|
||||
|
||||
if (format_opt)
|
||||
gtk_widget_set_sensitive (format_opt,
|
||||
compression == DDS_COMPRESS_NONE);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"format",
|
||||
compression == DDS_COMPRESS_NONE,
|
||||
NULL, NULL, FALSE);
|
||||
|
||||
if (pm_check)
|
||||
gtk_widget_set_sensitive (pm_check,
|
||||
compression != DDS_COMPRESS_NONE);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"perceptual-metric",
|
||||
compression != DDS_COMPRESS_NONE,
|
||||
NULL, NULL, FALSE);
|
||||
}
|
||||
else if (! strcmp (pspec->name, "save-type"))
|
||||
{
|
||||
gint savetype;
|
||||
gint savetype;
|
||||
GtkWidget *widget;
|
||||
GtkWidget *combo;
|
||||
|
||||
g_object_get (config,
|
||||
"save-type", &savetype,
|
||||
@ -1838,20 +1840,26 @@ config_notify (GObject *config,
|
||||
case DDS_SAVE_VISIBLE_LAYERS:
|
||||
case DDS_SAVE_CUBEMAP:
|
||||
case DDS_SAVE_ARRAY:
|
||||
gtk_widget_set_sensitive (compress_opt, TRUE);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"compression-format", TRUE,
|
||||
NULL, NULL, FALSE);
|
||||
break;
|
||||
|
||||
case DDS_SAVE_VOLUMEMAP:
|
||||
g_object_set (config,
|
||||
"compression-format", DDS_COMPRESS_NONE,
|
||||
"compression-format", "none",
|
||||
NULL);
|
||||
gtk_widget_set_sensitive (compress_opt, FALSE);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"compression-format", FALSE,
|
||||
NULL, NULL, FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mipmap_opt)
|
||||
combo_set_item_sensitive (mipmap_opt, DDS_MIPMAP_EXISTING,
|
||||
check_mipmaps (image, savetype));
|
||||
widget = pika_procedure_dialog_get_widget (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"mipmaps", G_TYPE_NONE);
|
||||
combo = pika_label_int_widget_get_widget (PIKA_LABEL_INT_WIDGET (widget));
|
||||
combo_set_item_sensitive (combo, DDS_MIPMAP_EXISTING,
|
||||
check_mipmaps (savetype));
|
||||
}
|
||||
else if (! strcmp (pspec->name, "mipmaps"))
|
||||
{
|
||||
@ -1861,59 +1869,64 @@ config_notify (GObject *config,
|
||||
gboolean preserve_alpha_coverage;
|
||||
|
||||
g_object_get (config,
|
||||
"mipmaps", &mipmaps,
|
||||
"gamma-correct", &gamma_correct,
|
||||
"srgb", &srgb,
|
||||
"preserve-alpha-coverage", &preserve_alpha_coverage,
|
||||
"mipmaps", &mipmaps,
|
||||
NULL);
|
||||
|
||||
if (mipmap_filter_opt)
|
||||
gtk_widget_set_sensitive (mipmap_filter_opt,
|
||||
mipmaps == DDS_MIPMAP_GENERATE);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"mipmap-filter",
|
||||
mipmaps == DDS_MIPMAP_GENERATE,
|
||||
NULL, NULL, FALSE);
|
||||
|
||||
if (mipmap_wrap_opt)
|
||||
gtk_widget_set_sensitive (mipmap_wrap_opt,
|
||||
mipmaps == DDS_MIPMAP_GENERATE);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"mipmap-wrap",
|
||||
mipmaps == DDS_MIPMAP_GENERATE,
|
||||
NULL, NULL, FALSE);
|
||||
|
||||
if (gamma_check)
|
||||
gtk_widget_set_sensitive (gamma_check,
|
||||
mipmaps == DDS_MIPMAP_GENERATE);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"gamma-correct",
|
||||
mipmaps == DDS_MIPMAP_GENERATE,
|
||||
NULL, NULL, FALSE);
|
||||
|
||||
if (srgb_check)
|
||||
gtk_widget_set_sensitive (srgb_check,
|
||||
(mipmaps == DDS_MIPMAP_GENERATE) &&
|
||||
gamma_correct);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"srgb",
|
||||
((mipmaps == DDS_MIPMAP_GENERATE) &&
|
||||
gamma_correct),
|
||||
NULL, NULL, FALSE);
|
||||
|
||||
if (gamma_spin)
|
||||
gtk_widget_set_sensitive (gamma_spin,
|
||||
(mipmaps == DDS_MIPMAP_GENERATE) &&
|
||||
gamma_correct &&
|
||||
! srgb);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"gamma",
|
||||
((mipmaps == DDS_MIPMAP_GENERATE) &&
|
||||
gamma_correct && ! srgb),
|
||||
NULL, NULL, FALSE);
|
||||
|
||||
if (alpha_coverage_check)
|
||||
gtk_widget_set_sensitive (alpha_coverage_check,
|
||||
mipmaps == DDS_MIPMAP_GENERATE);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"preserve-alpha-coverage",
|
||||
mipmaps == DDS_MIPMAP_GENERATE,
|
||||
NULL, NULL, FALSE);
|
||||
|
||||
if (alpha_test_threshold_spin)
|
||||
gtk_widget_set_sensitive (alpha_test_threshold_spin,
|
||||
(mipmaps == DDS_MIPMAP_GENERATE) &&
|
||||
preserve_alpha_coverage);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"alpha-test-threshold",
|
||||
((mipmaps == DDS_MIPMAP_GENERATE) &&
|
||||
preserve_alpha_coverage),
|
||||
NULL, NULL, FALSE);
|
||||
}
|
||||
else if (! strcmp (pspec->name, "transparent-color"))
|
||||
{
|
||||
PikaImageBaseType base_type;
|
||||
gboolean transparent_color;
|
||||
|
||||
base_type = pika_image_get_base_type (image);
|
||||
gboolean transparent_color;
|
||||
|
||||
g_object_get (config,
|
||||
"transparent-color", &transparent_color,
|
||||
NULL);
|
||||
|
||||
if (transparent_spin)
|
||||
gtk_widget_set_sensitive (transparent_spin,
|
||||
transparent_color &&
|
||||
base_type == PIKA_INDEXED);
|
||||
if (transparent_check &&
|
||||
gtk_widget_get_sensitive (transparent_check))
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"transparent-index",
|
||||
transparent_color,
|
||||
NULL, NULL, FALSE);
|
||||
}
|
||||
else if (! strcmp (pspec->name, "gamma-correct"))
|
||||
{
|
||||
@ -1925,11 +1938,14 @@ config_notify (GObject *config,
|
||||
"srgb", &srgb,
|
||||
NULL);
|
||||
|
||||
if (srgb_check)
|
||||
gtk_widget_set_sensitive (srgb_check, gamma_correct);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"srgb", gamma_correct,
|
||||
NULL, NULL, FALSE);
|
||||
|
||||
if (gamma_spin)
|
||||
gtk_widget_set_sensitive (gamma_spin, gamma_correct && ! srgb);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"gamma",
|
||||
(gamma_correct && ! srgb),
|
||||
NULL, NULL, FALSE);
|
||||
}
|
||||
else if (! strcmp (pspec->name, "srgb"))
|
||||
{
|
||||
@ -1941,8 +1957,10 @@ config_notify (GObject *config,
|
||||
"srgb", &srgb,
|
||||
NULL);
|
||||
|
||||
if (gamma_spin)
|
||||
gtk_widget_set_sensitive (gamma_spin, gamma_correct && ! srgb);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"gamma",
|
||||
(gamma_correct && ! srgb),
|
||||
NULL, NULL, FALSE);
|
||||
}
|
||||
else if (! strcmp (pspec->name, "preserve-alpha-coverage"))
|
||||
{
|
||||
@ -1952,251 +1970,137 @@ config_notify (GObject *config,
|
||||
"preserve-alpha-coverage", &preserve_alpha_coverage,
|
||||
NULL);
|
||||
|
||||
if (alpha_test_threshold_spin)
|
||||
gtk_widget_set_sensitive (alpha_test_threshold_spin,
|
||||
preserve_alpha_coverage);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"alpha-test-threshold",
|
||||
preserve_alpha_coverage,
|
||||
NULL, NULL, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
save_dialog (PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
PikaProcedure *procedure,
|
||||
GObject *config)
|
||||
save_dialog (PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
PikaProcedure *procedure,
|
||||
PikaProcedureConfig *config)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *grid;
|
||||
GtkListStore *store;
|
||||
GtkWidget *opt;
|
||||
GtkWidget *check;
|
||||
GtkWidget *frame;
|
||||
gboolean run;
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *widget;
|
||||
GtkWidget *combo;
|
||||
GtkListStore *store;
|
||||
PikaImageBaseType base_type;
|
||||
gboolean run;
|
||||
|
||||
base_type = pika_image_get_base_type (image);
|
||||
|
||||
if (is_cubemap || is_volume || is_array)
|
||||
g_object_set (config,
|
||||
"save-type", DDS_SAVE_SELECTED_LAYER,
|
||||
NULL);
|
||||
|
||||
dialog = pika_procedure_dialog_new (procedure,
|
||||
PIKA_PROCEDURE_CONFIG (config),
|
||||
_("Export Image as DDS"));
|
||||
dialog = pika_save_procedure_dialog_new (PIKA_SAVE_PROCEDURE (procedure),
|
||||
PIKA_PROCEDURE_CONFIG (config),
|
||||
image);
|
||||
|
||||
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
||||
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
||||
vbox, TRUE, TRUE, 0);
|
||||
gtk_widget_show (vbox);
|
||||
transparent_check =
|
||||
pika_procedure_dialog_get_widget (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"transparent-color",
|
||||
G_TYPE_NONE);
|
||||
pika_procedure_dialog_set_sensitive (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"transparent-color",
|
||||
base_type == PIKA_INDEXED,
|
||||
NULL, NULL, FALSE);
|
||||
|
||||
grid = gtk_grid_new ();
|
||||
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
||||
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), grid, FALSE, FALSE, 0);
|
||||
gtk_widget_show (grid);
|
||||
pika_procedure_dialog_fill_frame (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"transparency-frame",
|
||||
"transparent-color", FALSE,
|
||||
"transparent-index");
|
||||
|
||||
store = pika_int_store_new ("None", DDS_COMPRESS_NONE,
|
||||
"BC1 / DXT1", DDS_COMPRESS_BC1,
|
||||
"BC2 / DXT3", DDS_COMPRESS_BC2,
|
||||
"BC3 / DXT5", DDS_COMPRESS_BC3,
|
||||
"BC3nm / DXT5nm", DDS_COMPRESS_BC3N,
|
||||
"BC4 / ATI1 (3Dc+)", DDS_COMPRESS_BC4,
|
||||
"BC5 / ATI2 (3Dc)", DDS_COMPRESS_BC5,
|
||||
"RXGB (DXT5)", DDS_COMPRESS_RXGB,
|
||||
"Alpha Exponent (DXT5)", DDS_COMPRESS_AEXP,
|
||||
"YCoCg (DXT5)", DDS_COMPRESS_YCOCG,
|
||||
"YCoCg scaled (DXT5)", DDS_COMPRESS_YCOCGS,
|
||||
pika_procedure_dialog_get_label (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"mipmap-options-label",
|
||||
_("Mipmap Options"),
|
||||
FALSE, FALSE);
|
||||
|
||||
pika_procedure_dialog_fill_box (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"mipmap-options-box",
|
||||
"mipmap-filter", "mipmap-wrap",
|
||||
"gamma-correct", "srgb", "gamma",
|
||||
"preserve-alpha-coverage",
|
||||
"alpha-test-threshold", NULL);
|
||||
|
||||
pika_procedure_dialog_fill_frame (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"mipmap-options-frame",
|
||||
"mipmap-options-label", FALSE,
|
||||
"mipmap-options-box");
|
||||
|
||||
store = pika_int_store_new (_("Selected layer"), DDS_SAVE_SELECTED_LAYER,
|
||||
_("All visible layers"), DDS_SAVE_VISIBLE_LAYERS,
|
||||
_("As cube map"), DDS_SAVE_CUBEMAP,
|
||||
_("As volume map"), DDS_SAVE_VOLUMEMAP,
|
||||
_("As texture array"), DDS_SAVE_ARRAY,
|
||||
NULL);
|
||||
compress_opt = pika_prop_int_combo_box_new (config, "compression-format",
|
||||
PIKA_INT_STORE (store));
|
||||
pika_grid_attach_aligned (GTK_GRID (grid), 0, 0,
|
||||
_("_Compression:"),
|
||||
0.0, 0.5,
|
||||
compress_opt, 1);
|
||||
|
||||
pm_check = pika_prop_check_button_new (config, "perceptual-metric",
|
||||
_("Use _perceptual error metric"));
|
||||
gtk_grid_attach (GTK_GRID (grid), pm_check, 1, 1, 1, 1);
|
||||
|
||||
store = pika_int_store_new ("Default", DDS_FORMAT_DEFAULT,
|
||||
"RGB8", DDS_FORMAT_RGB8,
|
||||
"RGBA8", DDS_FORMAT_RGBA8,
|
||||
"BGR8", DDS_FORMAT_BGR8,
|
||||
"ABGR8", DDS_FORMAT_ABGR8,
|
||||
"R5G6B5", DDS_FORMAT_R5G6B5,
|
||||
"RGBA4", DDS_FORMAT_RGBA4,
|
||||
"RGB5A1", DDS_FORMAT_RGB5A1,
|
||||
"RGB10A2", DDS_FORMAT_RGB10A2,
|
||||
"R3G3B2", DDS_FORMAT_R3G3B2,
|
||||
"A8", DDS_FORMAT_A8,
|
||||
"L8", DDS_FORMAT_L8,
|
||||
"L8A8", DDS_FORMAT_L8A8,
|
||||
"AExp", DDS_FORMAT_AEXP,
|
||||
"YCoCg", DDS_FORMAT_YCOCG,
|
||||
NULL);
|
||||
format_opt = pika_prop_int_combo_box_new (config, "format",
|
||||
PIKA_INT_STORE (store));
|
||||
pika_grid_attach_aligned (GTK_GRID (grid), 0, 2,
|
||||
_("_Format:"),
|
||||
0.0, 0.5,
|
||||
format_opt, 1);
|
||||
|
||||
store = pika_int_store_new (_("Selected layer"), DDS_SAVE_SELECTED_LAYER,
|
||||
_("All visible layers"), DDS_SAVE_VISIBLE_LAYERS,
|
||||
_("As cube map"), DDS_SAVE_CUBEMAP,
|
||||
_("As volume map"), DDS_SAVE_VOLUMEMAP,
|
||||
_("As texture array"), DDS_SAVE_ARRAY,
|
||||
NULL);
|
||||
opt = pika_prop_int_combo_box_new (config, "save-type",
|
||||
PIKA_INT_STORE (store));
|
||||
pika_grid_attach_aligned (GTK_GRID (grid), 0, 3,
|
||||
_("_Save:"),
|
||||
0.0, 0.5,
|
||||
opt, 1);
|
||||
|
||||
pika_int_combo_box_set_sensitivity (PIKA_INT_COMBO_BOX (opt),
|
||||
combo_sensitivity_func,
|
||||
opt, NULL);
|
||||
|
||||
combo_set_item_sensitive (opt, DDS_SAVE_CUBEMAP, is_cubemap);
|
||||
combo_set_item_sensitive (opt, DDS_SAVE_VOLUMEMAP, is_volume);
|
||||
combo_set_item_sensitive (opt, DDS_SAVE_ARRAY, is_array);
|
||||
|
||||
flip_check = pika_prop_check_button_new (config, "flip-image",
|
||||
_("Flip image _vertically on export"));
|
||||
gtk_grid_attach (GTK_GRID (grid), flip_check, 1, 4, 1, 1);
|
||||
widget = pika_procedure_dialog_get_int_combo (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"save-type",
|
||||
PIKA_INT_STORE (store));
|
||||
combo = pika_label_int_widget_get_widget (PIKA_LABEL_INT_WIDGET (widget));
|
||||
pika_int_combo_box_set_sensitivity (PIKA_INT_COMBO_BOX (combo),
|
||||
combo_sensitivity_func, combo, NULL);
|
||||
combo_set_item_sensitive (combo, DDS_SAVE_CUBEMAP, is_cubemap);
|
||||
combo_set_item_sensitive (combo, DDS_SAVE_VOLUMEMAP, is_volume);
|
||||
combo_set_item_sensitive (combo, DDS_SAVE_ARRAY, is_array);
|
||||
|
||||
store = pika_int_store_new (_("No mipmaps"), DDS_MIPMAP_NONE,
|
||||
_("Generate mipmaps"), DDS_MIPMAP_GENERATE,
|
||||
_("Use existing mipmaps"), DDS_MIPMAP_EXISTING,
|
||||
NULL);
|
||||
mipmap_opt = pika_prop_int_combo_box_new (config, "mipmaps",
|
||||
PIKA_INT_STORE (store));
|
||||
pika_grid_attach_aligned (GTK_GRID (grid), 0, 5,
|
||||
_("_Mipmaps:"),
|
||||
0.0, 0.5,
|
||||
mipmap_opt, 1);
|
||||
|
||||
pika_int_combo_box_set_sensitivity (PIKA_INT_COMBO_BOX (mipmap_opt),
|
||||
combo_sensitivity_func,
|
||||
mipmap_opt, NULL);
|
||||
|
||||
combo_set_item_sensitive (mipmap_opt, DDS_MIPMAP_EXISTING,
|
||||
widget = pika_procedure_dialog_get_int_combo (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"mipmaps",
|
||||
PIKA_INT_STORE (store));
|
||||
combo = pika_label_int_widget_get_widget (PIKA_LABEL_INT_WIDGET (widget));
|
||||
pika_int_combo_box_set_sensitivity (PIKA_INT_COMBO_BOX (combo),
|
||||
combo_sensitivity_func, combo, NULL);
|
||||
combo_set_item_sensitive (combo, DDS_MIPMAP_EXISTING,
|
||||
! (is_volume || is_cubemap) &&
|
||||
is_mipmap_chain_valid);
|
||||
|
||||
pika_procedure_dialog_fill (PIKA_PROCEDURE_DIALOG (dialog),
|
||||
"compression-format", "perceptual-metric",
|
||||
"format", "save-type", "flip-image",
|
||||
"mipmaps", "transparency-frame",
|
||||
"mipmap-options-frame", NULL);
|
||||
|
||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
||||
gtk_widget_show (hbox);
|
||||
|
||||
check = pika_prop_check_button_new (config, "transparent-color",
|
||||
_("Transparent index:"));
|
||||
gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, FALSE, 0);
|
||||
gtk_widget_show (check);
|
||||
|
||||
transparent_spin = pika_prop_spin_button_new (config, "transparent-index",
|
||||
1, 8, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), transparent_spin, TRUE, TRUE, 0);
|
||||
|
||||
frame = pika_frame_new (_("Mipmap Options"));
|
||||
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
||||
gtk_widget_show (frame);
|
||||
|
||||
grid = gtk_grid_new ();
|
||||
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
||||
gtk_grid_set_column_spacing (GTK_GRID (grid), 8);
|
||||
gtk_container_add (GTK_CONTAINER (frame), grid);
|
||||
gtk_widget_show (grid);
|
||||
|
||||
store = pika_int_store_new ("Default", DDS_MIPMAP_FILTER_DEFAULT,
|
||||
"Nearest", DDS_MIPMAP_FILTER_NEAREST,
|
||||
"Box", DDS_MIPMAP_FILTER_BOX,
|
||||
"Triangle", DDS_MIPMAP_FILTER_TRIANGLE,
|
||||
"Quadratic", DDS_MIPMAP_FILTER_QUADRATIC,
|
||||
"B-Spline", DDS_MIPMAP_FILTER_BSPLINE,
|
||||
"Mitchell", DDS_MIPMAP_FILTER_MITCHELL,
|
||||
"Lanczos", DDS_MIPMAP_FILTER_LANCZOS,
|
||||
"Kaiser", DDS_MIPMAP_FILTER_KAISER,
|
||||
NULL);
|
||||
mipmap_filter_opt = pika_prop_int_combo_box_new (config, "mipmap-filter",
|
||||
PIKA_INT_STORE (store));
|
||||
pika_grid_attach_aligned (GTK_GRID (grid), 0, 0,
|
||||
_("F_ilter:"),
|
||||
0.0, 0.5,
|
||||
mipmap_filter_opt, 1);
|
||||
|
||||
store = pika_int_store_new ("Default", DDS_MIPMAP_WRAP_DEFAULT,
|
||||
"Mirror", DDS_MIPMAP_WRAP_MIRROR,
|
||||
"Repeat", DDS_MIPMAP_WRAP_REPEAT,
|
||||
"Clamp", DDS_MIPMAP_WRAP_CLAMP,
|
||||
NULL);
|
||||
mipmap_wrap_opt = pika_prop_int_combo_box_new (config, "mipmap-wrap",
|
||||
PIKA_INT_STORE (store));
|
||||
pika_grid_attach_aligned (GTK_GRID (grid), 0, 1,
|
||||
_("_Wrap mode:"),
|
||||
0.0, 0.5,
|
||||
mipmap_wrap_opt, 1);
|
||||
|
||||
gamma_check = pika_prop_check_button_new (config, "gamma-correct",
|
||||
_("Appl_y gamma correction"));
|
||||
gtk_grid_attach (GTK_GRID (grid), gamma_check, 1, 2, 1, 1);
|
||||
|
||||
srgb_check = pika_prop_check_button_new (config, "srgb",
|
||||
_("Use s_RGB colorspace"));
|
||||
gtk_grid_attach (GTK_GRID (grid), srgb_check, 1, 3, 1, 1);
|
||||
|
||||
gamma_spin = pika_prop_spin_button_new (config, "gamma",
|
||||
0.1, 0.5, 1);
|
||||
pika_grid_attach_aligned (GTK_GRID (grid), 0, 4,
|
||||
_("_Gamma:"), 0.0, 0.5,
|
||||
gamma_spin, 1);
|
||||
|
||||
alpha_coverage_check =
|
||||
pika_prop_check_button_new (config, "preserve-alpha-coverage",
|
||||
_("Preserve alpha _test coverage"));
|
||||
gtk_grid_attach (GTK_GRID (grid), alpha_coverage_check, 1, 5, 1, 1);
|
||||
|
||||
alpha_test_threshold_spin =
|
||||
pika_prop_spin_button_new (config, "alpha-test-threshold",
|
||||
0.01, 0.1, 2);
|
||||
pika_grid_attach_aligned (GTK_GRID (grid), 0, 6,
|
||||
_("_Alpha test threshold:"), 0.0, 0.5,
|
||||
alpha_test_threshold_spin, 1);
|
||||
|
||||
config_notify (config,
|
||||
config_notify (PIKA_PROCEDURE_CONFIG (config),
|
||||
g_object_class_find_property (G_OBJECT_GET_CLASS (config),
|
||||
"compression-format"),
|
||||
image);
|
||||
PIKA_PROCEDURE_DIALOG (dialog));
|
||||
|
||||
config_notify (config,
|
||||
config_notify (PIKA_PROCEDURE_CONFIG (config),
|
||||
g_object_class_find_property (G_OBJECT_GET_CLASS (config),
|
||||
"mipmaps"),
|
||||
image);
|
||||
PIKA_PROCEDURE_DIALOG (dialog));
|
||||
|
||||
config_notify (config,
|
||||
config_notify (PIKA_PROCEDURE_CONFIG (config),
|
||||
g_object_class_find_property (G_OBJECT_GET_CLASS (config),
|
||||
"save-type"),
|
||||
image);
|
||||
PIKA_PROCEDURE_DIALOG (dialog));
|
||||
|
||||
config_notify (config,
|
||||
config_notify (PIKA_PROCEDURE_CONFIG (config),
|
||||
g_object_class_find_property (G_OBJECT_GET_CLASS (config),
|
||||
"transparent-color"),
|
||||
image);
|
||||
PIKA_PROCEDURE_DIALOG (dialog));
|
||||
|
||||
g_signal_connect (config, "notify",
|
||||
g_signal_connect (PIKA_PROCEDURE_CONFIG (config), "notify",
|
||||
G_CALLBACK (config_notify),
|
||||
image);
|
||||
PIKA_PROCEDURE_DIALOG (dialog));
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
|
||||
run = pika_procedure_dialog_run (PIKA_PROCEDURE_DIALOG (dialog));
|
||||
|
||||
g_signal_handlers_disconnect_by_func (config,
|
||||
g_signal_handlers_disconnect_by_func (PIKA_PROCEDURE_CONFIG (config),
|
||||
config_notify,
|
||||
image);
|
||||
PIKA_PROCEDURE_DIALOG (dialog));
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
||||
|
@ -22,13 +22,13 @@
|
||||
#define __DDSWRITE_H__
|
||||
|
||||
|
||||
extern PikaPDBStatusType write_dds (GFile *file,
|
||||
PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
gboolean interactive,
|
||||
PikaProcedure *procedure,
|
||||
GObject *config,
|
||||
gboolean is_duplicate_image);
|
||||
extern PikaPDBStatusType write_dds (GFile *file,
|
||||
PikaImage *image,
|
||||
PikaDrawable *drawable,
|
||||
gboolean interactive,
|
||||
PikaProcedure *procedure,
|
||||
PikaProcedureConfig *config,
|
||||
gboolean is_duplicate_image);
|
||||
|
||||
|
||||
#endif /* __DDSWRITE_H__ */
|
||||
|
Reference in New Issue
Block a user