📄 jdapistd.c
字号:
// plane_width[i] = ((plane_width[i] - 1)/cinfo->cur_comp_info[i]->DCT_scaled_size + 1) * cinfo->cur_comp_info[i]->DCT_scaled_size;// plane_height[i] = ((plane_height[i] - 1)/cinfo->cur_comp_info[i]->DCT_scaled_size + 1) * cinfo->cur_comp_info[i]->DCT_scaled_size; // padd size to next 16x16 block plane_width[Y_PLANE] = ((plane_width[Y_PLANE] - 1)/16 + 1) * 16; plane_height[Y_PLANE] = ((plane_height[Y_PLANE] - 1)/16 + 1) * 16; for(i=1; i<3; i++) { if (i < cinfo->num_components) { plane_width[i] = plane_width[Y_PLANE]*H_samp[i]/H_samp[Y_PLANE]; plane_height[i] = plane_height[Y_PLANE]*V_samp[i]/V_samp[Y_PLANE]; } else { plane_width[i] = plane_width[Y_PLANE]; plane_height[i] = plane_height[Y_PLANE]; } }#if 0 for(i=0; i<cinfo->num_components; i++) { printf("XXX Plane %i : dssz=%dx%d, dctsz=%d, plane=%dx%d, sf=%dx%x, adjsf=%dx%d\n",i, cinfo->cur_comp_info[i]->downsampled_width, cinfo->cur_comp_info[i]->downsampled_height, cinfo->cur_comp_info[i]->DCT_scaled_size, plane_width[i], plane_height[i], cinfo->cur_comp_info[i]->h_samp_factor, cinfo->cur_comp_info[i]->v_samp_factor, H_samp[i], V_samp[i]); }#endif /////// plane_buff[Y_PLANE] = Y_plane; for(i=1; i<cinfo->num_components;i++) { plane_buff[i] = (JSAMPROW) (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, plane_width[i]*plane_height[i]* sizeof(JSAMPLE)); } { JDIMENSION j; JSAMPROW rowptr = plane_buff[Y_PLANE] + center_ajust_h + center_ajust_v; JDIMENSION lines_in_row = cinfo->cur_comp_info[Y_PLANE]->v_samp_factor * cinfo->cur_comp_info[Y_PLANE]->DCT_scaled_size; buff[Y_PLANE] = alloca(lines_in_row*sizeof(JSAMPARRAY)); for(j=0; j<lines_in_row; j++) { buff[Y_PLANE][j] = rowptr; rowptr += plane_width[Y_PLANE]; } } for(i=1; i<cinfo->num_components;i++) { JDIMENSION j; JSAMPROW rowptr = plane_buff[i]; JDIMENSION lines_in_row = cinfo->cur_comp_info[i]->v_samp_factor * cinfo->cur_comp_info[i]->DCT_scaled_size; buff[i] = alloca(lines_in_row*sizeof(JSAMPARRAY)); for(j=0; j<lines_in_row; j++) { buff[i][j] = rowptr; rowptr += plane_width[i]; } } /* Process data */ while (cinfo->output_scanline < cinfo->output_height) { JDIMENSION j; JDIMENSION lines_in_row; num_scanlines = jpeg_read_raw_data(cinfo, buff, lines_per_iMCU_row); lines_in_row = cinfo->cur_comp_info[Y_PLANE]->v_samp_factor * cinfo->cur_comp_info[Y_PLANE]->DCT_scaled_size; for(j=0; j<lines_in_row; j++) { buff[Y_PLANE][j] += lines_in_row*plane_width[Y_PLANE]; } for(i=1; i<cinfo->num_components;i++) { lines_in_row = cinfo->cur_comp_info[i]->v_samp_factor * cinfo->cur_comp_info[i]->DCT_scaled_size; for(j=0; j<lines_in_row; j++) { buff[i][j] += lines_in_row*plane_width[i]; } } } { //convert U & V planes to UVUV plane 4:2:0 JDIMENSION i; JSAMPROW urow0 = plane_buff[U_PLANE]; JSAMPROW urow1 = urow0 + plane_width[U_PLANE]; JSAMPROW vrow0 = plane_buff[V_PLANE]; JSAMPROW vrow1 = vrow0 + plane_width[V_PLANE]; UV_ptr = UV_plane + center_ajust_h + (center_ajust_v>>1); if (cinfo->num_components < 3) { // case Y1 (4:0:0) black&white for(i=0; i<plane_height[U_PLANE];i+=2) { JDIMENSION j; for(j=0; j<plane_width[U_PLANE]; j+=2) { *UV_ptr++ = 0x80; *UV_ptr++ = 0x80; } } } else if(H_samp[Y_PLANE]==H_samp[U_PLANE] && H_samp[Y_PLANE]==H_samp[V_PLANE] && H_samp[Y_PLANE]==V_samp[U_PLANE] && V_samp[Y_PLANE]==V_samp[V_PLANE] ) { // case Y1:U1:V1 (4:4:4)// cinfo->output_width&=~1;//deleteme // urow_width = (urow_width + urow_width - cinfo->output_width)*sizeof(JSAMPLE);// vrow_width = (vrow_width + vrow_width - cinfo->output_width)*sizeof(JSAMPLE); for(i=0; i<plane_height[U_PLANE];i+=2) { JDIMENSION j; for(j=0; j<plane_width[U_PLANE]; j+=2) { //calc average U & V from 4 to 1 unsigned char a, b, c, d; a = *urow0; urow0++; b = *urow0; urow0++; c = *urow1; urow1++; d = *urow1; urow1++; *UV_ptr++ = (a + b + c + d)>>2; a = *vrow0; vrow0++; b = *vrow0; vrow0++; c = *vrow1; vrow1++; d = *vrow1; vrow1++; *UV_ptr++ = (a + b + c + d)>>2;// *UV_ptr++ = (*urow0++ + *urow0++ + *urow1++ + *urow1++)>>2;// *UV_ptr++ = (*vrow0++ + *vrow0++ + *vrow1++ + *vrow1++)>>2; } urow0+= plane_width[U_PLANE]; urow1+= plane_width[U_PLANE]; vrow0+= plane_width[U_PLANE]; vrow1+= plane_width[U_PLANE]; } } else if( H_samp[Y_PLANE]==2*H_samp[U_PLANE] && H_samp[Y_PLANE]==2*H_samp[V_PLANE] && H_samp[Y_PLANE]==2*V_samp[U_PLANE] && V_samp[Y_PLANE]==2*V_samp[V_PLANE]) {// case Y4:U1:V1 (4:2:0) for(i=0; i<plane_height[U_PLANE];i++) { JDIMENSION j; for(j=0; j<plane_width[U_PLANE]; j++) { // jast mix U & V *UV_ptr++ = *urow0++; *UV_ptr++ = *vrow0++; } } }else if(H_samp[Y_PLANE]==2*H_samp[U_PLANE] && H_samp[Y_PLANE]==2*H_samp[V_PLANE] && V_samp[Y_PLANE]==V_samp[U_PLANE] && V_samp[Y_PLANE]==V_samp[V_PLANE]) {// case YY:U:V (4:2:2) for(i=0; i<plane_height[U_PLANE];i+=2) { JDIMENSION j; for(j=0; j<plane_width[U_PLANE]; j++) { //calc average U & V from 4 to 1 *UV_ptr++ = (*urow0++ + *urow1++)>>1; *UV_ptr++ = (*vrow0++ + *vrow1++)>>1; } urow0+= plane_width[U_PLANE]; urow1+= plane_width[U_PLANE]; vrow0+= plane_width[V_PLANE]; vrow1+= plane_width[V_PLANE]; } } else if( H_samp[Y_PLANE]==H_samp[U_PLANE] && H_samp[Y_PLANE]==H_samp[V_PLANE] && V_samp[Y_PLANE]==2*V_samp[U_PLANE] && V_samp[Y_PLANE]==2*V_samp[V_PLANE]) {// case Y:U:V (4:2:2 rotated) // Y: for(i=0; i<plane_height[U_PLANE];i++) { JDIMENSION j; for(j=0; j<plane_width[U_PLANE]; j+=2) { //calc average U & V from 2 to 1 unsigned char a, b; a = *urow0; urow0++; b = *urow0; urow0++; *UV_ptr++ = (a + b)>>1; a = *vrow0; vrow0++; b = *vrow0; vrow0++; *UV_ptr++ = (a + b)>>1;// *UV_ptr++ = (*urow0++ + *urow0++)>>1;// *UV_ptr++ = (*vrow0++ + *vrow0++)>>1; } } } else { printf("\n**** Usupported format****\n"); printf("H_samp[Y] == %d H_samp[U] == %d H_samp[V] == %d\n", H_samp[Y_PLANE], H_samp[U_PLANE], H_samp[V_PLANE]); printf("V_samp[Y] == %d V_samp[U] == %d V_samp[V] == %d\n", V_samp[Y_PLANE], V_samp[U_PLANE], V_samp[V_PLANE]); } } return cinfo->output_scanline;}#endif //YYYY_UV/* Additional entry points for buffered-image mode. */#ifdef D_MULTISCAN_FILES_SUPPORTED/* * Initialize for an output pass in buffered-image mode. */GLOBAL(boolean)jpeg_start_output (j_decompress_ptr cinfo, int scan_number){ if (cinfo->global_state != DSTATE_BUFIMAGE && cinfo->global_state != DSTATE_PRESCAN) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); /* Limit scan number to valid range */ if (scan_number <= 0) scan_number = 1; if (cinfo->inputctl->eoi_reached && scan_number > cinfo->input_scan_number) scan_number = cinfo->input_scan_number; cinfo->output_scan_number = scan_number; /* Perform any dummy output passes, and set up for the real pass */ return output_pass_setup(cinfo);}/* * Finish up after an output pass in buffered-image mode. * * Returns FALSE if suspended. The return value need be inspected only if * a suspending data source is used. */GLOBAL(boolean)jpeg_finish_output (j_decompress_ptr cinfo){ if ((cinfo->global_state == DSTATE_SCANNING || cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) { /* Terminate this pass. */ /* We do not require the whole pass to have been completed. */ (*cinfo->master->finish_output_pass) (cinfo); cinfo->global_state = DSTATE_BUFPOST; } else if (cinfo->global_state != DSTATE_BUFPOST) { /* BUFPOST = repeat call after a suspension, anything else is error */ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); } /* Read markers looking for SOS or EOI */ while (cinfo->input_scan_number <= cinfo->output_scan_number && ! cinfo->inputctl->eoi_reached) { if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) return FALSE; /* Suspend, come back later */ } cinfo->global_state = DSTATE_BUFIMAGE; return TRUE;}#endif /* D_MULTISCAN_FILES_SUPPORTED */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -