nanogui: GdJPEG for PF_TRUECOLOR patch


Previous by date: 23 Feb 2000 21:59:12 -0000 ELKS client/server, Greg Haerr
Next by date: 23 Feb 2000 21:59:12 -0000 Re: Shared memory + SDL, Greg Haerr
Previous in thread:
Next in thread: 23 Feb 2000 21:59:12 -0000 Re: GdJPEG for PF_TRUECOLOR patch, Greg Haerr

Subject: GdJPEG for PF_TRUECOLOR patch
From: Kyle Harris ####@####.####
Date: 23 Feb 2000 21:59:12 -0000
Message-Id: <38B4553A.3B36A168@nexus-tech.net>

Hi All,

I made a few minor changes to the GdJPEG function to handle various
pixel types. I believe the jpeg lib will always return a 24 bit pixel
value unless requested to do otherwise. So, I think this patch is safe.
I've only tested it with 16bpp. I think there may have been a bug in the
original version. It seems that within the "while (destx++ != maxx)"
loop, k should be incremented outside of the if construct. Maybe I'm
missing something (not unusual :).

Kyle.

--- include/device.h	Sat Feb 12 23:28:09 2000
+++ include/device.h.new	Thu Feb 24 00:06:37 2000
@@ -105,6 +105,7 @@
 
 #if SCREEN_PIXTYPE == PF_PALETTE
 typedef unsigned char PIXELVAL;
+#define RGB2PIXEL(r,g,b)	(r)
 #define _SCREEN_PIXTYPE_OK
 #endif
 


--- engine/devimage.c	Mon Jan 31 20:46:11 2000
+++ engine/devimage.c.new	Thu Feb 24 00:03:50 2000
@@ -106,7 +106,8 @@
 	SCREENINFO si;
 	FILE *infile;		/* source file */
 	JSAMPARRAY buffer;	/* Output row buffer */
-	
+	int jpeg_pixelsize;
+
 	/* This struct contains the JPEG decompression parameters and pointers
to
 	 * working space (which is allocated as needed by the JPEG library).
 	 */
@@ -140,13 +141,12 @@
 	/* Get system information */
 	GdGetScreenInfo(&scrdev, &si);
 
-	/* Support only palettized for now ... */
-	if (si.pixtype == PF_PALETTE)
+	if (!fast_grayscale)
 	{
-		cinfo.quantize_colors = TRUE;
-
-		if (!fast_grayscale)
+		if (si.pixtype == PF_PALETTE)
 		{
+			cinfo.quantize_colors = TRUE;
+	
 			/* Get system palette */
 			cinfo.actual_number_of_colors = GdGetPalette(0,si.ncolors,palette);
 	
@@ -162,18 +162,19 @@
 				cinfo.colormap[2][l] = palette[l].b;
 			}
 		}
-		else
-		{
-			/* Grayscale output asked */
-			cinfo.out_color_space = JCS_GRAYSCALE;
-			cinfo.desired_number_of_colors = si.ncolors;
-		}
+	}
+	else 
+	{
+		/* Grayscale output asked */
+		cinfo.out_color_space = JCS_GRAYSCALE;
+		cinfo.desired_number_of_colors = si.ncolors;
 	}
 
 	/* Step 5: Start decompressor */
 	jpeg_start_decompress (&cinfo);
 
 	/* Make a one-row-high sample array that will go away when done with
image */
+	jpeg_pixelsize = cinfo.output_components;
 	buffer = (*cinfo.mem->alloc_sarray)
 		((j_common_ptr) &cinfo, JPOOL_IMAGE,
 		cinfo.output_width * cinfo.output_components, 1);
@@ -203,11 +204,14 @@
 		k = 0;
 		while (destx++ != maxx)
 		{
+			unsigned char *rgb;
+
+			rgb = &buffer[0][k];
 			if(clip == CLIP_VISIBLE || GdClipPoint(destx, desty)) {
-				psd->DrawPixel(psd, destx, desty, buffer[0][k++]);
+				psd->DrawPixel(psd, destx,
desty,RGB2PIXEL(*rgb,*(rgb+1),*(rgb+2)));
 			}
+			k += jpeg_pixelsize;
 		}
-
 		destx = minx;
 		desty++;
 		height--;

Previous by date: 23 Feb 2000 21:59:12 -0000 ELKS client/server, Greg Haerr
Next by date: 23 Feb 2000 21:59:12 -0000 Re: Shared memory + SDL, Greg Haerr
Previous in thread:
Next in thread: 23 Feb 2000 21:59:12 -0000 Re: GdJPEG for PF_TRUECOLOR patch, Greg Haerr


Powered by ezmlm-browse 0.20.