Index: xsane/src/xsane-save.c diff -u xsane/src/xsane-save.c:1.2 xsane/src/xsane-save.c:1.2.2.1 --- xsane/src/xsane-save.c:1.2 Thu Apr 25 11:38:06 2002 +++ xsane/src/xsane-save.c Wed May 8 15:29:49 2002 @@ -2090,12 +2090,14 @@ int xsane_save_jpeg(FILE *outfile, FILE *imagefile, Image_info *image_info, int quality, GtkProgressBar *progress_bar, int *cancel_save) { unsigned char *data; + unsigned short *data_16bit = NULL; char buf[256]; int x,y; int components = 1; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; JSAMPROW row_pointer[1]; + int bytespp; /* bytes per pixel */ DBG(DBG_proc, "xsane_save_jpeg\n"); @@ -2106,15 +2108,27 @@ components = 3; } + if ( image_info->depth > 8 ) { + bytespp = 2; + data_16bit = malloc(image_info->image_width * components * bytespp); + if (!data_16bit) { + snprintf(buf, sizeof(buf), "%s %s", ERR_DURING_SAVE, ERR_NO_MEM); + xsane_back_gtk_error(buf, TRUE); + return -1; /* error */ + } + } else { + bytespp = 1; + } + data = malloc(image_info->image_width * components); - + if (!data) { snprintf(buf, sizeof(buf), "%s %s", ERR_DURING_SAVE, ERR_NO_MEM); xsane_back_gtk_error(buf, TRUE); return -1; /* error */ } - + cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); jpeg_stdio_dest(&cinfo, outfile); @@ -2174,7 +2188,17 @@ } else { - fread(data, components, image_info->image_width, imagefile); + switch(bytespp) { + case 2: + /* convert 16 bit data to 8 bit, because of limitation of jpeg lib */ + fread(data_16bit, components * bytespp, image_info->image_width, imagefile); + for (x = 0; x < image_info->image_width * components; x++) { + data[x] = data_16bit[x] / 256; + } + break; + default: + fread(data, components, image_info->image_width, imagefile); + } } row_pointer[0] = data; @@ -2188,6 +2212,9 @@ } jpeg_finish_compress(&cinfo); + if ( data_16bit != NULL ) { + free(data_16bit); + } free(data); return (*cancel_save);