summaryrefslogtreecommitdiff
path: root/graphics/xzgv/patches/patch-ac
blob: c7e23180c08774db7edfd517e3321f33350ac401 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
$NetBSD: patch-ac,v 1.3 2006/09/23 14:59:34 adrianp Exp $

--- src/readjpeg.c.orig	2006-09-23 15:52:41.000000000 +0100
+++ src/readjpeg.c
@@ -179,11 +179,13 @@ static unsigned char **lineptrs;
 static int have_image;
 static int width,height;
 static unsigned char *image;
+static int cmyk;
 unsigned char *ptr,*ptr2;
 int chkw,chkh;
 int f,rec;
 static int greyscale;	/* static to satisfy gcc -Wall */
 
+cmyk=0;
 greyscale=0;
 
 lineptrs=NULL;
@@ -225,6 +227,15 @@ if(cinfo.jpeg_color_space==JCS_GRAYSCALE
   greyscale=1;
   }
 
+if(cinfo.jpeg_color_space==JCS_CMYK)
+  cmyk=1;
+
+if(cinfo.jpeg_color_space==JCS_YCCK)
+  {
+  cmyk=1;
+  cinfo.out_color_space=JCS_CMYK;
+  }
+
 *wp=width=cinfo.image_width;
 *hp=height=cinfo.image_height;
 
@@ -266,7 +277,7 @@ if(!careful_jpeg)
 /* this one shouldn't hurt */
 cinfo.do_block_smoothing=FALSE;
 
-if(WH_BAD(width,height) || (*imagep=image=malloc(width*height*3))==NULL)
+if(WH_BAD(width,height) || (*imagep=image=malloc(width*(height+cmyk)*3))==NULL)
   longjmp(jerr.setjmp_buffer,1);
 
 jpeg_start_decompress(&cinfo);
@@ -279,12 +290,33 @@ ptr=image+width*2*greyscale;	/* put data
 for(f=0;f<height;f++,ptr+=width*3)
   lineptrs[f]=ptr;
 
-rec=cinfo.rec_outbuf_height;
-while(cinfo.output_scanline<height)
+if(!cmyk)
   {
-  f=height-cinfo.output_scanline;
-  jpeg_read_scanlines(&cinfo,lineptrs+cinfo.output_scanline,
-                      f>rec?rec:f);
+  rec=cinfo.rec_outbuf_height;
+  while(cinfo.output_scanline<height)
+    {
+    f=height-cinfo.output_scanline;
+    jpeg_read_scanlines(&cinfo,lineptrs+cinfo.output_scanline,
+                        f>rec?rec:f);
+    }
+  }
+else	/* cmyk output */
+  {
+  int tmp;
+
+  ptr=image;
+  while(cinfo.output_scanline<height)
+    {
+    jpeg_read_scanlines(&cinfo,&ptr,1);
+    ptr2=ptr;
+    for(f=0;f<width;f++,ptr+=3,ptr2+=4)
+      {
+      tmp=ptr2[3];
+      ptr[0]=(tmp*ptr2[0])/255;
+      ptr[1]=(tmp*ptr2[1])/255;
+      ptr[2]=(tmp*ptr2[2])/255;
+      }
+    }
   }
 
 free(lineptrs);