Commit b4e48c7e authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins: pass GFiles around instead of filenames in file-tiff

This is no port to GIO yet.
parent 76adffa9
......@@ -41,10 +41,12 @@ static void tiff_error (const gchar *module,
TIFF *
tiff_open (const gchar *filename,
tiff_open (GFile *file,
const gchar *mode,
GError **error)
{
gchar *filename = g_file_get_path (file);
TIFFSetWarningHandler (tiff_warning);
TIFFSetErrorHandler (tiff_error);
......
......@@ -23,7 +23,7 @@
#define __FILE_TIFF_IO_H__
TIFF * tiff_open (const gchar *filename,
TIFF * tiff_open (GFile *file,
const gchar *mode,
GError **error);
......
......@@ -218,7 +218,7 @@ load_dialog (TIFF *tif,
}
gint32
load_image (const gchar *filename,
load_image (GFile *file,
TIFF *tif,
TiffSelectedPages *pages,
gboolean *resolution_loaded,
......@@ -234,7 +234,7 @@ load_image (const gchar *filename,
gint li;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
gimp_file_get_utf8_name (file));
/* We will loop through the all pages in case of multipage TIFF
* and load every page as a separate layer.
......@@ -370,14 +370,14 @@ load_image (const gchar *filename,
if (! TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &cols))
{
g_message ("Could not get image width from '%s'",
gimp_filename_to_utf8 (filename));
gimp_file_get_utf8_name (file));
return -1;
}
if (! TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &rows))
{
g_message ("Could not get image length from '%s'",
gimp_filename_to_utf8 (filename));
gimp_file_get_utf8_name (file));
return -1;
}
......@@ -393,14 +393,14 @@ load_image (const gchar *filename,
{
g_message ("Could not get photometric from '%s'. "
"Image is CCITT compressed, assuming min-is-white",
filename);
gimp_file_get_utf8_name (file));
photomet = PHOTOMETRIC_MINISWHITE;
}
else
{
g_message ("Could not get photometric from '%s'. "
"Assuming min-is-black",
filename);
gimp_file_get_utf8_name (file));
/* old AppleScan software misses out the photometric tag
* (and incidentally assumes min-is-white, but xv
......@@ -429,7 +429,7 @@ load_image (const gchar *filename,
/* assuming unassociated alpha if unspecified */
g_message ("alpha channel type not defined for file %s. "
"Assuming alpha is not premultiplied",
gimp_filename_to_utf8 (filename));
gimp_file_get_utf8_name (file));
alpha = TRUE;
tsvals.save_transp_pixels = TRUE;
extra--;
......@@ -704,7 +704,8 @@ load_image (const gchar *filename,
if (pages->target == GIMP_PAGE_SELECTOR_TARGET_IMAGES)
{
gchar *fname = g_strdup_printf ("%s-%d", filename, ilayer);
gchar *fname = g_strdup_printf ("%s-%d", g_file_get_uri (file),
ilayer);
gimp_image_set_filename (image, fname);
g_free (fname);
......@@ -714,7 +715,8 @@ load_image (const gchar *filename,
}
else if (pages->o_pages != pages->n_pages)
{
gchar *fname = g_strdup_printf (_("%s-%d-of-%d-pages"), filename,
gchar *fname = g_strdup_printf (_("%s-%d-of-%d-pages"),
g_file_get_uri (file),
pages->n_pages, pages->o_pages);
gimp_image_set_filename (image, fname);
......@@ -722,7 +724,7 @@ load_image (const gchar *filename,
}
else
{
gimp_image_set_filename (image, filename);
gimp_image_set_filename (image, g_file_get_uri (file));
}
}
......@@ -883,7 +885,7 @@ load_image (const gchar *filename,
&redmap, &greenmap, &bluemap))
{
g_message ("Could not get colormaps from '%s'",
gimp_filename_to_utf8 (filename));
gimp_file_get_utf8_name (file));
return -1;
}
......
......@@ -36,7 +36,7 @@ gboolean load_dialog (TIFF *tif,
const gchar *help_id,
TiffSelectedPages *pages);
gint32 load_image (const gchar *filename,
gint32 load_image (GFile *file,
TIFF *tif,
TiffSelectedPages *pages,
gboolean *resolution_loaded,
......
......@@ -255,7 +255,7 @@ save_paths (TIFF *tif,
*/
gboolean
save_image (const gchar *filename,
save_image (GFile *file,
TiffSaveVals *tsvals,
gint32 image,
gint32 layer,
......@@ -312,7 +312,7 @@ save_image (const gchar *filename,
rowsperstrip = tile_height;
gimp_progress_init_printf (_("Exporting '%s'"),
gimp_filename_to_utf8 (filename));
gimp_file_get_utf8_name (file));
drawable_type = gimp_drawable_type (layer);
buffer = gimp_drawable_get_buffer (layer);
......@@ -512,14 +512,14 @@ save_image (const gchar *filename,
}
}
tif = tiff_open (filename, "w", error);
tif = tiff_open (file, "w", error);
if (! tif)
{
if (! error)
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_file_get_utf8_name (file), g_strerror (errno));
goto out;
}
......@@ -551,7 +551,7 @@ save_image (const gchar *filename,
}
TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField (tif, TIFFTAG_DOCUMENTNAME, filename);
TIFFSetField (tif, TIFFTAG_DOCUMENTNAME, g_file_get_path (file));
TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
/* TIFFSetField( tif, TIFFTAG_STRIPBYTECOUNTS, rows / rowsperstrip ); */
......@@ -776,7 +776,7 @@ save_image (const gchar *filename,
*p++ = *thumb_pixels++; /* r */
*p++ = *thumb_pixels++; /* g */
*p++ = *thumb_pixels++; /* b */
*thumb_pixels++;
thumb_pixels++;
}
TIFFWriteScanline (tif, buf, y, 0);
......
......@@ -35,7 +35,7 @@ typedef struct
} TiffSaveVals;
gboolean save_image (const gchar *filename,
gboolean save_image (GFile *file,
TiffSaveVals *tsvals,
gint32 image,
gint32 drawable,
......
......@@ -207,10 +207,10 @@ run (const gchar *name,
if (strcmp (name, LOAD_PROC) == 0)
{
const gchar *filename = param[1].data.d_string;
TIFF *tif;
GFile *file = g_file_new_for_path (param[1].data.d_string);
TIFF *tif;
tif = tiff_open (filename, "r", &error);
tif = tiff_open (file, "r", &error);
if (tif)
{
......@@ -226,7 +226,7 @@ run (const gchar *name,
{
g_set_error (&error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("TIFF '%s' does not contain any directories"),
gimp_filename_to_utf8 (filename));
gimp_file_get_utf8_name (file));
status = GIMP_PDB_EXECUTION_ERROR;
}
......@@ -262,13 +262,13 @@ run (const gchar *name,
if (run_it)
{
gint32 image;
gboolean resolution_loaded = FALSE;
gint32 image;
gboolean resolution_loaded = FALSE;
gimp_set_data (LOAD_PROC,
&pages.target, sizeof (pages.target));
image = load_image (param[1].data.d_string, tif, &pages,
image = load_image (file, tif, &pages,
&resolution_loaded,
&error);
......@@ -276,11 +276,8 @@ run (const gchar *name,
if (image > 0)
{
GFile *file;
GimpMetadata *metadata;
file = g_file_new_for_path (param[1].data.d_string);
metadata = gimp_image_metadata_load_prepare (image,
"image/tiff",
file, NULL);
......@@ -299,8 +296,6 @@ run (const gchar *name,
g_object_unref (metadata);
}
g_object_unref (file);
*nreturn_vals = 2;
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image;
......@@ -309,6 +304,7 @@ run (const gchar *name,
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
else
{
......@@ -322,6 +318,8 @@ run (const gchar *name,
{
status = GIMP_PDB_EXECUTION_ERROR;
}
g_object_unref (file);
}
else if ((strcmp (name, SAVE_PROC) == 0) ||
(strcmp (name, SAVE2_PROC) == 0))
......@@ -455,15 +453,17 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS)
{
gint saved_bpp;
GFile *file;
gint saved_bpp;
file = g_file_new_for_path (param[3].data.d_string);
if (save_image (param[3].data.d_string, &tsvals,
if (save_image (file, &tsvals,
image, drawable, orig_image, image_comment,
&saved_bpp, &error))
{
if (metadata)
{
GFile *file;
/* See bug 758909: clear TIFFTAG_MIN/MAXSAMPLEVALUE because
* exiv2 saves them with wrong type and the original values
......@@ -492,12 +492,10 @@ run (const gchar *name,
/* never save metadata thumbnails for TIFF, see bug #729952 */
metadata_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
file = g_file_new_for_path (param[3].data.d_string);
gimp_image_metadata_save_finish (image,
"image/tiff",
metadata, metadata_flags,
file, NULL);
g_object_unref (file);
}
/* Store mvals data */
......@@ -507,6 +505,8 @@ run (const gchar *name,
{
status = GIMP_PDB_EXECUTION_ERROR;
}
g_object_unref (file);
}
if (export == GIMP_EXPORT_EXPORT)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment