*** src/readJPEG.c.patched	Mon Oct  2 21:51:09 1995
--- src/readJPEG.c	Tue Oct  3 11:08:07 1995
***************
*** 2,21 ****
  #include <stdio.h>
  #include <X11/Intrinsic.h>
  
- #define MAXCOLORMAPSIZE         256
- 
- 
  #include "mosaic.h"
  #include "jpeglib.h"
  #include <setjmp.h>
  
  
  
- extern JSAMPLE * image_buffer;	/* Points to large array of R,G,B-order data */
- extern int image_height;	/* Number of rows in image */
- extern int image_width;		/* Number of columns in image */
- 
- 
  struct my_error_mgr {
    struct jpeg_error_mgr pub;	/* "public" fields */
    jmp_buf setjmp_buffer;	/* for return to caller */
--- 2,13 ----
***************
*** 28,34 ****
  my_error_exit (j_common_ptr cinfo)
  {
  	my_error_ptr myerr = (my_error_ptr) cinfo->err;
! 	/*fprintf(stderr,"Error reading JPEG image \n");*/
  	longjmp(myerr->setjmp_buffer, 1);
  }
  
--- 20,29 ----
  my_error_exit (j_common_ptr cinfo)
  {
  	my_error_ptr myerr = (my_error_ptr) cinfo->err;
! #if 0
! 	fprintf(stderr,"Error reading JPEG image: ");
! 	(*cinfo->err->output_message) (cinfo);
! #endif
  	longjmp(myerr->setjmp_buffer, 1);
  }
  
***************
*** 37,51 ****
  unsigned char *
  ReadJPEG(FILE *infile,int *width, int *height, XColor *colrs)
  {
- int scale = 65536/MAXCOLORMAPSIZE;
- int i;
- 
  struct jpeg_decompress_struct cinfo;
  struct my_error_mgr jerr;
! unsigned char *retBuffer=NULL;
  unsigned char *r;
! JSAMPARRAY buffer;		/* Output row buffer */
  int row_stride;		/* physical row width in output buffer */
  
  	/*printf("ReadJPEG(): I've been called\n");*/
  
--- 32,44 ----
  unsigned char *
  ReadJPEG(FILE *infile,int *width, int *height, XColor *colrs)
  {
  struct jpeg_decompress_struct cinfo;
  struct my_error_mgr jerr;
! unsigned char *retBuffer=NULL;	/* Output image buffer */
  unsigned char *r;
! JSAMPROW buffer[1];		/* row pointer array for read_scanlines */
  int row_stride;		/* physical row width in output buffer */
+ int i;
  
  	/*printf("ReadJPEG(): I've been called\n");*/
  
***************
*** 71,80 ****
  
  	jpeg_stdio_src(&cinfo, infile);
  
- 
  	(void) jpeg_read_header(&cinfo, TRUE);
  
- 
  	/* We can ignore the return value from jpeg_read_header since
  	*   (a) suspension is not possible with the stdio data source, and
  	*   (b) we passed TRUE to reject a tables-only JPEG file as an error.
--- 64,71 ----
***************
*** 85,92 ****
  	/*cinfo.desired_number_of_colors = 50;*/
  	cinfo.desired_number_of_colors = Rdata.colors_per_inlined_image;
  	cinfo.two_pass_quantize = TRUE;
- 	cinfo.out_color_space = JCS_RGB;
- 
  
  	jpeg_start_decompress(&cinfo);
  
--- 76,81 ----
***************
*** 97,136 ****
  		return(0);
  		}
  
- 
- 	row_stride = cinfo.output_width * cinfo.output_components;
- 	/* Make a one-row-high sample array that will go away when 
- 			done with image */
- 	buffer = (*cinfo.mem->alloc_sarray)
-                 ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
- 
- 
- 
- 
- 
  	/*
  	printf("buffer size is width=%d x height=%d x depth=%d\n",
  		cinfo.output_width , cinfo.output_height , 
  		cinfo.output_components);
  	*/
  
- 
- 
  	r = retBuffer;
  	row_stride = cinfo.output_width * cinfo.output_components;
  	while (cinfo.output_scanline < cinfo.output_height) {
  		(void) jpeg_read_scanlines(&cinfo, buffer, 1);
- 		memcpy(r,buffer[0],row_stride);
  		r += row_stride;
    		}
  
- 
- 
- /*
- 	(void) jpeg_finish_decompress(&cinfo);
- */
- 
- 
  	*width =  cinfo.output_width;
  	*height =  cinfo.output_height;
  
--- 86,105 ----
  		return(0);
  		}
  
  	/*
  	printf("buffer size is width=%d x height=%d x depth=%d\n",
  		cinfo.output_width , cinfo.output_height , 
  		cinfo.output_components);
  	*/
  
  	r = retBuffer;
  	row_stride = cinfo.output_width * cinfo.output_components;
  	while (cinfo.output_scanline < cinfo.output_height) {
+ 		buffer[0] = r;
  		(void) jpeg_read_scanlines(&cinfo, buffer, 1);
  		r += row_stride;
    		}
  
  	*width =  cinfo.output_width;
  	*height =  cinfo.output_height;
  
***************
*** 143,154 ****
  {char dummy[80]; printf("RETURN\n"); gets(dummy);}
  */
  		for (i=0; i < cinfo.actual_number_of_colors; i++) {
! /*
! printf("[%d]\n",i);
! */
! 			colrs[i].red = cinfo.colormap[0][i] * scale;
! 			colrs[i].green = cinfo.colormap[1][i]*scale;
! 			colrs[i].blue = cinfo.colormap[2][i]*scale;
  			colrs[i].pixel = i;
  			colrs[i].flags = DoRed|DoGreen|DoBlue;
  			}
--- 112,120 ----
  {char dummy[80]; printf("RETURN\n"); gets(dummy);}
  */
  		for (i=0; i < cinfo.actual_number_of_colors; i++) {
! 			colrs[i].red = cinfo.colormap[0][i] << 8;
! 			colrs[i].green = cinfo.colormap[1][i] << 8;
! 			colrs[i].blue = cinfo.colormap[2][i] << 8;
  			colrs[i].pixel = i;
  			colrs[i].flags = DoRed|DoGreen|DoBlue;
  			}
***************
*** 156,162 ****
  	else {
  		for (i=0; i < cinfo.actual_number_of_colors; i++) {
  			colrs[i].red = colrs[i].green = 
! 				colrs[i].blue = cinfo.colormap[0][i] * scale;
  			colrs[i].pixel = i;
  			colrs[i].flags = DoRed|DoGreen|DoBlue;
  			}
--- 122,128 ----
  	else {
  		for (i=0; i < cinfo.actual_number_of_colors; i++) {
  			colrs[i].red = colrs[i].green = 
! 				colrs[i].blue = cinfo.colormap[0][i] << 8;
  			colrs[i].pixel = i;
  			colrs[i].flags = DoRed|DoGreen|DoBlue;
  			}
