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

Side by Side Diff: turbojpeg.c

Issue 10700197: Update libjpeg-turbo to r856. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libjpeg_turbo/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « turbojpeg.h ('k') | turbojpeg-jni.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C)2009-2012 D. R. Commander. All Rights Reserved. 2 * Copyright (C)2009-2012 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
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 else 138 else
139 { 139 {
140 if(flags&TJ_BGR) return TJPF_BGRX; 140 if(flags&TJ_BGR) return TJPF_BGRX;
141 else return TJPF_RGBX; 141 else return TJPF_RGBX;
142 } 142 }
143 } 143 }
144 return -1; 144 return -1;
145 } 145 }
146 146
147 static int setCompDefaults(struct jpeg_compress_struct *cinfo, 147 static int setCompDefaults(struct jpeg_compress_struct *cinfo,
148 » int pixelFormat, int subsamp, int jpegQual) 148 » int pixelFormat, int subsamp, int jpegQual, int flags)
149 { 149 {
150 int retval=0; 150 int retval=0;
151 151
152 switch(pixelFormat) 152 switch(pixelFormat)
153 { 153 {
154 case TJPF_GRAY: 154 case TJPF_GRAY:
155 cinfo->in_color_space=JCS_GRAYSCALE; break; 155 cinfo->in_color_space=JCS_GRAYSCALE; break;
156 #if JCS_EXTENSIONS==1 156 #if JCS_EXTENSIONS==1
157 case TJPF_RGB: 157 case TJPF_RGB:
158 cinfo->in_color_space=JCS_EXT_RGB; break; 158 cinfo->in_color_space=JCS_EXT_RGB; break;
(...skipping 25 matching lines...) Expand all
184 cinfo->in_color_space=JCS_RGB; pixelFormat=TJPF_RGB; 184 cinfo->in_color_space=JCS_RGB; pixelFormat=TJPF_RGB;
185 break; 185 break;
186 #endif 186 #endif
187 } 187 }
188 188
189 cinfo->input_components=tjPixelSize[pixelFormat]; 189 cinfo->input_components=tjPixelSize[pixelFormat];
190 jpeg_set_defaults(cinfo); 190 jpeg_set_defaults(cinfo);
191 if(jpegQual>=0) 191 if(jpegQual>=0)
192 { 192 {
193 jpeg_set_quality(cinfo, jpegQual, TRUE); 193 jpeg_set_quality(cinfo, jpegQual, TRUE);
194 » » if(jpegQual>=96) cinfo->dct_method=JDCT_ISLOW; 194 » » if(jpegQual>=96 || flags&TJFLAG_ACCURATEDCT) cinfo->dct_method=J DCT_ISLOW;
195 else cinfo->dct_method=JDCT_FASTEST; 195 else cinfo->dct_method=JDCT_FASTEST;
196 } 196 }
197 if(subsamp==TJSAMP_GRAY) 197 if(subsamp==TJSAMP_GRAY)
198 jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); 198 jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
199 else 199 else
200 jpeg_set_colorspace(cinfo, JCS_YCbCr); 200 jpeg_set_colorspace(cinfo, JCS_YCbCr);
201 201
202 cinfo->comp_info[0].h_samp_factor=tjMCUWidth[subsamp]/8; 202 cinfo->comp_info[0].h_samp_factor=tjMCUWidth[subsamp]/8;
203 cinfo->comp_info[1].h_samp_factor=1; 203 cinfo->comp_info[1].h_samp_factor=1;
204 cinfo->comp_info[2].h_samp_factor=1; 204 cinfo->comp_info[2].h_samp_factor=1;
205 cinfo->comp_info[0].v_samp_factor=tjMCUHeight[subsamp]/8; 205 cinfo->comp_info[0].v_samp_factor=tjMCUHeight[subsamp]/8;
206 cinfo->comp_info[1].v_samp_factor=1; 206 cinfo->comp_info[1].v_samp_factor=1;
207 cinfo->comp_info[2].v_samp_factor=1; 207 cinfo->comp_info[2].v_samp_factor=1;
208 208
209 return retval; 209 return retval;
210 } 210 }
211 211
212 static int setDecompDefaults(struct jpeg_decompress_struct *dinfo, 212 static int setDecompDefaults(struct jpeg_decompress_struct *dinfo,
213 » int pixelFormat) 213 » int pixelFormat, int flags)
214 { 214 {
215 int retval=0; 215 int retval=0;
216 216
217 switch(pixelFormat) 217 switch(pixelFormat)
218 { 218 {
219 case TJPF_GRAY: 219 case TJPF_GRAY:
220 dinfo->out_color_space=JCS_GRAYSCALE; break; 220 dinfo->out_color_space=JCS_GRAYSCALE; break;
221 #if JCS_EXTENSIONS==1 221 #if JCS_EXTENSIONS==1
222 case TJPF_RGB: 222 case TJPF_RGB:
223 dinfo->out_color_space=JCS_EXT_RGB; break; 223 dinfo->out_color_space=JCS_EXT_RGB; break;
(...skipping 27 matching lines...) Expand all
251 case TJPF_RGBA: 251 case TJPF_RGBA:
252 case TJPF_BGRA: 252 case TJPF_BGRA:
253 case TJPF_ARGB: 253 case TJPF_ARGB:
254 case TJPF_ABGR: 254 case TJPF_ABGR:
255 dinfo->out_color_space=JCS_RGB; break; 255 dinfo->out_color_space=JCS_RGB; break;
256 #endif 256 #endif
257 default: 257 default:
258 _throw("Unsupported pixel format"); 258 _throw("Unsupported pixel format");
259 } 259 }
260 260
261 if(flags&TJFLAG_FASTDCT) dinfo->dct_method=JDCT_FASTEST;
262
261 bailout: 263 bailout:
262 return retval; 264 return retval;
263 } 265 }
264 266
265 267
266 static int getSubsamp(j_decompress_ptr dinfo) 268 static int getSubsamp(j_decompress_ptr dinfo)
267 { 269 {
268 int retval=-1, i, k; 270 int retval=-1, i, k;
269 for(i=0; i<NUMSUBOPT; i++) 271 for(i=0; i<NUMSUBOPT; i++)
270 { 272 {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 613
612 if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); 614 if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
613 else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); 615 else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
614 else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); 616 else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
615 617
616 if(flags&TJFLAG_NOREALLOC) 618 if(flags&TJFLAG_NOREALLOC)
617 { 619 {
618 alloc=0; *jpegSize=tjBufSize(width, height, jpegSubsamp); 620 alloc=0; *jpegSize=tjBufSize(width, height, jpegSubsamp);
619 } 621 }
620 jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc); 622 jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc);
621 » if(setCompDefaults(cinfo, pixelFormat, jpegSubsamp, jpegQual)==-1) 623 » if(setCompDefaults(cinfo, pixelFormat, jpegSubsamp, jpegQual, flags)==-1 )
622 return -1; 624 return -1;
623 625
624 jpeg_start_compress(cinfo, TRUE); 626 jpeg_start_compress(cinfo, TRUE);
625 if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL) 627 if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL)
626 _throw("tjCompress2(): Memory allocation failure"); 628 _throw("tjCompress2(): Memory allocation failure");
627 for(i=0; i<height; i++) 629 for(i=0; i<height; i++)
628 { 630 {
629 if(flags&TJFLAG_BOTTOMUP) row_pointer[i]=&srcBuf[(height-i-1)*pi tch]; 631 if(flags&TJFLAG_BOTTOMUP) row_pointer[i]=&srcBuf[(height-i-1)*pi tch];
630 else row_pointer[i]=&srcBuf[i*pitch]; 632 else row_pointer[i]=&srcBuf[i*pitch];
631 } 633 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 721
720 cinfo->image_width=width; 722 cinfo->image_width=width;
721 cinfo->image_height=height; 723 cinfo->image_height=height;
722 724
723 if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); 725 if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
724 else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); 726 else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
725 else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); 727 else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
726 728
727 yuvsize=tjBufSizeYUV(width, height, subsamp); 729 yuvsize=tjBufSizeYUV(width, height, subsamp);
728 jpeg_mem_dest_tj(cinfo, &dstBuf, &yuvsize, 0); 730 jpeg_mem_dest_tj(cinfo, &dstBuf, &yuvsize, 0);
729 » if(setCompDefaults(cinfo, pixelFormat, subsamp, -1)==-1) return -1; 731 » if(setCompDefaults(cinfo, pixelFormat, subsamp, -1, flags)==-1) return - 1;
730 732
731 jpeg_start_compress(cinfo, TRUE); 733 jpeg_start_compress(cinfo, TRUE);
732 pw=PAD(width, cinfo->max_h_samp_factor); 734 pw=PAD(width, cinfo->max_h_samp_factor);
733 ph=PAD(height, cinfo->max_v_samp_factor); 735 ph=PAD(height, cinfo->max_v_samp_factor);
734 736
735 if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL) 737 if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL)
736 _throw("tjEncodeYUV2(): Memory allocation failure"); 738 _throw("tjEncodeYUV2(): Memory allocation failure");
737 for(i=0; i<height; i++) 739 for(i=0; i<height; i++)
738 { 740 {
739 if(flags&TJFLAG_BOTTOMUP) row_pointer[i]=&srcBuf[(height-i-1)*pi tch]; 741 if(flags&TJFLAG_BOTTOMUP) row_pointer[i]=&srcBuf[(height-i-1)*pi tch];
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 950
949 if(setjmp(this->jerr.setjmp_buffer)) 951 if(setjmp(this->jerr.setjmp_buffer))
950 { 952 {
951 /* If we get here, the JPEG code has signaled an error. */ 953 /* If we get here, the JPEG code has signaled an error. */
952 retval=-1; 954 retval=-1;
953 goto bailout; 955 goto bailout;
954 } 956 }
955 957
956 jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); 958 jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize);
957 jpeg_read_header(dinfo, TRUE); 959 jpeg_read_header(dinfo, TRUE);
958 » if(setDecompDefaults(dinfo, pixelFormat)==-1) 960 » if(setDecompDefaults(dinfo, pixelFormat, flags)==-1)
959 { 961 {
960 retval=-1; goto bailout; 962 retval=-1; goto bailout;
961 } 963 }
962 964
963 if(flags&TJFLAG_FASTUPSAMPLE) dinfo->do_fancy_upsampling=FALSE; 965 if(flags&TJFLAG_FASTUPSAMPLE) dinfo->do_fancy_upsampling=FALSE;
964 966
965 jpegwidth=dinfo->image_width; jpegheight=dinfo->image_height; 967 jpegwidth=dinfo->image_width; jpegheight=dinfo->image_height;
966 if(width==0) width=jpegwidth; 968 if(width==0) width=jpegwidth;
967 if(height==0) height=jpegheight; 969 if(height==0) height=jpegheight;
968 for(i=0; i<NUMSF; i++) 970 for(i=0; i<NUMSF; i++)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 _throw("tjDecompressToYUV(): Memory allocation f ailure"); 1105 _throw("tjDecompressToYUV(): Memory allocation f ailure");
1104 for(row=0; row<th[i]; row++) 1106 for(row=0; row<th[i]; row++)
1105 { 1107 {
1106 tmpbuf[i][row]=ptr; 1108 tmpbuf[i][row]=ptr;
1107 ptr+=iw[i]; 1109 ptr+=iw[i];
1108 } 1110 }
1109 } 1111 }
1110 } 1112 }
1111 1113
1112 if(flags&TJFLAG_FASTUPSAMPLE) dinfo->do_fancy_upsampling=FALSE; 1114 if(flags&TJFLAG_FASTUPSAMPLE) dinfo->do_fancy_upsampling=FALSE;
1115 if(flags&TJFLAG_FASTDCT) dinfo->dct_method=JDCT_FASTEST;
1113 dinfo->raw_data_out=TRUE; 1116 dinfo->raw_data_out=TRUE;
1114 1117
1115 jpeg_start_decompress(dinfo); 1118 jpeg_start_decompress(dinfo);
1116 for(row=0; row<(int)dinfo->output_height; 1119 for(row=0; row<(int)dinfo->output_height;
1117 row+=dinfo->max_v_samp_factor*DCTSIZE) 1120 row+=dinfo->max_v_samp_factor*DCTSIZE)
1118 { 1121 {
1119 JSAMPARRAY yuvptr[MAX_COMPONENTS]; 1122 JSAMPARRAY yuvptr[MAX_COMPONENTS];
1120 int crow[MAX_COMPONENTS]; 1123 int crow[MAX_COMPONENTS];
1121 for(i=0; i<dinfo->num_components; i++) 1124 for(i=0; i<dinfo->num_components; i++)
1122 { 1125 {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 } 1319 }
1317 1320
1318 jpeg_finish_decompress(dinfo); 1321 jpeg_finish_decompress(dinfo);
1319 1322
1320 bailout: 1323 bailout:
1321 if(cinfo->global_state>CSTATE_START) jpeg_abort_compress(cinfo); 1324 if(cinfo->global_state>CSTATE_START) jpeg_abort_compress(cinfo);
1322 if(dinfo->global_state>DSTATE_START) jpeg_abort_decompress(dinfo); 1325 if(dinfo->global_state>DSTATE_START) jpeg_abort_decompress(dinfo);
1323 if(xinfo) free(xinfo); 1326 if(xinfo) free(xinfo);
1324 return retval; 1327 return retval;
1325 } 1328 }
OLDNEW
« no previous file with comments | « turbojpeg.h ('k') | turbojpeg-jni.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698