static GeglRectangle gegl_rgbe_load_get_bounding_box (GeglOperation *operation) { GeglChantO *o = GEGL_CHANT_PROPERTIES (operation); GeglRectangle result = {0,0,0,0}; rgbe_file *file; guint width, height; gegl_operation_set_format (operation, "output", babl_format (FORMAT)); file = rgbe_load_path (o->path); if (!file) goto cleanup; if (!rgbe_get_size (file, &width, &height)) goto cleanup; result.width = width; result.height = height; cleanup: rgbe_file_free (file); return result; }
static rgbe_file* rgbe_file_new (const gchar *path) { rgbe_file *file; g_return_val_if_fail (path, NULL); file = g_new (rgbe_file, 1); if (!rgbe_file_init (file, path)) { rgbe_file_free (file); file = NULL; } return file; }
rgbe_file * rgbe_load_path (const gchar *path) { gboolean success = FALSE; rgbe_file *file; file = rgbe_file_new (path); if (!file) goto cleanup; if (!rgbe_header_read (file)) goto cleanup; success = TRUE; cleanup: if (!success) { rgbe_file_free (file); file = NULL; } return file; }
static gboolean gegl_rgbe_load_process (GeglOperation *operation, GeglBuffer *output, const GeglRectangle *result, gint level) { GeglChantO *o = GEGL_CHANT_PROPERTIES (operation); gboolean success = FALSE; gfloat *pixels = NULL; rgbe_file *file; guint width, height; file = rgbe_load_path (o->path); if (!file) goto cleanup; if (!rgbe_get_size (file, &width, &height)) goto cleanup; if (width != result->width || height != result->height) goto cleanup; pixels = rgbe_read_scanlines (file); if (!pixels) goto cleanup; gegl_buffer_set (output, result, 0, babl_format (FORMAT), pixels, GEGL_AUTO_ROWSTRIDE); success = TRUE; cleanup: g_free (pixels); rgbe_file_free (file); return success; }