1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
/* JPEG loading and saving routines adapted for the GIMP XJT fileformat
22
* This filter is heavily based upon the "example.c" file in libjpeg.
23
* In fact most of the loading and saving code was simply cut-and-pasted
24
* from that file. The filter, therefore, also uses libjpeg.
28
* version 1.1.15a; 2000/01/25 hof: use g_malloc, g_free
29
* version 1.00.00; 1998/10/26 hof: 1.st (pre) release
38
#include <glib/gstdio.h>
40
/* Include for External Libraries */
44
#include "libgimp/gimp.h"
50
/* Declare local functions.
54
typedef struct my_error_mgr {
55
struct jpeg_error_mgr pub; /* "public" fields */
57
jmp_buf setjmp_buffer; /* for return to caller */
62
* Here's the routine that will replace the standard error_exit method:
66
my_error_exit (j_common_ptr cinfo)
68
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
69
my_error_ptr myerr = (my_error_ptr) cinfo->err;
71
/* Always display the message. */
72
/* We could postpone this until after returning, if we chose. */
73
(*cinfo->err->output_message) (cinfo);
75
/* Return control to the setjmp point */
76
longjmp (myerr->setjmp_buffer, 1);
80
/* ============================================================================
82
* load layer from jpeg file
83
* ============================================================================
87
xjpg_load_layer (const char *filename,
91
gdouble layer_opacity,
92
GimpLayerModeEffects layer_mode
95
GimpPixelRgn l_pixel_rgn;
96
GimpDrawable *l_drawable;
98
GimpImageType l_layer_type;
99
struct jpeg_decompress_struct cinfo;
100
struct my_error_mgr jerr;
106
int l_idx, l_start, l_end;
108
/* We set up the normal JPEG error routines. */
109
cinfo.err = jpeg_std_error (&jerr.pub);
110
jerr.pub.error_exit = my_error_exit;
112
l_layer_type = GIMP_GRAY_IMAGE;
114
if ((infile = g_fopen (filename, "rb")) == NULL)
116
g_warning ("can't open \"%s\"\n", filename);
121
/* Establish the setjmp return context for my_error_exit to use. */
122
if (setjmp (jerr.setjmp_buffer))
124
/* If we get here, the JPEG code has signaled an error.
125
* We need to clean up the JPEG object, close the input file, and return.
127
jpeg_destroy_decompress (&cinfo);
131
g_printerr ("XJT: JPEG load error\n");
135
/* Now we can initialize the JPEG decompression object. */
136
jpeg_create_decompress (&cinfo);
138
/* Step 2: specify data source (eg, a file) */
140
jpeg_stdio_src (&cinfo, infile);
142
/* Step 3: read file parameters with jpeg_read_header() */
144
(void) jpeg_read_header (&cinfo, TRUE);
145
/* We can ignore the return value from jpeg_read_header since
146
* (a) suspension is not possible with the stdio data source, and
147
* (b) we passed TRUE to reject a tables-only JPEG file as an error.
148
* See libjpeg.doc for more info.
151
/* Step 4: set parameters for decompression */
153
/* In this example, we don't need to change any of the defaults set by
154
* jpeg_read_header(), so we do nothing here.
157
/* Step 5: Start decompressor */
159
jpeg_start_decompress (&cinfo);
161
/* We may need to do some setup of our own at this point before reading
162
* the data. After jpeg_start_decompress() we have the correct scaled
163
* output image dimensions available, as well as the output colormap
164
* if we asked for color quantization.
165
* In this example, we need to make an output work buffer of the right size.
167
/* temporary buffer */
168
l_tile_height = gimp_tile_height ();
169
l_buf = g_new (guchar, l_tile_height * cinfo.output_width * cinfo.output_components);
170
l_rowbuf = g_new (guchar*, l_tile_height);
172
for (l_idx = 0; l_idx < l_tile_height; l_idx++)
174
l_rowbuf[l_idx] = l_buf + cinfo.output_width * cinfo.output_components * l_idx;
177
/* Check jpeg file for layer type */
178
switch (cinfo.output_components)
181
l_layer_type = GIMP_GRAY_IMAGE;
184
l_layer_type = GIMP_RGB_IMAGE;
187
g_printerr ("XJT: cant load layer %s (type is not GRAY and not RGB)\n", filename);
193
l_layer_id = gimp_layer_new (image_id, layer_name,
201
g_printerr ("XJT: cant create new layer\n");
206
l_drawable = gimp_drawable_get (l_layer_id);
207
gimp_pixel_rgn_init (&l_pixel_rgn, l_drawable, 0, 0, l_drawable->width, l_drawable->height, TRUE, FALSE);
209
/* Step 6: while (scan lines remain to be read) */
210
/* jpeg_read_scanlines(...); */
212
/* Here we use the library's state variable cinfo.output_scanline as the
213
* loop counter, so that we don't have to keep track ourselves.
215
while (cinfo.output_scanline < cinfo.output_height)
217
l_start = cinfo.output_scanline;
218
l_end = cinfo.output_scanline + l_tile_height;
219
l_end = MIN (l_end, cinfo.output_height);
220
l_scanlines = l_end - l_start;
222
for (l_idx = 0; l_idx < l_scanlines; l_idx++)
224
jpeg_read_scanlines (&cinfo, (JSAMPARRAY) &l_rowbuf[l_idx], 1);
227
gimp_pixel_rgn_set_rect (&l_pixel_rgn, l_buf, 0, l_start, l_drawable->width, l_scanlines);
229
gimp_progress_update ((double) cinfo.output_scanline / (double) cinfo.output_height);
232
/* Step 7: Finish decompression */
234
jpeg_finish_decompress (&cinfo);
235
/* We can ignore the return value since suspension is not possible
236
* with the stdio data source.
239
/* Step 8: Release JPEG decompression object */
241
/* This is an important step since it will release a good deal of memory. */
242
jpeg_destroy_decompress (&cinfo);
244
/* free up the temporary buffers */
248
/* After finish_decompress, we can close the input file.
249
* Here we postpone it until after no more JPEG errors are possible,
250
* so as to simplify the setjmp error logic above. (Actually, I don't
251
* think that jpeg_destroy can do an error exit, but why assume anything...)
255
/* At this point you may want to check to see whether any corrupt-data
256
* warnings occurred (test whether jerr.num_warnings is nonzero).
261
} /* end xjpg_load_layer */
264
/* ============================================================================
265
* xjpg_load_layer_alpha
266
* load the layers alpha channel from jpeg file.
267
* ============================================================================
271
xjpg_load_layer_alpha (const char *filename,
275
GimpPixelRgn l_pixel_rgn;
276
GimpDrawable *l_drawable;
277
GimpImageType l_layer_type;
278
struct jpeg_decompress_struct cinfo;
279
struct my_error_mgr jerr;
286
int l_idx, l_start, l_end;
289
guchar *l_dstbuf_ptr;
291
/* We set up the normal JPEG error routines. */
292
cinfo.err = jpeg_std_error (&jerr.pub);
293
jerr.pub.error_exit = my_error_exit;
295
l_layer_type = GIMP_GRAY_IMAGE;
297
/* add alpha channel */
298
gimp_layer_add_alpha (layer_id);
300
if ((infile = g_fopen (filename, "rb")) == NULL)
302
/* No alpha found, thats OK, use full opaque alpha channel
303
* (there is no need not store alpha channels on full opaque channels)
304
* (fixme: if filename exists but is not readable
305
* we should return -1 to indicate an error
310
/* Establish the setjmp return context for my_error_exit to use. */
311
if (setjmp (jerr.setjmp_buffer))
313
/* If we get here, the JPEG code has signaled an error.
314
* We need to clean up the JPEG object, close the input file, and return.
316
jpeg_destroy_decompress (&cinfo);
320
g_printerr ("XJT: JPEG alpha load error\n");
324
/* Now we can initialize the JPEG decompression object. */
325
jpeg_create_decompress (&cinfo);
327
/* Step 2: specify data source (eg, a file) */
329
jpeg_stdio_src (&cinfo, infile);
331
/* Step 3: read file parameters with jpeg_read_header() */
333
(void) jpeg_read_header (&cinfo, TRUE);
334
/* We can ignore the return value from jpeg_read_header since
335
* (a) suspension is not possible with the stdio data source, and
336
* (b) we passed TRUE to reject a tables-only JPEG file as an error.
337
* See libjpeg.doc for more info.
340
/* Step 4: set parameters for decompression */
342
/* In this example, we don't need to change any of the defaults set by
343
* jpeg_read_header(), so we do nothing here.
346
/* Step 5: Start decompressor */
348
jpeg_start_decompress (&cinfo);
350
/* We may need to do some setup of our own at this point before reading
351
* the data. After jpeg_start_decompress() we have the correct scaled
352
* output image dimensions available, as well as the output colormap
353
* if we asked for color quantization.
354
* In this example, we need to make an output work buffer of the right size.
356
/* temporary buffer (for read in jpeg lines) */
357
l_tile_height = gimp_tile_height ();
358
l_buf = g_new (guchar, l_tile_height * cinfo.output_width * cinfo.output_components);
359
l_rowbuf = g_new (guchar*, l_tile_height);
361
for (l_idx = 0; l_idx < l_tile_height; l_idx++)
363
l_rowbuf[l_idx] = l_buf + cinfo.output_width * cinfo.output_components * l_idx;
366
l_drawable = gimp_drawable_get (layer_id);
367
if(l_drawable == NULL)
369
g_printerr ("XJT: gimp_drawable_get failed on layer id %d\n", (int)layer_id);
374
/* Check if jpeg file can be used as alpha channel
376
if((cinfo.output_components != 1) ||
377
(cinfo.output_width != l_drawable->width) ||
378
(cinfo.output_height != l_drawable->height))
380
g_printerr ("XJT: cant load %s as alpha channel\n", filename);
385
/* buffer to read in the layer and merge with the alpha from jpeg file */
386
l_dstbuf = g_new (guchar, l_tile_height * l_drawable->width * l_drawable->bpp);
388
gimp_pixel_rgn_init (&l_pixel_rgn, l_drawable, 0, 0, l_drawable->width, l_drawable->height, TRUE, FALSE);
389
l_alpha_offset = l_drawable->bpp -1;
391
/* Step 6: while (scan lines remain to be read) */
392
/* jpeg_read_scanlines(...); */
394
/* Here we use the library's state variable cinfo.output_scanline as the
395
* loop counter, so that we don't have to keep track ourselves.
397
while (cinfo.output_scanline < cinfo.output_height)
399
l_start = cinfo.output_scanline;
400
l_end = cinfo.output_scanline + l_tile_height;
401
l_end = MIN (l_end, cinfo.output_height);
402
l_scanlines = l_end - l_start;
404
for (l_idx = 0; l_idx < l_scanlines; l_idx++)
406
jpeg_read_scanlines (&cinfo, (JSAMPARRAY) &l_rowbuf[l_idx], 1);
409
gimp_pixel_rgn_get_rect (&l_pixel_rgn, l_dstbuf, 0, l_start, l_drawable->width, l_scanlines);
411
/* copy the loaded jpeg data (from buf) to the layers alpha channel data */
412
l_idx = l_tile_height * l_drawable->width;
414
l_dstbuf_ptr = l_dstbuf;
417
l_dstbuf_ptr += l_alpha_offset;
418
*l_dstbuf_ptr++ = *l_buf_ptr++;
421
gimp_pixel_rgn_set_rect (&l_pixel_rgn, l_dstbuf, 0, l_start, l_drawable->width, l_scanlines);
423
gimp_progress_update ((double) cinfo.output_scanline / (double) cinfo.output_height);
426
/* Step 7: Finish decompression */
428
jpeg_finish_decompress (&cinfo);
429
/* We can ignore the return value since suspension is not possible
430
* with the stdio data source.
433
/* Step 8: Release JPEG decompression object */
435
/* This is an important step since it will release a good deal of memory. */
436
jpeg_destroy_decompress (&cinfo);
438
/* free up the temporary buffers */
443
/* After finish_decompress, we can close the input file.
444
* Here we postpone it until after no more JPEG errors are possible,
445
* so as to simplify the setjmp error logic above. (Actually, I don't
446
* think that jpeg_destroy can do an error exit, but why assume anything...)
450
/* At this point you may want to check to see whether any corrupt-data
451
* warnings occurred (test whether jerr.num_warnings is nonzero).
457
} /* xjpg_load_layer_alpha */
460
/* ============================================================================
462
* load channel from jpeg file
463
* (call this procedure with drawable_id == -1 to create a new channel,
464
* if a positive drawable_id is supplied, its content will be overwritten)
465
* ============================================================================
469
xjpg_load_channel (const char *filename,
473
gdouble channel_opacity,
474
guchar red, guchar green, guchar blue)
476
GimpPixelRgn l_pixel_rgn;
477
GimpDrawable *l_drawable;
478
gint32 l_drawable_id;
479
struct jpeg_decompress_struct cinfo;
480
struct my_error_mgr jerr;
486
int l_idx, l_start, l_end;
489
gimp_rgba_set_uchar (&l_color, red, green, blue, 255);
491
/* We set up the normal JPEG error routines. */
492
cinfo.err = jpeg_std_error (&jerr.pub);
493
jerr.pub.error_exit = my_error_exit;
495
if ((infile = g_fopen (filename, "rb")) == NULL)
497
g_warning ("can't open \"%s\"\n", filename);
502
/* Establish the setjmp return context for my_error_exit to use. */
503
if (setjmp (jerr.setjmp_buffer))
505
/* If we get here, the JPEG code has signaled an error.
506
* We need to clean up the JPEG object, close the input file, and return.
508
jpeg_destroy_decompress (&cinfo);
512
g_printerr ("XJT: JPEG load error\n");
516
/* Now we can initialize the JPEG decompression object. */
517
jpeg_create_decompress (&cinfo);
519
/* Step 2: specify data source (eg, a file) */
521
jpeg_stdio_src (&cinfo, infile);
523
/* Step 3: read file parameters with jpeg_read_header() */
525
(void) jpeg_read_header (&cinfo, TRUE);
526
/* We can ignore the return value from jpeg_read_header since
527
* (a) suspension is not possible with the stdio data source, and
528
* (b) we passed TRUE to reject a tables-only JPEG file as an error.
529
* See libjpeg.doc for more info.
532
/* Step 4: set parameters for decompression */
534
/* In this example, we don't need to change any of the defaults set by
535
* jpeg_read_header(), so we do nothing here.
538
/* Step 5: Start decompressor */
540
jpeg_start_decompress (&cinfo);
542
/* We may need to do some setup of our own at this point before reading
543
* the data. After jpeg_start_decompress() we have the correct scaled
544
* output image dimensions available, as well as the output colormap
545
* if we asked for color quantization.
546
* In this example, we need to make an output work buffer of the right size.
548
/* temporary buffer */
549
l_tile_height = gimp_tile_height ();
550
l_buf = g_new (guchar, l_tile_height * cinfo.output_width * cinfo.output_components);
551
l_rowbuf = g_new (guchar*, l_tile_height);
553
for (l_idx = 0; l_idx < l_tile_height; l_idx++)
555
l_rowbuf[l_idx] = l_buf + cinfo.output_width * cinfo.output_components * l_idx;
558
/* Check if jpeg file has one component (a channel cant have more than one)
560
if(cinfo.output_components != 1)
562
g_printerr ("XJT: cant load RGB layer %s into GRAY Image\n", filename);
569
l_drawable_id = gimp_channel_new (image_id,
575
if(l_drawable_id < 0)
577
g_printerr ("XJT: cant create new channel\n");
584
l_drawable_id = drawable_id; /* overwrite the given drawable */
587
l_drawable = gimp_drawable_get (l_drawable_id);
589
if((l_drawable->width != cinfo.output_width)
590
|| (l_drawable->height != cinfo.output_height)
591
|| (l_drawable->bpp != cinfo.output_components) )
593
g_printerr ("XJT: cant load-overwrite drawable (size missmatch)\n");
598
gimp_pixel_rgn_init (&l_pixel_rgn, l_drawable, 0, 0, l_drawable->width, l_drawable->height, TRUE, FALSE);
600
/* Step 6: while (scan lines remain to be read) */
601
/* jpeg_read_scanlines(...); */
603
/* Here we use the library's state variable cinfo.output_scanline as the
604
* loop counter, so that we don't have to keep track ourselves.
606
while (cinfo.output_scanline < cinfo.output_height)
608
l_start = cinfo.output_scanline;
609
l_end = cinfo.output_scanline + l_tile_height;
610
l_end = MIN (l_end, cinfo.output_height);
611
l_scanlines = l_end - l_start;
613
for (l_idx = 0; l_idx < l_scanlines; l_idx++)
615
jpeg_read_scanlines (&cinfo, (JSAMPARRAY) &l_rowbuf[l_idx], 1);
618
gimp_pixel_rgn_set_rect (&l_pixel_rgn, l_buf, 0, l_start, l_drawable->width, l_scanlines);
620
gimp_progress_update ((double) cinfo.output_scanline / (double) cinfo.output_height);
623
/* Step 7: Finish decompression */
625
jpeg_finish_decompress (&cinfo);
626
/* We can ignore the return value since suspension is not possible
627
* with the stdio data source.
630
/* Step 8: Release JPEG decompression object */
632
/* This is an important step since it will release a good deal of memory. */
633
jpeg_destroy_decompress (&cinfo);
635
/* free up the temporary buffers */
639
/* After finish_decompress, we can close the input file.
640
* Here we postpone it until after no more JPEG errors are possible,
641
* so as to simplify the setjmp error logic above. (Actually, I don't
642
* think that jpeg_destroy can do an error exit, but why assume anything...)
646
/* At this point you may want to check to see whether any corrupt-data
647
* warnings occurred (test whether jerr.num_warnings is nonzero).
650
/* Tell GIMP to display the image.
652
/* gimp_drawable_flush (l_drawable); */
654
return (l_drawable_id);
656
} /* end xjpg_load_channel */
660
/* ============================================================================
662
* save as drawable as jpeg file depending on save_mode:
663
* - save the drawable without alpha channel.
664
* (optional clear full transparent pixels to 0,
665
* resulting in better compression)
666
* - save the alpha channel
667
* ============================================================================
672
xjpg_save_drawable (const char *filename,
676
t_JpegSaveVals *jsvals)
678
GimpPixelRgn pixel_rgn;
679
GimpDrawable *drawable;
680
GimpImageType drawable_type;
681
struct jpeg_compress_struct cinfo;
682
struct my_error_mgr jerr;
683
FILE * volatile outfile;
692
guchar volatile l_alpha_sum;
701
drawable = gimp_drawable_get (drawable_ID);
702
drawable_type = gimp_drawable_type (drawable_ID);
703
switch (drawable_type)
706
case GIMP_GRAY_IMAGE:
707
if(save_mode == JSVM_ALPHA)
708
return FALSE; /* there is no alpha to save */
710
case GIMP_RGBA_IMAGE:
711
case GIMP_GRAYA_IMAGE:
714
case GIMP_INDEXED_IMAGE:
715
/*g_message ("jpeg: cannot operate on indexed color images");*/
719
/*g_message ("jpeg: cannot operate on unknown image types");*/
726
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, drawable->width, drawable->height, FALSE, FALSE);
729
/* Step 1: allocate and initialize JPEG compression object */
731
/* We have to set up the error handler first, in case the initialization
732
* step fails. (Unlikely, but it could happen if you are out of memory.)
733
* This routine fills in the contents of struct jerr, and returns jerr's
734
* address which we place into the link field in cinfo.
736
cinfo.err = jpeg_std_error (&jerr.pub);
737
jerr.pub.error_exit = my_error_exit;
740
/* Establish the setjmp return context for my_error_exit to use. */
741
if (setjmp (jerr.setjmp_buffer))
743
/* If we get here, the JPEG code has signaled an error.
744
* We need to clean up the JPEG object, close the input file, and return.
746
jpeg_destroy_compress (&cinfo);
750
gimp_drawable_detach (drawable);
755
/* Now we can initialize the JPEG compression object. */
756
jpeg_create_compress (&cinfo);
758
/* Step 2: specify data destination (eg, a file) */
759
/* Note: steps 2 and 3 can be done in either order. */
761
/* Here we use the library-supplied code to send compressed data to a
762
* stdio stream. You can also write your own code to do something else.
763
* VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
764
* requires it in order to write binary files.
766
if ((outfile = g_fopen (filename, "wb")) == NULL)
768
g_message ("can't open %s\n", filename);
771
jpeg_stdio_dest (&cinfo, outfile);
773
/* Get the input image and a pointer to its data.
775
switch (drawable_type)
778
case GIMP_GRAY_IMAGE:
779
/* # of color components per pixel */
780
cinfo.input_components = drawable->bpp;
784
case GIMP_RGBA_IMAGE:
785
case GIMP_GRAYA_IMAGE:
786
if(save_mode == JSVM_ALPHA)
788
cinfo.input_components = 1;
792
/* # of color components per pixel (minus the GIMP alpha channel) */
793
cinfo.input_components = drawable->bpp - 1;
795
alpha_offset = drawable->bpp -1;
803
/* Step 3: set parameters for compression */
805
/* First we supply a description of the input image.
806
* Four fields of the cinfo struct must be filled in:
808
/* image width and height, in pixels */
809
cinfo.image_width = drawable->width;
810
cinfo.image_height = drawable->height;
811
/* colorspace of input image */
812
cinfo.in_color_space = ( (save_mode != JSVM_ALPHA) &&
813
(drawable_type == GIMP_RGB_IMAGE ||
814
drawable_type == GIMP_RGBA_IMAGE))
815
? JCS_RGB : JCS_GRAYSCALE;
816
/* Now use the library's routine to set default compression parameters.
817
* (You must set at least cinfo.in_color_space before calling this,
818
* since the defaults depend on the source color space.)
820
jpeg_set_defaults (&cinfo);
821
/* Now you can set any non-default parameters you wish to.
822
* Here we just illustrate the use of quality (quantization table) scaling:
824
jpeg_set_quality (&cinfo, (int) (jsvals->quality * 100), TRUE /* limit to baseline-JPEG values */);
825
cinfo.smoothing_factor = (int) (jsvals->smoothing * 100);
826
cinfo.optimize_coding = jsvals->optimize;
828
/* Step 4: Start compressor */
830
/* TRUE ensures that we will write a complete interchange-JPEG file.
831
* Pass TRUE unless you are very sure of what you're doing.
833
jpeg_start_compress (&cinfo, TRUE);
835
/* Step 5: while (scan lines remain to be written) */
836
/* jpeg_write_scanlines(...); */
838
/* Here we use the library's state variable cinfo.next_scanline as the
839
* loop counter, so that we don't have to keep track ourselves.
840
* To keep things simple, we pass one scanline per call; you can pass
841
* more if you wish, though.
843
/* JSAMPLEs per row in image_buffer */
844
rowstride = drawable->bpp * drawable->width;
845
temp = (guchar *) g_malloc (cinfo.image_width * cinfo.input_components);
846
data = (guchar *) g_malloc (rowstride * gimp_tile_height ());
849
while (cinfo.next_scanline < cinfo.image_height)
851
if ((cinfo.next_scanline % gimp_tile_height ()) == 0)
853
yend = cinfo.next_scanline + gimp_tile_height ();
854
yend = MIN (yend, cinfo.image_height);
855
gimp_pixel_rgn_get_rect (&pixel_rgn, data, 0, cinfo.next_scanline, cinfo.image_width,
856
(yend - cinfo.next_scanline));
862
i = cinfo.image_width;
867
if(jsvals->clr_transparent)
869
/* save drawable (clear pixels where alpha is full transparent) */
872
alpha_byte = s[cinfo.input_components];
873
for (j = 0; j < cinfo.input_components; j++)
875
if(alpha_byte != 0) { *t++ = *s++; }
876
else { *t++ = 0; s++; }
878
if (has_alpha) /* ignore alpha channel */
886
/* save the drawable as it is (ignore alpha channel) */
889
for (j = 0; j < cinfo.input_components; j++)
893
if (has_alpha) /* ignore alpha channel */
901
/* save the drawable's alpha cahnnel */
905
l_alpha_sum &= (*s); /* check all alpha bytes for full opacity */
912
jpeg_write_scanlines (&cinfo, (JSAMPARRAY) &temp, 1);
914
if ((cinfo.next_scanline % 5) == 0)
915
gimp_progress_update ((double) cinfo.next_scanline / (double) cinfo.image_height);
918
/* Step 6: Finish compression */
919
jpeg_finish_compress (&cinfo);
920
/* After finish_compress, we can close the output file. */
923
if((save_mode == JSVM_ALPHA) && (l_alpha_sum == 0xff))
925
/* all bytes in the alpha channel are set to 0xff
926
* == full opaque image. We can remove the file
932
/* Step 7: release JPEG compression object */
934
/* This is an important step since it will release a good deal of memory. */
935
jpeg_destroy_compress (&cinfo);
936
/* free the temporary buffer */
940
gimp_drawable_detach (drawable);
943
} /* end xjpg_save_drawable */