jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize) { int i; /* Guard against version mismatches between library and caller. */ cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ if (version != JPEG_LIB_VERSION) ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); if (structsize != sizeof(struct jpeg_decompress_struct)) ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, (int) sizeof(struct jpeg_decompress_struct), (int) structsize); /* For debugging purposes, we zero the whole master structure. * But the application has already set the err pointer, and may have set * client_data, so we have to save and restore those fields. * Note: if application hasn't set client_data, tools like Purify may * complain here. */ { struct jpeg_error_mgr * err = cinfo->err; void * client_data = cinfo->client_data; /* ignore Purify complaint here */ MEMZERO(cinfo, sizeof(struct jpeg_decompress_struct)); cinfo->err = err; cinfo->client_data = client_data; } cinfo->is_decompressor = TRUE; /* Initialize a memory manager instance for this object */ jinit_memory_mgr((j_common_ptr) cinfo); /* Zero out pointers to permanent structures. */ cinfo->progress = NULL; cinfo->src = NULL; for (i = 0; i < NUM_QUANT_TBLS; i++) cinfo->quant_tbl_ptrs[i] = NULL; for (i = 0; i < NUM_HUFF_TBLS; i++) { cinfo->dc_huff_tbl_ptrs[i] = NULL; cinfo->ac_huff_tbl_ptrs[i] = NULL; } /* Initialize marker processor so application can override methods * for COM, APPn markers before calling jpeg_read_header. */ cinfo->marker_list = NULL; jinit_marker_reader(cinfo); /* And initialize the overall input controller. */ jinit_input_controller(cinfo); /* OK, I'm ready */ cinfo->global_state = DSTATE_START; }
jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, int structsize) { int i; //MsgNum("createDecompress","%d",sizeof(struct jpeg_decompress_struct)); /* Guard against version mismatches between library and caller. */ cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ if (version != JPEG_LIB_VERSION) ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); if (structsize != sizeof(struct jpeg_decompress_struct)) ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, (int) sizeof(struct jpeg_decompress_struct), (int) structsize); /* For debugging purposes, zero the whole master structure. * But error manager pointer is already there, so save and restore it. */ { struct jpeg_error_mgr * err = cinfo->err; MEMZERO(cinfo, sizeof(struct jpeg_decompress_struct)); cinfo->err = err; } cinfo->is_decompressor = TRUE; /* Initialize a memory manager instance for this object */ jinit_memory_mgr((j_common_ptr) cinfo); /* Zero out pointers to permanent structures. */ cinfo->progress = NULL; cinfo->src = NULL; for (i = 0; i < NUM_QUANT_TBLS; i++) cinfo->quant_tbl_ptrs[i] = NULL; for (i = 0; i < NUM_HUFF_TBLS; i++) { cinfo->dc_huff_tbl_ptrs[i] = NULL; cinfo->ac_huff_tbl_ptrs[i] = NULL; } /* Initialize marker processor so application can override methods * for COM, APPn markers before calling jpeg_read_header. */ jinit_marker_reader(cinfo); /* And initialize the overall input controller. */ jinit_input_controller(cinfo); /* OK, I'm ready */ cinfo->global_state = DSTATE_START; }
GLOBAL void jpeg_create_decompress (j_decompress_ptr cinfo) { int i; /* For debugging purposes, zero the whole master structure. * But error manager pointer is already there, so save and restore it. */ { struct jpeg_error_mgr * err = cinfo->err; i = sizeof(struct jpeg_decompress_struct); i = SIZEOF(struct jpeg_decompress_struct); MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct)); cinfo->err = err; } cinfo->is_decompressor = TRUE; /* Initialize a memory manager instance for this object */ jinit_memory_mgr((j_common_ptr) cinfo); /* Zero out pointers to permanent structures. */ cinfo->progress = NULL; cinfo->src = NULL; for (i = 0; i < NUM_QUANT_TBLS; i++) cinfo->quant_tbl_ptrs[i] = NULL; for (i = 0; i < NUM_HUFF_TBLS; i++) { cinfo->dc_huff_tbl_ptrs[i] = NULL; cinfo->ac_huff_tbl_ptrs[i] = NULL; } /* Initialize marker processor so application can override methods * for COM, APPn markers before calling jpeg_read_header. */ jinit_marker_reader(cinfo); /* And initialize the overall input controller. */ jinit_input_controller(cinfo); /* OK, I'm ready */ cinfo->global_state = DSTATE_START; }
jpeg_start_decompress (j_decompress_ptr cinfo) { JDIMENSION output_pitch; SkJpegDebugf("\n*******jpeg_start_decompress*******,out_color_space = %d\n",cinfo->out_color_space); SkJpegDebugf("2.1 image_width = %d, image_height = %d\n", cinfo->image_width, cinfo->image_height); #ifdef MTM_HWDEC RESTART_DEC: // SkJpegDebugf("------restartdec %d---------",IS_HW_DECODE()); if (IS_HW_DECODE()) { #ifdef SMALL_JPG_USE_SW if (((cinfo->image_width <640) && (cinfo->image_height<480))||(cinfo->out_color_space == JCS_RGB_565)) { SkJpegDebugf("Small jpg Switch to SW mode\n"); cinfo->fgforceswmode = TRUE; goto RESTART_DEC; } #endif #ifdef JPEG_FORCE_SW_FLOW cinfo->fgforceswmode=TRUE; #endif if(!fgJpgMutexInit) { pthread_mutex_init(&JpgLibMutex, NULL); SkJpegDebugf("pthread_mutex_init JpgLibMutex ....\n"); fgJpgMutexInit = TRUE; } pthread_mutex_lock(&JpgLibMutex); SkJpegDebugf("JpgLibMutex lock....\n"); MEMZERO(&hwcinfo, SIZEOF(HWCINFO)); pthread_cond_init(&JpgStopCond, NULL); pthread_cond_init(&JpgStopMutex, NULL); /* Hardwire it to "no scaling" */ switch (cinfo->out_color_space) { case JCS_GRAYSCALE: cinfo->out_color_components = 1; break; case JCS_RGB: cinfo->out_color_components = 3; break; case JCS_RGB_565: cinfo->out_color_components = 3; break; case JCS_RGBA_8888: cinfo->out_color_components = 4; break; default: /* else must be same colorspace as in file */ cinfo->out_color_components = cinfo->num_components; break; } cinfo->output_components = cinfo->out_color_components; #ifndef MTIMAGE_READ_HEADER if(cinfo->scale_denom) { cinfo->output_width = cinfo->image_width / cinfo->scale_denom ; cinfo->output_height = cinfo->image_height / cinfo->scale_denom ; } #endif //SkJpegDebugf("1.output_width = %d, output_height = %d\n", cinfo->output_width, cinfo->output_height); //SkJpegDebugf("image_width = %d, image_height = %d, output_component =%d\n", cinfo->image_width, cinfo->image_height, cinfo->out_color_components); switch(cinfo->out_color_space) { case JCS_RGBA_8888: Jpg_DesBytePerPixel = 4; Jpg_SrcBytePerPixel = 4; break; case JCS_RGB: Jpg_DesBytePerPixel = 3; Jpg_SrcBytePerPixel = 4; break; case JCS_RGB_565: Jpg_DesBytePerPixel = 2; Jpg_SrcBytePerPixel = 2; break; default: break; } #ifndef JPGMEM_IMPROVE output_pitch= (cinfo->output_width+0xf)&~0xf; if(!hwcinfo.image) { hwcinfo.image = malloc( output_pitch * cinfo->output_height * Jpg_SrcBytePerPixel * sizeof(UINTJ8)); // *4 for ARGB8888 buffer, YC422 to ARGB8888 if (!hwcinfo.image) { SkJpegDebugf("allocate fail\n"); return FALSE; } cinfo->input_iMCU_row = (JDIMENSION) hwcinfo.image; } #endif if (mtmplay_jpg_dec(cinfo)) { cinfo->output_scanline = 0; #ifndef JPGMEM_IMPROVE if(!hwcinfo.pimageRow) { hwcinfo.pimageRow = malloc( cinfo->output_width * Jpg_DesBytePerPixel); SkJpegDebugf("pimageRow ptr = %x\n", (JDIMENSION)hwcinfo.pimageRow); if (!hwcinfo.pimageRow) { printf("pimageRow malloc fail\n"); return -1; } } #endif #ifdef JPGMEM_IMPROVE hwcinfo.image = cinfo->input_iMCU_row; //hwcinfo.pimageRow = cinfo->input_iMCU_row - (cinfo->output_width * Jpg_DesBytePerPixel); hwcinfo.pimageRow = cinfo->input_iMCU_row + 0x7F8000; #endif SkJpegDebugf("HW original image_width = %d, image_height = %d\n", cinfo->image_width, cinfo->image_height); SkJpegDebugf("HW output_width = %d, output_height = %d,hwcinfo.image = %x %x\n", cinfo->output_width, cinfo->output_height,hwcinfo.image,hwcinfo.pimageRow); return TRUE; } else { SkJpegDebugf("\n!!!-->HW Err.\n"); #if 1 //return 0; /* Initialize marker processor so application can override methods * for COM, APPn markers before calling jpeg_read_header. */ cinfo->marker_list = NULL; jinit_marker_reader(cinfo); /* And initialize the overall input controller. */ jinit_input_controller(cinfo); /* OK, I'm ready */ cinfo->global_state = DSTATE_START; cinfo->fgforceswmode=TRUE; pthread_mutex_unlock(&JpgLibMutex); jpeg_read_header(cinfo, TRUE); if (!cinfo->progressive_mode && (cinfo->image_width > 17000 || cinfo->image_height > 10000)) { return FALSE; } if (cinfo->progressive_mode && (cinfo->image_width * cinfo->image_height) > 4000 * 4000) { return FALSE; } //jpeg_calc_output_dimensions(cinfo); goto RESTART_DEC; return TRUE; #else return FALSE; #endif } } else #endif//MTM_HWDEC { #ifdef JPEG_FORCE_HW_FLOW if((cinfo->out_color_space == JCS_RGB)||(cinfo->out_color_space == JCS_RGBA_8888)) { printf("***cinfo->out_color_space=[%d], never sw mode\n"); return 0; } #endif #ifdef MTM_HWDEC printf("\n****-->SW MODE\n"); #ifndef ANDROID_READ cinfo->src->next_input_byte = hwcinfo.gSOS_next_input_byte; cinfo->src->bytes_in_buffer = hwcinfo.gSOS_bytes_in_buffer; SkJpegDebugf("4. Cinfo src buf addr= 0x%x: len=%lu \n", cinfo->src->next_input_byte, cinfo->src->bytes_in_buffer); #endif #endif if (cinfo->global_state == DSTATE_READY) { /* First call: initialize master control, select active modules */ jinit_master_decompress(cinfo); if (cinfo->buffered_image) { /* No more work here; expecting jpeg_start_output next */ cinfo->global_state = DSTATE_BUFIMAGE; return TRUE; } cinfo->global_state = DSTATE_PRELOAD; } if (cinfo->global_state == DSTATE_PRELOAD) { /* If file has multiple scans, absorb them all into the coef buffer */ if (cinfo->inputctl->has_multiple_scans) { #ifdef D_MULTISCAN_FILES_SUPPORTED for (;;) { int retcode; /* Call progress monitor hook if present */ if (cinfo->progress != NULL) (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); /* Absorb some more input */ retcode = (*cinfo->inputctl->consume_input) (cinfo); if (retcode == JPEG_SUSPENDED) return FALSE; if (retcode == JPEG_REACHED_EOI) break; /* Advance progress counter if appropriate */ if (cinfo->progress != NULL && (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { /* jdmaster underestimated number of scans; ratchet up one scan */ cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; } } } #else ERREXIT(cinfo, JERR_NOT_COMPILED); #endif /* D_MULTISCAN_FILES_SUPPORTED */ } cinfo->output_scan_number = cinfo->input_scan_number; } else if (cinfo->global_state != DSTATE_PRESCAN) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); /* Perform any dummy output passes, and set up for the final pass */ return output_pass_setup(cinfo); }//if (!IS_HW_DECODE()) }