aboutsummaryrefslogtreecommitdiffstats
path: root/code/renderer/tr_image.c
diff options
context:
space:
mode:
authorzakk <zakk@edf5b092-35ff-0310-97b2-ce42778d08ea>2005-09-07 20:42:43 +0000
committerzakk <zakk@edf5b092-35ff-0310-97b2-ce42778d08ea>2005-09-07 20:42:43 +0000
commit2b1fe5f7811a847da2442e00596b633459dc2371 (patch)
tree84ad2188132f5b9906903a9df09a7aa0764e2242 /code/renderer/tr_image.c
parentddeba7ce765a30b6699eeb8fc0ed7f3f38397df1 (diff)
downloadioquake3-aero-2b1fe5f7811a847da2442e00596b633459dc2371.tar.gz
ioquake3-aero-2b1fe5f7811a847da2442e00596b633459dc2371.zip
8 bit jpeg support from Thilo Schulz
https://bugzilla.icculus.org/show_bug.cgi?id=2373 git-svn-id: svn://svn.icculus.org/quake3/trunk@88 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/renderer/tr_image.c')
-rw-r--r--code/renderer/tr_image.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/code/renderer/tr_image.c b/code/renderer/tr_image.c
index 68819ac..e3f58d8 100644
--- a/code/renderer/tr_image.c
+++ b/code/renderer/tr_image.c
@@ -1378,7 +1378,8 @@ static void LoadJPG( const char *filename, unsigned char **pic, int *width, int
/* More stuff */
JSAMPARRAY buffer; /* Output row buffer */
int row_stride; /* physical row width in output buffer */
- unsigned char *out;
+ int pixelcount;
+ unsigned char *out, *out_converted;
byte *fbuffer;
byte *bbuf;
@@ -1439,14 +1440,10 @@ static void LoadJPG( const char *filename, unsigned char **pic, int *width, int
*/
/* JSAMPLEs per row in output buffer */
- // This row_stride from libjpeg's example code doesn't work, since we
- // want to fill in an alpha channel ourselves and jpegs might be 8-bit.
- //row_stride = cinfo.output_width * cinfo.output_components;
- row_stride = cinfo.output_width * 4;
- out = ri.Malloc(row_stride*cinfo.output_height);
-
+ pixelcount = cinfo.output_width * cinfo.output_height;
+ row_stride = cinfo.output_width * cinfo.output_components;
+ out = ri.Malloc(pixelcount * 4);
- *pic = out;
*width = cinfo.output_width;
*height = cinfo.output_height;
@@ -1465,13 +1462,36 @@ static void LoadJPG( const char *filename, unsigned char **pic, int *width, int
buffer = &bbuf;
(void) jpeg_read_scanlines(&cinfo, buffer, 1);
}
+
+ // If we are processing an 8-bit JPEG (greyscale), we'll have to convert
+ // the greyscale values to RGBA.
+ if(cinfo.output_components == 1)
+ {
+ int sindex, dindex = 0;
+ unsigned char greyshade;
+
+ // allocate a new buffer for the transformed image
+ out_converted = ri.Malloc(pixelcount*4);
- // clear all the alphas to 255
+ for(sindex = 0; sindex < pixelcount; sindex++)
+ {
+ greyshade = out[sindex];
+ out_converted[dindex++] = greyshade;
+ out_converted[dindex++] = greyshade;
+ out_converted[dindex++] = greyshade;
+ out_converted[dindex++] = 255;
+ }
+
+ ri.Free(out);
+ out = out_converted;
+ }
+ else
{
+ // clear all the alphas to 255
int i, j;
byte *buf;
- buf = *pic;
+ buf = out;
j = cinfo.output_width * cinfo.output_height * 4;
for ( i = 3 ; i < j ; i+=4 ) {
@@ -1479,6 +1499,8 @@ static void LoadJPG( const char *filename, unsigned char **pic, int *width, int
}
}
+ *pic = out;
+
/* Step 7: Finish decompression */
(void) jpeg_finish_decompress(&cinfo);