| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C)2009-2011 D. R. Commander. All Rights Reserved. | 2 * Copyright (C)2009-2011 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 else | 126 else |
| 127 { | 127 { |
| 128 if(flags&TJ_BGR) return TJPF_BGRX; | 128 if(flags&TJ_BGR) return TJPF_BGRX; |
| 129 else return TJPF_RGBX; | 129 else return TJPF_RGBX; |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 return -1; | 132 return -1; |
| 133 } | 133 } |
| 134 | 134 |
| 135 static void setCompDefaults(struct jpeg_compress_struct *cinfo, | 135 static int setCompDefaults(struct jpeg_compress_struct *cinfo, |
| 136 int pixelFormat, int subsamp, int jpegQual) | 136 int pixelFormat, int subsamp, int jpegQual) |
| 137 { | 137 { |
| 138 int retval=0; |
| 139 |
| 138 switch(pixelFormat) | 140 switch(pixelFormat) |
| 139 { | 141 { |
| 140 case TJPF_GRAY: | 142 case TJPF_GRAY: |
| 141 cinfo->in_color_space=JCS_GRAYSCALE; break; | 143 cinfo->in_color_space=JCS_GRAYSCALE; break; |
| 142 #if JCS_EXTENSIONS==1 | 144 #if JCS_EXTENSIONS==1 |
| 143 case TJPF_RGB: | 145 case TJPF_RGB: |
| 144 cinfo->in_color_space=JCS_EXT_RGB; break; | 146 cinfo->in_color_space=JCS_EXT_RGB; break; |
| 145 case TJPF_BGR: | 147 case TJPF_BGR: |
| 146 cinfo->in_color_space=JCS_EXT_BGR; break; | 148 cinfo->in_color_space=JCS_EXT_BGR; break; |
| 147 case TJPF_RGBX: | 149 case TJPF_RGBX: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 175 jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); | 177 jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); |
| 176 else | 178 else |
| 177 jpeg_set_colorspace(cinfo, JCS_YCbCr); | 179 jpeg_set_colorspace(cinfo, JCS_YCbCr); |
| 178 | 180 |
| 179 cinfo->comp_info[0].h_samp_factor=tjMCUWidth[subsamp]/8; | 181 cinfo->comp_info[0].h_samp_factor=tjMCUWidth[subsamp]/8; |
| 180 cinfo->comp_info[1].h_samp_factor=1; | 182 cinfo->comp_info[1].h_samp_factor=1; |
| 181 cinfo->comp_info[2].h_samp_factor=1; | 183 cinfo->comp_info[2].h_samp_factor=1; |
| 182 cinfo->comp_info[0].v_samp_factor=tjMCUHeight[subsamp]/8; | 184 cinfo->comp_info[0].v_samp_factor=tjMCUHeight[subsamp]/8; |
| 183 cinfo->comp_info[1].v_samp_factor=1; | 185 cinfo->comp_info[1].v_samp_factor=1; |
| 184 cinfo->comp_info[2].v_samp_factor=1; | 186 cinfo->comp_info[2].v_samp_factor=1; |
| 187 |
| 188 #if JCS_EXTENSIONS!=1 |
| 189 bailout: |
| 190 #endif |
| 191 return retval; |
| 185 } | 192 } |
| 186 | 193 |
| 187 static void setDecompDefaults(struct jpeg_decompress_struct *dinfo, | 194 static int setDecompDefaults(struct jpeg_decompress_struct *dinfo, |
| 188 int pixelFormat) | 195 int pixelFormat) |
| 189 { | 196 { |
| 197 int retval=0; |
| 198 |
| 190 switch(pixelFormat) | 199 switch(pixelFormat) |
| 191 { | 200 { |
| 192 case TJPF_GRAY: | 201 case TJPF_GRAY: |
| 193 dinfo->out_color_space=JCS_GRAYSCALE; break; | 202 dinfo->out_color_space=JCS_GRAYSCALE; break; |
| 194 #if JCS_EXTENSIONS==1 | 203 #if JCS_EXTENSIONS==1 |
| 195 case TJPF_RGB: | 204 case TJPF_RGB: |
| 196 dinfo->out_color_space=JCS_EXT_RGB; break; | 205 dinfo->out_color_space=JCS_EXT_RGB; break; |
| 197 case TJPF_BGR: | 206 case TJPF_BGR: |
| 198 dinfo->out_color_space=JCS_EXT_BGR; break; | 207 dinfo->out_color_space=JCS_EXT_BGR; break; |
| 199 case TJPF_RGBX: | 208 case TJPF_RGBX: |
| 200 dinfo->out_color_space=JCS_EXT_RGBX; break; | 209 dinfo->out_color_space=JCS_EXT_RGBX; break; |
| 201 case TJPF_BGRX: | 210 case TJPF_BGRX: |
| 202 dinfo->out_color_space=JCS_EXT_BGRX; break; | 211 dinfo->out_color_space=JCS_EXT_BGRX; break; |
| 203 case TJPF_XRGB: | 212 case TJPF_XRGB: |
| 204 dinfo->out_color_space=JCS_EXT_XRGB; break; | 213 dinfo->out_color_space=JCS_EXT_XRGB; break; |
| 205 case TJPF_XBGR: | 214 case TJPF_XBGR: |
| 206 dinfo->out_color_space=JCS_EXT_XBGR; break; | 215 dinfo->out_color_space=JCS_EXT_XBGR; break; |
| 207 #else | 216 #else |
| 208 case TJPF_RGB: | 217 case TJPF_RGB: |
| 209 if(RGB_RED==0 && RGB_GREEN==1 && RGB_BLUE==2 && RGB_PIXE
LSIZE==3) | 218 if(RGB_RED==0 && RGB_GREEN==1 && RGB_BLUE==2 && RGB_PIXE
LSIZE==3) |
| 210 { | 219 { |
| 211 dinfo->out_color_space=JCS_RGB; break; | 220 dinfo->out_color_space=JCS_RGB; break; |
| 212 } | 221 } |
| 213 default: | 222 default: |
| 214 _throw("Unsupported pixel format"); | 223 _throw("Unsupported pixel format"); |
| 215 #endif | 224 #endif |
| 216 } | 225 } |
| 226 |
| 227 #if JCS_EXTENSIONS!=1 |
| 228 bailout: |
| 229 #endif |
| 230 return retval; |
| 217 } | 231 } |
| 218 | 232 |
| 219 | 233 |
| 220 static int getSubsamp(j_decompress_ptr dinfo) | 234 static int getSubsamp(j_decompress_ptr dinfo) |
| 221 { | 235 { |
| 222 int retval=-1, i, k; | 236 int retval=-1, i, k; |
| 223 for(i=0; i<NUMSUBOPT; i++) | 237 for(i=0; i<NUMSUBOPT; i++) |
| 224 { | 238 { |
| 225 if(dinfo->num_components==pixelsize[i]) | 239 if(dinfo->num_components==pixelsize[i]) |
| 226 { | 240 { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 | 423 |
| 410 if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); | 424 if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); |
| 411 else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); | 425 else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); |
| 412 else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); | 426 else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); |
| 413 | 427 |
| 414 if(flags&TJFLAG_NOREALLOC) | 428 if(flags&TJFLAG_NOREALLOC) |
| 415 { | 429 { |
| 416 alloc=0; *jpegSize=tjBufSize(width, height, jpegSubsamp); | 430 alloc=0; *jpegSize=tjBufSize(width, height, jpegSubsamp); |
| 417 } | 431 } |
| 418 jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc); | 432 jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc); |
| 419 » setCompDefaults(cinfo, pixelFormat, jpegSubsamp, jpegQual); | 433 » if(setCompDefaults(cinfo, pixelFormat, jpegSubsamp, jpegQual)==-1) |
| 434 » » return -1; |
| 420 | 435 |
| 421 jpeg_start_compress(cinfo, TRUE); | 436 jpeg_start_compress(cinfo, TRUE); |
| 422 if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL) | 437 if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL) |
| 423 _throw("tjCompress2(): Memory allocation failure"); | 438 _throw("tjCompress2(): Memory allocation failure"); |
| 424 for(i=0; i<height; i++) | 439 for(i=0; i<height; i++) |
| 425 { | 440 { |
| 426 if(flags&TJFLAG_BOTTOMUP) row_pointer[i]=&srcBuf[(height-i-1)*pi
tch]; | 441 if(flags&TJFLAG_BOTTOMUP) row_pointer[i]=&srcBuf[(height-i-1)*pi
tch]; |
| 427 else row_pointer[i]=&srcBuf[i*pitch]; | 442 else row_pointer[i]=&srcBuf[i*pitch]; |
| 428 } | 443 } |
| 429 while(cinfo->next_scanline<cinfo->image_height) | 444 while(cinfo->next_scanline<cinfo->image_height) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 515 |
| 501 cinfo->image_width=width; | 516 cinfo->image_width=width; |
| 502 cinfo->image_height=height; | 517 cinfo->image_height=height; |
| 503 | 518 |
| 504 if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); | 519 if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); |
| 505 else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); | 520 else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); |
| 506 else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); | 521 else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); |
| 507 | 522 |
| 508 yuvsize=tjBufSizeYUV(width, height, subsamp); | 523 yuvsize=tjBufSizeYUV(width, height, subsamp); |
| 509 jpeg_mem_dest_tj(cinfo, &dstBuf, &yuvsize, 0); | 524 jpeg_mem_dest_tj(cinfo, &dstBuf, &yuvsize, 0); |
| 510 » setCompDefaults(cinfo, pixelFormat, subsamp, -1); | 525 » if(setCompDefaults(cinfo, pixelFormat, subsamp, -1)==-1) return -1; |
| 511 | 526 |
| 512 jpeg_start_compress(cinfo, TRUE); | 527 jpeg_start_compress(cinfo, TRUE); |
| 513 pw=PAD(width, cinfo->max_h_samp_factor); | 528 pw=PAD(width, cinfo->max_h_samp_factor); |
| 514 ph=PAD(height, cinfo->max_v_samp_factor); | 529 ph=PAD(height, cinfo->max_v_samp_factor); |
| 515 | 530 |
| 516 if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL) | 531 if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL) |
| 517 _throw("tjEncodeYUV2(): Memory allocation failure"); | 532 _throw("tjEncodeYUV2(): Memory allocation failure"); |
| 518 for(i=0; i<height; i++) | 533 for(i=0; i<height; i++) |
| 519 { | 534 { |
| 520 if(flags&TJFLAG_BOTTOMUP) row_pointer[i]=&srcBuf[(height-i-1)*pi
tch]; | 535 if(flags&TJFLAG_BOTTOMUP) row_pointer[i]=&srcBuf[(height-i-1)*pi
tch]; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 | 737 |
| 723 if(setjmp(this->jerr.setjmp_buffer)) | 738 if(setjmp(this->jerr.setjmp_buffer)) |
| 724 { | 739 { |
| 725 /* If we get here, the JPEG code has signaled an error. */ | 740 /* If we get here, the JPEG code has signaled an error. */ |
| 726 retval=-1; | 741 retval=-1; |
| 727 goto bailout; | 742 goto bailout; |
| 728 } | 743 } |
| 729 | 744 |
| 730 jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); | 745 jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); |
| 731 jpeg_read_header(dinfo, TRUE); | 746 jpeg_read_header(dinfo, TRUE); |
| 732 » setDecompDefaults(dinfo, pixelFormat); | 747 » if(setDecompDefaults(dinfo, pixelFormat)==-1) return -1; |
| 733 | 748 |
| 734 if(flags&TJFLAG_FASTUPSAMPLE) dinfo->do_fancy_upsampling=FALSE; | 749 if(flags&TJFLAG_FASTUPSAMPLE) dinfo->do_fancy_upsampling=FALSE; |
| 735 | 750 |
| 736 jpegwidth=dinfo->image_width; jpegheight=dinfo->image_height; | 751 jpegwidth=dinfo->image_width; jpegheight=dinfo->image_height; |
| 737 if(width==0) width=jpegwidth; | 752 if(width==0) width=jpegwidth; |
| 738 if(height==0) height=jpegheight; | 753 if(height==0) height=jpegheight; |
| 739 for(i=0; i<NUMSF; i++) | 754 for(i=0; i<NUMSF; i++) |
| 740 { | 755 { |
| 741 scaledw=TJSCALED(jpegwidth, sf[i]); | 756 scaledw=TJSCALED(jpegwidth, sf[i]); |
| 742 scaledh=TJSCALED(jpegheight, sf[i]); | 757 scaledh=TJSCALED(jpegheight, sf[i]); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 w=dinfo->image_width; h=dinfo->image_height; | 1031 w=dinfo->image_width; h=dinfo->image_height; |
| 1017 } | 1032 } |
| 1018 else | 1033 else |
| 1019 { | 1034 { |
| 1020 w=xinfo[i].crop_width; h=xinfo[i].crop_height; | 1035 w=xinfo[i].crop_width; h=xinfo[i].crop_height; |
| 1021 } | 1036 } |
| 1022 if(flags&TJFLAG_NOREALLOC) | 1037 if(flags&TJFLAG_NOREALLOC) |
| 1023 { | 1038 { |
| 1024 alloc=0; dstSizes[i]=tjBufSize(w, h, jpegSubsamp); | 1039 alloc=0; dstSizes[i]=tjBufSize(w, h, jpegSubsamp); |
| 1025 } | 1040 } |
| 1026 » » jpeg_mem_dest_tj(cinfo, &dstBufs[i], &dstSizes[i], alloc); | 1041 » » if(!(t[i].options&TJXOPT_NOOUTPUT)) |
| 1042 » » » jpeg_mem_dest_tj(cinfo, &dstBufs[i], &dstSizes[i], alloc
); |
| 1027 jpeg_copy_critical_parameters(dinfo, cinfo); | 1043 jpeg_copy_critical_parameters(dinfo, cinfo); |
| 1028 dstcoefs=jtransform_adjust_parameters(dinfo, cinfo, srccoefs, | 1044 dstcoefs=jtransform_adjust_parameters(dinfo, cinfo, srccoefs, |
| 1029 &xinfo[i]); | 1045 &xinfo[i]); |
| 1030 » » jpeg_write_coefficients(cinfo, dstcoefs); | 1046 » » if(!(t[i].options&TJXOPT_NOOUTPUT)) |
| 1031 » » jcopy_markers_execute(dinfo, cinfo, JCOPYOPT_ALL); | 1047 » » { |
| 1048 » » » jpeg_write_coefficients(cinfo, dstcoefs); |
| 1049 » » » jcopy_markers_execute(dinfo, cinfo, JCOPYOPT_ALL); |
| 1050 » » } |
| 1051 » » else jinit_c_master_control(cinfo, TRUE); |
| 1032 jtransform_execute_transformation(dinfo, cinfo, srccoefs, | 1052 jtransform_execute_transformation(dinfo, cinfo, srccoefs, |
| 1033 &xinfo[i]); | 1053 &xinfo[i]); |
| 1034 » » jpeg_finish_compress(cinfo); | 1054 » » if(t[i].customFilter) |
| 1055 » » { |
| 1056 » » » int ci, by, y; |
| 1057 » » » for(ci=0; ci<cinfo->num_components; ci++) |
| 1058 » » » { |
| 1059 » » » » jpeg_component_info *compptr=&cinfo->comp_info[c
i]; |
| 1060 » » » » tjregion arrayRegion={0, 0, compptr->width_in_bl
ocks*DCTSIZE, |
| 1061 » » » » » DCTSIZE}; |
| 1062 » » » » tjregion planeRegion={0, 0, compptr->width_in_bl
ocks*DCTSIZE, |
| 1063 » » » » » compptr->height_in_blocks*DCTSIZE}; |
| 1064 » » » » for(by=0; by<compptr->height_in_blocks; by+=comp
ptr->v_samp_factor) |
| 1065 » » » » { |
| 1066 » » » » » JBLOCKARRAY barray=(dinfo->mem->access_v
irt_barray) |
| 1067 » » » » » » ((j_common_ptr)dinfo, dstcoefs[c
i], by, compptr->v_samp_factor, |
| 1068 » » » » » » TRUE); |
| 1069 » » » » » for(y=0; y<compptr->v_samp_factor; y++) |
| 1070 » » » » » { |
| 1071 » » » » » » if(t[i].customFilter(barray[y][0
], arrayRegion, planeRegion, |
| 1072 » » » » » » » ci, i, &t[i])==-1) |
| 1073 » » » » » » » _throw("tjTransform(): E
rror in custom filter"); |
| 1074 » » » » » » arrayRegion.y+=DCTSIZE; |
| 1075 » » » » » } |
| 1076 » » » » } |
| 1077 » » » } |
| 1078 » » } |
| 1079 » » if(!(t[i].options&TJXOPT_NOOUTPUT)) jpeg_finish_compress(cinfo); |
| 1035 } | 1080 } |
| 1036 | 1081 |
| 1037 jpeg_finish_decompress(dinfo); | 1082 jpeg_finish_decompress(dinfo); |
| 1038 | 1083 |
| 1039 bailout: | 1084 bailout: |
| 1040 if(cinfo->global_state>CSTATE_START) jpeg_abort_compress(cinfo); | 1085 if(cinfo->global_state>CSTATE_START) jpeg_abort_compress(cinfo); |
| 1041 if(dinfo->global_state>DSTATE_START) jpeg_abort_decompress(dinfo); | 1086 if(dinfo->global_state>DSTATE_START) jpeg_abort_decompress(dinfo); |
| 1042 if(xinfo) free(xinfo); | 1087 if(xinfo) free(xinfo); |
| 1043 return retval; | 1088 return retval; |
| 1044 } | 1089 } |
| OLD | NEW |