file-jpeg: GEGL convert load functions

drawable_global doesn't seem to be used anywhere. This commit removes
it.
This commit is contained in:
Mukund Sivaraman 2013-05-13 11:39:45 +05:30
parent 2df4fa2d6f
commit 51680fb987
4 changed files with 30 additions and 33 deletions

View File

@ -66,20 +66,15 @@ static void jpeg_load_cmyk_to_rgb (guchar *buf,
glong pixels,
gpointer transform);
GimpDrawable *drawable_global;
gint32 volatile preview_image_ID;
gint32 preview_layer_ID;
gint32
load_image (const gchar *filename,
GimpRunMode runmode,
gboolean preview,
GError **error)
{
GimpPixelRgn pixel_rgn;
GimpDrawable *drawable;
gint32 volatile image_ID;
gint32 layer_ID;
struct jpeg_decompress_struct cinfo;
@ -88,8 +83,9 @@ load_image (const gchar *filename,
FILE *infile;
guchar *buf;
guchar **rowbuf;
gint image_type;
gint layer_type;
GimpImageBaseType image_type;
GimpImageType layer_type;
GeglBuffer *buffer;
gint tile_height;
gint scanlines;
gint i, start, end;
@ -258,10 +254,6 @@ load_image (const gchar *filename,
layer_type, 100, GIMP_NORMAL_MODE);
}
drawable_global = drawable = gimp_drawable_get (layer_ID);
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
drawable->width, drawable->height, TRUE, FALSE);
if (! preview)
{
GString *comment_buffer = NULL;
@ -417,6 +409,9 @@ load_image (const gchar *filename,
/* Here we use the library's state variable cinfo.output_scanline as the
* loop counter, so that we don't have to keep track ourselves.
*/
buffer = gimp_drawable_get_buffer (layer_ID);
while (cinfo.output_scanline < cinfo.output_height)
{
start = cinfo.output_scanline;
@ -429,11 +424,15 @@ load_image (const gchar *filename,
jpeg_read_scanlines (&cinfo, (JSAMPARRAY) &rowbuf[i], 1);
if (cinfo.out_color_space == JCS_CMYK)
jpeg_load_cmyk_to_rgb (buf, drawable->width * scanlines,
jpeg_load_cmyk_to_rgb (buf, cinfo.output_width * scanlines,
cmyk_transform);
gimp_pixel_rgn_set_rect (&pixel_rgn, buf,
0, start, drawable->width, scanlines);
gegl_buffer_set (buffer,
GEGL_RECTANGLE (0, start, cinfo.output_width, scanlines),
0,
NULL,
buf,
GEGL_AUTO_ROWSTRIDE);
if (! preview && (cinfo.output_scanline % 32) == 0)
gimp_progress_update ((gdouble) cinfo.output_scanline /
@ -457,6 +456,8 @@ load_image (const gchar *filename,
/* This is an important step since it will release a good deal of memory. */
jpeg_destroy_decompress (&cinfo);
g_object_unref (buffer);
/* free up the temporary buffers */
g_free (rowbuf);
g_free (buf);
@ -477,7 +478,6 @@ load_image (const gchar *filename,
if (! preview)
{
gimp_progress_update (1.0);
gimp_drawable_detach (drawable);
}
gimp_image_insert_layer (image_ID, layer_ID, -1, 0);
@ -661,15 +661,14 @@ load_thumbnail_image (const gchar *filename,
{
gint32 volatile image_ID;
ExifData *exif_data;
GimpPixelRgn pixel_rgn;
GimpDrawable *drawable;
gint32 layer_ID;
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
guchar *buf;
guchar **rowbuf;
gint image_type;
gint layer_type;
GimpImageBaseType image_type;
GimpImageType layer_type;
GeglBuffer *buffer;
gint tile_height;
gint scanlines;
gint i, start, end;
@ -822,16 +821,14 @@ load_thumbnail_image (const gchar *filename,
cinfo.output_height,
layer_type, 100, GIMP_NORMAL_MODE);
drawable_global = drawable = gimp_drawable_get (layer_ID);
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
drawable->width, drawable->height, TRUE, FALSE);
/* Step 6: while (scan lines remain to be read) */
/* jpeg_read_scanlines(...); */
/* Here we use the library's state variable cinfo.output_scanline as the
* loop counter, so that we don't have to keep track ourselves.
*/
buffer = gimp_drawable_get_buffer (layer_ID);
while (cinfo.output_scanline < cinfo.output_height)
{
start = cinfo.output_scanline;
@ -843,10 +840,14 @@ load_thumbnail_image (const gchar *filename,
jpeg_read_scanlines (&cinfo, (JSAMPARRAY) &rowbuf[i], 1);
if (cinfo.out_color_space == JCS_CMYK)
jpeg_load_cmyk_to_rgb (buf, drawable->width * scanlines, NULL);
jpeg_load_cmyk_to_rgb (buf, cinfo.output_width * scanlines, NULL);
gimp_pixel_rgn_set_rect (&pixel_rgn, buf,
0, start, drawable->width, scanlines);
gegl_buffer_set (buffer,
GEGL_RECTANGLE (0, start, cinfo.output_width, scanlines),
0,
NULL,
buf,
GEGL_AUTO_ROWSTRIDE);
gimp_progress_update ((gdouble) cinfo.output_scanline /
(gdouble) cinfo.output_height);
@ -866,6 +867,8 @@ load_thumbnail_image (const gchar *filename,
*/
jpeg_destroy_decompress (&cinfo);
g_object_unref (buffer);
/* free up the temporary buffers */
g_free (rowbuf);
g_free (buf);

View File

@ -796,12 +796,6 @@ destroy_preview (void)
g_source_remove (id);
}
if (drawable_global)
{
gimp_drawable_detach (drawable_global);
drawable_global = NULL;
}
if (gimp_image_is_valid (preview_image_ID) &&
gimp_item_is_valid (preview_layer_ID))
{

View File

@ -204,6 +204,7 @@ run (const gchar *name,
run_mode = param[0].data.d_int32;
INIT_I18N ();
gegl_init (NULL, NULL);
*nreturn_vals = 1;
*return_vals = values;

View File

@ -53,7 +53,6 @@ typedef enum
extern gint32 volatile preview_image_ID;
extern gint32 preview_layer_ID;
extern GimpDrawable *drawable_global;
extern gboolean undo_touched;
extern gboolean load_interactive;
extern gint32 display_ID;