forked from AuroraMiddleware/gtk
texture: Rework error enum
1. Change INSUFFICIENT_MEMORY to TOO_LARGE GTK crashes on insufficient memory, we don't emit GErrors. 2. Split UNSUPPORTED into UNSUPPORTED_CONTENT and UNSUPPORTED_FORMAT So we know if you need to find an RPM with a loader or curse and the weird file. 3. Translate error messages, they are meant for end users.
This commit is contained in:
parent
e58f70d7bb
commit
b271a94f92
@ -45,17 +45,22 @@ GQuark gdk_texture_error_quark (void);
|
||||
|
||||
/**
|
||||
* GdkTextureError:
|
||||
* @GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY: Not enough memory to handle this image
|
||||
* @GDK_TEXTURE_ERROR_TOO_LARGE: Not enough memory to handle this image
|
||||
* @GDK_TEXTURE_ERROR_CORRUPT_IMAGE: The image data appears corrupted
|
||||
* @GDK_TEXTURE_ERROR_UNSUPPORTED: The image format is not supported
|
||||
* @GDK_TEXTURE_ERROR_UNSUPPORTED_CONTENT: The image contains features
|
||||
* that cannot be loaded
|
||||
* @GDK_TEXTURE_ERROR_UNSUPPORTED_FORMAT: The image format is not supported
|
||||
*
|
||||
* Possible errors that can be returned by `GdkTexture` constructors.
|
||||
*
|
||||
* Since: 4.6
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY,
|
||||
GDK_TEXTURE_ERROR_TOO_LARGE,
|
||||
GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
|
||||
GDK_TEXTURE_ERROR_UNSUPPORTED,
|
||||
GDK_TEXTURE_ERROR_UNSUPPORTED_CONTENT,
|
||||
GDK_TEXTURE_ERROR_UNSUPPORTED_FORMAT,
|
||||
} GdkTextureError;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
@ -19,8 +19,10 @@
|
||||
|
||||
#include "gdkjpegprivate.h"
|
||||
|
||||
#include "gdkintl.h"
|
||||
#include "gdktexture.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
|
||||
#include <jpeglib.h>
|
||||
#include <jerror.h>
|
||||
#include <setjmp.h>
|
||||
@ -53,10 +55,8 @@ fatal_error_handler (j_common_ptr cinfo)
|
||||
if (errmgr->error && *errmgr->error == NULL)
|
||||
g_set_error (errmgr->error,
|
||||
GDK_TEXTURE_ERROR,
|
||||
cinfo->err->msg_code == JERR_OUT_OF_MEMORY
|
||||
? GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY
|
||||
: GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
|
||||
"Error interpreting JPEG image file (%s)", buffer);
|
||||
GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
|
||||
_("Error interpreting JPEG image file (%s)"), buffer);
|
||||
|
||||
siglongjmp (errmgr->setjmp_buffer, 1);
|
||||
|
||||
@ -213,17 +213,17 @@ gdk_load_jpeg (GBytes *input_bytes,
|
||||
break;
|
||||
default:
|
||||
g_set_error (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED,
|
||||
"Unsupported colorspace in jpeg (%d)", info.out_color_space);
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED_CONTENT,
|
||||
_("Unsupported JPEG colorspace (%d)"), info.out_color_space);
|
||||
jpeg_destroy_decompress (&info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!data)
|
||||
{
|
||||
g_set_error_literal (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY,
|
||||
"Not enough memory to load jpeg");
|
||||
g_set_error (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_TOO_LARGE,
|
||||
_("Not enough memory for image size %ux%u"), width, height);
|
||||
jpeg_destroy_decompress (&info);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -19,9 +19,10 @@
|
||||
|
||||
#include "gdkpngprivate.h"
|
||||
|
||||
#include "gdkintl.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
#include "gdktexture.h"
|
||||
#include "gdktextureprivate.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
#include "gsk/ngl/fp16private.h"
|
||||
#include <png.h>
|
||||
#include <stdio.h>
|
||||
@ -113,7 +114,7 @@ png_simple_error_callback (png_structp png,
|
||||
if (error && !*error)
|
||||
g_set_error (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
|
||||
"Error reading png (%s)", error_msg);
|
||||
_("Error reading png (%s)"), error_msg);
|
||||
|
||||
longjmp (png_jmpbuf (png), 1);
|
||||
}
|
||||
@ -320,22 +321,11 @@ gdk_load_png (GBytes *bytes,
|
||||
png_malloc_callback,
|
||||
png_free_callback);
|
||||
if (png == NULL)
|
||||
{
|
||||
g_set_error (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY,
|
||||
"Failed to parse png image");
|
||||
return NULL;
|
||||
}
|
||||
g_error ("Out of memory");
|
||||
|
||||
info = png_create_info_struct (png);
|
||||
if (info == NULL)
|
||||
{
|
||||
png_destroy_read_struct (&png, NULL, NULL);
|
||||
g_set_error (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY,
|
||||
"Failed to parse png image");
|
||||
return NULL;
|
||||
}
|
||||
g_error ("Out of memory");
|
||||
|
||||
png_set_read_fn (png, &io, png_read_func);
|
||||
|
||||
@ -385,8 +375,8 @@ gdk_load_png (GBytes *bytes,
|
||||
{
|
||||
png_destroy_read_struct (&png, &info, NULL);
|
||||
g_set_error (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED,
|
||||
"Failed to parse png image");
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED_CONTENT,
|
||||
_("Failed to parse png image"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -437,9 +427,9 @@ gdk_load_png (GBytes *bytes,
|
||||
g_free (buffer);
|
||||
g_free (row_pointers);
|
||||
png_destroy_read_struct (&png, &info, NULL);
|
||||
g_set_error_literal (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY,
|
||||
"Not enough memory to load png");
|
||||
g_set_error (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_TOO_LARGE,
|
||||
_("Not enough memory for image size %ux%u"), width, height);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,11 @@
|
||||
|
||||
#include "gdktiffprivate.h"
|
||||
|
||||
#include "gdkintl.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
#include "gdktexture.h"
|
||||
#include "gdktextureprivate.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
|
||||
#include <tiffio.h>
|
||||
|
||||
/* Our main interest in tiff as an image format is that it is
|
||||
@ -374,7 +376,7 @@ load_fallback (TIFF *tif,
|
||||
{
|
||||
g_set_error_literal (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
|
||||
"Failed to load RGB data from TIFF file");
|
||||
_("Failed to load RGB data from TIFF file"));
|
||||
g_free (data);
|
||||
return NULL;
|
||||
}
|
||||
@ -471,8 +473,8 @@ gdk_load_tiff (GBytes *input_bytes,
|
||||
if (!data)
|
||||
{
|
||||
g_set_error (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY,
|
||||
"Not enough memory to read tiff");
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_TOO_LARGE,
|
||||
_("Not enough memory for image size %ux%u"), width, height);
|
||||
TIFFClose (tif);
|
||||
return NULL;
|
||||
}
|
||||
@ -484,7 +486,7 @@ gdk_load_tiff (GBytes *input_bytes,
|
||||
{
|
||||
g_set_error (error,
|
||||
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
|
||||
"Reading data failed at row %d", y);
|
||||
_("Reading data failed at row %d"), y);
|
||||
TIFFClose (tif);
|
||||
g_free (data);
|
||||
return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user