Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: bmp.c

Issue 1934113002: Update libjpeg_turbo to 1.4.90 from https://github.com/libjpeg-turbo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C)2011 D. R. Commander. All Rights Reserved. 2 * Copyright (C)2011, 2015 D. R. Commander. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met: 5 * modification, are permitted provided that the following conditions are met:
6 * 6 *
7 * - Redistributions of source code must retain the above copyright notice, 7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer. 8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice, 9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation 10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution. 11 * and/or other materials provided with the distribution.
12 * - Neither the name of the libjpeg-turbo Project nor the names of its 12 * - Neither the name of the libjpeg-turbo Project nor the names of its
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 #define _throw(m) {snprintf(errStr, JMSG_LENGTH_MAX, "%s", m); \ 69 #define _throw(m) {snprintf(errStr, JMSG_LENGTH_MAX, "%s", m); \
70 retval=-1; goto bailout;} 70 retval=-1; goto bailout;}
71 #define _throwunix(m) {snprintf(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, \ 71 #define _throwunix(m) {snprintf(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, \
72 strerror(errno)); retval=-1; goto bailout;} 72 strerror(errno)); retval=-1; goto bailout;}
73 73
74 74
75 static void pixelconvert(unsigned char *srcbuf, int srcpf, int srcbottomup, 75 static void pixelconvert(unsigned char *srcbuf, int srcpf, int srcbottomup,
76 unsigned char *dstbuf, int dstpf, int dstbottomup, int w, int h) 76 unsigned char *dstbuf, int dstpf, int dstbottomup, int w, int h)
77 { 77 {
78 » unsigned char *srcptr=srcbuf, *srcptr2; 78 » unsigned char *srcrowptr=srcbuf, *srccolptr;
79 int srcps=tjPixelSize[srcpf]; 79 int srcps=tjPixelSize[srcpf];
80 int srcstride=srcbottomup? -w*srcps:w*srcps; 80 int srcstride=srcbottomup? -w*srcps:w*srcps;
81 » unsigned char *dstptr=dstbuf, *dstptr2; 81 » unsigned char *dstrowptr=dstbuf, *dstcolptr;
82 int dstps=tjPixelSize[dstpf]; 82 int dstps=tjPixelSize[dstpf];
83 int dststride=dstbottomup? -w*dstps:w*dstps; 83 int dststride=dstbottomup? -w*dstps:w*dstps;
84 int row, col; 84 int row, col;
85 85
86 » if(srcbottomup) srcptr=&srcbuf[w*srcps*(h-1)]; 86 » if(srcbottomup) srcrowptr=&srcbuf[w*srcps*(h-1)];
87 » if(dstbottomup) dstptr=&dstbuf[w*dstps*(h-1)]; 87 » if(dstbottomup) dstrowptr=&dstbuf[w*dstps*(h-1)];
88 » for(row=0; row<h; row++, srcptr+=srcstride, dstptr+=dststride) 88
89 » /* NOTE: These quick & dirty CMYK<->RGB conversion routines are for test ing
90 » purposes only. Properly converting between CMYK and RGB requires a c olor
91 » management system. */
92
93 » if(dstpf==TJPF_CMYK)
89 { 94 {
90 » » for(col=0, srcptr2=srcptr, dstptr2=dstptr; col<w; col++, srcptr2 +=srcps, 95 » » for(row=0; row<h; row++, srcrowptr+=srcstride, dstrowptr+=dststr ide)
91 » » » dstptr2+=dstps)
92 { 96 {
93 » » » dstptr2[tjRedOffset[dstpf]]=srcptr2[tjRedOffset[srcpf]]; 97 » » » for(col=0, srccolptr=srcrowptr, dstcolptr=dstrowptr;
94 » » » dstptr2[tjGreenOffset[dstpf]]=srcptr2[tjGreenOffset[srcp f]]; 98 » » » » col<w; col++, srccolptr+=srcps)
95 » » » dstptr2[tjBlueOffset[dstpf]]=srcptr2[tjBlueOffset[srcpf] ]; 99 » » » {
100 » » » » double c=1.0-((double)(srccolptr[tjRedOffset[src pf]])/255.);
101 » » » » double m=1.0-((double)(srccolptr[tjGreenOffset[s rcpf]])/255.);
102 » » » » double y=1.0-((double)(srccolptr[tjBlueOffset[sr cpf]])/255.);
103 » » » » double k=min(min(c,m),min(y,1.0));
104 » » » » if(k==1.0) c=m=y=0.0;
105 » » » » else
106 » » » » {
107 » » » » » c=(c-k)/(1.0-k);
108 » » » » » m=(m-k)/(1.0-k);
109 » » » » » y=(y-k)/(1.0-k);
110 » » » » }
111 » » » » if(c>1.0) c=1.0; if(c<0.) c=0.;
112 » » » » if(m>1.0) m=1.0; if(m<0.) m=0.;
113 » » » » if(y>1.0) y=1.0; if(y<0.) y=0.;
114 » » » » if(k>1.0) k=1.0; if(k<0.) k=0.;
115 » » » » *dstcolptr++=(unsigned char)(255.0-c*255.0+0.5);
116 » » » » *dstcolptr++=(unsigned char)(255.0-m*255.0+0.5);
117 » » » » *dstcolptr++=(unsigned char)(255.0-y*255.0+0.5);
118 » » » » *dstcolptr++=(unsigned char)(255.0-k*255.0+0.5);
119 » » » }
120 » » }
121 » }
122 » else if(srcpf==TJPF_CMYK)
123 » {
124 » » for(row=0; row<h; row++, srcrowptr+=srcstride, dstrowptr+=dststr ide)
125 » » {
126 » » » for(col=0, srccolptr=srcrowptr, dstcolptr=dstrowptr;
127 » » » » col<w; col++, dstcolptr+=dstps)
128 » » » {
129 » » » » double c=(double)(*srccolptr++);
130 » » » » double m=(double)(*srccolptr++);
131 » » » » double y=(double)(*srccolptr++);
132 » » » » double k=(double)(*srccolptr++);
133 » » » » double r=c*k/255.;
134 » » » » double g=m*k/255.;
135 » » » » double b=y*k/255.;
136 » » » » if(r>255.0) r=255.0; if(r<0.) r=0.;
137 » » » » if(g>255.0) g=255.0; if(g<0.) g=0.;
138 » » » » if(b>255.0) b=255.0; if(b<0.) b=0.;
139 » » » » dstcolptr[tjRedOffset[dstpf]]=(unsigned char)(r+ 0.5);
140 » » » » dstcolptr[tjGreenOffset[dstpf]]=(unsigned char)( g+0.5);
141 » » » » dstcolptr[tjBlueOffset[dstpf]]=(unsigned char)(b +0.5);
142 » » » }
143 » » }
144 » }
145 » else
146 » {
147 » » for(row=0; row<h; row++, srcrowptr+=srcstride, dstrowptr+=dststr ide)
148 » » {
149 » » » for(col=0, srccolptr=srcrowptr, dstcolptr=dstrowptr;
150 » » » » col<w; col++, srccolptr+=srcps, dstcolptr+=dstps )
151 » » » {
152 » » » » dstcolptr[tjRedOffset[dstpf]]=srccolptr[tjRedOff set[srcpf]];
153 » » » » dstcolptr[tjGreenOffset[dstpf]]=srccolptr[tjGree nOffset[srcpf]];
154 » » » » dstcolptr[tjBlueOffset[dstpf]]=srccolptr[tjBlueO ffset[srcpf]];
155 » » » }
96 } 156 }
97 } 157 }
98 } 158 }
99 159
100 160
101 int loadbmp(char *filename, unsigned char **buf, int *w, int *h, 161 int loadbmp(char *filename, unsigned char **buf, int *w, int *h,
102 int dstpf, int bottomup) 162 int dstpf, int bottomup)
103 { 163 {
104 int retval=0, dstps, srcpf, tempc; 164 int retval=0, dstps, srcpf, tempc;
105 struct jpeg_compress_struct cinfo; 165 struct jpeg_compress_struct cinfo;
106 struct my_error_mgr jerr; 166 struct my_error_mgr jerr;
107 cjpeg_source_ptr src; 167 cjpeg_source_ptr src;
108 FILE *file=NULL; 168 FILE *file=NULL;
109 169
110 memset(&cinfo, 0, sizeof(struct jpeg_compress_struct)); 170 memset(&cinfo, 0, sizeof(struct jpeg_compress_struct));
111 171
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 bailout: 325 bailout:
266 jpeg_destroy_decompress(&dinfo); 326 jpeg_destroy_decompress(&dinfo);
267 if(file) fclose(file); 327 if(file) fclose(file);
268 return retval; 328 return retval;
269 } 329 }
270 330
271 const char *bmpgeterr(void) 331 const char *bmpgeterr(void)
272 { 332 {
273 return errStr; 333 return errStr;
274 } 334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698