void wavelet3_thresh(unsigned int N, float lambda, unsigned int flags, const long shifts[N], const long dims[N], complex float* out, const complex float* in, const long minsize[N], long flen, const float filter[2][2][flen]) { unsigned long coeffs = wavelet_coeffs(N, flags, dims, minsize, flen); long istr[N]; md_calc_strides(N, istr, dims, CFL_SIZE); complex float* tmp = md_alloc_sameplace(1, MD_DIMS(coeffs), CFL_SIZE, out); fwt(N, flags, shifts, dims, tmp, istr, in, minsize, flen, filter); md_zsoftthresh(1, MD_DIMS(coeffs), lambda, 0u, tmp, tmp); iwt(N, flags, shifts, dims, istr, out, tmp, minsize, flen, filter); md_free(tmp); }
void iwt(unsigned int N, unsigned int flags, const long shifts[N], const long dims[N], const long ostr[N], complex float* out, const complex float* in, const long minsize[N], const long flen, const float filter[2][2][flen]) { if (0 == flags) { if (out != in) md_copy2(N, dims, ostr, out, ostr, in, CFL_SIZE); return; } unsigned long coeffs = wavelet_coeffs(N, flags, dims, minsize, flen); long wdims[2 * N]; wavelet_dims(N, flags, wdims, dims, flen); long istr[2 * N]; md_calc_strides(2 * N, istr, wdims, CFL_SIZE); long offset = coeffs - md_calc_size(2 * N, wdims); debug_printf(DP_DEBUG4, "%d %ld %ld\n", flags, coeffs, offset); complex float* tmp = md_alloc_sameplace(2 * N, wdims, CFL_SIZE, out); md_copy(2 * N, wdims, tmp, in + offset, CFL_SIZE); long shifts0[N]; for (unsigned int i = 0; i < N; i++) shifts0[i] = 0; // fix me we need temp storage iwt(N, wavelet_filter_flags(N, flags, wdims, minsize), shifts0, wdims, istr, tmp, in, minsize, flen, filter); iwtN(N, flags, shifts, dims, ostr, out, istr, tmp, flen, filter); md_free(tmp); }
/** * @brief Main decoder function. It all starts here. * Input parameters: * 1) input JPEG 2000 image * * @return 0 on success */ int main(int argc, char **argv) { // println_start(INFO); type_image *img = (type_image *)malloc(sizeof(type_image)); memset(img, 0, sizeof(type_image)); if((parse_args(argc, argv, img) == ERROR) || (check_args_dec(img) == ERROR)) { fprintf(stderr, "Error occurred while parsing arguments.\n"); fprintf(stdout, "%s", help); return 1; } type_parameters *param = (type_parameters*)malloc(sizeof(type_parameters)); if((parse_config(img->conf_file, param) == ERROR) || (check_config(param) == ERROR)) { fprintf(stderr, "Error occurred while parsing configuration file.\n"); fprintf(stdout, "%s", help); return 1; } init_device(param); FILE *fsrc = fopen(img->in_file, "rb"); if (!fsrc) { fprintf(stderr, "Error, failed to open %s for reading\n", img->in_file); return 1; } type_tile *tile; int i; if(strstr(img->in_file, ".jp2") != NULL) { println(INFO, "It's a JP2 file"); //parse the JP2 boxes jp2_parse_boxes(fsrc, img); fclose(fsrc); // Do decoding for all tiles for(i = 0; i < img->num_tiles; i++) { tile = &(img->tile[i]); /* Decode data */ decode_tile(tile); /* Dequantize data */ dequantize_tile(tile); /* Do inverse wavelet transform */ iwt(tile); } if(img->use_mct == 1) { // lossless decoder if(img->wavelet_type == 0) { color_decoder_lossless(img); } else { //lossy decoder color_decoder_lossy(img); } } else if (img->use_part2_mct == 1) { decode_klt(img); } else { if(img->sign == UNSIGNED) { idc_level_shifting(img); } } } else {//It is not a JP2 file. type_buffer *src_buff = (type_buffer *) malloc(sizeof(type_buffer)); init_dec_buffer(fsrc, src_buff); fclose(fsrc); decode_codestream(src_buff, img); // get_next_box(fsrc); // Do decoding for all tiles for(i = 0; i < img->num_tiles; i++) { tile = &(img->tile[i]); /* Decode data */ decode_tile(tile); /* Dequantize data */ dequantize_tile(tile); /* Do inverse wavelet transform */ iwt(tile); } if(img->use_mct == 1) { // lossless decoder if(img->wavelet_type == 0) { color_decoder_lossless(img); } else { //lossy decoder color_decoder_lossy(img); } } else if (img->use_part2_mct == 1) { decode_klt(img); } else { if(img->sign == UNSIGNED) { idc_level_shifting(img); } } } save_image(img); }