aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-05-27 18:46:18 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-05-27 18:46:18 -0700
commit0c3da11e39673f0a809426bb6cb745c75582ef6a (patch)
tree9bbc4c3b1d4b1c7e8ff70a4ca4d30288fa306391 /src
parent9bb664eef4345bbc3ec83faf3820304c7664fd6b (diff)
downloadmirror-meh-0c3da11e39673f0a809426bb6cb745c75582ef6a.tar.gz
mirror-meh-0c3da11e39673f0a809426bb6cb745c75582ef6a.tar.bz2
mirror-meh-0c3da11e39673f0a809426bb6cb745c75582ef6a.zip
support greyscale jpegs
Diffstat (limited to 'src')
-rw-r--r--src/jpeg.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/jpeg.c b/src/jpeg.c
index 427ef93..749d448 100644
--- a/src/jpeg.c
+++ b/src/jpeg.c
@@ -26,8 +26,7 @@ unsigned char *loadjpeg(FILE *infile, int *width, int *height){
JSAMPARRAY buffer;
int row_stride;
int i = 0;
- int j;
- int y;
+ int j, y, x;
unsigned char *retbuf;
cinfo.err = jpeg_std_error(&jerr.pub);
@@ -50,19 +49,29 @@ unsigned char *loadjpeg(FILE *infile, int *width, int *height){
jpeg_start_decompress(&cinfo);
*width = cinfo.output_width;
*height = cinfo.output_height;
- retbuf = malloc(4 * cinfo.output_components * (cinfo.output_width * cinfo.output_height));
+ retbuf = malloc(3 * (cinfo.output_width * cinfo.output_height));
- if(cinfo.output_components != 3){
- fprintf(stderr, "TODO: greyscale images are not supported\n");
- exit(1);
- }
- for(y = 0; y < cinfo.output_height; ){
- int n = jpeg_read_scanlines(&cinfo, buffer, 4);
- for(j = 0; j < n; j++){
- memcpy(&retbuf[i], buffer[j], row_stride);
- i += row_stride;
+ if(cinfo.output_components == 3){
+ for(y = 0; y < cinfo.output_height; ){
+ int n = jpeg_read_scanlines(&cinfo, buffer, 4);
+ for(j = 0; j < n; j++){
+ memcpy(&retbuf[i], buffer[j], row_stride);
+ i += row_stride;
+ }
+ y += n;
+ }
+ }else if(cinfo.output_components == 1){
+ for(y = 0; y < cinfo.output_height; ){
+ int n = jpeg_read_scanlines(&cinfo, buffer, 4);
+ for(j = 0; j < n; j++){
+ for(x = 0; x < cinfo.output_width; x++){
+ retbuf[i++] = buffer[j][x];
+ retbuf[i++] = buffer[j][x];
+ retbuf[i++] = buffer[j][x];
+ }
+ }
+ y += n;
}
- y += n;
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);