标签:
opj_dparameters_t parameters; /* decompression parameters */ opj_event_mgr_t event_mgr; /* event manager */ opj_image_t *image = NULL; FILE *fsrc = NULL; // 源文件句柄 unsigned char *src = NULL; // 存放源文件数据内存 int file_length; // 文件长度 opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ opj_cio_t *cio = NULL; // opj_codestream_info_t cstr_info; /* Codestream information structure */ // char indexfilename[OPJ_PATH_LEN]; /* index file name */ // char outfile[OPJ_PATH_LEN]; // configure the event callbacks (not required) / memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); // event_mgr.error_handler = error_callback; // event_mgr.warning_handler = warning_callback; // event_mgr.info_handler = info_callback; // set decoding parameters to default values opj_set_default_decoder_parameters(?meters); image = NULL; CString fileName; ///////////////////////////////////////////////////////////// CFileDialog dlgFile(TRUE); CString title; CString strFilter, strDefault, strFilename; VERIFY(title.LoadString(AFX_IDS_OPENFILE)); // 初始文件扩展名dat strFilter += "JP2 Files (*.jp2)"; strFilter += (TCHAR)‘\0‘; strFilter += _T("*.jp2"); strFilter += (TCHAR)‘\0‘; dlgFile.m_ofn.nMaxCustFilter++; CString allFilter; VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER)); dlgFile.m_ofn.lpstrFilter = strFilter; dlgFile.m_ofn.lpstrTitle = title; dlgFile.m_ofn.lpstrFile = strFilename.GetBuffer(_MAX_PATH); dlgFile.m_ofn.lpstrInitialDir = "D:\\"; // 显示文件选择对话框 INT_PTR nResult = dlgFile.DoModal(); // 如果文件打开则准备播放 if (nResult == IDOK) { strFilename=dlgFile.GetPathName(); fileName = strFilename; } strFilename.ReleaseBuffer(); /////////////////////////////////////////////////////////////// if(fileName != "") { fsrc = fopen(fileName, "rb"); if (!fsrc) return ; } else { return; } // read the input file and put it in memory fseek(fsrc, 0, SEEK_END); file_length = ftell(fsrc); fseek(fsrc, 0, SEEK_SET); src = (unsigned char *) malloc(file_length); fread(src, 1, file_length, fsrc); fclose(fsrc); // decode the code-stream // JPEG 2000 compressed image data // get a decoder handle dinfo = opj_create_decompress(CODEC_JP2); // catch events using our callbacks and give a local context opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); // setup the decoder decoding parameters using the current image and user parameters opj_setup_decoder(dinfo, ?meters); // open a byte stream cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); // decode the stream and fill the image structure image = opj_decode(dinfo, cio); if(!image) { //failed to decode image opj_destroy_decompress(dinfo); opj_cio_close(cio); return; } // close the byte stream opj_cio_close(cio); // free the memory containing the code-stream free(src); src = NULL; imagetoFile(image, "D:\\RGB.dat");//YUV422格式 // free remaining structures if(dinfo) opj_destroy_decompress(dinfo); // free codestream information structure // if (*indexfilename) // opj_destroy_cstr_info(&cstr_info); // free image data structure opj_image_destroy(image);
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/mao0514/article/details/47258681