From 63c964585c7eaef53266ce79b8d119e3a7438f66 Mon Sep 17 00:00:00 2001 From: openKylinBot Date: Sat, 14 May 2022 02:33:42 +0800 Subject: [PATCH] Import Upstream version 2.3.1 --- .gitignore | 18 + .travis.yml | 158 + AUTHORS.md | 21 + CHANGELOG.md | 683 + CMakeLists.txt | 396 + CTestConfig.cmake | 7 + INSTALL.md | 138 + LICENSE | 39 + NEWS.md | 111 + README.md | 83 + THANKS.md | 39 + appveyor.yml | 41 + cmake/CTestCustom.cmake.in | 40 + cmake/EnsureFileInclude.cmake | 26 + cmake/FindCPPCHECK.cmake | 16 + cmake/FindFCGI.cmake | 20 + cmake/FindJPYLYZER.cmake | 12 + cmake/FindKAKADU.cmake | 24 + cmake/FindLCMS.cmake | 31 + cmake/FindLCMS2.cmake | 31 + cmake/JPIPTestDriver.cmake | 9 + cmake/OpenJPEGCPack.cmake | 72 + cmake/OpenJPEGConfig.cmake.in | 53 + cmake/TestFileOffsetBits.c | 11 + cmake/TestLargeFiles.c.cmake.in | 23 + cmake/TestLargeFiles.cmake | 134 + cmake/TestWindowsFSeek.c | 11 + cmake/openjpeg_valgrind.supp | 39 + doc/CMakeLists.txt | 52 + doc/Doxyfile.dox.cmake.in | 279 + doc/jpip_architect.png | Bin 0 -> 62577 bytes doc/jpip_protocol.png | Bin 0 -> 6376 bytes doc/mainpage.dox.in | 62 + doc/man/man1/opj_compress.1 | 222 + doc/man/man1/opj_decompress.1 | 119 + doc/man/man1/opj_dump.1 | 62 + doc/man/man3/libopenjp2.3 | 337 + doc/openjpip.dox.in | 94 + src/CMakeLists.txt | 12 + src/bin/CMakeLists.txt | 21 + src/bin/common/CMakeLists.txt | 7 + src/bin/common/color.c | 1137 ++ src/bin/common/color.h | 47 + src/bin/common/format_defs.h | 55 + src/bin/common/opj_apps_config.h.cmake.in | 15 + src/bin/common/opj_getopt.c | 277 + src/bin/common/opj_getopt.h | 28 + src/bin/common/opj_string.h | 72 + src/bin/jp2/CMakeLists.txt | 88 + src/bin/jp2/convert.c | 2623 ++++ src/bin/jp2/convert.h | 126 + src/bin/jp2/convertbmp.c | 1135 ++ src/bin/jp2/convertpng.c | 517 + src/bin/jp2/converttif.c | 1508 ++ src/bin/jp2/index.c | 456 + src/bin/jp2/index.h | 54 + src/bin/jp2/opj_compress.c | 2080 +++ src/bin/jp2/opj_decompress.c | 1813 +++ src/bin/jp2/opj_dump.c | 642 + src/bin/jp2/windirent.h | 683 + src/bin/jp3d/CMakeLists.txt | 41 + src/bin/jp3d/convert.c | 1050 ++ src/bin/jp3d/convert.h | 52 + src/bin/jp3d/getopt.c | 119 + src/bin/jp3d/getopt.h | 14 + src/bin/jp3d/opj_jp3d_compress.c | 989 ++ src/bin/jp3d/opj_jp3d_decompress.c | 601 + src/bin/jp3d/tcltk/LPI_JP3D_VM.tcl | 115 + src/bin/jp3d/tcltk/README | 13 + src/bin/jp3d/tcltk/Thumbs.db | Bin 0 -> 18944 bytes src/bin/jp3d/tcltk/decoder.tcl | 272 + src/bin/jp3d/tcltk/encoder.tcl | 470 + src/bin/jp3d/tcltk/logoLPI.gif | Bin 0 -> 5212 bytes src/bin/jp3d/windirent.h | 679 + src/bin/jpip/CMakeLists.txt | 161 + src/bin/jpip/README | 149 + src/bin/jpip/opj_dec_server.c | 98 + src/bin/jpip/opj_jpip_addxml.c | 187 + src/bin/jpip/opj_jpip_test.c | 75 + src/bin/jpip/opj_jpip_transcode.c | 125 + src/bin/jpip/opj_server.c | 131 + src/bin/jpip/opj_viewer/dist/manifest.txt | 4 + src/bin/jpip/opj_viewer/src/ImageManager.java | 136 + src/bin/jpip/opj_viewer/src/ImageViewer.java | 266 + src/bin/jpip/opj_viewer/src/ImageWindow.java | 120 + src/bin/jpip/opj_viewer/src/ImgdecClient.java | 350 + .../jpip/opj_viewer/src/JPIPHttpClient.java | 503 + src/bin/jpip/opj_viewer/src/MML.java | 116 + src/bin/jpip/opj_viewer/src/PnmImage.java | 154 + src/bin/jpip/opj_viewer/src/RegimViewer.java | 114 + .../jpip/opj_viewer/src/ResizeListener.java | 67 + .../opj_viewer_xerces/dist/manifest.txt.in | 5 + .../opj_viewer_xerces/src/ImageViewer.java | 266 + .../opj_viewer_xerces/src/ImageWindow.java | 124 + .../opj_viewer_xerces/src/JP2XMLparser.java | 122 + .../opj_viewer_xerces/src/OptionPanel.java | 98 + src/bin/jpwl/CMakeLists.txt | 62 + src/bin/jpwl/convert.c | 3761 +++++ src/bin/jpwl/convert.h | 90 + src/bin/jpwl/index.c | 454 + src/bin/jpwl/index.h | 54 + src/bin/jpwl/opj_jpwl_compress.c | 1952 +++ src/bin/jpwl/opj_jpwl_decompress.c | 895 ++ src/bin/jpwl/windirent.h | 680 + src/bin/mj2/CMakeLists.txt | 47 + src/bin/mj2/meta_out.c | 2858 ++++ src/bin/mj2/meta_out.h | 14 + src/bin/mj2/mj2_to_metadata.c | 349 + src/bin/mj2/mj2_to_metadata.dtd | 425 + src/bin/mj2/mj2_to_metadata.h | 9 + src/bin/mj2/mj2_to_metadata.sln | 29 + src/bin/mj2/mj2_to_metadata.vcproj | 349 + src/bin/mj2/mj2_to_metadata_Notes.doc | Bin 0 -> 35328 bytes src/bin/mj2/opj_mj2_compress.c | 852 ++ src/bin/mj2/opj_mj2_decompress.c | 258 + src/bin/mj2/opj_mj2_extract.c | 178 + src/bin/mj2/opj_mj2_wrap.c | 537 + src/bin/mj2/readme.txt | 3 + src/bin/wx/CMakeLists.txt | 4 + src/bin/wx/OPJViewer/CMakeLists.txt | 29 + src/bin/wx/OPJViewer/OPJViewer.iss | 48 + src/bin/wx/OPJViewer/Readme.txt | 100 + src/bin/wx/OPJViewer/about/about.htm | 36 + src/bin/wx/OPJViewer/about/opj_logo.png | Bin 0 -> 6500 bytes src/bin/wx/OPJViewer/source/OPJAbout.cpp | 92 + src/bin/wx/OPJViewer/source/OPJChild.ico | Bin 0 -> 1078 bytes src/bin/wx/OPJViewer/source/OPJChild16.xpm | 28 + src/bin/wx/OPJViewer/source/OPJDialogs.cpp | 1378 ++ src/bin/wx/OPJViewer/source/OPJThreads.cpp | 1293 ++ src/bin/wx/OPJViewer/source/OPJViewer.cpp | 1671 +++ src/bin/wx/OPJViewer/source/OPJViewer.h | 869 ++ src/bin/wx/OPJViewer/source/OPJViewer.ico | Bin 0 -> 1078 bytes src/bin/wx/OPJViewer/source/OPJViewer.rc | 3 + src/bin/wx/OPJViewer/source/OPJViewer16.xpm | 26 + src/bin/wx/OPJViewer/source/about_htm.h | 56 + src/bin/wx/OPJViewer/source/build.h | 1 + src/bin/wx/OPJViewer/source/icon1.xpm | 79 + src/bin/wx/OPJViewer/source/icon2.xpm | 53 + src/bin/wx/OPJViewer/source/icon3.xpm | 79 + src/bin/wx/OPJViewer/source/icon4.xpm | 43 + src/bin/wx/OPJViewer/source/icon5.xpm | 79 + src/bin/wx/OPJViewer/source/imagjpeg2000.cpp | 1595 ++ src/bin/wx/OPJViewer/source/imagjpeg2000.h | 184 + src/bin/wx/OPJViewer/source/imagmxf.cpp | 507 + src/bin/wx/OPJViewer/source/imagmxf.h | 106 + src/bin/wx/OPJViewer/source/license.txt | 14 + src/bin/wx/OPJViewer/source/opj_logo.xpm | 285 + src/bin/wx/OPJViewer/source/readmeafter.txt | 34 + src/bin/wx/OPJViewer/source/readmebefore.txt | 11 + src/bin/wx/OPJViewer/source/wxj2kparser.cpp | 1470 ++ src/bin/wx/OPJViewer/source/wxjp2parser.cpp | 1121 ++ src/lib/CMakeLists.txt | 17 + src/lib/openjp2/CMakeLists.txt | 218 + src/lib/openjp2/bench_dwt.c | 273 + src/lib/openjp2/bio.c | 217 + src/lib/openjp2/bio.h | 134 + src/lib/openjp2/cidx_manager.c | 259 + src/lib/openjp2/cidx_manager.h | 70 + src/lib/openjp2/cio.c | 683 + src/lib/openjp2/cio.h | 412 + src/lib/openjp2/dwt.c | 2892 ++++ src/lib/openjp2/dwt.h | 128 + src/lib/openjp2/event.c | 151 + src/lib/openjp2/event.h | 108 + src/lib/openjp2/function_list.c | 117 + src/lib/openjp2/function_list.h | 134 + src/lib/openjp2/image.c | 264 + src/lib/openjp2/image.h | 70 + src/lib/openjp2/indexbox_manager.h | 157 + src/lib/openjp2/invert.c | 295 + src/lib/openjp2/invert.h | 64 + src/lib/openjp2/j2k.c | 12135 ++++++++++++++++ src/lib/openjp2/j2k.h | 880 ++ src/lib/openjp2/jp2.c | 3427 +++++ src/lib/openjp2/jp2.h | 498 + src/lib/openjp2/libopenjp2.pc.cmake.in | 14 + src/lib/openjp2/mct.c | 567 + src/lib/openjp2/mct.h | 159 + src/lib/openjp2/mqc.c | 560 + src/lib/openjp2/mqc.h | 271 + src/lib/openjp2/mqc_inl.h | 196 + src/lib/openjp2/openjpeg.c | 1065 ++ src/lib/openjp2/openjpeg.h | 1691 +++ src/lib/openjp2/opj_clock.c | 67 + src/lib/openjp2/opj_clock.h | 59 + src/lib/openjp2/opj_codec.h | 171 + src/lib/openjp2/opj_common.h | 41 + src/lib/openjp2/opj_config.h.cmake.in | 10 + src/lib/openjp2/opj_config_private.h.cmake.in | 49 + src/lib/openjp2/opj_includes.h | 265 + src/lib/openjp2/opj_intmath.h | 274 + src/lib/openjp2/opj_inttypes.h | 48 + src/lib/openjp2/opj_malloc.c | 249 + src/lib/openjp2/opj_malloc.h | 106 + src/lib/openjp2/opj_stdint.h | 52 + src/lib/openjp2/phix_manager.c | 210 + src/lib/openjp2/pi.c | 2089 +++ src/lib/openjp2/pi.h | 190 + src/lib/openjp2/ppix_manager.c | 215 + src/lib/openjp2/sparse_array.c | 346 + src/lib/openjp2/sparse_array.h | 141 + src/lib/openjp2/t1.c | 2428 ++++ src/lib/openjp2/t1.h | 269 + src/lib/openjp2/t1_generate_luts.c | 311 + src/lib/openjp2/t1_luts.h | 175 + src/lib/openjp2/t2.c | 1571 ++ src/lib/openjp2/t2.h | 140 + src/lib/openjp2/tcd.c | 2804 ++++ src/lib/openjp2/tcd.h | 486 + src/lib/openjp2/test_sparse_array.c | 174 + src/lib/openjp2/tgt.c | 344 + src/lib/openjp2/tgt.h | 148 + src/lib/openjp2/thix_manager.c | 146 + src/lib/openjp2/thread.c | 954 ++ src/lib/openjp2/thread.h | 256 + src/lib/openjp2/tls_keys.h | 37 + src/lib/openjp2/tpix_manager.c | 190 + src/lib/openjp3d/CMakeLists.txt | 45 + src/lib/openjp3d/bio.c | 207 + src/lib/openjp3d/bio.h | 137 + src/lib/openjp3d/cio.c | 240 + src/lib/openjp3d/cio.h | 105 + src/lib/openjp3d/dwt.c | 1158 ++ src/lib/openjp3d/dwt.h | 106 + src/lib/openjp3d/event.c | 189 + src/lib/openjp3d/event.h | 63 + src/lib/openjp3d/fix.h | 68 + src/lib/openjp3d/int.h | 138 + src/lib/openjp3d/jp3d.c | 2559 ++++ src/lib/openjp3d/jp3d.h | 525 + src/lib/openjp3d/jp3d_lib.c | 85 + src/lib/openjp3d/jp3d_lib.h | 80 + src/lib/openjp3d/libopenjp3d.pc.cmake.in | 14 + src/lib/openjp3d/mct.c | 142 + src/lib/openjp3d/mct.h | 102 + src/lib/openjp3d/mqc.c | 585 + src/lib/openjp3d/mqc.h | 206 + src/lib/openjp3d/openjp3d.c | 234 + src/lib/openjp3d/openjp3d.h | 736 + src/lib/openjp3d/opj_includes.h | 83 + src/lib/openjp3d/pi.c | 709 + src/lib/openjp3d/pi.h | 150 + src/lib/openjp3d/raw.c | 96 + src/lib/openjp3d/raw.h | 104 + src/lib/openjp3d/t1.c | 1294 ++ src/lib/openjp3d/t1.h | 179 + src/lib/openjp3d/t1_3d.c | 1366 ++ src/lib/openjp3d/t1_3d.h | 173 + src/lib/openjp3d/t2.c | 730 + src/lib/openjp3d/t2.h | 108 + src/lib/openjp3d/tcd.c | 1948 +++ src/lib/openjp3d/tcd.h | 343 + src/lib/openjp3d/tgt.c | 271 + src/lib/openjp3d/tgt.h | 131 + src/lib/openjp3d/volume.c | 101 + src/lib/openjp3d/volume.h | 48 + src/lib/openjpip/CMakeLists.txt | 91 + src/lib/openjpip/auxtrans_manager.c | 287 + src/lib/openjpip/auxtrans_manager.h | 74 + src/lib/openjpip/box_manager.c | 447 + src/lib/openjpip/box_manager.h | 267 + src/lib/openjpip/boxheader_manager.c | 85 + src/lib/openjpip/boxheader_manager.h | 73 + src/lib/openjpip/byte_manager.c | 177 + src/lib/openjpip/byte_manager.h | 130 + src/lib/openjpip/cache_manager.c | 294 + src/lib/openjpip/cache_manager.h | 181 + src/lib/openjpip/cachemodel_manager.c | 251 + src/lib/openjpip/cachemodel_manager.h | 116 + src/lib/openjpip/channel_manager.c | 192 + src/lib/openjpip/channel_manager.h | 125 + src/lib/openjpip/codestream_manager.c | 82 + src/lib/openjpip/codestream_manager.h | 104 + src/lib/openjpip/dec_clientmsg_handler.c | 273 + src/lib/openjpip/dec_clientmsg_handler.h | 120 + src/lib/openjpip/faixbox_manager.c | 216 + src/lib/openjpip/faixbox_manager.h | 148 + src/lib/openjpip/ihdrbox_manager.c | 81 + src/lib/openjpip/ihdrbox_manager.h | 57 + src/lib/openjpip/imgreg_manager.c | 161 + src/lib/openjpip/imgreg_manager.h | 102 + src/lib/openjpip/imgsock_manager.c | 225 + src/lib/openjpip/imgsock_manager.h | 180 + src/lib/openjpip/index_manager.c | 791 + src/lib/openjpip/index_manager.h | 195 + src/lib/openjpip/j2kheader_manager.c | 325 + src/lib/openjpip/j2kheader_manager.h | 75 + src/lib/openjpip/jp2k_decoder.c | 250 + src/lib/openjpip/jp2k_decoder.h | 39 + src/lib/openjpip/jp2k_encoder.c | 911 ++ src/lib/openjpip/jp2k_encoder.h | 77 + src/lib/openjpip/jpip_parser.c | 512 + src/lib/openjpip/jpip_parser.h | 114 + src/lib/openjpip/jpipstream_manager.c | 140 + src/lib/openjpip/jpipstream_manager.h | 44 + src/lib/openjpip/libopenjpip.pc.cmake.in | 15 + src/lib/openjpip/manfbox_manager.c | 117 + src/lib/openjpip/manfbox_manager.h | 81 + src/lib/openjpip/marker_manager.c | 69 + src/lib/openjpip/marker_manager.h | 87 + src/lib/openjpip/metadata_manager.c | 263 + src/lib/openjpip/metadata_manager.h | 155 + src/lib/openjpip/mhixbox_manager.c | 144 + src/lib/openjpip/mhixbox_manager.h | 102 + src/lib/openjpip/msgqueue_manager.c | 819 ++ src/lib/openjpip/msgqueue_manager.h | 194 + src/lib/openjpip/openjpip.c | 484 + src/lib/openjpip/openjpip.h | 312 + src/lib/openjpip/placeholder_manager.c | 151 + src/lib/openjpip/placeholder_manager.h | 116 + src/lib/openjpip/query_parser.c | 472 + src/lib/openjpip/query_parser.h | 98 + src/lib/openjpip/session_manager.c | 205 + src/lib/openjpip/session_manager.h | 117 + src/lib/openjpip/sock_manager.c | 187 + src/lib/openjpip/sock_manager.h | 106 + src/lib/openjpip/target_manager.c | 358 + src/lib/openjpip/target_manager.h | 163 + src/lib/openjpwl/CMakeLists.txt | 64 + src/lib/openjpwl/README.txt | 136 + src/lib/openjpwl/crc.c | 167 + src/lib/openjpwl/crc.h | 89 + src/lib/openjpwl/jpwl.c | 1458 ++ src/lib/openjpwl/jpwl.h | 438 + src/lib/openjpwl/jpwl_lib.c | 1944 +++ src/lib/openjpwl/libopenjpwl.pc.cmake.in | 15 + src/lib/openjpwl/rs.c | 625 + src/lib/openjpwl/rs.h | 113 + src/lib/openmj2/CMakeLists.txt | 64 + src/lib/openmj2/bio.c | 206 + src/lib/openmj2/bio.h | 131 + src/lib/openmj2/cio.c | 214 + src/lib/openmj2/cio.h | 100 + src/lib/openmj2/dwt.c | 965 ++ src/lib/openmj2/dwt.h | 119 + src/lib/openmj2/event.c | 137 + src/lib/openmj2/event.h | 64 + src/lib/openmj2/fix.h | 71 + src/lib/openmj2/image.c | 99 + src/lib/openmj2/image.h | 53 + src/lib/openmj2/int.h | 135 + src/lib/openmj2/j2k.c | 2778 ++++ src/lib/openmj2/j2k.h | 456 + src/lib/openmj2/j2k_lib.c | 65 + src/lib/openmj2/j2k_lib.h | 59 + src/lib/openmj2/jp2.c | 1215 ++ src/lib/openmj2/jp2.h | 234 + src/lib/openmj2/jpt.c | 168 + src/lib/openmj2/jpt.h | 81 + src/lib/openmj2/mct.c | 198 + src/lib/openmj2/mct.h | 104 + src/lib/openmj2/mj2.c | 3081 ++++ src/lib/openmj2/mj2.h | 396 + src/lib/openmj2/mj2_convert.c | 384 + src/lib/openmj2/mj2_convert.h | 47 + src/lib/openmj2/mqc.c | 629 + src/lib/openmj2/mqc.h | 206 + src/lib/openmj2/openjpeg.c | 389 + src/lib/openmj2/openjpeg.h | 958 ++ src/lib/openmj2/opj_includes.h | 143 + src/lib/openmj2/opj_malloc.h | 166 + src/lib/openmj2/pi.c | 1056 ++ src/lib/openmj2/pi.h | 165 + src/lib/openmj2/raw.c | 98 + src/lib/openmj2/raw.h | 106 + src/lib/openmj2/t1.c | 1628 +++ src/lib/openmj2/t1.h | 153 + src/lib/openmj2/t1_luts.h | 143 + src/lib/openmj2/t2.c | 884 ++ src/lib/openmj2/t2.h | 114 + src/lib/openmj2/tcd.c | 1663 +++ src/lib/openmj2/tcd.h | 305 + src/lib/openmj2/tgt.c | 231 + src/lib/openmj2/tgt.h | 121 + tests/CMakeLists.txt | 133 + tests/compare_dump_files.c | 184 + tests/compare_images.c | 952 ++ tests/compare_raw_files.c | 193 + tests/conformance/CMakeLists.txt | 708 + tests/fuzzers/GNUmakefile | 12 + tests/fuzzers/README.TXT | 52 + tests/fuzzers/build_google_oss_fuzzers.sh | 39 + tests/fuzzers/build_seed_corpus.sh | 15 + tests/fuzzers/fuzzingengine.c | 72 + tests/fuzzers/opj_decompress_fuzzer.cpp | 208 + tests/include_openjpeg.c | 9 + tests/j2k_random_tile_access.c | 292 + tests/nonregression/CMakeLists.txt | 448 + tests/nonregression/checkmd5refs.cmake | 56 + tests/nonregression/md5refs.txt | 320 + tests/nonregression/test_suite.ctest.in | 632 + tests/pdf2jp2.c | 142 + tests/performance/compare_perfs.py | 120 + tests/performance/perf_test.py | 140 + tests/performance/perf_test_filelist.csv | 7 + tests/ppm2rgb3.c | 139 + tests/profiling/filter_massif_output.py | 41 + tests/test_decode_area.c | 569 + tests/test_tile_decoder.c | 356 + tests/test_tile_encoder.c | 389 + tests/unit/CMakeLists.txt | 17 + tests/unit/testempty0.c | 7 + tests/unit/testempty1.c | 137 + tests/unit/testempty2.c | 183 + thirdparty/CMakeLists.txt | 124 + thirdparty/README.txt | 9 + thirdparty/include/zconf.h | 511 + thirdparty/include/zlib.h | 1768 +++ thirdparty/liblcms2/CMakeLists.txt | 20 + thirdparty/liblcms2/COPYING | 8 + thirdparty/liblcms2/include/lcms2.h | 1903 +++ thirdparty/liblcms2/include/lcms2_plugin.h | 665 + thirdparty/liblcms2/src/cmsalpha.c | 518 + thirdparty/liblcms2/src/cmscam02.c | 486 + thirdparty/liblcms2/src/cmscgats.c | 2775 ++++ thirdparty/liblcms2/src/cmscnvrt.c | 1161 ++ thirdparty/liblcms2/src/cmserr.c | 661 + thirdparty/liblcms2/src/cmsgamma.c | 1275 ++ thirdparty/liblcms2/src/cmsgmt.c | 590 + thirdparty/liblcms2/src/cmshalf.c | 535 + thirdparty/liblcms2/src/cmsintrp.c | 1506 ++ thirdparty/liblcms2/src/cmsio0.c | 1928 +++ thirdparty/liblcms2/src/cmsio1.c | 1029 ++ thirdparty/liblcms2/src/cmslut.c | 1812 +++ thirdparty/liblcms2/src/cmsmd5.c | 317 + thirdparty/liblcms2/src/cmsmtrx.c | 176 + thirdparty/liblcms2/src/cmsnamed.c | 956 ++ thirdparty/liblcms2/src/cmsopt.c | 1938 +++ thirdparty/liblcms2/src/cmspack.c | 3354 +++++ thirdparty/liblcms2/src/cmspcs.c | 940 ++ thirdparty/liblcms2/src/cmsplugin.c | 950 ++ thirdparty/liblcms2/src/cmsps2.c | 1598 ++ thirdparty/liblcms2/src/cmssamp.c | 547 + thirdparty/liblcms2/src/cmssm.c | 736 + thirdparty/liblcms2/src/cmstypes.c | 5573 +++++++ thirdparty/liblcms2/src/cmsvirt.c | 1208 ++ thirdparty/liblcms2/src/cmswtpnt.c | 351 + thirdparty/liblcms2/src/cmsxform.c | 1328 ++ thirdparty/liblcms2/src/lcms2_internal.h | 1057 ++ thirdparty/libpng/CMakeLists.txt | 29 + thirdparty/libpng/LICENSE | 130 + thirdparty/libpng/png.c | 4533 ++++++ thirdparty/libpng/png.h | 3266 +++++ thirdparty/libpng/pngconf.h | 622 + thirdparty/libpng/pngdebug.h | 153 + thirdparty/libpng/pngerror.c | 963 ++ thirdparty/libpng/pngget.c | 1219 ++ thirdparty/libpng/pnginfo.h | 259 + thirdparty/libpng/pnglibconf.h | 215 + thirdparty/libpng/pngmem.c | 284 + thirdparty/libpng/pngpread.c | 1090 ++ thirdparty/libpng/pngpriv.h | 1989 +++ thirdparty/libpng/pngread.c | 4194 ++++++ thirdparty/libpng/pngrio.c | 120 + thirdparty/libpng/pngrtran.c | 5000 +++++++ thirdparty/libpng/pngrutil.c | 4531 ++++++ thirdparty/libpng/pngset.c | 1737 +++ thirdparty/libpng/pngstruct.h | 483 + thirdparty/libpng/pngtrans.c | 850 ++ thirdparty/libpng/pngwio.c | 168 + thirdparty/libpng/pngwrite.c | 2383 +++ thirdparty/libpng/pngwtran.c | 576 + thirdparty/libpng/pngwutil.c | 2755 ++++ thirdparty/libtiff/CMakeLists.txt | 278 + thirdparty/libtiff/libport.h | 60 + thirdparty/libtiff/libtiff.def | 164 + thirdparty/libtiff/snprintf.c | 38 + thirdparty/libtiff/t4.h | 292 + thirdparty/libtiff/test_inline.c | 5 + thirdparty/libtiff/tif_aux.c | 358 + thirdparty/libtiff/tif_close.c | 140 + thirdparty/libtiff/tif_codec.c | 165 + thirdparty/libtiff/tif_color.c | 287 + thirdparty/libtiff/tif_compress.c | 304 + thirdparty/libtiff/tif_config.h.cmake.in | 261 + thirdparty/libtiff/tif_config.h.in | 410 + thirdparty/libtiff/tif_dir.c | 1705 +++ thirdparty/libtiff/tif_dir.h | 308 + thirdparty/libtiff/tif_dirinfo.c | 959 ++ thirdparty/libtiff/tif_dirread.c | 5614 +++++++ thirdparty/libtiff/tif_dirwrite.c | 2911 ++++ thirdparty/libtiff/tif_dumpmode.c | 143 + thirdparty/libtiff/tif_error.c | 80 + thirdparty/libtiff/tif_extension.c | 118 + thirdparty/libtiff/tif_fax3.c | 1596 ++ thirdparty/libtiff/tif_fax3.h | 538 + thirdparty/libtiff/tif_fax3sm.c | 1260 ++ thirdparty/libtiff/tif_flush.c | 118 + thirdparty/libtiff/tif_getimage.c | 2928 ++++ thirdparty/libtiff/tif_jbig.c | 213 + thirdparty/libtiff/tif_jpeg.c | 2421 +++ thirdparty/libtiff/tif_jpeg_12.c | 65 + thirdparty/libtiff/tif_luv.c | 1697 +++ thirdparty/libtiff/tif_lzma.c | 495 + thirdparty/libtiff/tif_lzw.c | 1178 ++ thirdparty/libtiff/tif_next.c | 181 + thirdparty/libtiff/tif_ojpeg.c | 2507 ++++ thirdparty/libtiff/tif_open.c | 725 + thirdparty/libtiff/tif_packbits.c | 300 + thirdparty/libtiff/tif_pixarlog.c | 1442 ++ thirdparty/libtiff/tif_predict.c | 794 + thirdparty/libtiff/tif_predict.h | 77 + thirdparty/libtiff/tif_print.c | 716 + thirdparty/libtiff/tif_read.c | 1094 ++ thirdparty/libtiff/tif_stream.cxx | 430 + thirdparty/libtiff/tif_strip.c | 389 + thirdparty/libtiff/tif_swab.c | 310 + thirdparty/libtiff/tif_thunder.c | 207 + thirdparty/libtiff/tif_tile.c | 322 + thirdparty/libtiff/tif_unix.c | 378 + thirdparty/libtiff/tif_version.c | 40 + thirdparty/libtiff/tif_warning.c | 81 + thirdparty/libtiff/tif_win32.c | 468 + thirdparty/libtiff/tif_write.c | 793 + thirdparty/libtiff/tif_zip.c | 472 + thirdparty/libtiff/tiff.h | 681 + thirdparty/libtiff/tiffconf.h.cmake.in | 115 + thirdparty/libtiff/tiffconf.h.in | 127 + thirdparty/libtiff/tiffio.h | 557 + thirdparty/libtiff/tiffio.hxx | 49 + thirdparty/libtiff/tiffiop.h | 420 + thirdparty/libtiff/tiffvers.h | 9 + thirdparty/libtiff/uvcode.h | 180 + thirdparty/libz/CMakeLists.txt | 102 + thirdparty/libz/adler32.c | 179 + thirdparty/libz/compress.c | 80 + thirdparty/libz/crc32.c | 425 + thirdparty/libz/crc32.h | 441 + thirdparty/libz/deflate.c | 1967 +++ thirdparty/libz/deflate.h | 346 + thirdparty/libz/gzclose.c | 25 + thirdparty/libz/gzguts.h | 209 + thirdparty/libz/gzlib.c | 634 + thirdparty/libz/gzread.c | 594 + thirdparty/libz/gzwrite.c | 577 + thirdparty/libz/infback.c | 640 + thirdparty/libz/inffast.c | 340 + thirdparty/libz/inffast.h | 11 + thirdparty/libz/inffixed.h | 94 + thirdparty/libz/inflate.c | 1512 ++ thirdparty/libz/inflate.h | 122 + thirdparty/libz/inftrees.c | 306 + thirdparty/libz/inftrees.h | 62 + thirdparty/libz/trees.c | 1226 ++ thirdparty/libz/trees.h | 128 + thirdparty/libz/uncompr.c | 59 + thirdparty/libz/zlib.h | 1768 +++ thirdparty/libz/zutil.c | 324 + thirdparty/libz/zutil.h | 253 + tools/abi-tracker/openjpeg.json | 144 + tools/ctest_scripts/toolchain-mingw32.cmake | 26 + tools/ctest_scripts/toolchain-mingw64.cmake | 26 + tools/ctest_scripts/travis-ci.cmake | 168 + tools/travis-ci/abi-check.sh | 144 + tools/travis-ci/detect-avx2.c | 152 + tools/travis-ci/install.sh | 121 + ...untu12.04-gcc4.6.3-x86_64-Release-3rdP.txt | 8 + ...tu14.04-clang3.8.0-x86_64-Release-3rdP.txt | 8 + ...Ubuntu14.04-gcc4.8.4-i386-Release-3rdP.txt | 56 + ...Ubuntu14.04-gcc4.8.4-x86_64-Debug-3rdP.txt | 8 + tools/travis-ci/knownfailures-all.txt | 2 + ...ilures-windows-vs2010-x86-Release-3rdP.txt | 46 + tools/travis-ci/run.sh | 413 + tools/travis-ci/travis_rsa.enc | Bin 0 -> 3248 bytes wrapping/CMakeLists.txt | 4 + wrapping/java/CMakeLists.txt | 2 + wrapping/java/openjp2/CMakeLists.txt | 73 + wrapping/java/openjp2/JavaOpenJPEG.c | 2141 +++ wrapping/java/openjp2/JavaOpenJPEGDecoder.c | 885 ++ wrapping/java/openjp2/index.c | 391 + wrapping/java/openjp2/index.h | 49 + .../org/openJpeg/OpenJPEGJavaDecoder.java | 250 + .../org/openJpeg/OpenJPEGJavaEncoder.java | 338 + .../org_openJpeg_OpenJPEGJavaDecoder.h | 21 + .../org_openJpeg_OpenJPEGJavaEncoder.h | 21 + 575 files changed, 290530 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 AUTHORS.md create mode 100644 CHANGELOG.md create mode 100644 CMakeLists.txt create mode 100644 CTestConfig.cmake create mode 100644 INSTALL.md create mode 100644 LICENSE create mode 100644 NEWS.md create mode 100644 README.md create mode 100644 THANKS.md create mode 100644 appveyor.yml create mode 100644 cmake/CTestCustom.cmake.in create mode 100644 cmake/EnsureFileInclude.cmake create mode 100644 cmake/FindCPPCHECK.cmake create mode 100644 cmake/FindFCGI.cmake create mode 100644 cmake/FindJPYLYZER.cmake create mode 100644 cmake/FindKAKADU.cmake create mode 100644 cmake/FindLCMS.cmake create mode 100644 cmake/FindLCMS2.cmake create mode 100644 cmake/JPIPTestDriver.cmake create mode 100644 cmake/OpenJPEGCPack.cmake create mode 100644 cmake/OpenJPEGConfig.cmake.in create mode 100644 cmake/TestFileOffsetBits.c create mode 100644 cmake/TestLargeFiles.c.cmake.in create mode 100644 cmake/TestLargeFiles.cmake create mode 100644 cmake/TestWindowsFSeek.c create mode 100644 cmake/openjpeg_valgrind.supp create mode 100644 doc/CMakeLists.txt create mode 100644 doc/Doxyfile.dox.cmake.in create mode 100644 doc/jpip_architect.png create mode 100644 doc/jpip_protocol.png create mode 100644 doc/mainpage.dox.in create mode 100644 doc/man/man1/opj_compress.1 create mode 100644 doc/man/man1/opj_decompress.1 create mode 100644 doc/man/man1/opj_dump.1 create mode 100644 doc/man/man3/libopenjp2.3 create mode 100644 doc/openjpip.dox.in create mode 100644 src/CMakeLists.txt create mode 100644 src/bin/CMakeLists.txt create mode 100644 src/bin/common/CMakeLists.txt create mode 100644 src/bin/common/color.c create mode 100644 src/bin/common/color.h create mode 100644 src/bin/common/format_defs.h create mode 100644 src/bin/common/opj_apps_config.h.cmake.in create mode 100644 src/bin/common/opj_getopt.c create mode 100644 src/bin/common/opj_getopt.h create mode 100644 src/bin/common/opj_string.h create mode 100644 src/bin/jp2/CMakeLists.txt create mode 100644 src/bin/jp2/convert.c create mode 100644 src/bin/jp2/convert.h create mode 100644 src/bin/jp2/convertbmp.c create mode 100644 src/bin/jp2/convertpng.c create mode 100644 src/bin/jp2/converttif.c create mode 100644 src/bin/jp2/index.c create mode 100644 src/bin/jp2/index.h create mode 100644 src/bin/jp2/opj_compress.c create mode 100644 src/bin/jp2/opj_decompress.c create mode 100644 src/bin/jp2/opj_dump.c create mode 100644 src/bin/jp2/windirent.h create mode 100644 src/bin/jp3d/CMakeLists.txt create mode 100644 src/bin/jp3d/convert.c create mode 100644 src/bin/jp3d/convert.h create mode 100644 src/bin/jp3d/getopt.c create mode 100644 src/bin/jp3d/getopt.h create mode 100644 src/bin/jp3d/opj_jp3d_compress.c create mode 100644 src/bin/jp3d/opj_jp3d_decompress.c create mode 100755 src/bin/jp3d/tcltk/LPI_JP3D_VM.tcl create mode 100644 src/bin/jp3d/tcltk/README create mode 100755 src/bin/jp3d/tcltk/Thumbs.db create mode 100755 src/bin/jp3d/tcltk/decoder.tcl create mode 100755 src/bin/jp3d/tcltk/encoder.tcl create mode 100755 src/bin/jp3d/tcltk/logoLPI.gif create mode 100644 src/bin/jp3d/windirent.h create mode 100644 src/bin/jpip/CMakeLists.txt create mode 100644 src/bin/jpip/README create mode 100644 src/bin/jpip/opj_dec_server.c create mode 100644 src/bin/jpip/opj_jpip_addxml.c create mode 100644 src/bin/jpip/opj_jpip_test.c create mode 100644 src/bin/jpip/opj_jpip_transcode.c create mode 100644 src/bin/jpip/opj_server.c create mode 100644 src/bin/jpip/opj_viewer/dist/manifest.txt create mode 100644 src/bin/jpip/opj_viewer/src/ImageManager.java create mode 100644 src/bin/jpip/opj_viewer/src/ImageViewer.java create mode 100644 src/bin/jpip/opj_viewer/src/ImageWindow.java create mode 100644 src/bin/jpip/opj_viewer/src/ImgdecClient.java create mode 100644 src/bin/jpip/opj_viewer/src/JPIPHttpClient.java create mode 100644 src/bin/jpip/opj_viewer/src/MML.java create mode 100644 src/bin/jpip/opj_viewer/src/PnmImage.java create mode 100644 src/bin/jpip/opj_viewer/src/RegimViewer.java create mode 100644 src/bin/jpip/opj_viewer/src/ResizeListener.java create mode 100644 src/bin/jpip/opj_viewer_xerces/dist/manifest.txt.in create mode 100644 src/bin/jpip/opj_viewer_xerces/src/ImageViewer.java create mode 100644 src/bin/jpip/opj_viewer_xerces/src/ImageWindow.java create mode 100644 src/bin/jpip/opj_viewer_xerces/src/JP2XMLparser.java create mode 100644 src/bin/jpip/opj_viewer_xerces/src/OptionPanel.java create mode 100644 src/bin/jpwl/CMakeLists.txt create mode 100644 src/bin/jpwl/convert.c create mode 100644 src/bin/jpwl/convert.h create mode 100644 src/bin/jpwl/index.c create mode 100644 src/bin/jpwl/index.h create mode 100644 src/bin/jpwl/opj_jpwl_compress.c create mode 100644 src/bin/jpwl/opj_jpwl_decompress.c create mode 100644 src/bin/jpwl/windirent.h create mode 100644 src/bin/mj2/CMakeLists.txt create mode 100644 src/bin/mj2/meta_out.c create mode 100644 src/bin/mj2/meta_out.h create mode 100644 src/bin/mj2/mj2_to_metadata.c create mode 100644 src/bin/mj2/mj2_to_metadata.dtd create mode 100644 src/bin/mj2/mj2_to_metadata.h create mode 100644 src/bin/mj2/mj2_to_metadata.sln create mode 100644 src/bin/mj2/mj2_to_metadata.vcproj create mode 100644 src/bin/mj2/mj2_to_metadata_Notes.doc create mode 100644 src/bin/mj2/opj_mj2_compress.c create mode 100644 src/bin/mj2/opj_mj2_decompress.c create mode 100644 src/bin/mj2/opj_mj2_extract.c create mode 100644 src/bin/mj2/opj_mj2_wrap.c create mode 100644 src/bin/mj2/readme.txt create mode 100644 src/bin/wx/CMakeLists.txt create mode 100644 src/bin/wx/OPJViewer/CMakeLists.txt create mode 100644 src/bin/wx/OPJViewer/OPJViewer.iss create mode 100644 src/bin/wx/OPJViewer/Readme.txt create mode 100644 src/bin/wx/OPJViewer/about/about.htm create mode 100644 src/bin/wx/OPJViewer/about/opj_logo.png create mode 100644 src/bin/wx/OPJViewer/source/OPJAbout.cpp create mode 100644 src/bin/wx/OPJViewer/source/OPJChild.ico create mode 100644 src/bin/wx/OPJViewer/source/OPJChild16.xpm create mode 100644 src/bin/wx/OPJViewer/source/OPJDialogs.cpp create mode 100644 src/bin/wx/OPJViewer/source/OPJThreads.cpp create mode 100644 src/bin/wx/OPJViewer/source/OPJViewer.cpp create mode 100644 src/bin/wx/OPJViewer/source/OPJViewer.h create mode 100644 src/bin/wx/OPJViewer/source/OPJViewer.ico create mode 100644 src/bin/wx/OPJViewer/source/OPJViewer.rc create mode 100644 src/bin/wx/OPJViewer/source/OPJViewer16.xpm create mode 100644 src/bin/wx/OPJViewer/source/about_htm.h create mode 100644 src/bin/wx/OPJViewer/source/build.h create mode 100644 src/bin/wx/OPJViewer/source/icon1.xpm create mode 100644 src/bin/wx/OPJViewer/source/icon2.xpm create mode 100644 src/bin/wx/OPJViewer/source/icon3.xpm create mode 100644 src/bin/wx/OPJViewer/source/icon4.xpm create mode 100644 src/bin/wx/OPJViewer/source/icon5.xpm create mode 100644 src/bin/wx/OPJViewer/source/imagjpeg2000.cpp create mode 100644 src/bin/wx/OPJViewer/source/imagjpeg2000.h create mode 100644 src/bin/wx/OPJViewer/source/imagmxf.cpp create mode 100644 src/bin/wx/OPJViewer/source/imagmxf.h create mode 100644 src/bin/wx/OPJViewer/source/license.txt create mode 100644 src/bin/wx/OPJViewer/source/opj_logo.xpm create mode 100644 src/bin/wx/OPJViewer/source/readmeafter.txt create mode 100644 src/bin/wx/OPJViewer/source/readmebefore.txt create mode 100644 src/bin/wx/OPJViewer/source/wxj2kparser.cpp create mode 100644 src/bin/wx/OPJViewer/source/wxjp2parser.cpp create mode 100644 src/lib/CMakeLists.txt create mode 100644 src/lib/openjp2/CMakeLists.txt create mode 100644 src/lib/openjp2/bench_dwt.c create mode 100644 src/lib/openjp2/bio.c create mode 100644 src/lib/openjp2/bio.h create mode 100644 src/lib/openjp2/cidx_manager.c create mode 100644 src/lib/openjp2/cidx_manager.h create mode 100644 src/lib/openjp2/cio.c create mode 100644 src/lib/openjp2/cio.h create mode 100644 src/lib/openjp2/dwt.c create mode 100644 src/lib/openjp2/dwt.h create mode 100644 src/lib/openjp2/event.c create mode 100644 src/lib/openjp2/event.h create mode 100644 src/lib/openjp2/function_list.c create mode 100644 src/lib/openjp2/function_list.h create mode 100644 src/lib/openjp2/image.c create mode 100644 src/lib/openjp2/image.h create mode 100644 src/lib/openjp2/indexbox_manager.h create mode 100644 src/lib/openjp2/invert.c create mode 100644 src/lib/openjp2/invert.h create mode 100644 src/lib/openjp2/j2k.c create mode 100644 src/lib/openjp2/j2k.h create mode 100644 src/lib/openjp2/jp2.c create mode 100644 src/lib/openjp2/jp2.h create mode 100644 src/lib/openjp2/libopenjp2.pc.cmake.in create mode 100644 src/lib/openjp2/mct.c create mode 100644 src/lib/openjp2/mct.h create mode 100644 src/lib/openjp2/mqc.c create mode 100644 src/lib/openjp2/mqc.h create mode 100644 src/lib/openjp2/mqc_inl.h create mode 100644 src/lib/openjp2/openjpeg.c create mode 100644 src/lib/openjp2/openjpeg.h create mode 100644 src/lib/openjp2/opj_clock.c create mode 100644 src/lib/openjp2/opj_clock.h create mode 100644 src/lib/openjp2/opj_codec.h create mode 100644 src/lib/openjp2/opj_common.h create mode 100644 src/lib/openjp2/opj_config.h.cmake.in create mode 100644 src/lib/openjp2/opj_config_private.h.cmake.in create mode 100644 src/lib/openjp2/opj_includes.h create mode 100644 src/lib/openjp2/opj_intmath.h create mode 100644 src/lib/openjp2/opj_inttypes.h create mode 100644 src/lib/openjp2/opj_malloc.c create mode 100644 src/lib/openjp2/opj_malloc.h create mode 100644 src/lib/openjp2/opj_stdint.h create mode 100644 src/lib/openjp2/phix_manager.c create mode 100644 src/lib/openjp2/pi.c create mode 100644 src/lib/openjp2/pi.h create mode 100644 src/lib/openjp2/ppix_manager.c create mode 100644 src/lib/openjp2/sparse_array.c create mode 100644 src/lib/openjp2/sparse_array.h create mode 100644 src/lib/openjp2/t1.c create mode 100644 src/lib/openjp2/t1.h create mode 100644 src/lib/openjp2/t1_generate_luts.c create mode 100644 src/lib/openjp2/t1_luts.h create mode 100644 src/lib/openjp2/t2.c create mode 100644 src/lib/openjp2/t2.h create mode 100644 src/lib/openjp2/tcd.c create mode 100644 src/lib/openjp2/tcd.h create mode 100644 src/lib/openjp2/test_sparse_array.c create mode 100644 src/lib/openjp2/tgt.c create mode 100644 src/lib/openjp2/tgt.h create mode 100644 src/lib/openjp2/thix_manager.c create mode 100644 src/lib/openjp2/thread.c create mode 100644 src/lib/openjp2/thread.h create mode 100644 src/lib/openjp2/tls_keys.h create mode 100644 src/lib/openjp2/tpix_manager.c create mode 100644 src/lib/openjp3d/CMakeLists.txt create mode 100644 src/lib/openjp3d/bio.c create mode 100644 src/lib/openjp3d/bio.h create mode 100644 src/lib/openjp3d/cio.c create mode 100644 src/lib/openjp3d/cio.h create mode 100644 src/lib/openjp3d/dwt.c create mode 100644 src/lib/openjp3d/dwt.h create mode 100644 src/lib/openjp3d/event.c create mode 100644 src/lib/openjp3d/event.h create mode 100644 src/lib/openjp3d/fix.h create mode 100644 src/lib/openjp3d/int.h create mode 100644 src/lib/openjp3d/jp3d.c create mode 100644 src/lib/openjp3d/jp3d.h create mode 100644 src/lib/openjp3d/jp3d_lib.c create mode 100644 src/lib/openjp3d/jp3d_lib.h create mode 100644 src/lib/openjp3d/libopenjp3d.pc.cmake.in create mode 100644 src/lib/openjp3d/mct.c create mode 100644 src/lib/openjp3d/mct.h create mode 100644 src/lib/openjp3d/mqc.c create mode 100644 src/lib/openjp3d/mqc.h create mode 100644 src/lib/openjp3d/openjp3d.c create mode 100644 src/lib/openjp3d/openjp3d.h create mode 100644 src/lib/openjp3d/opj_includes.h create mode 100644 src/lib/openjp3d/pi.c create mode 100644 src/lib/openjp3d/pi.h create mode 100644 src/lib/openjp3d/raw.c create mode 100644 src/lib/openjp3d/raw.h create mode 100644 src/lib/openjp3d/t1.c create mode 100644 src/lib/openjp3d/t1.h create mode 100644 src/lib/openjp3d/t1_3d.c create mode 100644 src/lib/openjp3d/t1_3d.h create mode 100644 src/lib/openjp3d/t2.c create mode 100644 src/lib/openjp3d/t2.h create mode 100644 src/lib/openjp3d/tcd.c create mode 100644 src/lib/openjp3d/tcd.h create mode 100644 src/lib/openjp3d/tgt.c create mode 100644 src/lib/openjp3d/tgt.h create mode 100644 src/lib/openjp3d/volume.c create mode 100644 src/lib/openjp3d/volume.h create mode 100644 src/lib/openjpip/CMakeLists.txt create mode 100644 src/lib/openjpip/auxtrans_manager.c create mode 100644 src/lib/openjpip/auxtrans_manager.h create mode 100644 src/lib/openjpip/box_manager.c create mode 100644 src/lib/openjpip/box_manager.h create mode 100644 src/lib/openjpip/boxheader_manager.c create mode 100644 src/lib/openjpip/boxheader_manager.h create mode 100644 src/lib/openjpip/byte_manager.c create mode 100644 src/lib/openjpip/byte_manager.h create mode 100644 src/lib/openjpip/cache_manager.c create mode 100644 src/lib/openjpip/cache_manager.h create mode 100644 src/lib/openjpip/cachemodel_manager.c create mode 100644 src/lib/openjpip/cachemodel_manager.h create mode 100644 src/lib/openjpip/channel_manager.c create mode 100644 src/lib/openjpip/channel_manager.h create mode 100644 src/lib/openjpip/codestream_manager.c create mode 100644 src/lib/openjpip/codestream_manager.h create mode 100644 src/lib/openjpip/dec_clientmsg_handler.c create mode 100644 src/lib/openjpip/dec_clientmsg_handler.h create mode 100644 src/lib/openjpip/faixbox_manager.c create mode 100644 src/lib/openjpip/faixbox_manager.h create mode 100644 src/lib/openjpip/ihdrbox_manager.c create mode 100644 src/lib/openjpip/ihdrbox_manager.h create mode 100644 src/lib/openjpip/imgreg_manager.c create mode 100644 src/lib/openjpip/imgreg_manager.h create mode 100644 src/lib/openjpip/imgsock_manager.c create mode 100644 src/lib/openjpip/imgsock_manager.h create mode 100644 src/lib/openjpip/index_manager.c create mode 100644 src/lib/openjpip/index_manager.h create mode 100644 src/lib/openjpip/j2kheader_manager.c create mode 100644 src/lib/openjpip/j2kheader_manager.h create mode 100644 src/lib/openjpip/jp2k_decoder.c create mode 100644 src/lib/openjpip/jp2k_decoder.h create mode 100644 src/lib/openjpip/jp2k_encoder.c create mode 100644 src/lib/openjpip/jp2k_encoder.h create mode 100644 src/lib/openjpip/jpip_parser.c create mode 100644 src/lib/openjpip/jpip_parser.h create mode 100644 src/lib/openjpip/jpipstream_manager.c create mode 100644 src/lib/openjpip/jpipstream_manager.h create mode 100644 src/lib/openjpip/libopenjpip.pc.cmake.in create mode 100644 src/lib/openjpip/manfbox_manager.c create mode 100644 src/lib/openjpip/manfbox_manager.h create mode 100644 src/lib/openjpip/marker_manager.c create mode 100644 src/lib/openjpip/marker_manager.h create mode 100644 src/lib/openjpip/metadata_manager.c create mode 100644 src/lib/openjpip/metadata_manager.h create mode 100644 src/lib/openjpip/mhixbox_manager.c create mode 100644 src/lib/openjpip/mhixbox_manager.h create mode 100644 src/lib/openjpip/msgqueue_manager.c create mode 100644 src/lib/openjpip/msgqueue_manager.h create mode 100644 src/lib/openjpip/openjpip.c create mode 100644 src/lib/openjpip/openjpip.h create mode 100644 src/lib/openjpip/placeholder_manager.c create mode 100644 src/lib/openjpip/placeholder_manager.h create mode 100644 src/lib/openjpip/query_parser.c create mode 100644 src/lib/openjpip/query_parser.h create mode 100644 src/lib/openjpip/session_manager.c create mode 100644 src/lib/openjpip/session_manager.h create mode 100644 src/lib/openjpip/sock_manager.c create mode 100644 src/lib/openjpip/sock_manager.h create mode 100644 src/lib/openjpip/target_manager.c create mode 100644 src/lib/openjpip/target_manager.h create mode 100644 src/lib/openjpwl/CMakeLists.txt create mode 100644 src/lib/openjpwl/README.txt create mode 100644 src/lib/openjpwl/crc.c create mode 100644 src/lib/openjpwl/crc.h create mode 100644 src/lib/openjpwl/jpwl.c create mode 100644 src/lib/openjpwl/jpwl.h create mode 100644 src/lib/openjpwl/jpwl_lib.c create mode 100644 src/lib/openjpwl/libopenjpwl.pc.cmake.in create mode 100644 src/lib/openjpwl/rs.c create mode 100644 src/lib/openjpwl/rs.h create mode 100644 src/lib/openmj2/CMakeLists.txt create mode 100644 src/lib/openmj2/bio.c create mode 100644 src/lib/openmj2/bio.h create mode 100644 src/lib/openmj2/cio.c create mode 100644 src/lib/openmj2/cio.h create mode 100644 src/lib/openmj2/dwt.c create mode 100644 src/lib/openmj2/dwt.h create mode 100644 src/lib/openmj2/event.c create mode 100644 src/lib/openmj2/event.h create mode 100644 src/lib/openmj2/fix.h create mode 100644 src/lib/openmj2/image.c create mode 100644 src/lib/openmj2/image.h create mode 100644 src/lib/openmj2/int.h create mode 100644 src/lib/openmj2/j2k.c create mode 100644 src/lib/openmj2/j2k.h create mode 100644 src/lib/openmj2/j2k_lib.c create mode 100644 src/lib/openmj2/j2k_lib.h create mode 100644 src/lib/openmj2/jp2.c create mode 100644 src/lib/openmj2/jp2.h create mode 100644 src/lib/openmj2/jpt.c create mode 100644 src/lib/openmj2/jpt.h create mode 100644 src/lib/openmj2/mct.c create mode 100644 src/lib/openmj2/mct.h create mode 100644 src/lib/openmj2/mj2.c create mode 100644 src/lib/openmj2/mj2.h create mode 100644 src/lib/openmj2/mj2_convert.c create mode 100644 src/lib/openmj2/mj2_convert.h create mode 100644 src/lib/openmj2/mqc.c create mode 100644 src/lib/openmj2/mqc.h create mode 100644 src/lib/openmj2/openjpeg.c create mode 100644 src/lib/openmj2/openjpeg.h create mode 100644 src/lib/openmj2/opj_includes.h create mode 100644 src/lib/openmj2/opj_malloc.h create mode 100644 src/lib/openmj2/pi.c create mode 100644 src/lib/openmj2/pi.h create mode 100644 src/lib/openmj2/raw.c create mode 100644 src/lib/openmj2/raw.h create mode 100644 src/lib/openmj2/t1.c create mode 100644 src/lib/openmj2/t1.h create mode 100644 src/lib/openmj2/t1_luts.h create mode 100644 src/lib/openmj2/t2.c create mode 100644 src/lib/openmj2/t2.h create mode 100644 src/lib/openmj2/tcd.c create mode 100644 src/lib/openmj2/tcd.h create mode 100644 src/lib/openmj2/tgt.c create mode 100644 src/lib/openmj2/tgt.h create mode 100644 tests/CMakeLists.txt create mode 100644 tests/compare_dump_files.c create mode 100644 tests/compare_images.c create mode 100644 tests/compare_raw_files.c create mode 100644 tests/conformance/CMakeLists.txt create mode 100644 tests/fuzzers/GNUmakefile create mode 100644 tests/fuzzers/README.TXT create mode 100755 tests/fuzzers/build_google_oss_fuzzers.sh create mode 100755 tests/fuzzers/build_seed_corpus.sh create mode 100644 tests/fuzzers/fuzzingengine.c create mode 100644 tests/fuzzers/opj_decompress_fuzzer.cpp create mode 100644 tests/include_openjpeg.c create mode 100644 tests/j2k_random_tile_access.c create mode 100644 tests/nonregression/CMakeLists.txt create mode 100644 tests/nonregression/checkmd5refs.cmake create mode 100644 tests/nonregression/md5refs.txt create mode 100644 tests/nonregression/test_suite.ctest.in create mode 100644 tests/pdf2jp2.c create mode 100755 tests/performance/compare_perfs.py create mode 100755 tests/performance/perf_test.py create mode 100644 tests/performance/perf_test_filelist.csv create mode 100644 tests/ppm2rgb3.c create mode 100644 tests/profiling/filter_massif_output.py create mode 100644 tests/test_decode_area.c create mode 100644 tests/test_tile_decoder.c create mode 100644 tests/test_tile_encoder.c create mode 100644 tests/unit/CMakeLists.txt create mode 100644 tests/unit/testempty0.c create mode 100644 tests/unit/testempty1.c create mode 100644 tests/unit/testempty2.c create mode 100644 thirdparty/CMakeLists.txt create mode 100644 thirdparty/README.txt create mode 100644 thirdparty/include/zconf.h create mode 100644 thirdparty/include/zlib.h create mode 100644 thirdparty/liblcms2/CMakeLists.txt create mode 100644 thirdparty/liblcms2/COPYING create mode 100644 thirdparty/liblcms2/include/lcms2.h create mode 100644 thirdparty/liblcms2/include/lcms2_plugin.h create mode 100644 thirdparty/liblcms2/src/cmsalpha.c create mode 100644 thirdparty/liblcms2/src/cmscam02.c create mode 100644 thirdparty/liblcms2/src/cmscgats.c create mode 100644 thirdparty/liblcms2/src/cmscnvrt.c create mode 100644 thirdparty/liblcms2/src/cmserr.c create mode 100644 thirdparty/liblcms2/src/cmsgamma.c create mode 100644 thirdparty/liblcms2/src/cmsgmt.c create mode 100644 thirdparty/liblcms2/src/cmshalf.c create mode 100644 thirdparty/liblcms2/src/cmsintrp.c create mode 100644 thirdparty/liblcms2/src/cmsio0.c create mode 100644 thirdparty/liblcms2/src/cmsio1.c create mode 100644 thirdparty/liblcms2/src/cmslut.c create mode 100644 thirdparty/liblcms2/src/cmsmd5.c create mode 100644 thirdparty/liblcms2/src/cmsmtrx.c create mode 100644 thirdparty/liblcms2/src/cmsnamed.c create mode 100644 thirdparty/liblcms2/src/cmsopt.c create mode 100644 thirdparty/liblcms2/src/cmspack.c create mode 100644 thirdparty/liblcms2/src/cmspcs.c create mode 100644 thirdparty/liblcms2/src/cmsplugin.c create mode 100644 thirdparty/liblcms2/src/cmsps2.c create mode 100644 thirdparty/liblcms2/src/cmssamp.c create mode 100644 thirdparty/liblcms2/src/cmssm.c create mode 100644 thirdparty/liblcms2/src/cmstypes.c create mode 100644 thirdparty/liblcms2/src/cmsvirt.c create mode 100644 thirdparty/liblcms2/src/cmswtpnt.c create mode 100644 thirdparty/liblcms2/src/cmsxform.c create mode 100644 thirdparty/liblcms2/src/lcms2_internal.h create mode 100644 thirdparty/libpng/CMakeLists.txt create mode 100644 thirdparty/libpng/LICENSE create mode 100644 thirdparty/libpng/png.c create mode 100644 thirdparty/libpng/png.h create mode 100644 thirdparty/libpng/pngconf.h create mode 100644 thirdparty/libpng/pngdebug.h create mode 100644 thirdparty/libpng/pngerror.c create mode 100644 thirdparty/libpng/pngget.c create mode 100644 thirdparty/libpng/pnginfo.h create mode 100644 thirdparty/libpng/pnglibconf.h create mode 100644 thirdparty/libpng/pngmem.c create mode 100644 thirdparty/libpng/pngpread.c create mode 100644 thirdparty/libpng/pngpriv.h create mode 100644 thirdparty/libpng/pngread.c create mode 100644 thirdparty/libpng/pngrio.c create mode 100644 thirdparty/libpng/pngrtran.c create mode 100644 thirdparty/libpng/pngrutil.c create mode 100644 thirdparty/libpng/pngset.c create mode 100644 thirdparty/libpng/pngstruct.h create mode 100644 thirdparty/libpng/pngtrans.c create mode 100644 thirdparty/libpng/pngwio.c create mode 100644 thirdparty/libpng/pngwrite.c create mode 100644 thirdparty/libpng/pngwtran.c create mode 100644 thirdparty/libpng/pngwutil.c create mode 100644 thirdparty/libtiff/CMakeLists.txt create mode 100644 thirdparty/libtiff/libport.h create mode 100644 thirdparty/libtiff/libtiff.def create mode 100644 thirdparty/libtiff/snprintf.c create mode 100644 thirdparty/libtiff/t4.h create mode 100644 thirdparty/libtiff/test_inline.c create mode 100644 thirdparty/libtiff/tif_aux.c create mode 100644 thirdparty/libtiff/tif_close.c create mode 100644 thirdparty/libtiff/tif_codec.c create mode 100644 thirdparty/libtiff/tif_color.c create mode 100644 thirdparty/libtiff/tif_compress.c create mode 100644 thirdparty/libtiff/tif_config.h.cmake.in create mode 100644 thirdparty/libtiff/tif_config.h.in create mode 100644 thirdparty/libtiff/tif_dir.c create mode 100644 thirdparty/libtiff/tif_dir.h create mode 100644 thirdparty/libtiff/tif_dirinfo.c create mode 100644 thirdparty/libtiff/tif_dirread.c create mode 100644 thirdparty/libtiff/tif_dirwrite.c create mode 100644 thirdparty/libtiff/tif_dumpmode.c create mode 100644 thirdparty/libtiff/tif_error.c create mode 100644 thirdparty/libtiff/tif_extension.c create mode 100644 thirdparty/libtiff/tif_fax3.c create mode 100644 thirdparty/libtiff/tif_fax3.h create mode 100644 thirdparty/libtiff/tif_fax3sm.c create mode 100644 thirdparty/libtiff/tif_flush.c create mode 100644 thirdparty/libtiff/tif_getimage.c create mode 100644 thirdparty/libtiff/tif_jbig.c create mode 100644 thirdparty/libtiff/tif_jpeg.c create mode 100644 thirdparty/libtiff/tif_jpeg_12.c create mode 100644 thirdparty/libtiff/tif_luv.c create mode 100644 thirdparty/libtiff/tif_lzma.c create mode 100644 thirdparty/libtiff/tif_lzw.c create mode 100644 thirdparty/libtiff/tif_next.c create mode 100644 thirdparty/libtiff/tif_ojpeg.c create mode 100644 thirdparty/libtiff/tif_open.c create mode 100644 thirdparty/libtiff/tif_packbits.c create mode 100644 thirdparty/libtiff/tif_pixarlog.c create mode 100644 thirdparty/libtiff/tif_predict.c create mode 100644 thirdparty/libtiff/tif_predict.h create mode 100644 thirdparty/libtiff/tif_print.c create mode 100644 thirdparty/libtiff/tif_read.c create mode 100644 thirdparty/libtiff/tif_stream.cxx create mode 100644 thirdparty/libtiff/tif_strip.c create mode 100644 thirdparty/libtiff/tif_swab.c create mode 100644 thirdparty/libtiff/tif_thunder.c create mode 100644 thirdparty/libtiff/tif_tile.c create mode 100644 thirdparty/libtiff/tif_unix.c create mode 100644 thirdparty/libtiff/tif_version.c create mode 100644 thirdparty/libtiff/tif_warning.c create mode 100644 thirdparty/libtiff/tif_win32.c create mode 100644 thirdparty/libtiff/tif_write.c create mode 100644 thirdparty/libtiff/tif_zip.c create mode 100644 thirdparty/libtiff/tiff.h create mode 100644 thirdparty/libtiff/tiffconf.h.cmake.in create mode 100644 thirdparty/libtiff/tiffconf.h.in create mode 100644 thirdparty/libtiff/tiffio.h create mode 100644 thirdparty/libtiff/tiffio.hxx create mode 100644 thirdparty/libtiff/tiffiop.h create mode 100644 thirdparty/libtiff/tiffvers.h create mode 100644 thirdparty/libtiff/uvcode.h create mode 100644 thirdparty/libz/CMakeLists.txt create mode 100644 thirdparty/libz/adler32.c create mode 100644 thirdparty/libz/compress.c create mode 100644 thirdparty/libz/crc32.c create mode 100644 thirdparty/libz/crc32.h create mode 100644 thirdparty/libz/deflate.c create mode 100644 thirdparty/libz/deflate.h create mode 100644 thirdparty/libz/gzclose.c create mode 100644 thirdparty/libz/gzguts.h create mode 100644 thirdparty/libz/gzlib.c create mode 100644 thirdparty/libz/gzread.c create mode 100644 thirdparty/libz/gzwrite.c create mode 100644 thirdparty/libz/infback.c create mode 100644 thirdparty/libz/inffast.c create mode 100644 thirdparty/libz/inffast.h create mode 100644 thirdparty/libz/inffixed.h create mode 100644 thirdparty/libz/inflate.c create mode 100644 thirdparty/libz/inflate.h create mode 100644 thirdparty/libz/inftrees.c create mode 100644 thirdparty/libz/inftrees.h create mode 100644 thirdparty/libz/trees.c create mode 100644 thirdparty/libz/trees.h create mode 100644 thirdparty/libz/uncompr.c create mode 100644 thirdparty/libz/zlib.h create mode 100644 thirdparty/libz/zutil.c create mode 100644 thirdparty/libz/zutil.h create mode 100644 tools/abi-tracker/openjpeg.json create mode 100644 tools/ctest_scripts/toolchain-mingw32.cmake create mode 100644 tools/ctest_scripts/toolchain-mingw64.cmake create mode 100644 tools/ctest_scripts/travis-ci.cmake create mode 100755 tools/travis-ci/abi-check.sh create mode 100644 tools/travis-ci/detect-avx2.c create mode 100755 tools/travis-ci/install.sh create mode 100644 tools/travis-ci/knownfailures-Ubuntu12.04-gcc4.6.3-x86_64-Release-3rdP.txt create mode 100644 tools/travis-ci/knownfailures-Ubuntu14.04-clang3.8.0-x86_64-Release-3rdP.txt create mode 100644 tools/travis-ci/knownfailures-Ubuntu14.04-gcc4.8.4-i386-Release-3rdP.txt create mode 100644 tools/travis-ci/knownfailures-Ubuntu14.04-gcc4.8.4-x86_64-Debug-3rdP.txt create mode 100644 tools/travis-ci/knownfailures-all.txt create mode 100644 tools/travis-ci/knownfailures-windows-vs2010-x86-Release-3rdP.txt create mode 100755 tools/travis-ci/run.sh create mode 100644 tools/travis-ci/travis_rsa.enc create mode 100644 wrapping/CMakeLists.txt create mode 100644 wrapping/java/CMakeLists.txt create mode 100644 wrapping/java/openjp2/CMakeLists.txt create mode 100644 wrapping/java/openjp2/JavaOpenJPEG.c create mode 100644 wrapping/java/openjp2/JavaOpenJPEGDecoder.c create mode 100644 wrapping/java/openjp2/index.c create mode 100644 wrapping/java/openjp2/index.h create mode 100644 wrapping/java/openjp2/java-sources/org/openJpeg/OpenJPEGJavaDecoder.java create mode 100644 wrapping/java/openjp2/java-sources/org/openJpeg/OpenJPEGJavaEncoder.java create mode 100644 wrapping/java/openjp2/org_openJpeg_OpenJPEGJavaDecoder.h create mode 100644 wrapping/java/openjp2/org_openJpeg_OpenJPEGJavaEncoder.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6f4eff --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Ignore files and directories made by `cmake .`. +CMakeFiles/ +Makefile +cmake_install.cmake +/CMakeCache.txt +/CPackConfig.cmake +/CPackSourceConfig.cmake +/CTestCustom.cmake +/LICENSE.txt +/OpenJPEGConfig.cmake +/libopenjp2.pc +/src/bin/common/opj_apps_config.h +/src/lib/openjp2/opj_config.h +/src/lib/openjp2/opj_config_private.h +scripts/opjstyle* + +# Ignore directories made by `make`. +/bin/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0891c8e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,158 @@ +language: cpp + +matrix: + include: +# OSX + - os: osx + compiler: clang + env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1 + +# Test code style + - os: linux + compiler: clang-3.8 + env: OPJ_CI_CC=clang-3.8 OPJ_CI_CXX=clang-3.8 OPJ_CI_CHECK_STYLE=1 OPJ_CI_SKIP_TESTS=1 + addons: + apt: + sources: + - llvm-toolchain-precise-3.8 + - ubuntu-toolchain-r-test + packages: + - clang-3.8 + - flip + +# Performance test with GCC + - os: linux + compiler: g++ + dist: precise + env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_INCLUDE_IF_DEPLOY=1 OPJ_CI_PERF_TESTS=1 + +# Test compilation with AVX2 + - os: linux + # "sudo: yes" and "dist: trusty" give us a worker with the AVX2 instruction set + sudo: yes + dist: trusty + compiler: clang-3.8 + env: OPJ_CI_CC=clang-3.8 OPJ_CI_CXX=clang-3.8 OPJ_CI_INSTRUCTION_SETS="-mavx2" OPJ_CI_BUILD_CONFIGURATION=Release + addons: + apt: + sources: + - llvm-toolchain-precise-3.8 + - ubuntu-toolchain-r-test + packages: + - clang-3.8 + +# Test multi-threading + - os: linux + compiler: g++ + dist: precise + env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_NUM_THREADS=2 + +# Test 32-bit compilation + - os: linux + compiler: g++ + env: OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release + dist: trusty + addons: + apt: + packages: + - gcc-multilib + - g++-multilib + +# Profile code (gcc -pg) + - os: linux + compiler: g++ + env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug OPJ_CI_PROFILE=1 + dist: trusty + addons: + apt: + packages: + - valgrind + +# Test under ASAN +# Temporarily disabled since broken. See https://github.com/uclouvain/openjpeg/issues/1091 +# - os: linux +# compiler: clang +# env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug OPJ_CI_ASAN=1 + +# Test with CLang 3.8 + - os: linux + compiler: clang-3.8 + env: OPJ_CI_CC=clang-3.8 OPJ_CI_CXX=clang-3.8 OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release OPJ_CI_PERF_TESTS=1 OPJ_CI_BUILD_FUZZERS=1 + dist: trusty + addons: + apt: + sources: + - llvm-toolchain-precise-3.8 + - ubuntu-toolchain-r-test + packages: + - clang-3.8 + +# Test with mingw 32 bit + - os: linux + compiler: x86_64-w64-mingw32-g++ + env: OPJ_CI_CC=x86_64-w64-mingw32-gcc OPJ_CI_CXX=x86_64-w64-mingw32-g++ OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release + dist: trusty + addons: + apt: + packages: + - gcc-mingw-w64-base + - binutils-mingw-w64-i686 + - gcc-mingw-w64-i686 + - gcc-mingw-w64 + - g++-mingw-w64-i686 + - gcc-multilib + - g++-multilib + +# Test with mingw 64 bit + - os: linux + compiler: x86_64-w64-mingw32-g++ + env: OPJ_CI_CC=x86_64-w64-mingw32-gcc OPJ_CI_CXX=x86_64-w64-mingw32-g++ OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release + dist: trusty + addons: + apt: + packages: + - gcc-mingw-w64-base + - binutils-mingw-w64-x86-64 + - gcc-mingw-w64-x86-64 + - gcc-mingw-w64 + - g++-mingw-w64-x86-64 + +# Test with gcc 4.8 + - os: linux + compiler: g++-4.8 + env: OPJ_CI_CC=gcc-4.8 OPJ_CI_CXX=g++-4.8 OPJ_CI_ABI_CHECK=1 + dist: precise + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.8 + - g++-4.8 + - libelf-dev + - elfutils + - texinfo + - exuberant-ctags + +install: + - "./tools/travis-ci/install.sh" + +script: + - "./tools/travis-ci/run.sh" + - "./tools/travis-ci/abi-check.sh" + +before_deploy: + - export OPJ_RELEASE_PKG_FILE=$(ls build/openjpeg-${TRAVIS_TAG}*) + - echo "deploying $OPJ_RELEASE_PKG_FILE to GitHub releases" + +deploy: + provider: releases + api_key: + secure: dJXdzoFwk9wYWIKztnXKlVIr1QDmeXtk3oK+2MEzy22fBTKPuphU/cYMvhi5B7sWDwm77f43vbAYO6z7IFmuThwhkuVMD/o+lUyCqGffGeiU1pKpxEvB+LbO/C5asdSnor3RfYdOyo3x4cNlhNtfhXIn7FcAg371yEY6VSIP87adoQcuE+taig0cYWcrNWYGHirHlzEz1utnKwCT/nlhV4nSIWxjwYUp3nt8PAw3RbqQkPPNBniW92g6JA25vLRc3HMD18ISCfNLC2fI6a/dTR+vd+bCySA7JvqeDZnv8SxbVIabu5T+A5CHzHbdp2l2kynPwqHOO47pGa+VfisXEwSsOpa+4EZsPLdwOhaFFnvDwKwR3EjI1TkRVd26IcK61Y5zVZQgalnXBowBEZoI4fT/oEPF7VZMjN3sy/do1U6d5kO0UGqCHCJIVwPeELhwq5z7Ld04K7dSFFVenZhhQKCwxI1o8vgkGNJUWD2Ii6ZLrZKYZ0lC65hr2d39e/KoK3Yh5KHF0cVn6ppBTcUjYr/tdHHO43rwoaf3r1CdAQAYpFvfi3900hl9I/GPwky0YJ6W2QDS2vincwaqWDQ0+WNGf4AKSdx5kCgQU45PSfDb/lxAyXkqmBuI3h/C2ellleaWVL9sGtNRWa/w6WseGMGwfCXgN82XRVM2bgP6pYg= + file_glob: true + file: "${OPJ_RELEASE_PKG_FILE}" + skip_cleanup: true + on: + repo: uclouvain/openjpeg + tags: true + condition: "$OPJ_CI_INCLUDE_IF_DEPLOY = 1" diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 0000000..35aa84b --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,21 @@ +# Authors of OpenJPEG +See also [THANKS](https://github.com/uclouvain/openjpeg/blob/master/THANKS.md) + +David Janssens designed and implemented the first version of OpenJPEG. + +Kaori Hagihara designed and implemented the first version of OpenJPIP. + +Jerome Fimes implemented the alpha version of OpenJPEG 2.0. + +Giuseppe Baruffa added the JPWL functionalities. + +Mickaël Savinaud implemented the final OpenJPEG 2.0 version based on a big merge between 1.5 version and alpha version of 2.0. + +Mathieu Malaterre participated to the OpenJPEG 2.0 version and improved the libraries and utilities. + +Yannick Verschueren, +Herve Drolon, +Francois-Olivier Devaux, +Antonin Descampe + improved the libraries and utilities. + diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e45b324 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,683 @@ +# Changelog + +## [v2.3.1](https://github.com/uclouvain/openjpeg/releases/v2.3.1) (2019-04-02) +[Full Changelog](https://github.com/uclouvain/openjpeg/compare/v2.3.0...v2.3.1) + +**Closed issues:** + +- v2.2.0 regression for decoding images where TNsot == 0 [\#1120](https://github.com/uclouvain/openjpeg/issues/1120) +- Int overflow in jp3d [\#1162](https://github.com/uclouvain/openjpeg/issues/1162) +- Heap buffer overflow in opj\_j2k\_update\_image\_data\(\) triggered with Ghostscript [\#1157](https://github.com/uclouvain/openjpeg/issues/1157) +- LINUX install doesn't work when building shared libraries is disabled [\#1155](https://github.com/uclouvain/openjpeg/issues/1155) +- OPENJPEG null ptr dereference in openjpeg-2.3.0/src/bin/jp2/convert.c:2243 [\#1152](https://github.com/uclouvain/openjpeg/issues/1152) +- How to drop certain subbands/layers in DWT [\#1147](https://github.com/uclouvain/openjpeg/issues/1147) +- where is the MQ-Coder ouput stream in t2.c? [\#1146](https://github.com/uclouvain/openjpeg/issues/1146) +- OpenJPEG 2.3 \(and 2.2?\) multi component image fails to decode with KDU v7.10 [\#1132](https://github.com/uclouvain/openjpeg/issues/1132) +- Missing checks for header\_info.height and header\_info.width in function pnmtoimage in src/bin/jpwl/convert.c, which can lead to heap buffer overflow [\#1126](https://github.com/uclouvain/openjpeg/issues/1126) +- Assertion Failure in jp2.c [\#1125](https://github.com/uclouvain/openjpeg/issues/1125) +- Division-by-zero vulnerabilities in the function pi\_next\_pcrl, pi\_next\_cprl and pi\_next\_rpcl in src/lib/openjp3d/pi.c [\#1123](https://github.com/uclouvain/openjpeg/issues/1123) +- Precinct switch \(-c\) doesn't right-shift last record to remaining resolution levels [\#1117](https://github.com/uclouvain/openjpeg/issues/1117) +- Sample: encode J2K a data using streams??? [\#1114](https://github.com/uclouvain/openjpeg/issues/1114) +- HIGH THROUGHPUT JPEG 2000 \(HTJ2K\) [\#1112](https://github.com/uclouvain/openjpeg/issues/1112) +- How to build openjpeg for arm linux? [\#1108](https://github.com/uclouvain/openjpeg/issues/1108) +- crash [\#1106](https://github.com/uclouvain/openjpeg/issues/1106) +- JP2000 returning OPJ\_CLRSPC\_UNKNOWN color space [\#1103](https://github.com/uclouvain/openjpeg/issues/1103) +- Compilation successful but install unsuccessful: Calling executables throws libraries missing error [\#1102](https://github.com/uclouvain/openjpeg/issues/1102) +- fprintf format string requires 1 parameter but only 0 are given [\#1093](https://github.com/uclouvain/openjpeg/issues/1093) +- fprintf format string requires 1 parameter but only 0 are given [\#1092](https://github.com/uclouvain/openjpeg/issues/1092) +- sprintf buffer overflow [\#1088](https://github.com/uclouvain/openjpeg/issues/1088) +- sprintf buffer overflow [\#1085](https://github.com/uclouvain/openjpeg/issues/1085) +- Infinite loop when reading jp2 [\#1081](https://github.com/uclouvain/openjpeg/issues/1081) +- missing format string parameter [\#1074](https://github.com/uclouvain/openjpeg/issues/1074) +- Excessive Iteration in opj\_t1\_encode\_cblks \(src/lib/openjp2/t1.c\) [\#1059](https://github.com/uclouvain/openjpeg/issues/1059) +- Out-of-bound left shift in opj\_j2k\_setup\_encoder \(src/lib/openjp2/j2k.c\) [\#1057](https://github.com/uclouvain/openjpeg/issues/1057) +- Encode image on Unsplash [\#1054](https://github.com/uclouvain/openjpeg/issues/1054) +- Integer overflow in opj\_t1\_encode\_cblks \(src/lib/openjp2/t1.c\) [\#1053](https://github.com/uclouvain/openjpeg/issues/1053) +- Signed Integer Overflow - 68065512 [\#1048](https://github.com/uclouvain/openjpeg/issues/1048) +- Similar vulnerable functions related to CVE-2017-14041 [\#1044](https://github.com/uclouvain/openjpeg/issues/1044) +- \[ERROR\] COD marker already read. No more than one COD marker per tile. [\#1043](https://github.com/uclouvain/openjpeg/issues/1043) +- failing to install latest version of openjpeg from source [\#1041](https://github.com/uclouvain/openjpeg/issues/1041) +- Trouble compressing large raw image [\#1032](https://github.com/uclouvain/openjpeg/issues/1032) +- Download and installed code from 2.3 archive. Installing 2.2? [\#1030](https://github.com/uclouvain/openjpeg/issues/1030) +- missing fclose [\#1029](https://github.com/uclouvain/openjpeg/issues/1029) +- NULL Pointer Access in function imagetopnm of convert.c\(jp2\):1289 [\#860](https://github.com/uclouvain/openjpeg/issues/860) +- NULL Pointer Access in function imagetopnm of convert.c:2226\(jp2\) [\#859](https://github.com/uclouvain/openjpeg/issues/859) +- Heap Buffer Overflow in function imagetotga of convert.c\(jp2\):942 [\#858](https://github.com/uclouvain/openjpeg/issues/858) + +**Merged pull requests:** + +- abi-check.sh: fix broken download URL [\#1188](https://github.com/uclouvain/openjpeg/pull/1188) ([rouault](https://github.com/rouault)) +- opj\_t1\_encode\_cblks: fix UBSAN signed integer overflow [\#1187](https://github.com/uclouvain/openjpeg/pull/1187) ([rouault](https://github.com/rouault)) +- convertbmp: detect invalid file dimensions early \(CVE-2018-6616\) [\#1172](https://github.com/uclouvain/openjpeg/pull/1172) ([hlef](https://github.com/hlef)) +- color\_apply\_icc\_profile: avoid potential heap buffer overflow [\#1170](https://github.com/uclouvain/openjpeg/pull/1170) ([rouault](https://github.com/rouault)) +- Fix multiple potential vulnerabilities and bugs [\#1168](https://github.com/uclouvain/openjpeg/pull/1168) ([Young-X](https://github.com/Young-X)) +- Fix several memory and resource leaks [\#1163](https://github.com/uclouvain/openjpeg/pull/1163) ([nforro](https://github.com/nforro)) +- Fix some potential overflow issues [\#1161](https://github.com/uclouvain/openjpeg/pull/1161) ([stweil](https://github.com/stweil)) +- jp3d/jpwl convert: fix write stack buffer overflow [\#1160](https://github.com/uclouvain/openjpeg/pull/1160) ([hlef](https://github.com/hlef)) +- Int overflow fixed [\#1159](https://github.com/uclouvain/openjpeg/pull/1159) ([ichlubna](https://github.com/ichlubna)) +- Update knownfailures- files given current configurations [\#1149](https://github.com/uclouvain/openjpeg/pull/1149) ([rouault](https://github.com/rouault)) +- CVE-2018-5785: fix issues with zero bitmasks [\#1148](https://github.com/uclouvain/openjpeg/pull/1148) ([hlef](https://github.com/hlef)) +- openjp2/jp2: Fix two format strings [\#1143](https://github.com/uclouvain/openjpeg/pull/1143) ([stweil](https://github.com/stweil)) +- Changes in pnmtoimage if image data are missing [\#1141](https://github.com/uclouvain/openjpeg/pull/1141) ([szukw000](https://github.com/szukw000)) +- Relative path to header files is hardcoded in OpenJPEGConfig.cmake.in file [\#1140](https://github.com/uclouvain/openjpeg/pull/1140) ([bukatlib](https://github.com/bukatlib)) +- Cast on uint ceildiv [\#1136](https://github.com/uclouvain/openjpeg/pull/1136) ([reverson](https://github.com/reverson)) +- Add -DBUILD\_PKGCONFIG\_FILES to install instructions [\#1133](https://github.com/uclouvain/openjpeg/pull/1133) ([robe2](https://github.com/robe2)) +- Fix some typos in code comments and documentation [\#1128](https://github.com/uclouvain/openjpeg/pull/1128) ([stweil](https://github.com/stweil)) +- Fix regression in reading files with TNsot == 0 \(refs \#1120\) [\#1121](https://github.com/uclouvain/openjpeg/pull/1121) ([rouault](https://github.com/rouault)) +- Use local type declaration for POSIX standard type only for MS compiler [\#1119](https://github.com/uclouvain/openjpeg/pull/1119) ([stweil](https://github.com/stweil)) +- Fix Mac builds [\#1104](https://github.com/uclouvain/openjpeg/pull/1104) ([rouault](https://github.com/rouault)) +- jp3d: Replace sprintf\(\) by snprintf\(\) in volumetobin\(\) [\#1101](https://github.com/uclouvain/openjpeg/pull/1101) ([kbabioch](https://github.com/kbabioch)) +- opj\_mj2\_extract: Rename output\_location to output\_prefix [\#1096](https://github.com/uclouvain/openjpeg/pull/1096) ([kbabioch](https://github.com/kbabioch)) +- mj2: Add missing variable to format string in fprintf\(\) invocation in meta\_out.c [\#1094](https://github.com/uclouvain/openjpeg/pull/1094) ([kbabioch](https://github.com/kbabioch)) +- Convert files to UTF-8 encoding [\#1090](https://github.com/uclouvain/openjpeg/pull/1090) ([stweil](https://github.com/stweil)) +- fix unchecked integer multiplication overflow [\#1080](https://github.com/uclouvain/openjpeg/pull/1080) ([setharnold](https://github.com/setharnold)) +- Fixed typos [\#1062](https://github.com/uclouvain/openjpeg/pull/1062) ([radarhere](https://github.com/radarhere)) +- Note that seek uses SEEK\_SET behavior. [\#1055](https://github.com/uclouvain/openjpeg/pull/1055) ([ideasman42](https://github.com/ideasman42)) +- Some Doxygen tags are removed [\#1050](https://github.com/uclouvain/openjpeg/pull/1050) ([szukw000](https://github.com/szukw000)) +- Fix resource leak \(CID 179466\) [\#1047](https://github.com/uclouvain/openjpeg/pull/1047) ([stweil](https://github.com/stweil)) +- Changed cmake version test to allow for cmake 2.8.11.x [\#1042](https://github.com/uclouvain/openjpeg/pull/1042) ([radarhere](https://github.com/radarhere)) +- Add missing fclose\(\) statement in error condition. [\#1037](https://github.com/uclouvain/openjpeg/pull/1037) ([gfiumara](https://github.com/gfiumara)) + +## [v2.3.0](https://github.com/uclouvain/openjpeg/releases/v2.3.0) (2017-10-04) +[Full Changelog](https://github.com/uclouvain/openjpeg/compare/v2.2.0...v2.3.0) + +**Implemented enhancements:** + +- Sub-tile decoding: only decode precincts and codeblocks that intersect the window specified in opj_set_decode_area() [\#990](https://github.com/uclouvain/openjpeg/pull/990) ([rouault](https://github.com/rouault)) +- Sub-tile decoding: only apply IDWT on areas that participate to the window of interest [\#1001](https://github.com/uclouvain/openjpeg/pull/1001) ([rouault](https://github.com/rouault)) +- Sub-tile decoding: memory use reduction and perf improvements [\#1010](https://github.com/uclouvain/openjpeg/pull/1010) ([rouault](https://github.com/rouault)) +- Add capability to decode only a subset of all components of an image. [\#1022](https://github.com/uclouvain/openjpeg/pull/1022) ([rouault](https://github.com/rouault)) + +**Fixed bugs:** + +- Setting x offset of decode region to -1 causes opj\_decompress to go into infinite loop [\#736](https://github.com/uclouvain/openjpeg/issues/736) +- Problem decoding multiple tiles with get\_decoded\_tile when cmap/pclr/cdef boxes are present in jp2 file [\#484](https://github.com/uclouvain/openjpeg/issues/484) +- set reduce\_factor\_may\_fail [\#474](https://github.com/uclouvain/openjpeg/issues/474) +- opj\_compress.exe, command line parser, infinite loop [\#469](https://github.com/uclouvain/openjpeg/issues/469) +- Various memory access issues found via fuzzing [\#448](https://github.com/uclouvain/openjpeg/issues/448) +- Multiple warnings when building OpenJPEG \(trunk\) [\#442](https://github.com/uclouvain/openjpeg/issues/442) +- Bulk fuzz-testing report [\#427](https://github.com/uclouvain/openjpeg/issues/427) +- remove all printf from openjpeg / use proper function pointer for logging [\#371](https://github.com/uclouvain/openjpeg/issues/371) +- minor changes, clean-up [\#349](https://github.com/uclouvain/openjpeg/issues/349) +- image-\>numcomps \> 4 [\#333](https://github.com/uclouvain/openjpeg/issues/333) +- Improve support for region of interest [\#39](https://github.com/uclouvain/openjpeg/issues/39) +- Public function to tell kernel type used \(5x3 vs 9x7\) [\#3](https://github.com/uclouvain/openjpeg/issues/3) +- elf binary in source package ? [\#1026](https://github.com/uclouvain/openjpeg/issues/1026) +- opj\_cio\_open [\#1025](https://github.com/uclouvain/openjpeg/issues/1025) +- Building with Visual Studio 2015 [\#1023](https://github.com/uclouvain/openjpeg/issues/1023) +- tcd.cpp\>:1617:33: error: assigning to 'OPJ\_INT32 \*' \(aka 'int \*'\) from incompatible type 'void \*' [\#1021](https://github.com/uclouvain/openjpeg/issues/1021) +- j2k.cpp \> comparison of address of 'p\_j2k-\>m\_cp.tcps\[0\].m\_data' not equal to a null pointer is always true [\#1020](https://github.com/uclouvain/openjpeg/issues/1020) +- Openjpeg 2.2.0 always build shared library even though -DBUILD\_SHARED\_LIBS:bool=off [\#1019](https://github.com/uclouvain/openjpeg/issues/1019) +- missing fclose [\#1018](https://github.com/uclouvain/openjpeg/issues/1018) +- Use opj\_image\_data\_free instead of opj\_free for image-\>comps\[\].data [\#1014](https://github.com/uclouvain/openjpeg/issues/1014) +- malloc poison on some compilers - cross compiling [\#1013](https://github.com/uclouvain/openjpeg/issues/1013) +- Add OPJ\_VERSION\_MAJOR, OPJ\_VERSION\_MINOR, OPJ\_VERSION\_MICRO macros in openjpeg.h [\#1011](https://github.com/uclouvain/openjpeg/issues/1011) +- Encode: do not perform rate control for single-tile lossless [\#1009](https://github.com/uclouvain/openjpeg/issues/1009) +- opj\_set\_decoded\_resolution\_factor\(\): bad interaction with opj\_set\_decode\_area\(\) and/or opj\_decode\(\) [\#1006](https://github.com/uclouvain/openjpeg/issues/1006) +- memory allocation failure with .pgx file [\#999](https://github.com/uclouvain/openjpeg/issues/999) +- Unable to fuzz with raw image as input [\#998](https://github.com/uclouvain/openjpeg/issues/998) +- stack-based buffer overflow write in pgxtoimage \(/convert.c\) [\#997](https://github.com/uclouvain/openjpeg/issues/997) +- freeze with a crafted bmp [\#996](https://github.com/uclouvain/openjpeg/issues/996) +- invalid memory write in tgatoimage \(convert.c\) [\#995](https://github.com/uclouvain/openjpeg/issues/995) +- static build on Windows fails [\#994](https://github.com/uclouvain/openjpeg/issues/994) +- another heap-based buffer overflow in opj\_t2\_encode\_packet \(t2.c\) [\#993](https://github.com/uclouvain/openjpeg/issues/993) +- heap-based buffer overflow in opj\_t2\_encode\_packet \(t2.c\) [\#992](https://github.com/uclouvain/openjpeg/issues/992) +- heap-based buffer overflow in opj\_write\_bytes\_LE \(cio.c\) \(unfixed \#985\) [\#991](https://github.com/uclouvain/openjpeg/issues/991) +- heap overflow in opj\_compress [\#988](https://github.com/uclouvain/openjpeg/issues/988) +- heap overflow in opj\_decompress [\#987](https://github.com/uclouvain/openjpeg/issues/987) +- heap-based buffer overflow in opj\_bio\_byteout \(bio.c\) [\#986](https://github.com/uclouvain/openjpeg/issues/986) +- heap-based buffer overflow in opj\_write\_bytes\_LE \(cio.c\) [\#985](https://github.com/uclouvain/openjpeg/issues/985) +- memory allocation failure in opj\_aligned\_alloc\_n \(opj\_malloc.c\) [\#983](https://github.com/uclouvain/openjpeg/issues/983) +- heap-base buffer overflow in opj\_mqc\_flush \(mqc.c\) [\#982](https://github.com/uclouvain/openjpeg/issues/982) +- Decode fails for JP2s with ICC profile [\#981](https://github.com/uclouvain/openjpeg/issues/981) +- Unit tests failing on Ubuntu 17.04 [\#916](https://github.com/uclouvain/openjpeg/issues/916) +- Encoder crashes on small images [\#901](https://github.com/uclouvain/openjpeg/issues/901) +- openjpeg-1.5.3 fails to compile [\#830](https://github.com/uclouvain/openjpeg/issues/830) +- opj\_compress crops image \(win\) or creates a jp2 which cannot be decompressed \(lin\) [\#716](https://github.com/uclouvain/openjpeg/issues/716) +- -d flag is silently ignored when decoding a single tile [\#693](https://github.com/uclouvain/openjpeg/issues/693) +- transition away from dev-utils [\#628](https://github.com/uclouvain/openjpeg/issues/628) +- update instructions to build with Visual Studio and 64-Bit Visual C++ Toolset. [\#1028](https://github.com/uclouvain/openjpeg/pull/1028) ([quangnh89](https://github.com/quangnh89)) +- Add missing newline at end of file [\#1024](https://github.com/uclouvain/openjpeg/pull/1024) ([stweil](https://github.com/stweil)) +- merge master into coverity\_scan to update coverity results [\#1008](https://github.com/uclouvain/openjpeg/pull/1008) ([detonin](https://github.com/detonin)) +- Use more const qualifiers [\#984](https://github.com/uclouvain/openjpeg/pull/984) ([stweil](https://github.com/stweil)) +- Changes in converttif.c for PPC64 [\#980](https://github.com/uclouvain/openjpeg/pull/980) ([szukw000](https://github.com/szukw000)) + +## [v2.2.0](https://github.com/uclouvain/openjpeg/releases/v2.2.0) (2017-08-10) +[Full Changelog](https://github.com/uclouvain/openjpeg/compare/v2.1.2...v2.2.0) + +**Implemented enhancements:** + +- Memory consumption reduction at decoding side [\#968](https://github.com/uclouvain/openjpeg/pull/968) ([rouault](https://github.com/rouault)) +- T1 & DWT multithreading decoding optimizations [\#786](https://github.com/uclouvain/openjpeg/pull/786) ([rouault](https://github.com/rouault)) +- Tier1 decoder speed optimizations [\#783](https://github.com/uclouvain/openjpeg/pull/783) ([rouault](https://github.com/rouault)) +- Inverse DWT 5x3: lift implementation / SSE accelerated version [\#953](https://github.com/uclouvain/openjpeg/issues/953) +- install static libraries [\#969](https://github.com/uclouvain/openjpeg/pull/969) ([jeroen](https://github.com/jeroen)) +- IDWT 5x3 single-pass lifting and SSE2/AVX2 implementation [\#957](https://github.com/uclouvain/openjpeg/pull/957) ([rouault](https://github.com/rouault)) +- build both shared and static library [\#954](https://github.com/uclouvain/openjpeg/pull/954) ([jeroen](https://github.com/jeroen)) +- T1 flag optimizations \(\#172\) [\#945](https://github.com/uclouvain/openjpeg/pull/945) ([rouault](https://github.com/rouault)) +- CMake: add stronger warnings for openjp2 lib/bin by default, and error out on declaration-after-statement [\#936](https://github.com/uclouvain/openjpeg/pull/936) ([rouault](https://github.com/rouault)) +- Quiet mode for opj\_decompress via -quiet long parameter. [\#928](https://github.com/uclouvain/openjpeg/pull/928) ([RussellMcOrmond](https://github.com/RussellMcOrmond)) +- Implement predictive termination check [\#800](https://github.com/uclouvain/openjpeg/pull/800) ([rouault](https://github.com/rouault)) + +**Fixed bugs:** + +- Several issues spotted by Google OSS Fuzz - [see here](https://github.com/search?l=&q=OSS+Fuzz+author-date%3A2017-07-04..2017-08-01+repo%3Auclouvain%2Fopenjpeg&ref=advsearch&type=Commits&utf8=%E2%9C%93) +- Missing fclose [\#976](https://github.com/uclouvain/openjpeg/issues/976) +- Heap buffer overflow read in openjpeg imagetopnm [\#970](https://github.com/uclouvain/openjpeg/issues/970) +- opj\_decompress opj\_j2k\_update\_image\_data\(\) Segment falut [\#948](https://github.com/uclouvain/openjpeg/issues/948) +- Generic Crash in 1.5.0 [\#941](https://github.com/uclouvain/openjpeg/issues/941) +- Segmentation Faults [\#940](https://github.com/uclouvain/openjpeg/issues/940) +- Assertions thrown [\#939](https://github.com/uclouvain/openjpeg/issues/939) +- Floating Point Errors [\#938](https://github.com/uclouvain/openjpeg/issues/938) +- Division by zero crash [\#937](https://github.com/uclouvain/openjpeg/issues/937) +- malformed jp2 can cause heap-buffer-overflow [\#909](https://github.com/uclouvain/openjpeg/issues/909) +- NULL dereference can cause by malformed file [\#908](https://github.com/uclouvain/openjpeg/issues/908) +- Out of bound read in opj\_j2k\_add\_mct [\#907](https://github.com/uclouvain/openjpeg/issues/907) +- Check bpno\_plus\_one in opj\_t1\_decode\_cblk [\#903](https://github.com/uclouvain/openjpeg/issues/903) +- Undefined-shift in opj\_j2k\_read\_siz [\#902](https://github.com/uclouvain/openjpeg/issues/902) +- opj\_compress v2.1.2 can create images opj\_decompress cannot read [\#891](https://github.com/uclouvain/openjpeg/issues/891) +- Improper usage of opj\_int\_ceildiv can cause overflows [\#889](https://github.com/uclouvain/openjpeg/issues/889) +- Undefined shift in opj\_get\_all\_encoding\_parameters [\#885](https://github.com/uclouvain/openjpeg/issues/885) +- Denial of service \(crash\) due to use-after-free when decoding an illegal JPEG2000 image file v2.1.2 \(2017-04 [\#880](https://github.com/uclouvain/openjpeg/issues/880) +- Denial of service \(crash\) when decoding an illegal JPEG2000 image file v2.1.2 \(2017-03\) [\#879](https://github.com/uclouvain/openjpeg/issues/879) +- bug png 2 j2k [\#868](https://github.com/uclouvain/openjpeg/issues/868) +- Inconsistent compression using cinema settings on folder of non-compliant image [\#864](https://github.com/uclouvain/openjpeg/issues/864) +- Openjpeg-2.1.2 Heap Buffer Overflow Vulnerability due to Insufficient check [\#862](https://github.com/uclouvain/openjpeg/issues/862) +- Heap Buffer Overflow in function pnmtoimage of convert.c [\#861](https://github.com/uclouvain/openjpeg/issues/861) +- CVE-2016-9112 FPE\(Floating Point Exception\) in lib/openjp2/pi.c:523 [\#855](https://github.com/uclouvain/openjpeg/issues/855) +- CVE-2016-5139, CVE-2016-5152, CVE-2016-5158, CVE-2016-5159 [\#854](https://github.com/uclouvain/openjpeg/issues/854) +- Undefined Reference error [\#853](https://github.com/uclouvain/openjpeg/issues/853) +- opj\_compress with lossy compression results in strange pixel values [\#851](https://github.com/uclouvain/openjpeg/issues/851) +- CVE-2016-1626 and CVE-2016-1628 [\#850](https://github.com/uclouvain/openjpeg/issues/850) +- Out-of-Bounds Write in opj\_mqc\_byteout of mqc.c [\#835](https://github.com/uclouvain/openjpeg/issues/835) +- WARNING in tgt\_create tree-\>numnodes == 0, no tree created. [\#794](https://github.com/uclouvain/openjpeg/issues/794) +- Potential overflow when precision is larger than 32 [\#781](https://github.com/uclouvain/openjpeg/issues/781) +- division-by-zero in function opj\_pi\_next\_rpcl of pi.c \(line 366\) [\#780](https://github.com/uclouvain/openjpeg/issues/780) +- division-by-zero in function opj\_pi\_next\_rpcl of pi.c \(line 363\) [\#779](https://github.com/uclouvain/openjpeg/issues/779) +- division-by-zero in function opj\_pi\_next\_pcrl of pi.c \(line 447\) [\#778](https://github.com/uclouvain/openjpeg/issues/778) +- division-by-zero in function opj\_pi\_next\_pcrl of pi.c \(line 444\) [\#777](https://github.com/uclouvain/openjpeg/issues/777) +- Encoding the following file with 32x32 tiling produces jp2 image with artifact [\#737](https://github.com/uclouvain/openjpeg/issues/737) +- division-by-zero \(SIGFPE\) error in opj\_pi\_next\_cprl function \(line 526 of pi.c\) [\#732](https://github.com/uclouvain/openjpeg/issues/732) +- division-by-zero \(SIGFPE\) error in opj\_pi\_next\_cprl function \(line 523 of pi.c\) [\#731](https://github.com/uclouvain/openjpeg/issues/731) +- OpenJpeg 2.1 and 1.4 fails to decompress this file correctly [\#721](https://github.com/uclouvain/openjpeg/issues/721) +- MQ Encode :uninitialized memory access when first pass does not output any bytes [\#709](https://github.com/uclouvain/openjpeg/issues/709) +- Out-of-bounds read in opj\_j2k\_update\_image\_data and opj\_tgt\_reset function [\#704](https://github.com/uclouvain/openjpeg/issues/704) +- Remove opj\_aligned\_malloc / opj\_aligned\_realloc / opj\_aligned\_free? [\#689](https://github.com/uclouvain/openjpeg/issues/689) +- There is an issue with rendering some type of jpeg file. Please ref the link. [\#672](https://github.com/uclouvain/openjpeg/issues/672) +- Null Dereference in tcd\_malloc\_decode\_tile [\#657](https://github.com/uclouvain/openjpeg/issues/657) +- ETS-C1P0-p0\_12.j2k-compare2ref & NR-C1P0-p0\_12.j2k-compare2base failing under windows [\#655](https://github.com/uclouvain/openjpeg/issues/655) +- Memory leak [\#631](https://github.com/uclouvain/openjpeg/issues/631) +- Test 481 reports error in valgrind memcheck [\#612](https://github.com/uclouvain/openjpeg/issues/612) +- reserved identifier violation [\#587](https://github.com/uclouvain/openjpeg/issues/587) +- Buffer overflow when compressing some 16 bits images of the test suite [\#539](https://github.com/uclouvain/openjpeg/issues/539) +- Heap-buffer-overflow in opj\_dwt\_decode\_1 [\#480](https://github.com/uclouvain/openjpeg/issues/480) +- Automated fuzz testing [\#468](https://github.com/uclouvain/openjpeg/issues/468) +- Expected to find EPH marker [\#425](https://github.com/uclouvain/openjpeg/issues/425) +- read: segment too long \(6182\) with max \(35872\) for codeblock 0 \(p=19, b=2, r=5, c=1\) [\#284](https://github.com/uclouvain/openjpeg/issues/284) +- building 64bit version has lots of warnings [\#244](https://github.com/uclouvain/openjpeg/issues/244) +- Wrong encoding of small tiles with high level number [\#239](https://github.com/uclouvain/openjpeg/issues/239) +- Errors raised in pi.c by VS11 analyzer [\#190](https://github.com/uclouvain/openjpeg/issues/190) +- Undocumented optimization found in v2 branch of openjpeg [\#183](https://github.com/uclouvain/openjpeg/issues/183) +- T1 optimisations jpeg2000 [\#172](https://github.com/uclouvain/openjpeg/issues/172) +- Remove OPJ\_NOSANITIZE in opj\_bio\_read\(\) and opj\_bio\_write\(\) \(\#761\) [\#955](https://github.com/uclouvain/openjpeg/pull/955) ([rouault](https://github.com/rouault)) +- Fix bypass pterm termall and lossless decomposition issue \(\#891, \#892\) [\#949](https://github.com/uclouvain/openjpeg/pull/949) ([rouault](https://github.com/rouault)) +- Escape quotes to ensure README renders on GitHub correctly [\#914](https://github.com/uclouvain/openjpeg/pull/914) ([alexwlchan](https://github.com/alexwlchan)) +- Remove spurious .R macros from manpages [\#899](https://github.com/uclouvain/openjpeg/pull/899) ([jwilk](https://github.com/jwilk)) +- Remove warnings related to empty tag-trees. [\#893](https://github.com/uclouvain/openjpeg/pull/893) ([rouault](https://github.com/rouault)) + +**Maintenance-related tasks:** + +- Submit OpenJPEG to oss-fuzz [\#965](https://github.com/uclouvain/openjpeg/issues/965) +- Updates for Doxygen to suppress warnings [\#849](https://github.com/uclouvain/openjpeg/issues/849) +- Remove useless knownfailures \(since LAZY encoding is fixed\) [\#964](https://github.com/uclouvain/openjpeg/pull/964) ([rouault](https://github.com/rouault)) +- Enable AVX2 at runtime on Travis-CI and AppVeyor [\#963](https://github.com/uclouvain/openjpeg/pull/963) ([rouault](https://github.com/rouault)) +- Tests: test opj\_compress in VSC mode \(related to \#172\) [\#935](https://github.com/uclouvain/openjpeg/pull/935) ([rouault](https://github.com/rouault)) +- Reformat: apply reformattin on .h files \(\#128\) [\#926](https://github.com/uclouvain/openjpeg/pull/926) ([rouault](https://github.com/rouault)) +- Add mechanisms to reformat and check code style, and reformat whole codebase \(\#128\) [\#919](https://github.com/uclouvain/openjpeg/pull/919) ([rouault](https://github.com/rouault)) +- Add profiling of CPU and memory usage \(\#912\) [\#918](https://github.com/uclouvain/openjpeg/pull/918) ([rouault](https://github.com/rouault)) +- Add performance benchmarking scripts [\#917](https://github.com/uclouvain/openjpeg/pull/917) ([rouault](https://github.com/rouault)) +- Fix retrieval of jpylyzer in AppVeyor [\#915](https://github.com/uclouvain/openjpeg/pull/915) ([rouault](https://github.com/rouault)) + +## [v2.1.2](https://github.com/uclouvain/openjpeg/releases/v2.1.2) (2016-09-28) +[Full Changelog](https://github.com/uclouvain/openjpeg/compare/v2.1.1...v2.1.2) + +**Closed issues:** + +- null ptr dereference in convert.c:1331 [\#843](https://github.com/uclouvain/openjpeg/issues/843) +- Out-of-Bounds Read in function bmp24toimage of convertbmp.c [\#833](https://github.com/uclouvain/openjpeg/issues/833) +- Disable automatic compilation of t1\_generate\_luts in CMakeLists.txt [\#831](https://github.com/uclouvain/openjpeg/issues/831) +- CVE-2016-7163 Integer overflow in opj\_pi\_create\_decode [\#826](https://github.com/uclouvain/openjpeg/issues/826) +- Security Advisory for OpenJPEG [\#810](https://github.com/uclouvain/openjpeg/issues/810) +- Add dashboard with static lib [\#804](https://github.com/uclouvain/openjpeg/issues/804) +- hidden visibility for the static library / building with -DOPJ\_STATIC against shared lib [\#802](https://github.com/uclouvain/openjpeg/issues/802) +- Optimization when building library from source [\#799](https://github.com/uclouvain/openjpeg/issues/799) +- unsigned int16 on Solaris 11.2/sparc [\#796](https://github.com/uclouvain/openjpeg/issues/796) +- appveyor [\#793](https://github.com/uclouvain/openjpeg/issues/793) +- FFMpeg will not link to 2.1.1 release built as shared library [\#766](https://github.com/uclouvain/openjpeg/issues/766) +- API change since v2: opj\_event\_mgr\_t not available [\#754](https://github.com/uclouvain/openjpeg/issues/754) +- openjpeg.h needs dependencies [\#673](https://github.com/uclouvain/openjpeg/issues/673) +- "master" does not build on ubuntu [\#658](https://github.com/uclouvain/openjpeg/issues/658) +- Package 'openjp2', required by 'libopenjpip', not found [\#594](https://github.com/uclouvain/openjpeg/issues/594) + +**Merged pull requests:** + +- Fix PNM file reading [\#847](https://github.com/uclouvain/openjpeg/pull/847) ([mayeut](https://github.com/mayeut)) +- Fix some issues reported by Coverity Scan [\#846](https://github.com/uclouvain/openjpeg/pull/846) ([stweil](https://github.com/stweil)) +- Fix potential out-of-bounds read \(coverity\) [\#844](https://github.com/uclouvain/openjpeg/pull/844) ([stweil](https://github.com/stweil)) +- Remove TODO for overflow check [\#842](https://github.com/uclouvain/openjpeg/pull/842) ([mayeut](https://github.com/mayeut)) +- Add overflow checks for opj\_aligned\_malloc [\#841](https://github.com/uclouvain/openjpeg/pull/841) ([mayeut](https://github.com/mayeut)) +- Flags in T1 shall be unsigned [\#840](https://github.com/uclouvain/openjpeg/pull/840) ([mayeut](https://github.com/mayeut)) +- Fix some warnings [\#838](https://github.com/uclouvain/openjpeg/pull/838) ([mayeut](https://github.com/mayeut)) +- Fix issue 833. [\#834](https://github.com/uclouvain/openjpeg/pull/834) ([trylab](https://github.com/trylab)) +- Add overflow checks for opj\_aligned\_malloc [\#832](https://github.com/uclouvain/openjpeg/pull/832) ([mayeut](https://github.com/mayeut)) +- Add test for issue 820 [\#829](https://github.com/uclouvain/openjpeg/pull/829) ([mayeut](https://github.com/mayeut)) +- Add test for issue 826 [\#827](https://github.com/uclouvain/openjpeg/pull/827) ([mayeut](https://github.com/mayeut)) +- Fix coverity 113065 \(CWE-484\) [\#824](https://github.com/uclouvain/openjpeg/pull/824) ([mayeut](https://github.com/mayeut)) +- Add sanity check for tile coordinates [\#823](https://github.com/uclouvain/openjpeg/pull/823) ([mayeut](https://github.com/mayeut)) +- Add test for PR 818 [\#822](https://github.com/uclouvain/openjpeg/pull/822) ([mayeut](https://github.com/mayeut)) +- Update to libpng 1.6.25 [\#821](https://github.com/uclouvain/openjpeg/pull/821) ([mayeut](https://github.com/mayeut)) +- CVE-2016-8332: fix incrementing of "l\_tcp-\>m\_nb\_mcc\_records" in opj\_j2k\_read\_mcc [\#820](https://github.com/uclouvain/openjpeg/pull/820) ([mayeut](https://github.com/mayeut)) +- Add overflow check in opj\_tcd\_init\_tile [\#819](https://github.com/uclouvain/openjpeg/pull/819) ([mayeut](https://github.com/mayeut)) +- Fix leak & invalid behavior of opj\_jp2\_read\_ihdr [\#818](https://github.com/uclouvain/openjpeg/pull/818) ([mayeut](https://github.com/mayeut)) +- Add overflow check in opj\_j2k\_update\_image\_data [\#817](https://github.com/uclouvain/openjpeg/pull/817) ([mayeut](https://github.com/mayeut)) +- Change 'restrict' define to 'OPJ\_RESTRICT' [\#816](https://github.com/uclouvain/openjpeg/pull/816) ([mayeut](https://github.com/mayeut)) +- Switch to clang 3.8 [\#814](https://github.com/uclouvain/openjpeg/pull/814) ([mayeut](https://github.com/mayeut)) +- Fix an integer overflow issue [\#809](https://github.com/uclouvain/openjpeg/pull/809) ([trylab](https://github.com/trylab)) +- Update to lcms 2.8 [\#808](https://github.com/uclouvain/openjpeg/pull/808) ([mayeut](https://github.com/mayeut)) +- Update to libpng 1.6.24 [\#807](https://github.com/uclouvain/openjpeg/pull/807) ([mayeut](https://github.com/mayeut)) +- Reenable clang-3.9 build on travis [\#806](https://github.com/uclouvain/openjpeg/pull/806) ([mayeut](https://github.com/mayeut)) +- Bit fields type [\#805](https://github.com/uclouvain/openjpeg/pull/805) ([smuehlst](https://github.com/smuehlst)) +- Add compilation test for standalone inclusion of openjpeg.h [\#798](https://github.com/uclouvain/openjpeg/pull/798) ([mayeut](https://github.com/mayeut)) +- jpwl: Remove non-portable data type u\_int16\_t \(fix issue \#796\) [\#797](https://github.com/uclouvain/openjpeg/pull/797) ([stweil](https://github.com/stweil)) +- Fix dependency for pkg-config \(issue \#594\) [\#795](https://github.com/uclouvain/openjpeg/pull/795) ([stweil](https://github.com/stweil)) +- Add .gitignore [\#787](https://github.com/uclouvain/openjpeg/pull/787) ([stweil](https://github.com/stweil)) + +## [v2.1.1](https://github.com/uclouvain/openjpeg/releases/tag/v2.1.1) (2016-07-05) +[Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.2.1...v2.1.1) + +**Implemented enhancements:** + +- opj\_malloc replacement [\#625](https://github.com/uclouvain/openjpeg/issues/625) +- backport "-p" and "-force-rgb" options in 1.5 [\#606](https://github.com/uclouvain/openjpeg/issues/606) +- Use travis-ci matrix build [\#581](https://github.com/uclouvain/openjpeg/issues/581) +- Add Coverity Scan analysis [\#580](https://github.com/uclouvain/openjpeg/issues/580) +- Unnecessary rate distortion calculations [\#479](https://github.com/uclouvain/openjpeg/issues/479) +- Add images from various security issues to test suite [\#415](https://github.com/uclouvain/openjpeg/issues/415) +- Coding speed for 9/7 on 32bits platforms \(x86/ARM\) can be improved with a quick fix [\#220](https://github.com/uclouvain/openjpeg/issues/220) + +**Fixed bugs:** + +- Out-of-Bounds Access in function opj\_tgt\_reset of tgt.c [\#775](https://github.com/uclouvain/openjpeg/issues/775) +- Heap Buffer Overflow in function color\_cmyk\_to\_rgb of color.c [\#774](https://github.com/uclouvain/openjpeg/issues/774) +- division-by-zero \(SIGFPE\) error in opj\_tcd\_init\_tile function \(line 730 of tcd.c\) [\#733](https://github.com/uclouvain/openjpeg/issues/733) +- Out-Of-Bounds Read in sycc422\_to\_rgb function [\#726](https://github.com/uclouvain/openjpeg/issues/726) +- Heap Corruption in opj\_free function [\#725](https://github.com/uclouvain/openjpeg/issues/725) +- Out-Of-Bounds Read in opj\_tcd\_free\_tile function [\#724](https://github.com/uclouvain/openjpeg/issues/724) +- Cannot handle box of undefined size [\#653](https://github.com/uclouvain/openjpeg/issues/653) +- Compilation fails without platform-supplied aligned malloc [\#642](https://github.com/uclouvain/openjpeg/issues/642) +- HP compiler warns about redeclaration of static function [\#640](https://github.com/uclouvain/openjpeg/issues/640) +- Implementation-defined behavior of malloc causes different behavior on Linux and AIX [\#635](https://github.com/uclouvain/openjpeg/issues/635) +- Build on AIX fails because "opj\_includes.h" is included after system headers [\#633](https://github.com/uclouvain/openjpeg/issues/633) +- Compiling with SSE2 on Linux 32-bit causes crashes in OpenJPEG [\#624](https://github.com/uclouvain/openjpeg/issues/624) +- Build on AIX fails because of "restrict" pointers [\#620](https://github.com/uclouvain/openjpeg/issues/620) +- bug in new tif conversion code [\#609](https://github.com/uclouvain/openjpeg/issues/609) +- bin/jp2/convert.c line 1085 Resource leak [\#607](https://github.com/uclouvain/openjpeg/issues/607) +- bin/jp2/convert.c memory leak [\#601](https://github.com/uclouvain/openjpeg/issues/601) +- Resource leak in opj\_j2k\_create\_cstr\_index in case of failure [\#599](https://github.com/uclouvain/openjpeg/issues/599) +- Resource leak in opj\_j2k\_encode in case of failure [\#598](https://github.com/uclouvain/openjpeg/issues/598) +- Resource leak in opj\_j2k\_decode\_one\_tile in case of failure [\#597](https://github.com/uclouvain/openjpeg/issues/597) +- Resource Leak [\#573](https://github.com/uclouvain/openjpeg/issues/573) +- opj\_compress fails to compress lossless on gcc/x86 \(-m32\) [\#571](https://github.com/uclouvain/openjpeg/issues/571) +- Use-after-free in opj\_j2k\_write\_mco [\#563](https://github.com/uclouvain/openjpeg/issues/563) +- openjpeg-master-2015-07-30 failed to compile on LINUX [\#556](https://github.com/uclouvain/openjpeg/issues/556) +- PNG images are always read as RGB\(A\) images [\#536](https://github.com/uclouvain/openjpeg/issues/536) +- g4\_colr.j2c not handled properly [\#532](https://github.com/uclouvain/openjpeg/issues/532) +- Bigendian: opj\_compress + opj\_decompress fails [\#518](https://github.com/uclouvain/openjpeg/issues/518) +- Suspicious code in j2k.c [\#517](https://github.com/uclouvain/openjpeg/issues/517) +- Decode times almost double\(!!\) on Visual Studio 2013, 2015 [\#505](https://github.com/uclouvain/openjpeg/issues/505) +- opj\_data/input/nonregression/issue226.j2k [\#500](https://github.com/uclouvain/openjpeg/issues/500) +- opj\_setup\_encoder always returns true [\#497](https://github.com/uclouvain/openjpeg/issues/497) +- Double free in j2k\_read\_ppm\_v3 parsing \(\(presumably invalid\) image. [\#496](https://github.com/uclouvain/openjpeg/issues/496) +- Invalid write in opj\_j2k\_update\_image\_data [\#495](https://github.com/uclouvain/openjpeg/issues/495) +- Undefined printf format specifier %ud used in code [\#494](https://github.com/uclouvain/openjpeg/issues/494) +- Potential double free on malloc failure in opj\_j2k\_copy\_default\_tcp\_and\_create\_tcp\(\) [\#492](https://github.com/uclouvain/openjpeg/issues/492) +- Do not link with -ffast-math [\#488](https://github.com/uclouvain/openjpeg/issues/488) +- Heap-buffer-overflow in opj\_dwt\_decode [\#486](https://github.com/uclouvain/openjpeg/issues/486) +- opj\_dump fails on Windows 7, 64 bits [\#482](https://github.com/uclouvain/openjpeg/issues/482) +- SIGSEGV in opj\_j2k\_update\_image\_data via pdfium\_test [\#481](https://github.com/uclouvain/openjpeg/issues/481) +- Heap-buffer-overflow in opj\_j2k\_tcp\_destroy [\#477](https://github.com/uclouvain/openjpeg/issues/477) +- Invalid image causes write past end of heap buffer [\#476](https://github.com/uclouvain/openjpeg/issues/476) +- Assertion `l\_res-\>x0 \>= 0' fails when parsing invalid images [\#475](https://github.com/uclouvain/openjpeg/issues/475) +- Bug on opj\_write\_bytes\_BE function [\#472](https://github.com/uclouvain/openjpeg/issues/472) +- Refactor j2k\_read\_ppm\_v3 function [\#470](https://github.com/uclouvain/openjpeg/issues/470) +- compression: strange precinct dimensions [\#466](https://github.com/uclouvain/openjpeg/issues/466) +- \(:- Console message in opj\_decompress -:\) [\#465](https://github.com/uclouvain/openjpeg/issues/465) +- opj\_decompress fails to decompress any files [\#463](https://github.com/uclouvain/openjpeg/issues/463) +- bio-\>ct is unnecessarily set to zero in opj\_bio\_flush method [\#461](https://github.com/uclouvain/openjpeg/issues/461) +- Maximal unsigned short is 65535, not 65536 [\#460](https://github.com/uclouvain/openjpeg/issues/460) +- OpenJpeg fails to encode components with different precision properly [\#459](https://github.com/uclouvain/openjpeg/issues/459) +- component precision upscaling isn't correct in opj\_decompress [\#458](https://github.com/uclouvain/openjpeg/issues/458) +- Multiple precision components won't get encoded to jp2 if 1 component is unsigned 1 bit [\#457](https://github.com/uclouvain/openjpeg/issues/457) +- Incorrect code in ../bin/jp2/convert.c, function rawtoimage\_common\(...\) [\#456](https://github.com/uclouvain/openjpeg/issues/456) +- \[OpenJPEG-trunk\] opj\_stream\_get\_number\_byte\_left throws assert [\#455](https://github.com/uclouvain/openjpeg/issues/455) +- NR-DEC-kodak\_2layers\_lrcp.j2c-31-decode-md5 fails randomly when running tests in parallel [\#454](https://github.com/uclouvain/openjpeg/issues/454) +- compare\_raw\_files doesn't report an error on invalid arguments / missing input files [\#453](https://github.com/uclouvain/openjpeg/issues/453) +- Forward discrete wavelet transform: implement periodic symmetric extension at boundaries [\#452](https://github.com/uclouvain/openjpeg/issues/452) +- Bug in tiff reading method in convert.c [\#449](https://github.com/uclouvain/openjpeg/issues/449) +- Image in pdf don't display [\#447](https://github.com/uclouvain/openjpeg/issues/447) +- Multiple issues causing opj\_decompress to segfault [\#446](https://github.com/uclouvain/openjpeg/issues/446) +- opj\_compress: 40% of encode time is spent freeing data [\#445](https://github.com/uclouvain/openjpeg/issues/445) +- Multiple warnings when configuring OpenJPEG on MacOS with CMake 3.x \(trunk\) [\#443](https://github.com/uclouvain/openjpeg/issues/443) +- valgrind memleak found [\#437](https://github.com/uclouvain/openjpeg/issues/437) +- global-buffer-overflow src/lib/openjp2/t1.c:1146 opj\_t1\_getwmsedec [\#436](https://github.com/uclouvain/openjpeg/issues/436) +- Warning introduced on trunk r2923 & r2924 [\#435](https://github.com/uclouvain/openjpeg/issues/435) +- heap-buffer-overflow in opj\_t1\_decode\_cblks [\#432](https://github.com/uclouvain/openjpeg/issues/432) +- Heap-buffer-overflow in opj\_tcd\_init\_decode\_tile [\#431](https://github.com/uclouvain/openjpeg/issues/431) +- Heap-buffer-overflow in opj\_j2k\_tcp\_destroy [\#430](https://github.com/uclouvain/openjpeg/issues/430) +- Heap-buffer-overflow in opj\_jp2\_apply\_pclr [\#429](https://github.com/uclouvain/openjpeg/issues/429) +- issue412 revisited [\#428](https://github.com/uclouvain/openjpeg/issues/428) +- Image distorted \(sides look cankered\) [\#423](https://github.com/uclouvain/openjpeg/issues/423) +- openjpeg-2.x-trunk-r2918 is broken in color.c [\#422](https://github.com/uclouvain/openjpeg/issues/422) +- Heap-buffer-overflow in opj\_tcd\_init\_decode\_tile [\#420](https://github.com/uclouvain/openjpeg/issues/420) +- Heap-use-after-free in opj\_t1\_decode\_cblks [\#418](https://github.com/uclouvain/openjpeg/issues/418) +- UNKNOWN in opj\_read\_bytes\_LE [\#417](https://github.com/uclouvain/openjpeg/issues/417) +- Transparency problem [\#416](https://github.com/uclouvain/openjpeg/issues/416) +- Image with per channel alpha \(cdef\) does not decode properly [\#414](https://github.com/uclouvain/openjpeg/issues/414) +- OpenJPEG crashes with attached image [\#413](https://github.com/uclouvain/openjpeg/issues/413) +- Palette image with cdef fails to decompress [\#412](https://github.com/uclouvain/openjpeg/issues/412) +- Invalid member values from opj\_read\_header or opj\_decode ? [\#411](https://github.com/uclouvain/openjpeg/issues/411) +- MD5 Checksum hangs under valgrind on MacOS X [\#410](https://github.com/uclouvain/openjpeg/issues/410) +- Heap-buffer-overflow in opj\_tcd\_get\_decoded\_tile\_size [\#408](https://github.com/uclouvain/openjpeg/issues/408) +- C++ style comments in trunk/src/lib/openjp2/j2k.c [\#407](https://github.com/uclouvain/openjpeg/issues/407) +- Backport bugfixes from trunk to 2.1 branch [\#405](https://github.com/uclouvain/openjpeg/issues/405) +- Heap-buffer-overflow in parse\_cmdline\_encoder [\#403](https://github.com/uclouvain/openjpeg/issues/403) +- Heap-buffer-overflow in opj\_v4dwt\_interleave\_h [\#400](https://github.com/uclouvain/openjpeg/issues/400) +- Heap-buffer-overflow in opj\_dwt\_decode [\#399](https://github.com/uclouvain/openjpeg/issues/399) +- Heap-use-after-free in opj\_t1\_decode\_cblks [\#398](https://github.com/uclouvain/openjpeg/issues/398) +- Heap-buffer-overflow in opj\_jp2\_apply\_cdef [\#397](https://github.com/uclouvain/openjpeg/issues/397) +- Heap-buffer-overflow in opj\_t2\_read\_packet\_header [\#396](https://github.com/uclouvain/openjpeg/issues/396) +- Heap-buffer-overflow in opj\_t2\_read\_packet\_header [\#395](https://github.com/uclouvain/openjpeg/issues/395) +- Heap-buffer-overflow in opj\_dwt\_decode\_1 [\#394](https://github.com/uclouvain/openjpeg/issues/394) +- Heap-double-free in j2k\_read\_ppm\_v3 [\#393](https://github.com/uclouvain/openjpeg/issues/393) +- Security hole in j2k.c [\#392](https://github.com/uclouvain/openjpeg/issues/392) +- Security: double-free in opj\_tcd\_code\_block\_dec\_deallocate [\#391](https://github.com/uclouvain/openjpeg/issues/391) +- check for negative-size params in code [\#390](https://github.com/uclouvain/openjpeg/issues/390) +- Heap-buffer-overflow in opj\_t2\_read\_packet\_header [\#389](https://github.com/uclouvain/openjpeg/issues/389) +- Heap overflow in OpenJpeg 1.5.2 [\#388](https://github.com/uclouvain/openjpeg/issues/388) +- openjpip.so.6 file too short [\#387](https://github.com/uclouvain/openjpeg/issues/387) +- Corrupted JP3D file [\#386](https://github.com/uclouvain/openjpeg/issues/386) +- variable assigned to itself [\#383](https://github.com/uclouvain/openjpeg/issues/383) +- Null pointer dereferencing [\#382](https://github.com/uclouvain/openjpeg/issues/382) +- bad use of case statement [\#381](https://github.com/uclouvain/openjpeg/issues/381) +- Release 2.1 as a Ubuntu package [\#380](https://github.com/uclouvain/openjpeg/issues/380) +- Bug in libopenjpwl.pc [\#374](https://github.com/uclouvain/openjpeg/issues/374) +- inconsistent tile numbering in decode output message [\#370](https://github.com/uclouvain/openjpeg/issues/370) +- error in code block calculations [\#369](https://github.com/uclouvain/openjpeg/issues/369) +- r2872 fails to compile due to "attempt to use poisoned malloc" error in j2k.c [\#368](https://github.com/uclouvain/openjpeg/issues/368) +- OSX build gives libopenjp2.6.dylib with not-absolute install name id [\#367](https://github.com/uclouvain/openjpeg/issues/367) +- opj\_decompress gives error but successfully decompress in OPJ 2.1 [\#366](https://github.com/uclouvain/openjpeg/issues/366) +- pngtoimage\(\) and imagetopng\(\) have wrong byte order for 16-Bit image [\#365](https://github.com/uclouvain/openjpeg/issues/365) +- PDF crash in chrome - part2 \(due to attachment limit\) [\#364](https://github.com/uclouvain/openjpeg/issues/364) +- PDF crash in chrome - part1 [\#363](https://github.com/uclouvain/openjpeg/issues/363) +- PDF crash in chrome - part0 [\#362](https://github.com/uclouvain/openjpeg/issues/362) +- Compilation fails on Windows with mingw32 gcc4.8 [\#361](https://github.com/uclouvain/openjpeg/issues/361) +- security issue [\#360](https://github.com/uclouvain/openjpeg/issues/360) +- improve memory management [\#359](https://github.com/uclouvain/openjpeg/issues/359) +- how to compress a yuv420 raw data using opj\_compress [\#357](https://github.com/uclouvain/openjpeg/issues/357) +- Some memory allocation are not checked [\#355](https://github.com/uclouvain/openjpeg/issues/355) +- Static library symbols shall be marked as hidden [\#354](https://github.com/uclouvain/openjpeg/issues/354) +- opj\_compress rejects valid bmp files [\#353](https://github.com/uclouvain/openjpeg/issues/353) +- opj\_compress crashes when number of resolutions is set to zero [\#352](https://github.com/uclouvain/openjpeg/issues/352) +- Compilation error under Visual Studio 2003 [\#351](https://github.com/uclouvain/openjpeg/issues/351) +- opj\_compress description example error \[Low priority\] [\#350](https://github.com/uclouvain/openjpeg/issues/350) +- opj\_write\_bytes\_BE is wrong in trunk [\#345](https://github.com/uclouvain/openjpeg/issues/345) +- PART1ONLY option in release.sh doesn't work properly [\#332](https://github.com/uclouvain/openjpeg/issues/332) +- openjpeg crash error [\#330](https://github.com/uclouvain/openjpeg/issues/330) +- openjpeg decompress error [\#329](https://github.com/uclouvain/openjpeg/issues/329) +- openjpeg decompress issue [\#326](https://github.com/uclouvain/openjpeg/issues/326) +- limited tif support [\#322](https://github.com/uclouvain/openjpeg/issues/322) +- asoc value of 65536 is allowed [\#321](https://github.com/uclouvain/openjpeg/issues/321) +- opj\_skip\_from\_file error [\#314](https://github.com/uclouvain/openjpeg/issues/314) +- Heavy quota usage in openjpeg [\#309](https://github.com/uclouvain/openjpeg/issues/309) +- Verify -help actually match letter [\#307](https://github.com/uclouvain/openjpeg/issues/307) +- g3\_colr.j2c not handled [\#288](https://github.com/uclouvain/openjpeg/issues/288) +- reopen/fix issue 165 [\#280](https://github.com/uclouvain/openjpeg/issues/280) +- kakadu conformance tests [\#279](https://github.com/uclouvain/openjpeg/issues/279) +- missing break after case statement in opj\_dwt\_decode\_real [\#274](https://github.com/uclouvain/openjpeg/issues/274) +- Run Coverity on trunk [\#270](https://github.com/uclouvain/openjpeg/issues/270) +- NR-ENC-random-issue-0005.tif-12-encode [\#259](https://github.com/uclouvain/openjpeg/issues/259) +- Use new add\_test signature to handle cross compilation [\#258](https://github.com/uclouvain/openjpeg/issues/258) +- Loss decoding quality in 2.0.0 [\#254](https://github.com/uclouvain/openjpeg/issues/254) +- Decompress that worked in 1.5.1 fails in 2.0 [\#252](https://github.com/uclouvain/openjpeg/issues/252) +- Expected endianness with raw input is not documented leading to SEGFAULT [\#251](https://github.com/uclouvain/openjpeg/issues/251) +- OpenJPEG writes to stderr [\#246](https://github.com/uclouvain/openjpeg/issues/246) +- Inconsistent logging of tile index [\#245](https://github.com/uclouvain/openjpeg/issues/245) +- patch for openjpeg-trunk-r2347 and BIG\_ENDIAN [\#242](https://github.com/uclouvain/openjpeg/issues/242) +- CMAP: MTYP == 0 \(direct use\) not handled properly [\#235](https://github.com/uclouvain/openjpeg/issues/235) +- Black Pixel [\#233](https://github.com/uclouvain/openjpeg/issues/233) +- opj\_compress runtime error after fresh Linux install due to apparent failure to execute ldconfig [\#219](https://github.com/uclouvain/openjpeg/issues/219) +- openjp2 debug works, release build does not [\#217](https://github.com/uclouvain/openjpeg/issues/217) +- openjpeg-branch15-r2299 and openjpeg-trunk-r2299 fail to decode a JP2 file [\#212](https://github.com/uclouvain/openjpeg/issues/212) +- openjpeg-trunk issue with Win7 [\#201](https://github.com/uclouvain/openjpeg/issues/201) +- undefined reference to `opj\_version' [\#200](https://github.com/uclouvain/openjpeg/issues/200) +- In tgt.c we used fprintf not the openjpeg message reporter [\#184](https://github.com/uclouvain/openjpeg/issues/184) +- Windows binaries not working under WinXP [\#176](https://github.com/uclouvain/openjpeg/issues/176) +- add ability to use intel ipp \(performance primitive\) within OpenJPEG [\#164](https://github.com/uclouvain/openjpeg/issues/164) +- Migration guide v2 [\#160](https://github.com/uclouvain/openjpeg/issues/160) +- Cannot decompress JPEG2000Aware3.18.7.3Win32\_kdutranscode6.3.1.j2k [\#158](https://github.com/uclouvain/openjpeg/issues/158) +- Cannot decompress JPEG2000Aware3.18.7.3Win32.j2k [\#157](https://github.com/uclouvain/openjpeg/issues/157) +- openjpeg@googlegroups.com has disappeared [\#153](https://github.com/uclouvain/openjpeg/issues/153) +- OpenJPEG 1.5.0 crashes on a ridiculously big file... [\#151](https://github.com/uclouvain/openjpeg/issues/151) +- opj\_image vs free [\#146](https://github.com/uclouvain/openjpeg/issues/146) +- Windows .dll file invalid [\#140](https://github.com/uclouvain/openjpeg/issues/140) +- Problem with second layer of a 2 layer coded LRCP \(with precincts\) [\#135](https://github.com/uclouvain/openjpeg/issues/135) +- version 1.4 crashes when opening PDF file with JPEG2000 images [\#133](https://github.com/uclouvain/openjpeg/issues/133) +- Setup a win64 dashboard [\#132](https://github.com/uclouvain/openjpeg/issues/132) +- J2KP4files/codestreams\_profile0/p0\_13.j2k question jpeg2000 [\#131](https://github.com/uclouvain/openjpeg/issues/131) +- Out of memory: Kill process 11204 \(opj\_server\) score 917 or sacrifice child [\#123](https://github.com/uclouvain/openjpeg/issues/123) +- FILE\* in opj API is unsafe [\#120](https://github.com/uclouvain/openjpeg/issues/120) +- third-party lib order [\#119](https://github.com/uclouvain/openjpeg/issues/119) +- openjpeg-1.5.0-Darwin-powerpc.dmg is huge ! [\#113](https://github.com/uclouvain/openjpeg/issues/113) +- misleading info in JP2 box lead to wrong number of components [\#110](https://github.com/uclouvain/openjpeg/issues/110) +- Image\_to\_j2k says that j2k files is generated but no file is on the HDD [\#109](https://github.com/uclouvain/openjpeg/issues/109) +- Error in openjpegV1.4 on compiling image\_to\_j2k: crash on reading bmp file [\#108](https://github.com/uclouvain/openjpeg/issues/108) +- Update to abi-compliance-checker 1.96 [\#106](https://github.com/uclouvain/openjpeg/issues/106) +- Decode error on the attached JPEG...works in KDU and with JASPER...please help! [\#101](https://github.com/uclouvain/openjpeg/issues/101) +- Mac binaries v1.4 is broken [\#95](https://github.com/uclouvain/openjpeg/issues/95) +- jp2\_read\_boxhdr\(\) has size bug in version 1 [\#92](https://github.com/uclouvain/openjpeg/issues/92) +- Support for Java JAI Imageio [\#90](https://github.com/uclouvain/openjpeg/issues/90) +- encoding test failing [\#86](https://github.com/uclouvain/openjpeg/issues/86) +- source archive on demand [\#85](https://github.com/uclouvain/openjpeg/issues/85) +- CMakeLists.txt and Makefile.am for JPIP are buggy [\#84](https://github.com/uclouvain/openjpeg/issues/84) +- pclr-cmap-cdef [\#82](https://github.com/uclouvain/openjpeg/issues/82) +- Error when compiling openjpeg\_v1\_4\_sources\_r697 [\#79](https://github.com/uclouvain/openjpeg/issues/79) +- J2K codec issue on Windows Mobile [\#77](https://github.com/uclouvain/openjpeg/issues/77) +- image\_to\_j2k.exe crashes on large .bmp file [\#75](https://github.com/uclouvain/openjpeg/issues/75) +- fatal error C1900 building the project on windows [\#65](https://github.com/uclouvain/openjpeg/issues/65) +- same option but different size [\#54](https://github.com/uclouvain/openjpeg/issues/54) +- Missing openjpegConfigure.h [\#38](https://github.com/uclouvain/openjpeg/issues/38) +- Not an issue in openjpeg, but ... [\#37](https://github.com/uclouvain/openjpeg/issues/37) +- OpenJPEG-1.3.0 pclr, cmap and cdef [\#27](https://github.com/uclouvain/openjpeg/issues/27) +- realloc maybe too big \(t2.c\) [\#26](https://github.com/uclouvain/openjpeg/issues/26) +- libopenjpeg/opj\_malloc.h breaks on FreeBSD/Darwin systems [\#20](https://github.com/uclouvain/openjpeg/issues/20) +- image\_to\_j2k not outputting to win32 console properly [\#18](https://github.com/uclouvain/openjpeg/issues/18) +- \[OpenJPEG\] OpenJPEG\_v13: tiled image part 2 [\#17](https://github.com/uclouvain/openjpeg/issues/17) +- JP2 Color Space modification by Matteo Italia [\#13](https://github.com/uclouvain/openjpeg/issues/13) +- Patch submission \( exotic video formats, and a few things \) [\#12](https://github.com/uclouvain/openjpeg/issues/12) +- 16 bits lossy compression [\#10](https://github.com/uclouvain/openjpeg/issues/10) +- pnm file formats not accepting bitdepth greater than 8 bpp [\#8](https://github.com/uclouvain/openjpeg/issues/8) +- Heap corruption in j2k encoder [\#5](https://github.com/uclouvain/openjpeg/issues/5) +- JPWL crash in marker reallocation\(+patch\), segfault while decoding image with main header protection [\#4](https://github.com/uclouvain/openjpeg/issues/4) +- a couple of small errors in libopenjpeg detected by coverity [\#1](https://github.com/uclouvain/openjpeg/issues/1) + +**Closed issues:** + +- Shared library build broken on ubuntu [\#728](https://github.com/uclouvain/openjpeg/issues/728) +- opj\_includes.h shouldn't define `\_\_attribute\_\_` [\#727](https://github.com/uclouvain/openjpeg/issues/727) +- Possible website problems due to Jekyll upgrade [\#713](https://github.com/uclouvain/openjpeg/issues/713) +- Stable Release? [\#712](https://github.com/uclouvain/openjpeg/issues/712) +- Meta Issue : try to fix some of these critical bugs before thinking about optimizing the library [\#710](https://github.com/uclouvain/openjpeg/issues/710) +- Tiled encoding broken for images with non power of 2 dimensions [\#702](https://github.com/uclouvain/openjpeg/issues/702) +- install\_name \(still\) not set on OS X [\#700](https://github.com/uclouvain/openjpeg/issues/700) +- Add section in wiki describing where one can get test images [\#699](https://github.com/uclouvain/openjpeg/issues/699) +- Make EvenManager into singleton [\#698](https://github.com/uclouvain/openjpeg/issues/698) +- Remove old branches from repo [\#696](https://github.com/uclouvain/openjpeg/issues/696) +- MQ Coder encode: Conditional jump or move depends on uninitialised value\(s\) [\#695](https://github.com/uclouvain/openjpeg/issues/695) +- Can we add these files to our test suite ? [\#688](https://github.com/uclouvain/openjpeg/issues/688) +- -t and -d command line flags for decode are not documented on OpenJPEG website [\#685](https://github.com/uclouvain/openjpeg/issues/685) +- Decoding at the precinct level [\#676](https://github.com/uclouvain/openjpeg/issues/676) +- Support unscaled 10 bit data for 2K cinema @ 48 FPS, as per DCI standard [\#671](https://github.com/uclouvain/openjpeg/issues/671) +- Use parallel jobs in ctest [\#664](https://github.com/uclouvain/openjpeg/issues/664) +- \[Security\]Multiple Memory error [\#663](https://github.com/uclouvain/openjpeg/issues/663) +- lossy encoding a 16 bit TIF file : severe artifacts in decompressed image [\#660](https://github.com/uclouvain/openjpeg/issues/660) +- opj\_compress and opj\_decompress : get\_next\_file method uses hard-coded unix path separator [\#630](https://github.com/uclouvain/openjpeg/issues/630) +- Uninitialized variable [\#629](https://github.com/uclouvain/openjpeg/issues/629) +- Use of enum variable for bit flags prevents compilation as C++ source [\#619](https://github.com/uclouvain/openjpeg/issues/619) +- Serious problem with quantization during lossy encoding [\#615](https://github.com/uclouvain/openjpeg/issues/615) +- Decompression does not work with sequential data source [\#613](https://github.com/uclouvain/openjpeg/issues/613) +- potential overflow in opj\_tcd\_tile\_t [\#605](https://github.com/uclouvain/openjpeg/issues/605) +- Logical condition [\#596](https://github.com/uclouvain/openjpeg/issues/596) +- file9.jp2 does not dump correctly on 1.5 [\#595](https://github.com/uclouvain/openjpeg/issues/595) +- opj\_compress man page is missing documentation of -jpip option [\#593](https://github.com/uclouvain/openjpeg/issues/593) +- opj\_compress fails to compress lossless on gcc/x86 \(-m32\) in 1.5 branch [\#591](https://github.com/uclouvain/openjpeg/issues/591) +- Example: opj\_compress -i image.j2k -o image.pgm [\#577](https://github.com/uclouvain/openjpeg/issues/577) +- Mismatching delete [\#575](https://github.com/uclouvain/openjpeg/issues/575) +- Compilation fails on Win7 [\#546](https://github.com/uclouvain/openjpeg/issues/546) +- NR-JP2-file5.jp2-compare2base fails with third party libcms [\#540](https://github.com/uclouvain/openjpeg/issues/540) +- CTest spits out an error at the end of the test run [\#516](https://github.com/uclouvain/openjpeg/issues/516) +- opj\_uint\_adds\(\) is questionable [\#515](https://github.com/uclouvain/openjpeg/issues/515) +- Might consider renaming this method: [\#491](https://github.com/uclouvain/openjpeg/issues/491) +- opj\_compress run twice gives different fiile sizes for same file [\#490](https://github.com/uclouvain/openjpeg/issues/490) +- Android Support [\#483](https://github.com/uclouvain/openjpeg/issues/483) +- Add SSE2/SSE41 implementations for mct.c [\#451](https://github.com/uclouvain/openjpeg/issues/451) +- Reduce encoder code block memory usage for non 64x64 code block sizes [\#444](https://github.com/uclouvain/openjpeg/issues/444) +- valgrind "Uninitialized Memory Read" & "Uninitialized Memory Conditional" found [\#438](https://github.com/uclouvain/openjpeg/issues/438) +- No way to debug opj\_tcd\_init\_encode\_tile or opj\_tcd\_init\_decode\_tile [\#433](https://github.com/uclouvain/openjpeg/issues/433) +- Add option to call dsymutil on built binaries [\#409](https://github.com/uclouvain/openjpeg/issues/409) +- Allow opj\_compress and opj\_decompress to read/write images over stdin/stdout [\#379](https://github.com/uclouvain/openjpeg/issues/379) +- reduce memory significantly for single tile RGB encoding [\#375](https://github.com/uclouvain/openjpeg/issues/375) +- Switch code repo to github and start using pull request workflow [\#373](https://github.com/uclouvain/openjpeg/issues/373) +- This is a BigTIFF file. This format not supported [\#125](https://github.com/uclouvain/openjpeg/issues/125) +- Add a test suite to check the convert functions [\#99](https://github.com/uclouvain/openjpeg/issues/99) +- Add build config to the dashboard to verify the autotools build [\#88](https://github.com/uclouvain/openjpeg/issues/88) + +**Merged pull requests:** + +- Correct abi-check.sh for PR [\#791](https://github.com/uclouvain/openjpeg/pull/791) ([mayeut](https://github.com/mayeut)) +- Update tcd.c [\#790](https://github.com/uclouvain/openjpeg/pull/790) ([maddin200](https://github.com/maddin200)) +- Update lcms2 [\#773](https://github.com/uclouvain/openjpeg/pull/773) ([mayeut](https://github.com/mayeut)) +- Use lowercase for cmake commands consistently [\#769](https://github.com/uclouvain/openjpeg/pull/769) ([julienmalik](https://github.com/julienmalik)) +- Ignore clang's summary warning [\#768](https://github.com/uclouvain/openjpeg/pull/768) ([julienmalik](https://github.com/julienmalik)) +- Fix UBSan gcc warning for first arg to memset non null [\#767](https://github.com/uclouvain/openjpeg/pull/767) ([julienmalik](https://github.com/julienmalik)) +- Update to libtiff-4.0.6 [\#764](https://github.com/uclouvain/openjpeg/pull/764) ([mayeut](https://github.com/mayeut)) +- Fix warnings [\#763](https://github.com/uclouvain/openjpeg/pull/763) ([mayeut](https://github.com/mayeut)) +- Check SSIZ is valid in opj\_j2k\_read\_siz [\#762](https://github.com/uclouvain/openjpeg/pull/762) ([mayeut](https://github.com/mayeut)) +- Fix unsigned int overflow reported by UBSan [\#761](https://github.com/uclouvain/openjpeg/pull/761) ([mayeut](https://github.com/mayeut)) +- Fix unsigned int overflow reported by UBSan [\#759](https://github.com/uclouvain/openjpeg/pull/759) ([mayeut](https://github.com/mayeut)) +- Fix negative shift left reported by UBSan [\#758](https://github.com/uclouvain/openjpeg/pull/758) ([mayeut](https://github.com/mayeut)) +- Fix negative shift left reported by UBSan [\#757](https://github.com/uclouvain/openjpeg/pull/757) ([mayeut](https://github.com/mayeut)) +- Add clang 3.9 build to Travis matrix [\#753](https://github.com/uclouvain/openjpeg/pull/753) ([julienmalik](https://github.com/julienmalik)) +- Fix implicit floating bool conversion [\#752](https://github.com/uclouvain/openjpeg/pull/752) ([julienmalik](https://github.com/julienmalik)) +- Do not define \_\_attribute\_\_ in opj\_includes.h [\#751](https://github.com/uclouvain/openjpeg/pull/751) ([mayeut](https://github.com/mayeut)) +- Allow to read/write 3/5/7/9/11/13/15 bpp TIF files [\#750](https://github.com/uclouvain/openjpeg/pull/750) ([mayeut](https://github.com/mayeut)) +- Fix heap-buffer-overflow in color\_esycc\_to\_rgb [\#748](https://github.com/uclouvain/openjpeg/pull/748) ([mayeut](https://github.com/mayeut)) +- update libpng to from 1.6.17 to 1.6.21 [\#747](https://github.com/uclouvain/openjpeg/pull/747) ([julienmalik](https://github.com/julienmalik)) +- Update cmake & jpylyzer for travis builds [\#746](https://github.com/uclouvain/openjpeg/pull/746) ([julienmalik](https://github.com/julienmalik)) +- Fix Out-Of-Bounds Read in sycc42x\_to\_rgb function [\#745](https://github.com/uclouvain/openjpeg/pull/745) ([mayeut](https://github.com/mayeut)) +- cppcheck fix for openjp2 [\#740](https://github.com/uclouvain/openjpeg/pull/740) ([julienmalik](https://github.com/julienmalik)) +- Fix uninitialized variable reported by cppcheck [\#735](https://github.com/uclouvain/openjpeg/pull/735) ([julienmalik](https://github.com/julienmalik)) +- Remove dead code in opj\_dump [\#734](https://github.com/uclouvain/openjpeg/pull/734) ([julienmalik](https://github.com/julienmalik)) +- issue \#695 MQ Encode: ensure that bp pointer never points to uninitialized memory [\#708](https://github.com/uclouvain/openjpeg/pull/708) ([boxerab](https://github.com/boxerab)) +- Fix issue 135 [\#706](https://github.com/uclouvain/openjpeg/pull/706) ([mayeut](https://github.com/mayeut)) +- Fix implementation of opj\_calloc [\#705](https://github.com/uclouvain/openjpeg/pull/705) ([stweil](https://github.com/stweil)) +- \[git/2.1 regression\] Fix opj\_write\_tile\(\) failure when numresolutions=1 [\#690](https://github.com/uclouvain/openjpeg/pull/690) ([rouault](https://github.com/rouault)) +- Fix fatal crash on 64 bit Linux [\#687](https://github.com/uclouvain/openjpeg/pull/687) ([stweil](https://github.com/stweil)) +- \[libtiff\] Add missing include statement for ssize\_t [\#686](https://github.com/uclouvain/openjpeg/pull/686) ([mayeut](https://github.com/mayeut)) +- Fix duplicate article in comments [\#684](https://github.com/uclouvain/openjpeg/pull/684) ([stweil](https://github.com/stweil)) +- Fix grammar in comment [\#679](https://github.com/uclouvain/openjpeg/pull/679) ([stweil](https://github.com/stweil)) +- Remove whitespace and CR at line endings [\#678](https://github.com/uclouvain/openjpeg/pull/678) ([stweil](https://github.com/stweil)) +- Fix typos [\#665](https://github.com/uclouvain/openjpeg/pull/665) ([jwilk](https://github.com/jwilk)) +- Add missing source for the JPIP library and executables \(issue \#658\) [\#659](https://github.com/uclouvain/openjpeg/pull/659) ([stweil](https://github.com/stweil)) +- Fix undefined size jp2 box handling [\#654](https://github.com/uclouvain/openjpeg/pull/654) ([mayeut](https://github.com/mayeut)) +- opj\_decompress: Update error message [\#651](https://github.com/uclouvain/openjpeg/pull/651) ([stweil](https://github.com/stweil)) +- Fix support of posix\_memalloc for Linux [\#648](https://github.com/uclouvain/openjpeg/pull/648) ([stweil](https://github.com/stweil)) +- Fix typo in comments [\#647](https://github.com/uclouvain/openjpeg/pull/647) ([stweil](https://github.com/stweil)) +- Avoid pointer arithmetic with \(void \*\) pointers [\#644](https://github.com/uclouvain/openjpeg/pull/644) ([smuehlst](https://github.com/smuehlst)) +- Fix HP compiler warning about redeclaration of function \(\#640\) [\#641](https://github.com/uclouvain/openjpeg/pull/641) ([smuehlst](https://github.com/smuehlst)) +- Fix format strings and unneeded assignment [\#638](https://github.com/uclouvain/openjpeg/pull/638) ([stweil](https://github.com/stweil)) +- Fix repository for JPEG2000 test data [\#637](https://github.com/uclouvain/openjpeg/pull/637) ([stweil](https://github.com/stweil)) +- Update allocation functions [\#636](https://github.com/uclouvain/openjpeg/pull/636) ([mayeut](https://github.com/mayeut)) +- Fix OpenJPEG GitHub issue \#633. [\#634](https://github.com/uclouvain/openjpeg/pull/634) ([smuehlst](https://github.com/smuehlst)) +- travis-ci: Include add ons in matrix [\#632](https://github.com/uclouvain/openjpeg/pull/632) ([mayeut](https://github.com/mayeut)) +- Add Appveyor [\#627](https://github.com/uclouvain/openjpeg/pull/627) ([mayeut](https://github.com/mayeut)) +- Use Travis-ci to run ABI check [\#626](https://github.com/uclouvain/openjpeg/pull/626) ([mayeut](https://github.com/mayeut)) +- Fix warnings for C++ [\#623](https://github.com/uclouvain/openjpeg/pull/623) ([stweil](https://github.com/stweil)) +- Fixed problem that C++ compilation failed because of enum variable. [\#622](https://github.com/uclouvain/openjpeg/pull/622) ([smuehlst](https://github.com/smuehlst)) +- Added missing casts for return values of opj\_malloc\(\)/opj\_calloc\(\). [\#618](https://github.com/uclouvain/openjpeg/pull/618) ([smuehlst](https://github.com/smuehlst)) +- Add check for seek support before trying TPsot==TNsot workaround [\#617](https://github.com/uclouvain/openjpeg/pull/617) ([mayeut](https://github.com/mayeut)) +- Fix some typos found by codespell [\#610](https://github.com/uclouvain/openjpeg/pull/610) ([stweil](https://github.com/stweil)) +- Correct leak in color\_cielab\_to\_rgb [\#590](https://github.com/uclouvain/openjpeg/pull/590) ([mayeut](https://github.com/mayeut)) +- Add Travis-ci build matrix [\#584](https://github.com/uclouvain/openjpeg/pull/584) ([mayeut](https://github.com/mayeut)) +- Correct lossless issue on linux x86 [\#579](https://github.com/uclouvain/openjpeg/pull/579) ([mayeut](https://github.com/mayeut)) +- Travis-ci update [\#578](https://github.com/uclouvain/openjpeg/pull/578) ([mayeut](https://github.com/mayeut)) +- Correct CMake version requirements [\#572](https://github.com/uclouvain/openjpeg/pull/572) ([mayeut](https://github.com/mayeut)) +- Add tests for CMYK/esYCC/CIELab [\#567](https://github.com/uclouvain/openjpeg/pull/567) ([mayeut](https://github.com/mayeut)) +- Add support for CIELab, EYCC and CMYK [\#559](https://github.com/uclouvain/openjpeg/pull/559) ([szukw000](https://github.com/szukw000)) +- Remove printf/fprintf to stdout/stderr throughout openjp2 lib [\#558](https://github.com/uclouvain/openjpeg/pull/558) ([mayeut](https://github.com/mayeut)) +- better -ffast-math handling [\#555](https://github.com/uclouvain/openjpeg/pull/555) ([rdieter](https://github.com/rdieter)) +- Add jpylyzer tests for JP2 compression [\#552](https://github.com/uclouvain/openjpeg/pull/552) ([mayeut](https://github.com/mayeut)) +- Add COC/QCC in main header when needed [\#551](https://github.com/uclouvain/openjpeg/pull/551) ([mayeut](https://github.com/mayeut)) +- Use \_\_emul under msvc x86 for fast 64 = 32 \* 32 [\#550](https://github.com/uclouvain/openjpeg/pull/550) ([mayeut](https://github.com/mayeut)) +- Update convert for PNG output [\#549](https://github.com/uclouvain/openjpeg/pull/549) ([mayeut](https://github.com/mayeut)) +- Remove some warnings when building [\#548](https://github.com/uclouvain/openjpeg/pull/548) ([mayeut](https://github.com/mayeut)) +- Switch to libpng-1.6.17 [\#547](https://github.com/uclouvain/openjpeg/pull/547) ([mayeut](https://github.com/mayeut)) +- Add some missing static keywords [\#545](https://github.com/uclouvain/openjpeg/pull/545) ([mayeut](https://github.com/mayeut)) +- Switch to libcms2 mm2/Little-CMS@0e8234e090d6aab33f90e2eb0296f30aa0705e57 [\#544](https://github.com/uclouvain/openjpeg/pull/544) ([mayeut](https://github.com/mayeut)) +- Prevent overflow when coding 16 bits images [\#543](https://github.com/uclouvain/openjpeg/pull/543) ([mayeut](https://github.com/mayeut)) +- Switch to libcms2-2.6 [\#542](https://github.com/uclouvain/openjpeg/pull/542) ([mayeut](https://github.com/mayeut)) +- Update PNG support [\#538](https://github.com/uclouvain/openjpeg/pull/538) ([mayeut](https://github.com/mayeut)) +- Various Minor fixes [\#537](https://github.com/uclouvain/openjpeg/pull/537) ([mayeut](https://github.com/mayeut)) +- Update TIFF conversion to support more bit depth. [\#535](https://github.com/uclouvain/openjpeg/pull/535) ([mayeut](https://github.com/mayeut)) +- Add checks for odd looking cmap & for cmap outside jp2h box [\#534](https://github.com/uclouvain/openjpeg/pull/534) ([mayeut](https://github.com/mayeut)) +- Refactor opj\_j2k\_read\_ppm & opj\_j2k\_read\_ppt [\#533](https://github.com/uclouvain/openjpeg/pull/533) ([mayeut](https://github.com/mayeut)) +- Add option to force component splitting in imagetopnm [\#531](https://github.com/uclouvain/openjpeg/pull/531) ([mayeut](https://github.com/mayeut)) +- fix Suspicious code in j2k.c \#517 [\#529](https://github.com/uclouvain/openjpeg/pull/529) ([renevanderark](https://github.com/renevanderark)) +- Update zlib to version 1.2.8 [\#528](https://github.com/uclouvain/openjpeg/pull/528) ([mayeut](https://github.com/mayeut)) +- Fix opj\_write\_bytes\_BE \(\#518\) [\#521](https://github.com/uclouvain/openjpeg/pull/521) ([manisandro](https://github.com/manisandro)) +- Correctly decode files with incorrect tile-part header fields \(TPsot==TNsot\) [\#514](https://github.com/uclouvain/openjpeg/pull/514) ([mayeut](https://github.com/mayeut)) +- Fixed typos [\#510](https://github.com/uclouvain/openjpeg/pull/510) ([radarhere](https://github.com/radarhere)) +- Formatted the readme file [\#507](https://github.com/uclouvain/openjpeg/pull/507) ([htmfilho](https://github.com/htmfilho)) + +## [version.2.1](https://github.com/uclouvain/openjpeg/releases/tag/version.2.1) (2014-04-29) +List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.2.0.1...version.2.1) + +## [version.2.0.1](https://github.com/uclouvain/openjpeg/releases/tag/version.2.0.1) (2014-04-22) +List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.5.2...version.2.0.1) + +## [version.1.5.2](https://github.com/uclouvain/openjpeg/releases/tag/version.1.5.2) (2014-03-28) +List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.2.0...version.1.5.2) + +## [version.2.0](https://github.com/uclouvain/openjpeg/releases/tag/version.2.0) (2014-03-28) +List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.5.1...version.2.0) + +## [version.1.5.1](https://github.com/uclouvain/openjpeg/releases/tag/version.1.5.1) (2012-09-13) +List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.5...version.1.5.1) + +## [version.1.5](https://github.com/uclouvain/openjpeg/releases/tag/version.1.5) (2012-02-07) +List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.3...version.1.5) + +## [version.1.3](https://github.com/uclouvain/openjpeg/releases/tag/version.1.3) (2011-07-03) +List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.4...version.1.3) + +## [version.1.4](https://github.com/uclouvain/openjpeg/releases/tag/version.1.4) (2011-07-03) +List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.2...version.1.4) + +## [version.1.2](https://github.com/uclouvain/openjpeg/releases/tag/version.1.2) (2007-06-04) +List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.1...version.1.2) + +## [version.1.1](https://github.com/uclouvain/openjpeg/releases/tag/version.1.1) (2007-01-31) +List of fixed issues and enhancements unavailable, see [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) or [Full Changelog](https://github.com/uclouvain/openjpeg/compare/version.1.0...version.1.1) + + + +\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3ea2424 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,396 @@ +# Main CMakeLists.txt to build the OpenJPEG project using CMake (www.cmake.org) +# Written by Mathieu Malaterre + +# This CMake project will by default create a library called openjpeg +# But if you want to use this project within your own (CMake) project +# you will eventually like to prefix the library to avoid linking confusion +# For this purpose you can define a CMake var: OPENJPEG_NAMESPACE to whatever you like +# e.g.: +# set(OPENJPEG_NAMESPACE "GDCMOPENJPEG") +cmake_minimum_required(VERSION 2.8.2) + +if(COMMAND CMAKE_POLICY) + cmake_policy(SET CMP0003 NEW) + if (NOT (${CMAKE_VERSION} VERSION_LESS 3.0)) + cmake_policy(SET CMP0042 NEW) + endif() +endif() + +if(NOT OPENJPEG_NAMESPACE) + set(OPENJPEG_NAMESPACE "OPENJPEG") + set(OPENJPEG_STANDALONE 1) +endif() +# In all cases: +#string(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME) +set(OPENJPEG_LIBRARY_NAME openjp2) + +project(${OPENJPEG_NAMESPACE}) + +# Do full dependency headers. +include_regular_expression("^.*$") + +#----------------------------------------------------------------------------- +# OPENJPEG version number, useful for packaging and doxygen doc: +set(OPENJPEG_VERSION_MAJOR 2) +set(OPENJPEG_VERSION_MINOR 3) +set(OPENJPEG_VERSION_BUILD 1) +set(OPENJPEG_VERSION + "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}") +set(PACKAGE_VERSION + "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}") + +# Because autotools does not support X.Y notation for SOVERSION, we have to use +# two numbering, one for the openjpeg version and one for openjpeg soversion +# version | soversion +# 1.0 | 0 +# 1.1 | 1 +# 1.2 | 2 +# 1.3 | 3 +# 1.4 | 4 +# 1.5 | 5 +# 1.5.1 | 5 +# 2.0 | 6 +# 2.0.1 | 6 +# 2.1 | 7 +# 2.1.1 | 7 +# 2.1.2 | 7 +# 2.2.0 | 7 +# 2.3.0 | 7 +# 2.3.1 | 7 +# above is the recommendation by the OPJ team. If you really need to override this default, +# you can specify your own OPENJPEG_SOVERSION at cmake configuration time: +# cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg +if(NOT OPENJPEG_SOVERSION) + set(OPENJPEG_SOVERSION 7) +endif(NOT OPENJPEG_SOVERSION) +set(OPENJPEG_LIBRARY_PROPERTIES + VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}" + SOVERSION "${OPENJPEG_SOVERSION}" +) + +# -------------------------------------------------------------------------- +# Path to additional CMake modules +set(CMAKE_MODULE_PATH + ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake + ${CMAKE_MODULE_PATH}) + +# -------------------------------------------------------------------------- +# On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security +# warnings +if(WIN32) + if(NOT BORLAND) + if(NOT CYGWIN) + if(NOT MINGW) + if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS) + add_definitions( + -D_CRT_FAR_MAPPINGS_NO_DEPRECATE + -D_CRT_IS_WCTYPE_NO_DEPRECATE + -D_CRT_MANAGED_FP_NO_DEPRECATE + -D_CRT_NONSTDC_NO_DEPRECATE + -D_CRT_SECURE_NO_DEPRECATE + -D_CRT_SECURE_NO_DEPRECATE_GLOBALS + -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE + -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE + -D_CRT_VCCLRIT_NO_DEPRECATE + -D_SCL_SECURE_NO_DEPRECATE + ) + endif() + endif() + endif() + endif() +endif() + + +# -------------------------------------------------------------------------- +# Install directories +# Build DOCUMENTATION (not in ALL target and only if Doxygen is found) +option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF) + +string(TOLOWER ${PROJECT_NAME} projectname) +set(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}") + +if(NOT OPENJPEG_INSTALL_BIN_DIR) + set(OPENJPEG_INSTALL_BIN_DIR "bin") +endif() + +if(NOT OPENJPEG_INSTALL_LIB_DIR) + set(OPENJPEG_INSTALL_LIB_DIR "lib") +endif() + +if(NOT OPENJPEG_INSTALL_SHARE_DIR) + set(OPENJPEG_INSTALL_SHARE_DIR "share") +endif() + +if(NOT OPENJPEG_INSTALL_DATA_DIR) + set(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}") +endif() + +if(NOT OPENJPEG_INSTALL_INCLUDE_DIR) + set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}") +endif() + +if(BUILD_DOC) +if(NOT OPENJPEG_INSTALL_MAN_DIR) + set(OPENJPEG_INSTALL_MAN_DIR "share/man/") +endif() + +if(NOT OPENJPEG_INSTALL_DOC_DIR) + set(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}") +endif() +endif() + +if(NOT OPENJPEG_INSTALL_JNI_DIR) + if(WIN32) + set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_BIN_DIR}) + else() + set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR}) + endif() +endif() + +if(NOT OPENJPEG_INSTALL_PACKAGE_DIR) + # We could install *.cmake files in share/ however those files contains + # hardcoded path to libraries on a multi-arch system (fedora/debian) those + # path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu) + set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}") +endif() + +if (APPLE) + list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_LIB_DIR}") + option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF) +endif() + +#----------------------------------------------------------------------------- +# Big endian test: +include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake) +TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN) + +#----------------------------------------------------------------------------- +# Setup file for setting custom ctest vars +configure_file( + ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/CTestCustom.cmake.in + ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/CTestCustom.cmake + @ONLY + ) + +#----------------------------------------------------------------------------- +# OpenJPEG build configuration options. +option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON) +option(BUILD_STATIC_LIBS "Build OpenJPEG static library." ON) +set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.") +set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.") +mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH) + +#----------------------------------------------------------------------------- +# configure name mangling to allow multiple libraries to coexist +# peacefully +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in) +set(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME}) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in + ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h + @ONLY) +endif() + +#----------------------------------------------------------------------------- +# Compiler specific flags: +if(CMAKE_COMPILER_IS_GNUCC) + # For all builds, make sure openjpeg is std99 compliant: + # set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build. + # Do not use ffast-math for all build, it would produce incorrect results, only set for release: + set(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$:-ffast-math>") + set(OPENJP2_COMPILE_OPTIONS ${OPENJP2_COMPILE_OPTIONS} "$<$:-ffast-math>" -Wall -Wextra -Wconversion -Wunused-parameter -Wdeclaration-after-statement -Werror=declaration-after-statement) +endif() + +#----------------------------------------------------------------------------- +# opj_config.h generation (1/2) + +# Check if some include files are provided by the system +include(EnsureFileInclude) +# These files are mandatory +ensure_file_include("string.h" HAVE_STRING_H YES) +ensure_file_include("memory.h" HAVE_MEMORY_H YES) +ensure_file_include("stdlib.h" HAVE_STDLIB_H YES) +ensure_file_include("stdio.h" HAVE_STDIO_H YES) +ensure_file_include("math.h" HAVE_MATH_H YES) +ensure_file_include("float.h" HAVE_FLOAT_H YES) +ensure_file_include("time.h" HAVE_TIME_H YES) +ensure_file_include("stdarg.h" HAVE_STDARG_H YES) +ensure_file_include("ctype.h" HAVE_CTYPE_H YES) +ensure_file_include("assert.h" HAVE_ASSERT_H YES) + +# For the following files, we provide an alternative, they are not mandatory +ensure_file_include("stdint.h" OPJ_HAVE_STDINT_H NO) +ensure_file_include("inttypes.h" OPJ_HAVE_INTTYPES_H NO) + +# why check this one ? for openjpip ? +include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) +CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) +CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) +CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H) +CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) + +# Enable Large file support +include(TestLargeFiles) +OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES) + +# Allocating Aligned Memory Blocks +include(CheckIncludeFiles) +check_include_files(malloc.h OPJ_HAVE_MALLOC_H) +include(CheckSymbolExists) +# _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx +check_symbol_exists(_aligned_malloc malloc.h OPJ_HAVE__ALIGNED_MALLOC) +# posix_memalign (needs _POSIX_C_SOURCE >= 200112L on Linux) +set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L) +check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN) +unset(CMAKE_REQUIRED_DEFINITIONS) +# memalign (obsolete) +check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN) +#----------------------------------------------------------------------------- +# Build Library +if(BUILD_JPIP_SERVER) + find_package(CURL REQUIRED) + find_package(FCGI REQUIRED) + find_package(Threads REQUIRED) + if(NOT CMAKE_USE_PTHREADS_INIT) + message(FATAL_ERROR "Only pthread are supported") + endif() +endif() +add_subdirectory(src/lib) +option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF) +option(BUILD_UNIT_TESTS "Build unit tests (bench_dwt, test_sparse_array, etc..)" OFF) + +#----------------------------------------------------------------------------- +# Build Applications +option(BUILD_CODEC "Build the CODEC executables" ON) +option(BUILD_MJ2 "Build the MJ2 executables." OFF) +option(BUILD_JPWL "Build the JPWL library and executables" OFF) +option(BUILD_JPIP "Build the JPIP library and executables." OFF) +if(BUILD_JPIP) + option(BUILD_JPIP_SERVER "Build the JPIP server." OFF) +endif() +option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF) +option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF) +option(BUILD_JP3D "Build the JP3D comp" OFF) +mark_as_advanced(BUILD_VIEWER) +mark_as_advanced(BUILD_JAVA) +mark_as_advanced(BUILD_JP3D) + +if(BUILD_CODEC OR BUILD_MJ2) + # OFF: It will only build 3rd party libs if they are not found on the system + # ON: 3rd party libs will ALWAYS be build, and used + option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF) + add_subdirectory(thirdparty) + add_subdirectory(src/bin) +endif () +add_subdirectory(wrapping) + +#----------------------------------------------------------------------------- +# opj_config.h generation (2/2) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h + @ONLY + ) + + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h + @ONLY + ) + +#----------------------------------------------------------------------------- +# build documentation in doc subdir: +if(BUILD_DOC) + add_subdirectory(doc) +endif() + +#----------------------------------------------------------------------------- +# Buld Testing +option(BUILD_TESTING "Build the tests." OFF) +if(BUILD_TESTING) + if(BUILD_CODEC) + enable_testing() + include(CTest) + + # Search openjpeg data needed for the tests + # They could be found via git on the OpenJPEG GitHub code project + # git clone https://github.com/uclouvain/openjpeg-data.git + find_path(OPJ_DATA_ROOT README-OPJ-Data + PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data + NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH + ) + + # Add repository where to find tests + add_subdirectory(tests) + + else() + message(FATAL_ERROR "You need build codec to run the tests") + endif() +endif() + +#----------------------------------------------------------------------------- +# install all targets referenced as OPENJPEGTargets +install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}) +configure_file( ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in + ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/OpenJPEGConfig.cmake + @ONLY +) +install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake + DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR} +) + +#----------------------------------------------------------------------------- +# install CHANGES and LICENSE +if(BUILD_DOC) +if(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES) + install(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR}) +endif() + +install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR}) +endif() + +include (cmake/OpenJPEGCPack.cmake) + +#----------------------------------------------------------------------------- +# pkgconfig support +# enabled by default on Unix or if using GCC, disabled by default on other platforms +if(UNIX OR CMAKE_COMPILER_IS_GNUCC) + option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" ON) +else() + option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" OFF) +endif() +if(BUILD_PKGCONFIG_FILES) + # install in lib and not share (see multi-arch note above) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION + ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) +# + if(BUILD_JPWL) + # install in lib and not share (see multi-arch note above) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpwl/libopenjpwl.pc.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc @ONLY) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc DESTINATION + ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) + endif() +# + if(BUILD_JPIP) + # install in lib and not share (see multi-arch note above) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION + ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) + endif() +# + if(BUILD_JP3D) + # install in lib and not share (see multi-arch note above) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp3d/libopenjp3d.pc.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc @ONLY) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc DESTINATION + ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) + endif() +endif() + +#----------------------------------------------------------------------------- + +# build our version of astyle +SET (WITH_ASTYLE FALSE CACHE BOOL "If you plan to contribute you should reindent with scripts/prepare-commit.sh (using 'our' astyle)") diff --git a/CTestConfig.cmake b/CTestConfig.cmake new file mode 100644 index 0000000..6d3866e --- /dev/null +++ b/CTestConfig.cmake @@ -0,0 +1,7 @@ +set(CTEST_PROJECT_NAME "OPENJPEG") +set(CTEST_NIGHTLY_START_TIME "3:00:00 UTC") + +set(CTEST_DROP_METHOD "http") +set(CTEST_DROP_SITE "my.cdash.org") +set(CTEST_DROP_LOCATION "/submit.php?project=OPENJPEG") +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..1c0f1e4 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,138 @@ + +# OpenJPEG installation + +The build method maintained by OpenJPEG is [CMake](https://cmake.org/). + +## UNIX/LINUX - MacOS (terminal) - WINDOWS (cygwin, MinGW) + +To build the library, type from source tree directory: +``` +mkdir build +cd build +cmake .. -DCMAKE_BUILD_TYPE=Release +make +``` +Binaries are then located in the 'bin' directory. + +To install the library, type with root privileges: +``` +make install +make clean +``` + +To build the html documentation, you need doxygen to be installed on your system. +It will create an "html" directory in TOP\_LEVEL/build/doc) +``` +make doc +``` + +Main available cmake flags: + * To specify the install path: '-DCMAKE\_INSTALL\_PREFIX=/path' + * To build the shared libraries and links the executables against it: '-DBUILD\_SHARED\_LIBS:bool=on' (default: 'ON') +> Note: when using this option, static libraries are not built and executables are dynamically linked. + * PKG_CONFIG files are by default built for Unix compile, you can force to build on other platforms by adding: '-DBUILD_PKGCONFIG_FILES=on' + * To build the CODEC executables: '-DBUILD\_CODEC:bool=on' (default: 'ON') + * To build opjstyle (internal version of astyle) for OpenJPEG development: '-DWITH_ASTYLE=ON' + * [OBSOLETE] To build the MJ2 executables: '-DBUILD\_MJ2:bool=on' (default: 'OFF') + * [OBSOLETE] To build the JPWL executables and JPWL library: '-DBUILD\_JPWL:bool=on' (default: 'OFF') + * [OBSOLETE] To build the JPIP client (java compiler recommended) library and executables: '-DBUILD\_JPIP:bool=on' (default: 'OFF') + * [OBSOLETE] To build the JPIP server (need fcgi) library and executables: '-DBUILD\_JPIP\_SERVER:bool=on' (default: 'OFF') + * To enable testing (and automatic result upload to http://my.cdash.org/index.php?project=OPENJPEG): +``` +cmake . -DBUILD_TESTING:BOOL=ON -DOPJ_DATA_ROOT:PATH='path/to/the/data/directory' -DBUILDNAME:STRING='name_of_the_build' +make +make Experimental +``` +Note : test data is available on the following github repo: https://github.com/uclouvain/openjpeg-data + +If '-DOPJ\_DATA\_ROOT:PATH' option is omitted, test files will be automatically searched in '${CMAKE\_SOURCE\_DIR}/../data'. + +Note 2 : to execute the encoding test suite, kakadu binaries are needed to decode encoded image and compare it to the baseline. Kakadu binaries are freely available for non-commercial purposes at http://www.kakadusoftware.com. kdu\_expand will need to be in your PATH for cmake to find it. + +Note 3 : OpenJPEG encoder and decoder (not the library itself !) depends on several libraries: png, tiff, lcms, z. If these libraries are not found on the system, they are automatically built from the versions available in the source tree. You can force the use of these embedded version with BUILD\_THIRDPARTY:BOOL=ON. On a Debian-like system you can also simply install these libraries with: +``` +sudo apt-get install liblcms2-dev libtiff-dev libpng-dev libz-dev +``` + +Note 4 : On MacOS, if it does not work, try adding the following flag to the cmake command : +``` +-DCMAKE_OSX_ARCHITECTURES:STRING=i386 +``` + +## MacOS (XCode) - WINDOWS (VisualStudio, etc) + +You can use cmake to generate the project files for the IDE you are using (VC2010, XCode, etc). +Type `cmake --help` for available generators on your platform. + +Examples for Windows with Visual Studio C++ compiler: + +If using directly the cl compiler: + +``` +cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" .. +``` + +To compile a 64-bit application, open 64-Bit Visual C\+\+ toolset on the command line and run cmake. For further information, please refer to: [How to: Enable a 64-Bit Visual C\+\+ Toolset on the Command Line](https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx). + + +If you do not want directly use the cl compiler, you could use: + +``` +cmake -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" .. +``` + +To create Visual Studio solution (.sln) and project files (.vcproj / .vcxproj): +``` +cmake -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" .. +``` + +64-bit application: +``` +cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" .. +``` + + +# Enabling CPU specific optimizations + +For Intel/AMD processors, OpenJPEG implements optimizations using the SSE4.1 +instruction set (for example, for the 9x7 inverse MCT transform) and the AVX2 +instruction set (for example, for the 5x3 inverse discrete wavelet transform). +Currently, those optimizations are only available if OpenJPEG is built to +use those instruction sets (and the resulting binary will only run on compatible +CPUs) + +With gcc/clang, it is possible to enable those instruction sets with the following : + +``` +cmake -DCMAKE_C_FLAGS="-O3 -msse4.1 -DNDEBUG" .. +``` + +``` +cmake -DCMAKE_C_FLAGS="-O3 -mavx2 -DNDEBUG" .. +``` + +(AVX2 implies SSE4.1) + +Or if the binary is dedicated to run on the machine where it has +been compiled : + +``` +cmake -DCMAKE_C_FLAGS="-O3 -march=native -DNDEBUG" .. +``` + +# Modifying OpenJPEG + +Before committing changes, run: +```scripts/prepare-commit.sh``` + +# Using OpenJPEG + +To use openjpeg exported cmake file, simply create your application doing: + +``` +$ cat CMakeLists.txt +find_package(OpenJPEG REQUIRED) +include_directories(${OPENJPEG_INCLUDE_DIRS}) +add_executable(myapp myapp.c) +target_link_libraries(myapp ${OPENJPEG_LIBRARIES}) +``` diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e8fa410 --- /dev/null +++ b/LICENSE @@ -0,0 +1,39 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2003-2009, Francois-Olivier Devaux + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France + * Copyright (c) 2012, CS Systemes d'Information, France + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..794a796 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,111 @@ +# OpenJPEG NEWS + +More details in the [CHANGELOG](https://github.com/uclouvain/openjpeg/blob/master/CHANGELOG.md) + +## OpenJPEG 2.3.1 (April 2019) + +No API/ABI break compared to v2.3.0 + +* Many bug fixes (including security fixes) + +## OpenJPEG 2.3.0 (October 2017) + +No API/ABI break compared to v2.2.0 but additional symbols for subset of components decoding (hence the MINOR version bump). + +* Sub-tile decoding: when setting a window of interest through the API function opj_set_decode_area(), only codeblocks that intersect this window are now decoded (i.e. MCT, IDWT, and entropy decoding are only done on the window of interest). Moreover, memory allocation now depends on the size of the window of interest (instead of the full tile size). +[\#990](https://github.com/uclouvain/openjpeg/pull/990) [\#1001](https://github.com/uclouvain/openjpeg/pull/1001) [\#1010](https://github.com/uclouvain/openjpeg/pull/1010) +* Ability to decode only a subset of components. This adds the following function `opj_set_decoded_components(opj_codec_t p_codec, OPJ_UINT32 numcomps, const OPJ_UINT32 comps_indices, OPJ_BOOL apply_color_transforms)` and equivalent `opj_decompress -c compno[,compno]*` +option. +[\#1022](https://github.com/uclouvain/openjpeg/pull/1022) +* Many bug fixes (including security fixes) + +## OpenJPEG 2.2.0 (August 2017) + +No API/ABI break compared to v2.1.2 but additional symbols for multithreading support (hence the MINOR version bump). + +### Codebase improvements + +* Memory consumption reduction at decoding side [\#968](https://github.com/uclouvain/openjpeg/pull/968) +* Multi-threading support at decoding side [\#786](https://github.com/uclouvain/openjpeg/pull/786) +* Tier-1 speed optimizations (encoder and decoder) [\#945](https://github.com/uclouvain/openjpeg/pull/945) +* Tier-1 decoder further optimization [\#783](https://github.com/uclouvain/openjpeg/pull/783) +* Inverse 5x3 DWT speed optimization: single-pass lifting and SSE2/AVX2 implementation [\#957](https://github.com/uclouvain/openjpeg/pull/957) +* Fixed a bug that prevented OpenJPEG to compress losslessly in some situations [\#949](https://github.com/uclouvain/openjpeg/pull/949) +* Fixed BYPASS/LAZY, RESTART/TERMALL and PTERM mode switches +* Many other bug fixes (including security fixes) + +### Maintenance improvements + +* Benchmarking scripts to automatically compare the speed of latest OpenJPEG build with latest release and/or Kakadu binaries [\#917](https://github.com/uclouvain/openjpeg/pull/917) +* CPU and RAM usage profiling scripts [\#918](https://github.com/uclouvain/openjpeg/pull/918) +* Codebase reformatting (with astyle) and scripts to automatically check that new commits comply with formatting guidelines [\#919](https://github.com/uclouvain/openjpeg/pull/919) +* Register OpenJPEG at Google OSS Fuzz initiative, so as to automatically have OpenJPEG tested against Google fuzzer [\#965](https://github.com/uclouvain/openjpeg/issues/965) + +## OpenJPEG 2.1.2 (September 2016) + +* Bug fixes (including security fixes) +* No API/ABI break compared to v2.1.1 + +## OpenJPEG 2.1.1 (July 2016) + +* Huge amount of critical bugfixes +* Speed improvements +* No API/ABI break compared to v2.1 + +## OpenJPEG 2.1.0 (April 2014) + +### New Features + + * Digital Cinema profiles have been fixed and updated + * New option to disable MCT if needed + * extended RAW support: it is now possible to input raw images + with subsampled color components (422, 420, etc) + * New way to deal with profiles + +### API/ABI modifications +(see [here](http://www.openjpeg.org/abi-check/timeline/openjpeg/) for details) + + * Removed deprecated functions + * opj_stream_create_default_file_stream(FILE*,...) + * opj_stream_create_file_stream(FILE*,...) + * opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data) + * Added + * opj_stream_create_default_file_stream(char*,...) + * opj_stream_create_file_stream(char*,...) + * opj_stream_destroy(opj_stream_t*) + * opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data, + ... opj_stream_free_user_data_fn p_function) + * JPEG 2000 profiles and Part-2 extensions defined through '#define' + * Changed + * 'alpha' field added to 'opj_image_comp' structure + * 'OPJ_CLRSPC_EYCC' added to enum COLOR_SPACE + * 'OPJ_CLRSPC_CMYK' added to enum COLOR_SPACE + * 'OPJ_CODEC_JPP' and 'OPJ_CODEC_JPX' added to CODEC_FORMAT + (not yet used in use) + * 'max_cs_size' and 'rsiz' fields added to opj_cparameters_t + +### Misc + + * OpenJPEG is now officially conformant with JPEG 2000 Part-1 + and will soon become official reference software at the + JPEG committee. + * Huge amount of bug fixes. See CHANGES for details. + + +## OpenJPEG 2.0.0 + +### New Features + + * streaming capabilities + * merge JP3D + +### API modifications +(see [here](http://www.openjpeg.org/abi-check/timeline/openjpeg/) for details) + + * Use a 64bits capable API + +### Misc + + * removed autotools build system + * folders hierarchies reorganisation + * Huge amount of bug fixes. See CHANGES for details. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f703d0e --- /dev/null +++ b/README.md @@ -0,0 +1,83 @@ + +# OPENJPEG Library and Applications + +## What is OpenJPEG ? + +OpenJPEG is an open-source JPEG 2000 codec written in C language. It has been developed in order to promote the use of [JPEG 2000](http://www.jpeg.org/jpeg2000), a still-image compression standard from the Joint Photographic Experts Group ([JPEG](http://www.jpeg.org)). Since April 2015, it is officially recognized by ISO/IEC and ITU-T as a [JPEG 2000 Reference Software](http://www.itu.int/rec/T-REC-T.804-201504-I!Amd2). + +## Who can use the code ? +[![badge-license]][link-license] + +Anyone. As the OpenJPEG code is released under the [BSD 2-clause "Simplified" License][link-license], anyone can use or modify the code, even for commercial applications. The only restriction is to retain the copyright in the sources or in the binaries documentation. Of course, if you modified the code in a way that might be of interest for other users, you are encouraged to share it (through a [github pull request](https://github.com/uclouvain/openjpeg/pulls) or by filling an [issue](https://github.com/uclouvain/openjpeg/issues)) but this is not a requirement. + +## How to install and use OpenJPEG ? +API Documentation needs a major refactoring. Meanwhile, you can check [installation](https://github.com/uclouvain/openjpeg/wiki/Installation) instructions and [codec documentation](https://github.com/uclouvain/openjpeg/wiki/DocJ2KCodec). + +## Current Status +[![badge-build]][link-build] + +[![badge-msvc-build]][link-msvc-build] + +[![badge-coverity]][link-coverity] + +## Who are the developers ? + +The library is developed and maintained by the Image and Signal Processing Group ([ISPGroup](http://sites.uclouvain.be/ispgroup/)), in the Université catholique de Louvain ([UCL](http://www.uclouvain.be/en-index.html), with the support of the [CNES](https://cnes.fr/), the [CS](http://www.c-s.fr/) company and the [intoPIX](http://www.intopix.com) company. The JPWL module has been developed by the Digital Signal Processing Lab ([DSPLab](http://dsplab.diei.unipg.it/)) of the University of Perugia, Italy ([UNIPG](http://www.unipg.it/)). + +## Details on folders hierarchy + +* src + * lib + * openjp2: contains the sources of the openjp2 library (Part 1 & 2) + * openjpwl: contains the additional sources if you want to build a JPWL-flavoured library. + * openjpip: complete client-server architecture for remote browsing of jpeg 2000 images. + * openjp3d: JP3D implementation + * openmj2: MJ2 implementation + * bin: contains all applications that use the openjpeg library + * common: common files to all applications + * jp2: a basic codec + * mj2: motion jpeg 2000 executables + * jpip: OpenJPIP applications (server and dec server) + * java: a Java client viewer for JPIP + * jp3d: JP3D applications + * tcltk: a test tool for JP3D + * wx + * OPJViewer: gui for displaying j2k files (based on wxWidget) +* wrapping + * java: java jni to use openjpeg in a java program +* thirdparty: thirdparty libraries used by some applications. These libraries will be built only if there are not found on the system. Note that libopenjpeg itself does not have any dependency. +* doc: doxygen documentation setup file and man pages +* tests: configuration files and utilities for the openjpeg test suite. All test images are located in [openjpeg-data](https://github.com/uclouvain/openjpeg-data) repository. +* cmake: cmake related files +* scripts: scripts for developers + +See [LICENSE][link-license] for license and copyright information. + +See [INSTALL](https://github.com/uclouvain/openjpeg/blob/master/INSTALL.md) for installation procedures. + +See [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS.md) for user visible changes in successive releases. + +## API/ABI + +An API/ABI timeline is automatically updated [here][link-api-timeline]. + +OpenJPEG strives to provide a stable API/ABI for your applications. As such it +only exposes a limited subset of its functions. It uses a mechanism of +exporting/hiding functions. If you are unsure which functions you can use in +your applications, you should compile OpenJPEG using something similar to gcc: +`-fvisibility=hidden` compilation flag. +See also: http://gcc.gnu.org/wiki/Visibility + +On windows, MSVC directly supports export/hiding function and as such the only +API available is the one supported by OpenJPEG. + +[comment-license]: https://img.shields.io/github/license/uclouvain/openjpeg.svg "https://img.shields.io/badge/license-BSD--2--Clause-blue.svg" +[badge-license]: https://img.shields.io/badge/license-BSD--2--Clause-blue.svg "BSD 2-clause \"Simplified\" License" +[link-license]: https://github.com/uclouvain/openjpeg/blob/master/LICENSE "BSD 2-clause \"Simplified\" License" +[badge-build]: https://travis-ci.org/uclouvain/openjpeg.svg?branch=master "Build Status" +[link-build]: https://travis-ci.org/uclouvain/openjpeg "Build Status" +[badge-msvc-build]: https://ci.appveyor.com/api/projects/status/github/uclouvain/openjpeg?branch=master&svg=true "Windows Build Status" +[link-msvc-build]: https://ci.appveyor.com/project/detonin/openjpeg/branch/master "Windows Build Status" +[badge-coverity]: https://scan.coverity.com/projects/6383/badge.svg "Coverity Scan Build Status" +[link-coverity]: https://scan.coverity.com/projects/uclouvain-openjpeg "Coverity Scan Build Status" +[link-api-timeline]: http://www.openjpeg.org/abi-check/timeline/openjpeg "OpenJPEG API/ABI timeline" diff --git a/THANKS.md b/THANKS.md new file mode 100644 index 0000000..460eab1 --- /dev/null +++ b/THANKS.md @@ -0,0 +1,39 @@ +# OpenJPEG THANKS file + +Many people have contributed to OpenJPEG by reporting problems, suggesting various improvements, +or submitting actual code. Here is a list of these people. Help me keep +it complete and exempt of errors. + +* Giuseppe Baruffa +* Ben Boeckel +* Aaron Boxer +* David Burken +* Matthieu Darbois +* Rex Dieter +* Herve Drolon +* Antonin Descampe +* Francois-Olivier Devaux +* Parvatha Elangovan +* Jerôme Fimes +* Bob Friesenhahn +* Kaori Hagihara +* Luc Hermitte +* Luis Ibanez +* David Janssens +* Hans Johnson +* Callum Lerwick +* Ke Liu (Tencent's Xuanwu LAB) +* Sebastien Lugan +* Benoit Macq +* Mathieu Malaterre +* Julien Malik +* Arnaud Maye +* Vincent Nicolas +* Aleksander Nikolic (Cisco Talos) +* Glenn Pearson +* Even Rouault +* Dzonatas Sol +* Winfried Szukalski +* Vincent Torri +* Yannick Verschueren +* Peter Wimmer diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..d6561f6 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,41 @@ +version: 2.3.1.{build} +branches: + except: + - coverity_scan +skip_tags: false +clone_depth: 50 +environment: + matrix: + - OPJ_CI_ARCH: x64 + OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS) + OPJ_CI_INSTRUCTION_SETS: "/arch:AVX2" + - OPJ_CI_ARCH: x86 + OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS) + OPJ_CI_INCLUDE_IF_DEPLOY: 1 + - OPJ_CI_ARCH: x64 + OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS) + OPJ_CI_INCLUDE_IF_DEPLOY: 1 + - OPJ_CI_ARCH: x86 + OPJ_CI_VSCOMNTOOLS: $(VS100COMNTOOLS) +install: +- cmd: c:\cygwin\bin\bash ./tools/travis-ci/install.sh +build_script: +- cmd: >- + "%OPJ_CI_VSCOMNTOOLS%..\..\VC\vcvarsall.bat" %OPJ_CI_ARCH% + + bash ./tools/travis-ci/run.sh +test: off +#before_deploy: +#- cmd: c:\cygwin\bin\bash ./tools/travis-ci/before_deploy.sh +deploy: + #release: openjpeg-$(appveyor_repo_tag_name) + description: 'OpenJPEG $(appveyor_repo_tag_name) has been released. More info [here](https://github.com/uclouvain/openjpeg/blob/$(appveyor_repo_tag_name)/NEWS) and a detailed view [here](https://github.com/uclouvain/openjpeg/blob/$(appveyor_repo_tag_name)/CHANGES).' + provider: GitHub + auth_token: + secure: XUL+IoRRw8U/4tupa/fMpinxurft7WRQHZiWHMLO5iuFbwZ+C3vCjVVVM+5Ebky7 # your encrypted token from GitHub + artifact: /.*\.zip/ # upload all zip packages to release assets + draft: true + prerelease: false + on: + appveyor_repo_tag: true # deploy on tag push only + OPJ_CI_INCLUDE_IF_DEPLOY: 1 diff --git a/cmake/CTestCustom.cmake.in b/cmake/CTestCustom.cmake.in new file mode 100644 index 0000000..5afda93 --- /dev/null +++ b/cmake/CTestCustom.cmake.in @@ -0,0 +1,40 @@ +#---------------------------------------------------------------------- +# +# For further details regarding this file, +# see http://www.cmake.org/Wiki/CMake_Testing_With_CTest#Customizing_CTest +# +# and +# http://www.kitware.com/blog/home/post/27 +# +#---------------------------------------------------------------------- + +set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 1000000) +set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS 50) +set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS 2000) + +set(CTEST_CUSTOM_COVERAGE_EXCLUDE + ${CTEST_CUSTOM_COVERAGE_EXCLUDE} + + # Exclude files from the Testing directories + ".*/tests/.*" + + # Exclude files from the ThirdParty Utilities directories + ".*/thirdparty/.*" + ) + +set(CTEST_CUSTOM_WARNING_EXCEPTION + ${CTEST_CUSTOM_WARNING_EXCEPTION} + + # Ignore clang's summary warning, assuming prior text has matched some + # other warning expression: + "[0-9,]+ warnings? generated." + # Suppress warning caused by intentional messages about deprecation + ".*warning,.* is deprecated" + # java also warns about deprecated API + ".*java.*deprecation" + ".*deprecation.*" + # suppress warnings caused by 3rd party libs: + ".*thirdparty.*" + "libtiff.*has no symbols" + "libpng.*has no symbols" + ) diff --git a/cmake/EnsureFileInclude.cmake b/cmake/EnsureFileInclude.cmake new file mode 100644 index 0000000..a4c064b --- /dev/null +++ b/cmake/EnsureFileInclude.cmake @@ -0,0 +1,26 @@ +# Ensure that an include file is provided by the system +# Add the check about the mandatory status to the check_include_file macro +# provided by cmake + +include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) + +macro(ensure_file_include INCLUDE_FILENAME VARIABLE_NAME MANDATORY_STATUS) + +#message(WARNING "INCLUDE_FILENAME=${INCLUDE_FILENAME} \n" +# "VARIABLE_NAME=${VARIABLE_NAME} \n" +# "MANDATORY_STATUS=${MANDATORY_STATUS}") + +CHECK_INCLUDE_FILE(${INCLUDE_FILENAME} ${VARIABLE_NAME}) + +#message(WARNING "INCLUDE_FILENAME=${INCLUDE_FILENAME} \n" +# "VARIABLE_NAME=${VARIABLE_NAME} \n" +# "VARIABLE_NAME_VALUE=${${VARIABLE_NAME}} \n" +# "MANDATORY_STATUS=${MANDATORY_STATUS}") + +if (NOT ${${VARIABLE_NAME}}) + if (${MANDATORY_STATUS}) + message(FATAL_ERROR "The file ${INCLUDE_FILENAME} is mandatory but not found on your system") + endif() +endif() + +endmacro() diff --git a/cmake/FindCPPCHECK.cmake b/cmake/FindCPPCHECK.cmake new file mode 100644 index 0000000..6e11bf7 --- /dev/null +++ b/cmake/FindCPPCHECK.cmake @@ -0,0 +1,16 @@ +# cppcheck +# +# Copyright (c) 2011 Mathieu Malaterre +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +find_program(CPPCHECK_EXECUTABLE + cppcheck + ) + +mark_as_advanced( + CPPCHECK_EXECUTABLE + ) diff --git a/cmake/FindFCGI.cmake b/cmake/FindFCGI.cmake new file mode 100644 index 0000000..309bdd4 --- /dev/null +++ b/cmake/FindFCGI.cmake @@ -0,0 +1,20 @@ +# Look for the header file. +find_path(FCGI_INCLUDE_DIR NAMES fastcgi.h) + +# Look for the library. +find_library(FCGI_LIBRARY NAMES fcgi) + +# Handle the QUIETLY and REQUIRED arguments and set FCGI_FOUND to TRUE if all listed variables are TRUE. +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(FCGI DEFAULT_MSG FCGI_LIBRARY FCGI_INCLUDE_DIR) + +# Copy the results to the output variables. +if(FCGI_FOUND) + set(FCGI_LIBRARIES ${FCGI_LIBRARY}) + set(FCGI_INCLUDE_DIRS ${FCGI_INCLUDE_DIR}) +else() + set(FCGI_LIBRARIES) + set(FCGI_INCLUDE_DIRS) +endif() + +mark_as_advanced(FCGI_INCLUDE_DIR FCGI_LIBRARY) diff --git a/cmake/FindJPYLYZER.cmake b/cmake/FindJPYLYZER.cmake new file mode 100644 index 0000000..4fbbaa8 --- /dev/null +++ b/cmake/FindJPYLYZER.cmake @@ -0,0 +1,12 @@ +# +# this module looks for JPYLYZER +# http://jpylyzer.openpreservation.org +# + +find_program(JPYLYZER_EXECUTABLE + jpylyzer + ) + +mark_as_advanced( + JPYLYZER_EXECUTABLE + ) diff --git a/cmake/FindKAKADU.cmake b/cmake/FindKAKADU.cmake new file mode 100644 index 0000000..0564a0e --- /dev/null +++ b/cmake/FindKAKADU.cmake @@ -0,0 +1,24 @@ +# +# this module looks for KAKADU +# http://www.kakadusoftware.com/ +# +# +# Copyright (c) 2006-2014 Mathieu Malaterre +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +find_program(KDU_EXPAND_EXECUTABLE + kdu_expand + ) + +find_program(KDU_COMPRESS_EXECUTABLE + kdu_compress + ) + +mark_as_advanced( + KDU_EXPAND_EXECUTABLE + KDU_COMPRESS_EXECUTABLE + ) diff --git a/cmake/FindLCMS.cmake b/cmake/FindLCMS.cmake new file mode 100644 index 0000000..e659895 --- /dev/null +++ b/cmake/FindLCMS.cmake @@ -0,0 +1,31 @@ +# - Find LCMS library +# Find the native LCMS includes and library +# Once done this will define +# +# LCMS_INCLUDE_DIR - Where to find lcms.h, etc. +# LCMS_LIBRARIES - Libraries to link against to use LCMS. +# LCMS_FOUND - If false, do not try to use LCMS. +# +# also defined, but not for general use are +# LCMS_LIBRARY, where to find the LCMS library. + +#============================================================================= +#============================================================================= + +find_path(LCMS_INCLUDE_DIR lcms.h PATHS /usr/include /usr/local/include /opt/include /opt/local/include) + +set(LCMS_NAMES ${LCMS_NAMES} lcms liblcms liblcms_static) + +find_library(LCMS_LIBRARY NAMES ${LCMS_NAMES} ) + +mark_as_advanced(LCMS_INCLUDE_DIR LCMS_LIBRARY) + +# handle the QUIETLY and REQUIRED arguments and set LCMS_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LCMS DEFAULT_MSG LCMS_LIBRARY LCMS_INCLUDE_DIR) + +if(LCMS_FOUND) + set( LCMS_INCLUDE_DIRS ${LCMS_INCLUDE_DIR}) + set( LCMS_LIBRARIES ${LCMS_LIBRARY} ) +endif() diff --git a/cmake/FindLCMS2.cmake b/cmake/FindLCMS2.cmake new file mode 100644 index 0000000..65b6525 --- /dev/null +++ b/cmake/FindLCMS2.cmake @@ -0,0 +1,31 @@ +# - Find LCMS2 library +# Find the native LCMS2 includes and library +# Once done this will define +# +# LCMS2_INCLUDE_DIR - Where to find lcms2.h, etc. +# LCMS2_LIBRARIES - Libraries to link against to use LCMS2. +# LCMS2_FOUND - If false, do not try to use LCMS2. +# +# also defined, but not for general use are +# LCMS2_LIBRARY - Where to find the LCMS2 library. + +#============================================================================= +#============================================================================= + +find_path(LCMS2_INCLUDE_DIR lcms2.h PATHS /usr/include /usr/local/include /opt/include /opt/local/include) + +set(LCMS2_NAMES ${LCMS2_NAMES} lcms2 liblcms2 liblcms2_static) + +find_library(LCMS2_LIBRARY NAMES ${LCMS2_NAMES} ) + +mark_as_advanced(LCMS2_INCLUDE_DIR LCMS2_LIBRARY) + +# handle the QUIETLY and REQUIRED arguments and set LCMS2_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LCMS2 DEFAULT_MSG LCMS2_LIBRARY LCMS2_INCLUDE_DIR) + +if(LCMS2_FOUND) + set( LCMS2_INCLUDE_DIRS ${LCMS2_INCLUDE_DIR}) + set( LCMS2_LIBRARIES ${LCMS2_LIBRARY} ) +endif() diff --git a/cmake/JPIPTestDriver.cmake b/cmake/JPIPTestDriver.cmake new file mode 100644 index 0000000..2147c46 --- /dev/null +++ b/cmake/JPIPTestDriver.cmake @@ -0,0 +1,9 @@ +# JPIP test driver +#message(STATUS "${D_URL}") +file(DOWNLOAD + "${D_URL}" + "${D_FILE}" + LOG log + EXPECTED_MD5 "${EXPECTED_MD5}" + ) +message(STATUS "LOG: ${log}") diff --git a/cmake/OpenJPEGCPack.cmake b/cmake/OpenJPEGCPack.cmake new file mode 100644 index 0000000..a6e9a86 --- /dev/null +++ b/cmake/OpenJPEGCPack.cmake @@ -0,0 +1,72 @@ +# package bundler +if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") + if(EXISTS "${CMAKE_ROOT}/Modules/InstallRequiredSystemLibraries.cmake") + set(CMAKE_INSTALL_MFC_LIBRARIES 0) + set(CMAKE_INSTALL_DEBUG_LIBRARIES 0) + if(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS) + set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON) + endif() + include(${CMAKE_ROOT}/Modules/InstallRequiredSystemLibraries.cmake) + endif() + + set(OPJ_PACKAGE_DESCRIPTION_SUMMARY "OpenJPEG - OpenJPEG a JPEG 2000 implementation.") + set(OPJ_PACKAGE_CONTACT "openjpeg users ") + + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${OPJ_PACKAGE_DESCRIPTION_SUMMARY}) + set(CPACK_PACKAGE_VENDOR "OpenJPEG Team") + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" + "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt" COPYONLY + ) + # For PackageMaker on MacOSX it is important to have a file extension: + set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt") + set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt") + set(CPACK_PACKAGE_VERSION_MAJOR "${OPENJPEG_VERSION_MAJOR}") + set(CPACK_PACKAGE_VERSION_MINOR "${OPENJPEG_VERSION_MINOR}") + set(CPACK_PACKAGE_VERSION_PATCH "${OPENJPEG_VERSION_BUILD}") + set(CPACK_PACKAGE_INSTALL_DIRECTORY "OpenJPEG ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}") + set(CPACK_SOURCE_PACKAGE_FILE_NAME "openjpeg-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") + + # Make this explicit here, rather than accepting the CPack default value, + # so we can refer to it: + set(CPACK_PACKAGE_NAME "${OPENJPEG_LIBRARY_NAME}") + + if(NOT DEFINED CPACK_SYSTEM_NAME) + # make sure package is not Cygwin-unknown, for Cygwin just + # cygwin is good for the system name + if("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN") + set(CPACK_SYSTEM_NAME Cygwin) + else() + set(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}) + endif() + endif() + if(${CPACK_SYSTEM_NAME} MATCHES Windows) + if(CMAKE_CL_64) + set(CPACK_SYSTEM_NAME win64-x64) + else() + set(CPACK_SYSTEM_NAME win32-x86) + endif() + endif() + + if(NOT DEFINED CPACK_PACKAGE_FILE_NAME) + # if the CPACK_PACKAGE_FILE_NAME is not defined by the cache + # default to source package - system, on cygwin system is not + # needed + if(CYGWIN) + set(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}") + else() + set(CPACK_PACKAGE_FILE_NAME + "${CPACK_SOURCE_PACKAGE_FILE_NAME}-${CPACK_SYSTEM_NAME}") + endif() + endif() + + set(CPACK_BUNDLE_NAME "OpenJPEG ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}") + if(APPLE) + configure_file(${CMAKE_ROOT}/Templates/AppleInfo.plist + ${CMAKE_CURRENT_BINARY_DIR}/opj.plist) + set(CPACK_BUNDLE_PLIST + ${CMAKE_CURRENT_BINARY_DIR}/opj.plist) + #include(BundleUtilities) + endif() + + include(CPack) +endiF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") diff --git a/cmake/OpenJPEGConfig.cmake.in b/cmake/OpenJPEGConfig.cmake.in new file mode 100644 index 0000000..2925108 --- /dev/null +++ b/cmake/OpenJPEGConfig.cmake.in @@ -0,0 +1,53 @@ +#----------------------------------------------------------------------------- +# +# OPENJPEGConfig.cmake - CMake configuration file for external projects. +# +# This file is configured by OPENJPEG and used by the UseOPENJPEG.cmake +# module to load OPENJPEG's settings for an external project. +@OPENJPEG_CONFIG_INSTALL_ONLY@ +# The OPENJPEG version number. +set(OPENJPEG_MAJOR_VERSION "@OPENJPEG_VERSION_MAJOR@") +set(OPENJPEG_MINOR_VERSION "@OPENJPEG_VERSION_MINOR@") +set(OPENJPEG_BUILD_VERSION "@OPENJPEG_VERSION_BUILD@") + +# The libraries. +set(OPENJPEG_LIBRARIES "@OPENJPEG_LIBRARY_NAME@") + +# The CMake macros dir. +set(OPENJPEG_CMAKE_DIR "@OPENJPEG_INSTALL_PACKAGE_DIR@") + +# The configuration options. +set(OPENJPEG_BUILD_SHARED_LIBS "@BUILD_SHARED_LIBS@") + +# The "use" file. +set(OPENJPEG_USE_FILE "@OPENJPEG_USE_FILE_CONFIG@") + +get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +if(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake) + # This is an install tree + include(${SELF_DIR}/OpenJPEGTargets.cmake) + + # We find a relative path from the PKG directory to header files. + set(PKG_DIR "@CMAKE_INSTALL_PREFIX@/@OPENJPEG_INSTALL_PACKAGE_DIR@") + set(INC_DIR "@CMAKE_INSTALL_PREFIX@/@OPENJPEG_INSTALL_INCLUDE_DIR@") + file(RELATIVE_PATH PKG_TO_INC_RPATH "${PKG_DIR}" "${INC_DIR}") + + get_filename_component(OPENJPEG_INCLUDE_DIRS "${SELF_DIR}/${PKG_TO_INC_RPATH}" ABSOLUTE) + +else() + if(EXISTS ${SELF_DIR}/OpenJPEGExports.cmake) + # This is a build tree + set( OPENJPEG_INCLUDE_DIRS @OPENJPEG_INCLUDE_PATH@) + + include(${SELF_DIR}/OpenJPEGExports.cmake) + + else() + message(FATAL_ERROR "ooops") + endif() +endif() + +set(OPENJPEG_USE_FILE ${SELF_DIR}/UseOPENJPEG.cmake) + +# Backward compatible part: +set(OPENJPEG_FOUND TRUE) + diff --git a/cmake/TestFileOffsetBits.c b/cmake/TestFileOffsetBits.c new file mode 100644 index 0000000..cd679c1 --- /dev/null +++ b/cmake/TestFileOffsetBits.c @@ -0,0 +1,11 @@ +#include + +/* Cause a compile-time error if off_t is smaller than 64 bits */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ]; + +int main(int argc, char **argv) +{ + return 0; +} + diff --git a/cmake/TestLargeFiles.c.cmake.in b/cmake/TestLargeFiles.c.cmake.in new file mode 100644 index 0000000..623f95f --- /dev/null +++ b/cmake/TestLargeFiles.c.cmake.in @@ -0,0 +1,23 @@ +#cmakedefine _LARGEFILE_SOURCE +#cmakedefine _LARGE_FILES +#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ + +#include +#include +#include + +int main(int argc, char **argv) +{ + /* Cause a compile-time error if off_t is smaller than 64 bits, + * and make sure we have ftello / fseeko. + */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ]; + FILE *fp = fopen(argv[0],"r"); + off_t offset = ftello( fp ); + + fseeko( fp, offset, SEEK_CUR ); + fclose(fp); + return 0; +} + diff --git a/cmake/TestLargeFiles.cmake b/cmake/TestLargeFiles.cmake new file mode 100644 index 0000000..01e4ea7 --- /dev/null +++ b/cmake/TestLargeFiles.cmake @@ -0,0 +1,134 @@ +# - Define macro to check large file support +# +# OPJ_TEST_LARGE_FILES(VARIABLE) +# +# VARIABLE will be set to true if off_t is 64 bits, and fseeko/ftello present. +# This macro will also defines the necessary variable enable large file support, for instance +# _LARGE_FILES +# _LARGEFILE_SOURCE +# _FILE_OFFSET_BITS 64 +# OPJ_HAVE_FSEEKO +# +# However, it is YOUR job to make sure these defines are set in a #cmakedefine so they +# end up in a config.h file that is included in your source if necessary! +# +# Adapted from Gromacs project (http://www.gromacs.org/) +# by Julien Malik +# + +macro(OPJ_TEST_LARGE_FILES VARIABLE) + if(NOT DEFINED ${VARIABLE}) + + # On most platforms it is probably overkill to first test the flags for 64-bit off_t, + # and then separately fseeko. However, in the future we might have 128-bit filesystems + # (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64. + + message(STATUS "Checking for 64-bit off_t") + + # First check without any special flags + try_compile(FILE64_OK "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c") + if(FILE64_OK) + message(STATUS "Checking for 64-bit off_t - present") + endif() + + if(NOT FILE64_OK) + # Test with _FILE_OFFSET_BITS=64 + try_compile(FILE64_OK "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c" + COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64" ) + if(FILE64_OK) + message(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64") + set(_FILE_OFFSET_BITS 64) + endif() + endif() + + if(NOT FILE64_OK) + # Test with _LARGE_FILES + try_compile(FILE64_OK "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c" + COMPILE_DEFINITIONS "-D_LARGE_FILES" ) + if(FILE64_OK) + message(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES") + set(_LARGE_FILES 1) + endif() + endif() + + if(NOT FILE64_OK) + # Test with _LARGEFILE_SOURCE + try_compile(FILE64_OK "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c" + COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" ) + if(FILE64_OK) + message(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE") + set(_LARGEFILE_SOURCE 1) + endif() + endif() + + + #if(NOT FILE64_OK) + # # now check for Windows stuff + # try_compile(FILE64_OK "${PROJECT_BINARY_DIR}" + # "${PROJECT_SOURCE_DIR}/cmake/TestWindowsFSeek.c") + # if(FILE64_OK) + # message(STATUS "Checking for 64-bit off_t - present with _fseeki64") + # set(HAVE__FSEEKI64 1) + # endif() + #endif() + + if(NOT FILE64_OK) + message(STATUS "Checking for 64-bit off_t - not present") + endif() + + set(_FILE_OFFSET_BITS ${_FILE_OFFSET_BITS} CACHE INTERNAL "Result of test for needed _FILE_OFFSET_BITS=64") + set(_LARGE_FILES ${_LARGE_FILES} CACHE INTERNAL "Result of test for needed _LARGE_FILES") + set(_LARGEFILE_SOURCE ${_LARGEFILE_SOURCE} CACHE INTERNAL "Result of test for needed _LARGEFILE_SOURCE") + + # Set the flags we might have determined to be required above + configure_file("${PROJECT_SOURCE_DIR}/cmake/TestLargeFiles.c.cmake.in" + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c") + + message(STATUS "Checking for fseeko/ftello") + + # Test if ftello/fseeko are available + try_compile(FSEEKO_COMPILE_OK + "${PROJECT_BINARY_DIR}" + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c") + + if(FSEEKO_COMPILE_OK) + message(STATUS "Checking for fseeko/ftello - present") + endif() + + if(NOT FSEEKO_COMPILE_OK) + # glibc 2.2 needs _LARGEFILE_SOURCE for fseeko (but not for 64-bit off_t...) + try_compile(FSEEKO_COMPILE_OK + "${PROJECT_BINARY_DIR}" + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c" + COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" ) + + if(FSEEKO_COMPILE_OK) + message(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE") + set(_LARGEFILE_SOURCE ${_LARGEFILE_SOURCE} CACHE INTERNAL "Result of test for needed _LARGEFILE_SOURCE") + endif() + endif() + + if(FSEEKO_COMPILE_OK) + set(OPJ_HAVE_FSEEKO ON CACHE INTERNAL "Result of test for fseeko/ftello") + else() + message(STATUS "Checking for fseeko/ftello - not found") + set(OPJ_HAVE_FSEEKO OFF CACHE INTERNAL "Result of test for fseeko/ftello") + endif() + + if(FILE64_OK AND FSEEKO_COMPILE_OK) + message(STATUS "Large File support - found") + set(${VARIABLE} ON CACHE INTERNAL "Result of test for large file support") + else() + message(STATUS "Large File support - not found") + set(${VARIABLE} OFF CACHE INTERNAL "Result of test for large file support") + endif() + + endif() +endmacro() + + + diff --git a/cmake/TestWindowsFSeek.c b/cmake/TestWindowsFSeek.c new file mode 100644 index 0000000..ad9f0be --- /dev/null +++ b/cmake/TestWindowsFSeek.c @@ -0,0 +1,11 @@ + +#include + +int main() +{ + __int64 off=0; + + _fseeki64(NULL, off, SEEK_SET); + + return 0; +} diff --git a/cmake/openjpeg_valgrind.supp b/cmake/openjpeg_valgrind.supp new file mode 100644 index 0000000..f107646 --- /dev/null +++ b/cmake/openjpeg_valgrind.supp @@ -0,0 +1,39 @@ + + +{ + + Memcheck:Cond + fun:deflate + obj:/lib/libpng12.so.0.42.0 + obj:/lib/libpng12.so.0.42.0 + obj:/lib/libpng12.so.0.42.0 + fun:png_write_row + fun:imagetopng + fun:main +} +{ + + Memcheck:Value8 + fun:crc32 + obj:/lib/libpng12.so.0.42.0 + fun:png_write_chunk + obj:/lib/libpng12.so.0.42.0 + obj:/lib/libpng12.so.0.42.0 + obj:/lib/libpng12.so.0.42.0 + obj:/lib/libpng12.so.0.42.0 + fun:png_write_row + fun:imagetopng + fun:main +} +{ + + Memcheck:Param + write(buf) + fun:__write_nocancel + fun:_IO_file_write@@GLIBC_2.2.5 + fun:_IO_do_write@@GLIBC_2.2.5 + fun:_IO_file_close_it@@GLIBC_2.2.5 + fun:fclose@@GLIBC_2.2.5 + fun:imagetopng + fun:main +} diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt new file mode 100644 index 0000000..d4f3ddb --- /dev/null +++ b/doc/CMakeLists.txt @@ -0,0 +1,52 @@ +# Generate target to build the html documentation through CMake tool +# After having configured the project with the BUILD_DOC option you can run make doc +# to generate the html documentation in the doc/html repository of the build folder. + +# Try to find the doxygen tool +find_package(Doxygen) + +if(DOXYGEN_FOUND) + # Configure the doxygen config file with variable from CMake and move it + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.dox.cmake.in + ${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox @ONLY) + + # Configure the html mainpage file of the doxygen documentation with variable + # from CMake and move it + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mainpage.dox.in + ${CMAKE_BINARY_DIR}/doc/mainpage.dox @ONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpip.dox.in + ${CMAKE_BINARY_DIR}/doc/openjpip.dox @ONLY) + # copy png file to make local (binary tree) documentation valid: + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jpip_architect.png + ${CMAKE_BINARY_DIR}/doc/html/jpip_architect.png COPYONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jpip_protocol.png + ${CMAKE_BINARY_DIR}/doc/html/jpip_protocol.png COPYONLY) + + file(GLOB headers + ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2/*.h + ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2/*.c + ${OPENJPEG_SOURCE_DIR}/src/lib/openjpip/*.h + ${OPENJPEG_SOURCE_DIR}/src/lib/openjpip/*.c + ) + # Generate new target to build the html documentation + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox + DEPENDS ${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox + ${CMAKE_BINARY_DIR}/doc/mainpage.dox + ${CMAKE_BINARY_DIR}/doc/openjpip.dox + ${headers} + ) + add_custom_target(doc ALL + DEPENDS ${CMAKE_BINARY_DIR}/doc/html/index.html + COMMENT "Building doxygen documentation" + ) + + # install HTML documentation (install png files too): + install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/html + DESTINATION share/doc + PATTERN ".svn" EXCLUDE + ) +else() + message(STATUS "Doxygen not found, we cannot generate the documentation") +endif() diff --git a/doc/Doxyfile.dox.cmake.in b/doc/Doxyfile.dox.cmake.in new file mode 100644 index 0000000..439e133 --- /dev/null +++ b/doc/Doxyfile.dox.cmake.in @@ -0,0 +1,279 @@ +# Doxyfile 1.7.1 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = OpenJPEG +PROJECT_NUMBER = @OPENJPEG_VERSION@ +OUTPUT_DIRECTORY = @OPENJPEG_BINARY_DIR@/doc +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = C:// +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = YES +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +EXTENSION_MAPPING = +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +IDL_PROPERTY_SUPPORT = YES +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +TYPEDEF_HIDES_STRUCT = NO +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = YES +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = NO +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +FORCE_LOCAL_INCLUDES = NO +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_MEMBERS_CTORS_1ST = NO +SORT_GROUP_NAMES = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_FILES = YES +SHOW_NAMESPACES = YES +FILE_VERSION_FILTER = +LAYOUT_FILE = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = @OPENJPEG_SOURCE_DIR@/src/lib/openjp2 \ + @OPENJPEG_SOURCE_DIR@/src/lib/openjpip \ + @OPENJPEG_BINARY_DIR@/doc +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.h \ + *.c \ + *.dox +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = */.svn/* +EXCLUDE_SYMBOLS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = @OPENJPEG_SOURCE_DIR@/doc +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = ./html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_SAT = 100 +HTML_COLORSTYLE_GAMMA = 80 +HTML_TIMESTAMP = NO +HTML_DYNAMIC_SECTIONS = NO +GENERATE_DOCSET = NO +DOCSET_FEEDNAME = "Doxygen generated docs" +DOCSET_BUNDLE_ID = org.doxygen.Project +DOCSET_PUBLISHER_ID = org.doxygen.Publisher +DOCSET_PUBLISHER_NAME = Publisher +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +CHM_INDEX_ENCODING = +BINARY_TOC = NO +TOC_EXPAND = NO +GENERATE_QHP = NO +QCH_FILE = +QHP_NAMESPACE = org.doxygen.Project +QHP_VIRTUAL_FOLDER = doc +QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = +QHG_LOCATION = +GENERATE_ECLIPSEHELP = NO +ECLIPSE_DOC_ID = org.doxygen.Project +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = NO +TREEVIEW_WIDTH = 250 +EXT_LINKS_IN_WINDOW = NO +FORMULA_FONTSIZE = 10 +FORMULA_TRANSPARENT = YES +SEARCHENGINE = NO +SERVER_BASED_SEARCH = NO +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +LATEX_SOURCE_CODE = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = USE_JPWL \ + USE_JPSEC +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +MSCGEN_PATH = +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +DOT_NUM_THREADS = 0 +DOT_FONTNAME = Helvetica +DOT_FONTSIZE = 10 +DOT_FONTPATH = +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +DOT_GRAPH_MAX_NODES = 50 +MAX_DOT_GRAPH_DEPTH = 1000 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES diff --git a/doc/jpip_architect.png b/doc/jpip_architect.png new file mode 100644 index 0000000000000000000000000000000000000000..5375bf91f1305181ddcddcd0ab2fe63b9a2446ee GIT binary patch literal 62577 zcmYg&2RN2(__yr6LXw>xvdP{avcoHz?7c!n_IRwyN@SFgJtKRIBqV#6O=h-i-|7E9 zzVG-P$J=^&p8LM9>pIWhI-e*_bwwh48hkV~G$Lgsc`YS#N!Q6HbR4?I>%eU#?aZ=|`=?L>|rJQI*^`YKR0S7Q&A8 zYJMX06txFEJWJLddRsJkeddE3()!RFLR_G+Kia&u{guE%T?L{GvPNOib{rKzp> z4Gau!$1GBZ3x0c;bK?e=0&~1RCsl5GdhlYMVX1EM=)kS{t2b}RX`-KRO;yh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AfkjeTfW{*yr6s$MgrJ9aymDuqRp}5Yad^*K;XMb&t|JTYmG?&8*QWV?`^K)b zo|tt;YgKl*z~%@j42S{>$CSDIU25O}20K^L3u!UpbC2)T+#P{^cR_`0l#cVZkc`|x z7hn;hkNSsnFjjQ(f#Rc{k0z{-y1swv*={j*o)iG~( literal 0 HcmV?d00001 diff --git a/doc/jpip_protocol.png b/doc/jpip_protocol.png new file mode 100644 index 0000000000000000000000000000000000000000..bc326d456d6b120e641561faa3ce6e7ec3ae0c6b GIT binary patch literal 6376 zcmd6sc|4SR-^V98wydF&BUC4yqLl2*WK9VXjUgn=WXV33FizGip>1THB8?DZ8QJ$x z7-cYHj4dR~*bNzDo{N_Ioaesp=lSE@uh;YVW9Iexy{_w;Yvy|YKHvBEEBcDj1s<-0 zTp$pL=c2xjDG0=30Rrvv;a~w)JVHNMfj|ceFY0KT`KM6_)x8ETk=d>^PMnZ>$O6xO zSF_6>jPF2noNa^FyXukZ(}UbT>u{wl?zs}i*CJk}d2ScBi}U(Xj&lcJL;OjG6AH`wZz(clmJ^dO**~6~jqgv!-Qa2PmpMTEB`Phr7gga6}n-bh1`xR=sMyygB zf?2wR5kgiaX4ZrLw8&3T2vh2;JK9pU^jLi5hPL>17#}$3Qx1ETpazm(uX9nGHe1JD zUFltQi-JAWRE&7?X_jIL7AAB0jLmNiBKyLEGlss}&4u%=5~Ui4J#J$h%jPw}!M${l zia`p_id^COCPzG2A1#hU9dgz?unu)uRu3gb-&pqdXm7qtRn(k9wd;>(Amm9#a04@{ zHB|w^v*n?3^iNNh)h_%310rmZRC)Lpgs{=SrGQm3zXKd(%r$)? zO(NVZ21QSE8!|~hK!U(r0L>6Im^(ykm@6t$1aZcJ0_)TF2G8Qtqsb$bIp-sgRI1gRy}p|KT3Ui7 z$?;PI(8+9?!_C>+eZ^hDm*Gvl?2<%e`{Or*BkC7i7la`D(W&69J6{AFoI?5cP8&;n z9<-xh;4wM|n=J`mE?}U%U(4Twbg2fO@h1M_!CouR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A`>FqQJPqO0-Dkhd~_gOc{-P(gI8A%|Lc$B;VdVZSW(+Be-Xr7iISZRnic{ z=07>M!yta^P;kQ_a9lg%ti~9G@RH1C5eDe!ex|Tnex7clt6qkT63dH`e + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*! \mainpage OpenJPEG v@OPENJPEG_VERSION@ Documentation +* +* \section intro Introduction +* This manual documents the low-level OpenJPEG C API.\n +* The OpenJPEG library is an open-source JPEG 2000 library developed in order to promote the use of JPEG 2000.\n +* This documents is focused on the main part of the library which try to implement Part 1 and Part 2 of the JPEG2000 norm.\n +* +* \section home Home page +* +* The Home Page of the OpenJPEG project can be found at: +* +* http://www.openjpeg.org/ +* +* The source code repository is available here: +* +* http://github.com/uclouvain/openjpeg +* +* The OpenJPEG mailing list is located here: +* +* http://groups.google.com/group/openjpeg +* +* The test files repository is available here: +* +* http://github.com/uclouvain/openjpeg-data +* +* \section license License +* This software is released under the BSD license, anybody can use or modify the library, even for commercial applications.\n +* The only restriction is to retain the copyright in the sources or the binaries documentation.\n +* Neither the author, nor the university accept any responsibility for any kind of error or data loss which may occur during usage. +* +* \author OpenJPEG Team +* +*/ diff --git a/doc/man/man1/opj_compress.1 b/doc/man/man1/opj_compress.1 new file mode 100644 index 0000000..76ef01e --- /dev/null +++ b/doc/man/man1/opj_compress.1 @@ -0,0 +1,222 @@ +'\" t +'\" The line above instructs most `man' programs to invoke tbl +'\" +'\" Separate paragraphs; not the same as PP which resets indent level. +.de SP +.if t .sp .5 +.if n .sp +.. +'\" +'\" Replacement em-dash for nroff (default is too short). +.ie n .ds m " - +.el .ds m \(em +'\" +'\" Placeholder macro for if longer nroff arrow is needed. +.ds RA \(-> +'\" +'\" Decimal point set slightly raised +.if t .ds d \v'-.15m'.\v'+.15m' +.if n .ds d . +'\" +'\" Enclosure macro for examples +.de EX +.SP +.nf +.ft CW +.. +.de EE +.ft R +.SP +.fi +.. +.TH opj_compress 1 "Version 2.1.1" "opj_compress" "converts to jpeg2000 files" +.P +.SH NAME +opj_compress \- +This program reads in an image of a certain type and converts it to a +jpeg2000 file. It is part of the OpenJPEG library. +.SP +Valid input image extensions are +.B .bmp, .pgm, .pgx, .png, .pnm, .ppm, .raw, .tga, .tif \fR. For PNG resp. TIF it needs libpng resp. libtiff . +.SP +Valid output image extensions are +.B .j2k, .jp2 +.SH SYNOPSIS +.P +.B opj_compress \-i \fRinfile.bmp \fB-o \fRoutfile.j2k +.P +.B opj_compress \-ImgDir \fRdirectory_name \fB-OutFor \fRjp2 +.P +.B opj_compress \-h \fRPrint a help message and exit. +.P +See JPWL OPTIONS for special options +.SH OPTIONS +.TP +.B \-\^b " n,n" +(Size of code block (e.g. \-b 32,32). Default: 64 x 64) +.TP +.B \-\^c " n" +(Size of precinct (e.g. \-c 128,128). Default: 2^15 x 2^15) +.TP +.B \-\^cinema2K " fps" +Digital Cinema 2K profile compliant codestream. Valid \fBfps\fR values are 24 or 48. +.TP +.B \-\^cinema4K +Digital Cinema 4K profile compliant codestream. Does not need an fps: default is 24 fps. +.TP +.B \-\^d " X,Y" +(Offset of image origin (e.g. \-d 150,300)) +.TP +.B \-\^h +Print a help message and exit. +.TP +.B \-\^i " name" +(input file name) +.TP +.B \-\^n " n" +(Number of resolutions. Default: 6) +.TP +.B \-\^o " name" +(output file name) +.TP +.B \-\^p " name" +Progression order. \fBname\fR can be one out of:LRCP, RLCP, RPCL, PCRL, CPRL. Default: LRCP. +.TP +.B \-\^q " n" +different psnr for successive layers +.br +.B Note: \fR(options \-r and \-q cannot be used together) +.TP +.B \-\^r " n" +different compression ratio(s) for successive layers. The rate specified for each quality level is the desired compression factor. +.br +.B Note: \fR(options \-r and \-q cannot be used together) +.TP +.B \-\^s " X,Y" +sub-sampling factor (e.g. \-s 2,2). Default: No sub-sampling in x or y direction. +.br +.B Remark: \fRsub-sampling bigger than 2 can produce errors. +.TP +.B \-\^t " W,H" +(Size of tile (e.g. \-t 512,512) ) +.TP +.B \-\^x " name" +(Create index file and fill it. Default: no index file) +.TP +.B \-\^EPH +(Write EPH marker after each header packet. Default:no EPH) +.TP +.B \-\^F " rawWidth,rawHeight,rawComp,rawBitDepth,s_or_u" +characteristics of the raw input image +.TP +.B \-\^I +(Use the irreversible DWT 9-7. Default: Reversible DWT 5-3) +.TP +.B \-\^ImgDir " directory_name" +(directory containing input files) +.TP +.B \-\^M " n" +mode switch with values: 1, 2, 4, 8, 16, 32. Default:No mode switch activated. +.br +\fIMeaning:\fR +.br +BYPASS(1) +.br +RESET(2) +.br +RESTART(4) +.br +VSC(8) +.br +ERTERM(16) +.br +SEGMARK(32) +.br +Values can be added: RESTART(4) + RESET(2) + SEGMARK(32) = \-M 38 +.TP +.B \-\^OutFor "ext" +(extension for output files) +.TP +.B \-\^POC "TtileNr=resolutionStart, componentStart, layerEnd, resolutionEnd, componentEnd, progressionOrder" +(see Examples) +.TP +.B \-\^ROI "c=n,U=n" +quantization indices upshifted for component c (0 or 1 or 2) with a value of U (>= 0 and <= 37) +.br +e.g. \fB-ROI c=0,U=25\fR +.TP +.B \-\^SOP +(Write SOP marker before each packet. Default: No SOP marker in the codestream.) +.TP +.B \-\^T "X,Y" +(Offset of the origin of the tiles (e.g. \-T 100,75) ) +.TP +.B \-\^W +(see JPWL OPTIONS) +.P +.SH JPWL OPTIONS +Options usable only if the library has been compiled with \fB-DUSE_JPWL\fR +.P +.B \-W h<=type>, s<=method>, a=, z=, g=, p<=type> +.P +.B h\fR selects the header error protection (EPB): \fBtype\fR can be + [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS] + if \fBtilepart\fR is absent, it is for main and tile headers + if \fBtilepart\fR is present, it applies from that tile + onwards, up to the next h<> spec, or to the last tilepart + in the codestream (max. 16 specs) +.P +.B p \fRselects the packet error protection (EEP/UEP with EPBs) + to be applied to raw data: \fBtype\fR can be + [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS] + if \fBtilepart:pack\fR is absent, it is from tile 0, packet 0 + if \fBtilepart:pack\fR is present, it applies from that tile + and that packet onwards, up to the next packet spec + or to the last packet in the last tilepart in the stream + (max. 16 specs) +.P +.B s \fRenables sensitivity data insertion (ESD): \fBmethod\fR can be + [\-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR + 4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED] + if \fBtilepart\fR is absent, it is for main header only + if \fBtilepart\fR is present, it applies from that tile + onwards, up to the next s<> spec, or to the last tilepart + in the codestream (max. 16 specs) +.P +.B g \fRdetermines the addressing mode: \fBrange\fR can be + [0=PACKET 1=BYTE RANGE 2=PACKET RANGE] +.P +.B a \fRdetermines the size of data addressing: \fBaddr\fR can be + 2/4 bytes (small/large codestreams). If not set, auto-mode +.P +.B z \fRdetermines the size of sensitivity values: \fBsize\fR can be + 1/2 bytes, for the transformed pseudo-floating point value +.P +.SH EXAMPLES +.P +.B opj_compress \-i \fRfile.bmp \fB-o \fRfile.j2k \fB-r \fR20,10,1 (compress 20x, then 10x, then lossless). +.P +.B opj_compress \-i \fRfile.ppm \fB-o \fRfile.j2k \fB-q \fR30,40,50 +.P +.B opj_compress \-i \fRfile.pgx \fB-o \fRfile.j2k \fB-POC \fRT1=0,0,1,5,3,CPRL +.P +.B opj_compress \-i \fRlena.raw \fB-o \fRlena.j2k \fB-F \fR512,512,3,8,u +.P +.SH AUTHORS +Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium +.br +Copyright (c) 2002-2014, Professor Benoit Macq +.br +Copyright (c) 2001-2003, David Janssens +.br +Copyright (c) 2002-2003, Yannick Verschueren +.br +Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe +.br +Copyright (c) 2005, Herve Drolon, FreeImage Team +.br +Copyright (c) 2006-2007, Parvatha Elangovan +.P +.SH "SEE ALSO" +opj_decompress(1) opj_dump(1) + diff --git a/doc/man/man1/opj_decompress.1 b/doc/man/man1/opj_decompress.1 new file mode 100644 index 0000000..ae55f92 --- /dev/null +++ b/doc/man/man1/opj_decompress.1 @@ -0,0 +1,119 @@ +'\" t +'\" The line above instructs most `man' programs to invoke tbl +'\" +'\" Separate paragraphs; not the same as PP which resets indent level. +.de SP +.if t .sp .5 +.if n .sp +.. +'\" +'\" Replacement em-dash for nroff (default is too short). +.ie n .ds m " - +.el .ds m \(em +'\" +'\" Placeholder macro for if longer nroff arrow is needed. +.ds RA \(-> +'\" +'\" Decimal point set slightly raised +.if t .ds d \v'-.15m'.\v'+.15m' +.if n .ds d . +'\" +'\" Enclosure macro for examples +.de EX +.SP +.nf +.ft CW +.. +.de EE +.ft R +.SP +.fi +.. +.TH opj_decompress 1 "Version 2.1.1" "opj_decompress" "converts jpeg2000 files" +.P +.SH NAME +opj_decompress \- +This program reads in a jpeg2000 image and converts it to another +image type. It is part of the OpenJPEG library. +.SP +Valid input image extensions are +.B .j2k, .jp2, .j2c, .jpt +.SP +Valid output image extensions are +.B .bmp, .pgm, .pgx, .png, .pnm, .ppm, .raw, .tga, .tif \fR. For PNG resp. TIF it needs libpng resp. libtiff . +.SH SYNOPSIS +.P +.B opj_decompress \-i \fRinfile.j2k \fB-o \fRoutfile.png +.P +.B opj_decompress \-ImgDir \fRimages/ \fB-OutFor \fRbmp +.P +.B opj_decompress \-h \fRPrint help message and exit +.P +See JPWL OPTIONS for special options +.SH OPTIONS +.TP +.B \-\^i "name" +(jpeg2000 input file name) +.TP +.B \-\^l "n" +n is the maximum number of quality layers to decode. See LAYERS below) +.TP +.B \-\^o "name" +(output file name with extension) +.TP +.B \-\^r "n" +(n is the highest resolution level to be discarded. See REDUCTION below) +.TP +.B \-\^x "name" +(use name as index file and fill it) +.TP +.B \-\^ImgDir "directory_name" +(directory containing input files) +.TP +.B \-\^OutFor "ext" +(extension for output files) +.P +.SH JPIP OPTIONS +Options usable only if the library has been compiled with +.B BUILD_JPIP +.TP +.B -jpip +Embed index table box into the output JP2 file (compulsory for JPIP) +.TP +.B -TP R +Partition a tile into tile parts of different resolution levels (compulsory for JPT-stream) +.P +.SH JPWL OPTIONS +Options usable only if the library has been compiled with +.B BUILD_JPWL +.TP +.B -W c\fR[=Nc] (Nc is the number of expected components in the codestream; default:3) +.TP +.B -W t\fR[=Nt] (Nt is the maximum number of tiles in the codestream; default:8192) +.TP +.B -W c\fR[=Nc]\fB, t\fR[=Nt] \fR(same as above) +.P +.SH REDUCTION +Set the number of highest resolution levels to be discarded. +The image resolution is effectively divided by 2 to the power of the number of discarded levels. The reduce factor is limited by the smallest total number of decomposition levels among tiles. +.SH TILES +Set the maximum number of quality layers to decode. If there are less quality layers than the specified number, all the quality layers are decoded. +.P +'\".SH BUGS +.SH AUTHORS +Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium +.br +Copyright (c) 2002-2014, Professor Benoit Macq +.br +Copyright (c) 2001-2003, David Janssens +.br +Copyright (c) 2002-2003, Yannick Verschueren +.br +Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe +.br +Copyright (c) 2005, Herve Drolon, FreeImage Team +.br +Copyright (c) 2006-2007, Parvatha Elangovan +.P +.SH "SEE ALSO" +opj_compress(1) opj_dump(1) diff --git a/doc/man/man1/opj_dump.1 b/doc/man/man1/opj_dump.1 new file mode 100644 index 0000000..10b996d --- /dev/null +++ b/doc/man/man1/opj_dump.1 @@ -0,0 +1,62 @@ +'\" t +'\" The line above instructs most `man' programs to invoke tbl +'\" +'\" Separate paragraphs; not the same as PP which resets indent level. +.de SP +.if t .sp .5 +.if n .sp +.. +'\" +'\" Replacement em-dash for nroff (default is too short). +.ie n .ds m " - +.el .ds m \(em +'\" +'\" Placeholder macro for if longer nroff arrow is needed. +.ds RA \(-> +'\" +'\" Decimal point set slightly raised +.if t .ds d \v'-.15m'.\v'+.15m' +.if n .ds d . +'\" +'\" Enclosure macro for examples +.de EX +.SP +.nf +.ft CW +.. +.de EE +.ft R +.SP +.fi +.. +.TH opj_dump 1 "Version 2.1.1" "opj_dump" "dumps jpeg2000 files" +.P +.SH NAME +opj_dump \- +This program reads in a jpeg2000 image and dumps the contents to stdout. It is part of the OpenJPEG library. +.SP +Valid input image extensions are +.B .j2k, .jp2, .jpt +.SP +.SH SYNOPSIS +.P +.B opj_dump \-i \fRinfile.j2k +.P +.B opj_dump \-ImgDir \fRimages/ \fRDump all files in images/ +.P +.B opj_dump \-h \fRPrint help message and exit +.P +.SH OPTIONS +.TP +.B \-\^i "name" +(jpeg2000 input file name) +.TP +.B \-\^ImgDir "directory_name" +(directory containing jpeg2000 input files) +.P +'\".SH BUGS +.SH AUTHORS +Copyright (c) 2010, Mathieu Malaterre +.P +.SH "SEE ALSO" +opj_compress(1) opj_decompress(1) diff --git a/doc/man/man3/libopenjp2.3 b/doc/man/man3/libopenjp2.3 new file mode 100644 index 0000000..9b06cc8 --- /dev/null +++ b/doc/man/man3/libopenjp2.3 @@ -0,0 +1,337 @@ +'\" t +'\" The line above instructs most `man' programs to invoke tbl +'\" +'\" Separate paragraphs; not the same as PP which resets indent level. +.de SP +.if t .sp .5 +.if n .sp +.. +'\" +'\" Replacement em-dash for nroff (default is too short). +.ie n .ds m " - +.el .ds m \(em +'\" +'\" Placeholder macro for if longer nroff arrow is needed. +.ds RA \(-> +'\" +'\" Decimal point set slightly raised +.if t .ds d \v'-.15m'.\v'+.15m' +.if n .ds d . +'\" +'\" Enclosure macro for examples +.de EX +.SP +.nf +.ft CW +.. +.de EE +.ft R +.SP +.fi +.. +.TH libopenjp2 3 "Oct 2010" "Version 1.4.0" "Oct 2010" +.P +.SH NAME +libopenjp2 - +a library for reading and writing JPEG2000 image files. +.SP +.SH SYNOPSIS +.P +.B #include +.P +.SS CONVERSION FORMATS +.B PGX: imagetopgx() \fR/\fB pgxtoimage() +.P +.B PXM: imagetopnm() \fR/\fB pnmtoimage() +.P +.B BMP: imagetobmp() \fR/\fB bmptoimage() +.P +.B TIF: imagetotif() \fR/\fB tiftoimage() +.P +.B RAW: imagetoraw() \fR/\fB rawtoimage() +.P +.B TGA: imagetotga() \fR/\fB tgatoimage() +.P +.B PNG: imagetopng() \fR/\fB pngtoimage() +.P +.B YUV: imagetoyuv() \fR/\fB yuvtoimage() \fR(MJ2) +.P +.SS READ +.B opj_set_default_decoder_parameters(opj_dparameters_t *\fIparams\fB); +.P +.B opj_dinfo_t *opj_create_decompress(OPJ_CODEC_FORMAT \fIformat\fB); +.P +.B opj_event_mgr_t *opj_set_event_mgr(opj_common_ptr \fIinfo\fB, opj_event_mgr_t *\fIevent_mgr\fB, void *\fIcontext\fB); +.P +.B void opj_setup_decoder(opj_dinfo_t *\fIdinfo\fB, opj_dparameters_t * \fIparams\fB); +.P +.B opj_cio_t *opj_cio_open(opj_common_ptr \fIinfo\fB, unsigned char *\fIbuf\fB, int \fIbuf_len\fB); +.P +.B opj_image_t *opj_decode(opj_dinfo_t *\fIdinfo\fB, opj_cio_t *\fIcio\fB); +.P +.B void opj_cio_close(opj_cio_t *\fIcio\fB); +.P +.B void opj_destroy_decompress(opj_dinfo_t *\fIdinfo\fB); +.P +.B void opj_image_destroy(opj_image_t *\fIimage\fB); +.P +.SS WRITE +.B void opj_set_default_encoder_parameters(opj_cparameters_t *\fIparams\fB); +.P +/* +.B opj_image_t *FORMATtoimage(const char *\fIfname\fB, opj_cparameters_t *\fIparams\fB); +.P +*/ +.br +.B opj_cinfo_t* opj_create_compress(OPJ_CODEC_FORMAT \fIformat\fB); +.P +.B opj_event_mgr_t *opj_set_event_mgr(opj_common_ptr \fIinfo\fB, opj_event_mgr_t *\fIevent_mgr\fB, void *\fIcontext\fB); +.P +.B void opj_setup_encoder(opj_cinfo_t *\fIcinfo\fB, opj_cparameters_t *\fIparams\fB, opj_image_t *\fIimage\fB); +.P +.B opj_cio_t *opj_cio_open(opj_common_ptr \fIcinfo\fB, \fINULL\fB, \fI0\fB); +.P +.B bool opj_encode(opj_cinfo_t *\fIcinfo\fB, opj_cio_t *\fIcio\fB, opj_image_t *\fIimage\fB, char *\fIindex\fB); +.P +.B void opj_cio_close(opj_cio_t *\fIcio\fB); +.P +.B void opj_destroy_compress(opj_cinfo_t *\fIcinfo\fB); +.P +.B void opj_image_destroy(opj_image_t *\fIimage\fB); +.P +.SS GENERAL +.P +.B void opj_image_create(int \fInumcmpts\fB, opj_image_cmptparm_t *\fIcmptparms\fB, OPJ_COLOR_SPACE \fIclrspc\fB); +.P +.B int cio_tell(opj_cio_t *\fIcio\fB); +.P +.B void cio_seek(opj_cio_t *\fIcio\fB, int \fIpos\fB); +.P +.B opj_image_t *opj_decode_with_info(opj_dinfo_t *\fIdinfo\fB, opj_cio_t *\fIcio\fB, opj_codestream_info_t *\fIcstr_info\fB); +.P +.B bool opj_encode_with_info(opj_cinfo_t *\fIcinfo\fB, opj_cio_t *\fIcio\fB, opj_image_t *\fIimage\fB, opj_codestream_info_t *\fIcstr_info\fB); +.P +.B void opj_destroy_cstr_info(opj_codestream_info_t *\fIcstr_info\fB); +.P +.B const char *opj_version(\fIvoid\fB); +.P +.SH OPJ_CODEC_FORMAT +.P +.B CODEC_J2K\fR or \fBCODEC_JPT\fR or \fBCODEC_JP2 +.P +.SH OPJ_COLOR_SPACE +.P +.B CLRSPC_UNKNOWN\fR or \fBCLRSPC_UNSPECIFIED\fR or \fBCLRSPC_SRGB\fR or \fBCLRSPC_GRAY\fR or \fBCLRSPC_SYCC +.P +.SH DECOMPRESSION PARAMETERS +.p +typedef struct opj_dparameters +.br +{ + /* + Set the number of highest resolution levels to be discarded. + The image resolution is effectively divided by 2 to the power + of the number of discarded levels. + The reduce factor is limited by the smallest total number of + decomposition levels among tiles. + if != 0, then original dimension divided by 2^(reduce); + if == 0 or not used, image is decoded to the full resolution + */ + \fBint\fR cp_reduce; + /* + Set the maximum number of quality layers to decode. + If there are less quality layers than the specified number, + all the quality layers are decoded. + if != 0, then only the first "layer" layers are decoded; + if == 0 or not used, all the quality layers are decoded + */ + \fBint\fR cp_layer; + + /*command line encoder parameters (not used inside the library) */ + /* input file name */ + \fBchar\fR infile[OPJ_PATH_LEN]; + /* output file name */ + \fBchar\fR outfile[OPJ_PATH_LEN]; + /* input file format: see OPJ_CODEC_FORMAT */ + \fBint\fR decod_format; + /* output file format */ + \fBint\fR cod_format; + + /*JPWL decoding parameters */ + /* activates the JPWL correction capabilities */ + \fBbool\fR jpwl_correct; + /* expected number of components */ + \fBint\fR jpwl_exp_comps; + /* maximum number of tiles */ + \fBint\fR jpwl_max_tiles; + + /* + Specify whether the decoding should be done on the entire + codestream, or be limited to the main header + Limiting the decoding to the main header makes it possible + to extract the characteristics of the codestream + if == NO_LIMITATION, the entire codestream is decoded; + if == LIMIT_TO_MAIN_HEADER, only the main header is decoded; + */ + \fBOPJ_LIMIT_DECODING\fR cp_limit_decoding; +.br +} opj_dparameters_t; + +.SH COMPRESSION PARAMETERS +.P +typedef struct opj_cparameters +.br +{ + /* size of tile: tile_size_on = false (not in argument) + or tile_size_on = true (in argument) */ + \fBbool\fR tile_size_on; + /* XTOsiz */ + \fBint\fR cp_tx0; + /* YTOsiz */ + \fBint\fR cp_ty0; + /* XTsiz */ + \fBint\fR cp_tdx; + /* YTsiz */ + \fBint\fR cp_tdy; + /* allocation by rate/distortion */ + \fBint\fR cp_disto_alloc; + /* allocation by fixed layer */ + \fBint\fR cp_fixed_alloc; + /* add fixed_quality */ + \fBint\fR cp_fixed_quality; + /* fixed layer */ + \fBint *\fRcp_matrice; + /* comment for coding */ + \fBchar *\fRcp_comment; + /* coding style */ + \fBint\fR csty; + /* progression order: + PROG_UNKNOWN, LRCP(default), RLCP, RPCL, PCRL, CPRL */ + \fBOPJ_PROG_ORDER\fR prog_order; + /* progression order changes */ + \fBopj_poc_t\fR POC[32]; + /* number of progression order changes (POC), default: 0 */ + \fBint\fR numpocs; + /* number of layers */ + \fBint\fR tcp_numlayers; + /* rates of layers */ + \fBfloat\fR tcp_rates[100]; + /* different psnr for successive layers */ + \fBfloat\fR tcp_distoratio[100]; + /* number of resolutions */ + \fBint\fR numresolution; + /* initial code block width, default: 64 */ + \fBint\fR cblockw_init; + /* initial code block height, default: 64 */ + \fBint\fR cblockh_init; + /* mode switch (cblk_style) */ + /* 1 : use the irreversible DWT 9-7, + 0 : use lossless compression (default) */ + \fBint\fR irreversible; + /* region of interest: affected component in [0..3], + -1 means no ROI */ + \fBint\fR roi_compno; + /* region of interest: upshift value */ + \fBint\fR roi_shift; + /* number of precinct size specifications */ + \fBint\fR res_spec; + /* initial precinct width */ + \fBint\fR prcw_init[J2K_MAXRLVLS]; + /* initial precinct height */ + \fBint\fR prch_init[J2K_MAXRLVLS]; + + /*command line encoder parameters (not used inside the library) */ + /* input file name */ + \fBchar\fR infile[OPJ_PATH_LEN]; + /* output file name */ + \fBchar\fR outfile[OPJ_PATH_LEN]; + /* DEPRECATED. Index generation is now handeld with the + opj_encode_with_info() function. Set to NULL */ + \fBint\fR index_on; + /* DEPRECATED. Index generation is now handeld with the + opj_encode_with_info() function. Set to NULL */ + \fBchar\fR index[OPJ_PATH_LEN]; + /* subimage encoding: origin image offset in x direction */ + \fBint\fR image_offset_x0; + /* subimage encoding: origin image offset in y direction */ + \fBint\fR image_offset_y0; + /* subsampling value for dx */ + \fBint\fR subsampling_dx; + /* subsampling value for dy */ + \fBint\fR subsampling_dy; + /* input file format */ + \fBint\fR decod_format; + /* output file format: see OPJ_CODEC_FORMAT */ + \fBint\fR cod_format; + + /*JPWL encoding parameters */ + /* enables writing of EPC in MH, thus activating JPWL */ + \fBbool\fR jpwl_epc_on; + /* error protection method for MH (0,1,16,32,37-128) */ + \fBint\fR jpwl_hprot_MH; + /* tile number of header protection specification (>=0) */ + \fBint\fR jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS]; + /* error protection methods for TPHs (0,1,16,32,37-128) */ + \fBint\fR jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS]; + /* tile number of packet protection specification (>=0) */ + \fBint\fR jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS]; + /* packet number of packet protection specification (>=0) */ + \fBint\fR jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS]; + /* error protection methods for packets (0,1,16,32,37-128) */ + \fBint\fR jpwl_pprot[JPWL_MAX_NO_PACKSPECS]; + /* enables writing of ESD, (0=no/1/2 bytes) */ + \fBint\fR jpwl_sens_size; + /* sensitivity addressing size (0=auto/2/4 bytes) */ + \fBint\fR jpwl_sens_addr; + /* sensitivity range (0-3) */ + \fBint\fR jpwl_sens_range; + /* sensitivity method for MH (-1=no,0-7) */ + \fBint\fR jpwl_sens_MH; + /* tile number of sensitivity specification (>=0) */ + \fBint\fR jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS]; + /* sensitivity methods for TPHs (-1=no,0-7) */ + \fBint\fR jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS]; + + /* Digital Cinema compliance: OFF-not compliant, + CINEMA2K_24, CINEMA2K_48, CINEMA4K_24 */ + \fBOPJ_CINEMA_MODE\fR cp_cinema; + /* Maximum rate for each component. + If == 0, component size limitation is not considered */ + \fBint\fR max_comp_size; + /* Profile name*/ + \fBOPJ_RSIZ_CAPABILITIES\fR cp_rsiz; + /* Tile part generation*/ + \fBchar\fR tp_on; + /* Flag for Tile part generation*/ + \fBchar\fR tp_flag; + /* MCT (multiple component transform) */ + \fBchar\fR tcp_mct; +.br +} opj_cparameters_t; + + +'\".SH OPTIONS +'\".SH BUGS +.SH AUTHORS +Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + +Copyright (c) 2002-2014, Professor Benoit Macq + +Copyright (c) 2001-2003, David Janssens + +Copyright (c) 2002-2003, Yannick Verschueren + +Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + +Copyright (c) 2005, Herve Drolon, FreeImage Team + +Copyright (c) 2006-2007, Parvatha Elangovan + +.P +.SH "SEE ALSO" +\fBimage_to_j2k\fR(1) \fBj2k_to_image\fR(1) \fBj2k_dump\fR(1) + +\fBJPWL_image_to_j2k\fR(1) \fBJPWL_j2k_to_image\fR(1) + +\fBextract_j2k_from_mj2\fR(1) \fBwrap_j2k_in_mj2\fR(1) +\fBframes_to_mj2\fR(1) \fBmj2_to_frames\fR(1) diff --git a/doc/openjpip.dox.in b/doc/openjpip.dox.in new file mode 100644 index 0000000..fd06ee0 --- /dev/null +++ b/doc/openjpip.dox.in @@ -0,0 +1,94 @@ +/* + * $Id$ + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*! \page openjpippage OpenJPIP v@OPENJPEG_VERSION@ Documentation + * + * \section Introduction + * This manual documents the low-level OpenJPIP C API.\n + * OpenJPIP software is an implementation of JPEG 2000 Part9: Interactivity tools, APIs and protocols (JPIP).\n + * ( For more info about JPIP, check the website: http://www.jpeg.org/jpeg2000/j2kpart9.html)\n + * + * This whole documents covers the following six programs.\n + * - opj_server.c JPIP server supporting HTTP connection and JPT/JPP-stream + * - opj_dec_server.c Server to decode JPT/JPP-stream and communicate locally with JPIP client, which is coded in java + * - opj_jpip_addxml.c To Embed metadata into JP2 file + * - opj_jpip_transcode.c To Convert JPT/JPP-stream to JP2 or J2K + * - opj_jpip_test.c To test index code format of a JP2 file + * + * \section License + * This software is released under the BSD license, anybody can use or modify the library, even for commercial applications.\n + * The only restriction is to retain the copyright in the sources or the binaries documentation.\n + * Neither the author, nor the university accept any responsibility for any kind of error or data loss which may occur during usage. + * + * + * \section reqlibs Required libraries + * - OpenJPEG library + * - FastCGI development kit (C libraries) at server (http://www.fastcgi.com) + * - libcURL library + * + * We tested this software with a virtual server running on the same Linux machine as the clients. + * + * + * \section compilenotes Compiling Notes + * When you are making opj_server, set anything (e.g. yes) to the parameter jpipserver to define itself in the Makefile, which enables to make it in server mode.\n + * Otherwise do not define (or do not set to) the parameter jpipserver.\n + * Be sure that any object files and library file libopenjpip.a are not reused to compile in the two different mode (server mode and non server mode).\n + * In other words, do make clean before making new targets which are in different modes as previous make.\n + * + * + * \section sysarchtect System Architecture + * JPIP protocol is implemented between the JPIP server program (opj_server) and the JPIP client java program (opj_viewer).\n + * Figure below represents the overview of our system architecture.\n + * The JPIP server parses JPIP query and sends corresponding JPT/JPP-stream. + * The JPIP client viewer is an image viewer with GUI to publish JPIP requests and receive JPT/JPP-stream.\n + * Particularly, our system has the image decoding module implemented on a server (opj_dec_server, Image decoding Server). + * Image decoding Server and JPIP client viewer communicate closely. + * This specific architecture enables sharing cache of image codestream data among all viewers connected to the same Image decoding Server not only locally but also remotely. + * + * \image html jpip_architect.png "OpenJPIP system architecture" + * + * JPIP server follows up the client cache during a session. \n + * Concretely, the JPIP server models cache in each session, to which Channel IDs are associated. + * A Channel ID identifies a JPIP client viewer. + * And, new viewers can belong to a session by referring to one of its channel ID. + * The Image decoding Server maintains the association between channel IDs and targets, and provides a reference channel ID to a Viewer on demand.\n + * + * Typical requests and replies among JPIP server, JPIP client, and Image decoding server is presented below.\n + * The JPIP server parses HTTP query and sends corresponding JPT/JPP-stream back to the JPIP client (Viewer). + * JPT/JPP-stream is unreadable by JPIP client, and it is directly passed to Image decoding Server, and which provides the image in raw format (PGM or PPM) to the JPIP client. + * The Image decoding Server handles the decoding and caching of JPT/JPP-stream. + * JPIP client can read PGM and PPM images natively. + * Before connecting to the JPIP server, every JPIP client checks local cache data of the requesting image with the image decoding server. + * If its cache exists, the image decoding server provides ChannelID (CID), which identifies the image and its cache model on the JPIP server, and the whole system can continue the session using the CID. + * + * \image html jpip_protocol.png "Message Sequence Chart of OpenJPIP implementation" + * + * \author Kaori Hagihara UCL/SST/ICTM/ELEN + */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..87526cf --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,12 @@ +# required dep for server: +#if(BUILD_JPIP_SERVER) +# find_package(CURL REQUIRED) +# find_package(FCGI REQUIRED) +# find_package(Threads REQUIRED) +# if(NOT CMAKE_USE_PTHREADS_INIT) +# message(FATAL_ERROR "Only pthread are supported") +# endif() +#endif() + +#add_subdirectory(lib) +#add_subdirectory(bin) diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt new file mode 100644 index 0000000..edf85fe --- /dev/null +++ b/src/bin/CMakeLists.txt @@ -0,0 +1,21 @@ +# source code for openjpeg apps: +add_subdirectory(common) +# Part 1 & 2: +add_subdirectory(jp2) + +# optionals components: +if(BUILD_JPWL) + add_subdirectory(jpwl) +endif() +if(BUILD_MJ2) + add_subdirectory(mj2) +endif() +if(BUILD_JPIP) + add_subdirectory(jpip) +endif() +if(BUILD_JP3D) + add_subdirectory(jp3d) +endif() + +# wx apps: +add_subdirectory(wx) diff --git a/src/bin/common/CMakeLists.txt b/src/bin/common/CMakeLists.txt new file mode 100644 index 0000000..017c23d --- /dev/null +++ b/src/bin/common/CMakeLists.txt @@ -0,0 +1,7 @@ +#----------------------------------------------------------------------------- +# opj_apps_config.h generation +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/opj_apps_config.h.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/opj_apps_config.h + @ONLY + ) diff --git a/src/bin/common/color.c b/src/bin/common/color.c new file mode 100644 index 0000000..d3a2f38 --- /dev/null +++ b/src/bin/common/color.c @@ -0,0 +1,1137 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +#include "opj_apps_config.h" +#include "openjpeg.h" +#include "color.h" + +#ifdef OPJ_HAVE_LIBLCMS2 +#include +#endif +#ifdef OPJ_HAVE_LIBLCMS1 +#include +#endif + +#ifdef OPJ_USE_LEGACY +#define OPJ_CLRSPC_GRAY CLRSPC_GRAY +#define OPJ_CLRSPC_SRGB CLRSPC_SRGB +#endif + +/*-------------------------------------------------------- +Matrix for sYCC, Amendment 1 to IEC 61966-2-1 + +Y : 0.299 0.587 0.114 :R +Cb: -0.1687 -0.3312 0.5 :G +Cr: 0.5 -0.4187 -0.0812 :B + +Inverse: + +R: 1 -3.68213e-05 1.40199 :Y +G: 1.00003 -0.344125 -0.714128 :Cb - 2^(prec - 1) +B: 0.999823 1.77204 -8.04142e-06 :Cr - 2^(prec - 1) + +-----------------------------------------------------------*/ +static void sycc_to_rgb(int offset, int upb, int y, int cb, int cr, + int *out_r, int *out_g, int *out_b) +{ + int r, g, b; + + cb -= offset; + cr -= offset; + r = y + (int)(1.402 * (float)cr); + if (r < 0) { + r = 0; + } else if (r > upb) { + r = upb; + } + *out_r = r; + + g = y - (int)(0.344 * (float)cb + 0.714 * (float)cr); + if (g < 0) { + g = 0; + } else if (g > upb) { + g = upb; + } + *out_g = g; + + b = y + (int)(1.772 * (float)cb); + if (b < 0) { + b = 0; + } else if (b > upb) { + b = upb; + } + *out_b = b; +} + +static void sycc444_to_rgb(opj_image_t *img) +{ + int *d0, *d1, *d2, *r, *g, *b; + const int *y, *cb, *cr; + size_t maxw, maxh, max, i; + int offset, upb; + + upb = (int)img->comps[0].prec; + offset = 1 << (upb - 1); + upb = (1 << upb) - 1; + + maxw = (size_t)img->comps[0].w; + maxh = (size_t)img->comps[0].h; + max = maxw * maxh; + + y = img->comps[0].data; + cb = img->comps[1].data; + cr = img->comps[2].data; + + d0 = r = (int*)opj_image_data_alloc(sizeof(int) * max); + d1 = g = (int*)opj_image_data_alloc(sizeof(int) * max); + d2 = b = (int*)opj_image_data_alloc(sizeof(int) * max); + + if (r == NULL || g == NULL || b == NULL) { + goto fails; + } + + for (i = 0U; i < max; ++i) { + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + ++y; + ++cb; + ++cr; + ++r; + ++g; + ++b; + } + opj_image_data_free(img->comps[0].data); + img->comps[0].data = d0; + opj_image_data_free(img->comps[1].data); + img->comps[1].data = d1; + opj_image_data_free(img->comps[2].data); + img->comps[2].data = d2; + img->color_space = OPJ_CLRSPC_SRGB; + return; + +fails: + opj_image_data_free(r); + opj_image_data_free(g); + opj_image_data_free(b); +}/* sycc444_to_rgb() */ + +static void sycc422_to_rgb(opj_image_t *img) +{ + int *d0, *d1, *d2, *r, *g, *b; + const int *y, *cb, *cr; + size_t maxw, maxh, max, offx, loopmaxw; + int offset, upb; + size_t i; + + upb = (int)img->comps[0].prec; + offset = 1 << (upb - 1); + upb = (1 << upb) - 1; + + maxw = (size_t)img->comps[0].w; + maxh = (size_t)img->comps[0].h; + max = maxw * maxh; + + y = img->comps[0].data; + cb = img->comps[1].data; + cr = img->comps[2].data; + + d0 = r = (int*)opj_image_data_alloc(sizeof(int) * max); + d1 = g = (int*)opj_image_data_alloc(sizeof(int) * max); + d2 = b = (int*)opj_image_data_alloc(sizeof(int) * max); + + if (r == NULL || g == NULL || b == NULL) { + goto fails; + } + + /* if img->x0 is odd, then first column shall use Cb/Cr = 0 */ + offx = img->x0 & 1U; + loopmaxw = maxw - offx; + + for (i = 0U; i < maxh; ++i) { + size_t j; + + if (offx > 0U) { + sycc_to_rgb(offset, upb, *y, 0, 0, r, g, b); + ++y; + ++r; + ++g; + ++b; + } + + for (j = 0U; j < (loopmaxw & ~(size_t)1U); j += 2U) { + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + ++y; + ++r; + ++g; + ++b; + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + ++y; + ++r; + ++g; + ++b; + ++cb; + ++cr; + } + if (j < loopmaxw) { + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + ++y; + ++r; + ++g; + ++b; + ++cb; + ++cr; + } + } + + opj_image_data_free(img->comps[0].data); + img->comps[0].data = d0; + opj_image_data_free(img->comps[1].data); + img->comps[1].data = d1; + opj_image_data_free(img->comps[2].data); + img->comps[2].data = d2; + + img->comps[1].w = img->comps[2].w = img->comps[0].w; + img->comps[1].h = img->comps[2].h = img->comps[0].h; + img->comps[1].dx = img->comps[2].dx = img->comps[0].dx; + img->comps[1].dy = img->comps[2].dy = img->comps[0].dy; + img->color_space = OPJ_CLRSPC_SRGB; + return; + +fails: + opj_image_data_free(r); + opj_image_data_free(g); + opj_image_data_free(b); +}/* sycc422_to_rgb() */ + +static void sycc420_to_rgb(opj_image_t *img) +{ + int *d0, *d1, *d2, *r, *g, *b, *nr, *ng, *nb; + const int *y, *cb, *cr, *ny; + size_t maxw, maxh, max, offx, loopmaxw, offy, loopmaxh; + int offset, upb; + size_t i; + + upb = (int)img->comps[0].prec; + offset = 1 << (upb - 1); + upb = (1 << upb) - 1; + + maxw = (size_t)img->comps[0].w; + maxh = (size_t)img->comps[0].h; + max = maxw * maxh; + + y = img->comps[0].data; + cb = img->comps[1].data; + cr = img->comps[2].data; + + d0 = r = (int*)opj_image_data_alloc(sizeof(int) * max); + d1 = g = (int*)opj_image_data_alloc(sizeof(int) * max); + d2 = b = (int*)opj_image_data_alloc(sizeof(int) * max); + + if (r == NULL || g == NULL || b == NULL) { + goto fails; + } + + /* if img->x0 is odd, then first column shall use Cb/Cr = 0 */ + offx = img->x0 & 1U; + loopmaxw = maxw - offx; + /* if img->y0 is odd, then first line shall use Cb/Cr = 0 */ + offy = img->y0 & 1U; + loopmaxh = maxh - offy; + + if (offy > 0U) { + size_t j; + + for (j = 0; j < maxw; ++j) { + sycc_to_rgb(offset, upb, *y, 0, 0, r, g, b); + ++y; + ++r; + ++g; + ++b; + } + } + + for (i = 0U; i < (loopmaxh & ~(size_t)1U); i += 2U) { + size_t j; + + ny = y + maxw; + nr = r + maxw; + ng = g + maxw; + nb = b + maxw; + + if (offx > 0U) { + sycc_to_rgb(offset, upb, *y, 0, 0, r, g, b); + ++y; + ++r; + ++g; + ++b; + sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); + ++ny; + ++nr; + ++ng; + ++nb; + } + + for (j = 0; j < (loopmaxw & ~(size_t)1U); j += 2U) { + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + ++y; + ++r; + ++g; + ++b; + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + ++y; + ++r; + ++g; + ++b; + + sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); + ++ny; + ++nr; + ++ng; + ++nb; + sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); + ++ny; + ++nr; + ++ng; + ++nb; + ++cb; + ++cr; + } + if (j < loopmaxw) { + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + ++y; + ++r; + ++g; + ++b; + + sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); + ++ny; + ++nr; + ++ng; + ++nb; + ++cb; + ++cr; + } + y += maxw; + r += maxw; + g += maxw; + b += maxw; + } + if (i < loopmaxh) { + size_t j; + + for (j = 0U; j < (maxw & ~(size_t)1U); j += 2U) { + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + + ++y; + ++r; + ++g; + ++b; + + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + + ++y; + ++r; + ++g; + ++b; + ++cb; + ++cr; + } + if (j < maxw) { + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + } + } + + opj_image_data_free(img->comps[0].data); + img->comps[0].data = d0; + opj_image_data_free(img->comps[1].data); + img->comps[1].data = d1; + opj_image_data_free(img->comps[2].data); + img->comps[2].data = d2; + + img->comps[1].w = img->comps[2].w = img->comps[0].w; + img->comps[1].h = img->comps[2].h = img->comps[0].h; + img->comps[1].dx = img->comps[2].dx = img->comps[0].dx; + img->comps[1].dy = img->comps[2].dy = img->comps[0].dy; + img->color_space = OPJ_CLRSPC_SRGB; + return; + +fails: + opj_image_data_free(r); + opj_image_data_free(g); + opj_image_data_free(b); +}/* sycc420_to_rgb() */ + +void color_sycc_to_rgb(opj_image_t *img) +{ + if (img->numcomps < 3) { + img->color_space = OPJ_CLRSPC_GRAY; + return; + } + + if ((img->comps[0].dx == 1) + && (img->comps[1].dx == 2) + && (img->comps[2].dx == 2) + && (img->comps[0].dy == 1) + && (img->comps[1].dy == 2) + && (img->comps[2].dy == 2)) { /* horizontal and vertical sub-sample */ + sycc420_to_rgb(img); + } else if ((img->comps[0].dx == 1) + && (img->comps[1].dx == 2) + && (img->comps[2].dx == 2) + && (img->comps[0].dy == 1) + && (img->comps[1].dy == 1) + && (img->comps[2].dy == 1)) { /* horizontal sub-sample only */ + sycc422_to_rgb(img); + } else if ((img->comps[0].dx == 1) + && (img->comps[1].dx == 1) + && (img->comps[2].dx == 1) + && (img->comps[0].dy == 1) + && (img->comps[1].dy == 1) + && (img->comps[2].dy == 1)) { /* no sub-sample */ + sycc444_to_rgb(img); + } else { + fprintf(stderr, "%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__, + __LINE__); + return; + } +}/* color_sycc_to_rgb() */ + +#if defined(OPJ_HAVE_LIBLCMS2) || defined(OPJ_HAVE_LIBLCMS1) + +#ifdef OPJ_HAVE_LIBLCMS1 +/* Bob Friesenhahn proposed:*/ +#define cmsSigXYZData icSigXYZData +#define cmsSigLabData icSigLabData +#define cmsSigCmykData icSigCmykData +#define cmsSigYCbCrData icSigYCbCrData +#define cmsSigLuvData icSigLuvData +#define cmsSigGrayData icSigGrayData +#define cmsSigRgbData icSigRgbData +#define cmsUInt32Number DWORD + +#define cmsColorSpaceSignature icColorSpaceSignature +#define cmsGetHeaderRenderingIntent cmsTakeRenderingIntent + +#endif /* OPJ_HAVE_LIBLCMS1 */ + +/*#define DEBUG_PROFILE*/ +void color_apply_icc_profile(opj_image_t *image) +{ + cmsHPROFILE in_prof, out_prof; + cmsHTRANSFORM transform; + cmsColorSpaceSignature in_space, out_space; + cmsUInt32Number intent, in_type, out_type; + int *r, *g, *b; + size_t nr_samples, i, max, max_w, max_h; + int prec, ok = 0; + OPJ_COLOR_SPACE new_space; + + in_prof = cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); +#ifdef DEBUG_PROFILE + FILE *icm = fopen("debug.icm", "wb"); + fwrite(image->icc_profile_buf, 1, image->icc_profile_len, icm); + fclose(icm); +#endif + + if (in_prof == NULL) { + return; + } + + in_space = cmsGetPCS(in_prof); + out_space = cmsGetColorSpace(in_prof); + intent = cmsGetHeaderRenderingIntent(in_prof); + + + max_w = image->comps[0].w; + max_h = image->comps[0].h; + prec = (int)image->comps[0].prec; + + if (out_space == cmsSigRgbData) { /* enumCS 16 */ + unsigned int i, nr_comp = image->numcomps; + + if (nr_comp > 4) { + nr_comp = 4; + } + for (i = 1; i < nr_comp; ++i) { /* AFL test */ + if (image->comps[0].dx != image->comps[i].dx) { + break; + } + + if (image->comps[0].dy != image->comps[i].dy) { + break; + } + + if (image->comps[0].prec != image->comps[i].prec) { + break; + } + + if (image->comps[0].sgnd != image->comps[i].sgnd) { + break; + } + + } + if (i != nr_comp) { + cmsCloseProfile(in_prof); + return; + } + + if (prec <= 8) { + in_type = TYPE_RGB_8; + out_type = TYPE_RGB_8; + } else { + in_type = TYPE_RGB_16; + out_type = TYPE_RGB_16; + } + out_prof = cmsCreate_sRGBProfile(); + new_space = OPJ_CLRSPC_SRGB; + } else if (out_space == cmsSigGrayData) { /* enumCS 17 */ + in_type = TYPE_GRAY_8; + out_type = TYPE_RGB_8; + out_prof = cmsCreate_sRGBProfile(); + new_space = OPJ_CLRSPC_SRGB; + } else if (out_space == cmsSigYCbCrData) { /* enumCS 18 */ + in_type = TYPE_YCbCr_16; + out_type = TYPE_RGB_16; + out_prof = cmsCreate_sRGBProfile(); + new_space = OPJ_CLRSPC_SRGB; + } else { +#ifdef DEBUG_PROFILE + fprintf(stderr, "%s:%d: color_apply_icc_profile\n\tICC Profile has unknown " + "output colorspace(%#x)(%c%c%c%c)\n\tICC Profile ignored.\n", + __FILE__, __LINE__, out_space, + (out_space >> 24) & 0xff, (out_space >> 16) & 0xff, + (out_space >> 8) & 0xff, out_space & 0xff); +#endif + cmsCloseProfile(in_prof); + + return; + } + if (out_prof == NULL) { + cmsCloseProfile(in_prof); + return; + } + +#ifdef DEBUG_PROFILE + fprintf(stderr, + "%s:%d:color_apply_icc_profile\n\tchannels(%d) prec(%d) w(%d) h(%d)" + "\n\tprofile: in(%p) out(%p)\n", __FILE__, __LINE__, image->numcomps, prec, + max_w, max_h, (void*)in_prof, (void*)out_prof); + + fprintf(stderr, "\trender_intent (%u)\n\t" + "color_space: in(%#x)(%c%c%c%c) out:(%#x)(%c%c%c%c)\n\t" + " type: in(%u) out:(%u)\n", + intent, + in_space, + (in_space >> 24) & 0xff, (in_space >> 16) & 0xff, + (in_space >> 8) & 0xff, in_space & 0xff, + + out_space, + (out_space >> 24) & 0xff, (out_space >> 16) & 0xff, + (out_space >> 8) & 0xff, out_space & 0xff, + + in_type, out_type + ); +#else + (void)prec; + (void)in_space; +#endif /* DEBUG_PROFILE */ + + transform = cmsCreateTransform(in_prof, in_type, out_prof, out_type, intent, 0); + +#ifdef OPJ_HAVE_LIBLCMS2 + /* Possible for: LCMS_VERSION >= 2000 :*/ + cmsCloseProfile(in_prof); + cmsCloseProfile(out_prof); +#endif + + if (transform == NULL) { +#ifdef DEBUG_PROFILE + fprintf(stderr, "%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " + "ICC Profile ignored.\n", __FILE__, __LINE__); +#endif + +#ifdef OPJ_HAVE_LIBLCMS1 + cmsCloseProfile(in_prof); + cmsCloseProfile(out_prof); +#endif + return; + } + + if (image->numcomps > 2) { /* RGB, RGBA */ + if ((image->comps[0].w == image->comps[1].w && + image->comps[0].w == image->comps[2].w) && + (image->comps[0].h == image->comps[1].h && + image->comps[0].h == image->comps[2].h)) { + if (prec <= 8) { + unsigned char *inbuf, *outbuf, *in, *out; + + max = max_w * max_h; + nr_samples = (size_t)(max * 3U * sizeof(unsigned char)); + in = inbuf = (unsigned char*)opj_image_data_alloc(nr_samples); + out = outbuf = (unsigned char*)opj_image_data_alloc(nr_samples); + + if (inbuf == NULL || outbuf == NULL) { + goto fails0; + } + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for (i = 0U; i < max; ++i) { + *in++ = (unsigned char) * r++; + *in++ = (unsigned char) * g++; + *in++ = (unsigned char) * b++; + } + + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for (i = 0U; i < max; ++i) { + *r++ = (int) * out++; + *g++ = (int) * out++; + *b++ = (int) * out++; + } + ok = 1; + +fails0: + opj_image_data_free(inbuf); + opj_image_data_free(outbuf); + } else { /* prec > 8 */ + unsigned short *inbuf, *outbuf, *in, *out; + + max = max_w * max_h; + nr_samples = (size_t)(max * 3U * sizeof(unsigned short)); + in = inbuf = (unsigned short*)opj_image_data_alloc(nr_samples); + out = outbuf = (unsigned short*)opj_image_data_alloc(nr_samples); + + if (inbuf == NULL || outbuf == NULL) { + goto fails1; + } + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for (i = 0U ; i < max; ++i) { + *in++ = (unsigned short) * r++; + *in++ = (unsigned short) * g++; + *in++ = (unsigned short) * b++; + } + + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for (i = 0; i < max; ++i) { + *r++ = (int) * out++; + *g++ = (int) * out++; + *b++ = (int) * out++; + } + ok = 1; + +fails1: + opj_image_data_free(inbuf); + opj_image_data_free(outbuf); + } + } else { + fprintf(stderr, + "[ERROR] Image components should have the same width and height\n"); + cmsDeleteTransform(transform); + return; + } + } else { /* image->numcomps <= 2 : GRAY, GRAYA */ + if (prec <= 8) { + unsigned char *in, *inbuf, *out, *outbuf; + opj_image_comp_t *new_comps; + + max = max_w * max_h; + nr_samples = (size_t)(max * 3 * sizeof(unsigned char)); + in = inbuf = (unsigned char*)opj_image_data_alloc(nr_samples); + out = outbuf = (unsigned char*)opj_image_data_alloc(nr_samples); + g = (int*)opj_image_data_alloc((size_t)max * sizeof(int)); + b = (int*)opj_image_data_alloc((size_t)max * sizeof(int)); + + if (inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) { + goto fails2; + } + + new_comps = (opj_image_comp_t*)realloc(image->comps, + (image->numcomps + 2) * sizeof(opj_image_comp_t)); + + if (new_comps == NULL) { + goto fails2; + } + + image->comps = new_comps; + + if (image->numcomps == 2) { + image->comps[3] = image->comps[1]; + } + + image->comps[1] = image->comps[0]; + image->comps[2] = image->comps[0]; + + image->comps[1].data = g; + image->comps[2].data = b; + + image->numcomps += 2; + + r = image->comps[0].data; + + for (i = 0U; i < max; ++i) { + *in++ = (unsigned char) * r++; + } + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for (i = 0U; i < max; ++i) { + *r++ = (int) * out++; + *g++ = (int) * out++; + *b++ = (int) * out++; + } + r = g = b = NULL; + ok = 1; + +fails2: + opj_image_data_free(inbuf); + opj_image_data_free(outbuf); + opj_image_data_free(g); + opj_image_data_free(b); + } else { /* prec > 8 */ + unsigned short *in, *inbuf, *out, *outbuf; + opj_image_comp_t *new_comps; + + max = max_w * max_h; + nr_samples = (size_t)(max * 3U * sizeof(unsigned short)); + in = inbuf = (unsigned short*)opj_image_data_alloc(nr_samples); + out = outbuf = (unsigned short*)opj_image_data_alloc(nr_samples); + g = (int*)opj_image_data_alloc((size_t)max * sizeof(int)); + b = (int*)opj_image_data_alloc((size_t)max * sizeof(int)); + + if (inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) { + goto fails3; + } + + new_comps = (opj_image_comp_t*)realloc(image->comps, + (image->numcomps + 2) * sizeof(opj_image_comp_t)); + + if (new_comps == NULL) { + goto fails3; + } + + image->comps = new_comps; + + if (image->numcomps == 2) { + image->comps[3] = image->comps[1]; + } + + image->comps[1] = image->comps[0]; + image->comps[2] = image->comps[0]; + + image->comps[1].data = g; + image->comps[2].data = b; + + image->numcomps += 2; + + r = image->comps[0].data; + + for (i = 0U; i < max; ++i) { + *in++ = (unsigned short) * r++; + } + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for (i = 0; i < max; ++i) { + *r++ = (int) * out++; + *g++ = (int) * out++; + *b++ = (int) * out++; + } + r = g = b = NULL; + ok = 1; + +fails3: + opj_image_data_free(inbuf); + opj_image_data_free(outbuf); + opj_image_data_free(g); + opj_image_data_free(b); + } + }/* if(image->numcomps > 2) */ + + cmsDeleteTransform(transform); + +#ifdef OPJ_HAVE_LIBLCMS1 + cmsCloseProfile(in_prof); + cmsCloseProfile(out_prof); +#endif + if (ok) { + image->color_space = new_space; + } +}/* color_apply_icc_profile() */ + +static int are_comps_same_dimensions(opj_image_t * image) +{ + unsigned int i; + for (i = 1; i < image->numcomps; i++) { + if (image->comps[0].dx != image->comps[i].dx || + image->comps[0].dy != image->comps[i].dy) { + return OPJ_FALSE; + } + } + return OPJ_TRUE; +} + +void color_cielab_to_rgb(opj_image_t *image) +{ + int *row; + int enumcs, numcomps; + OPJ_COLOR_SPACE new_space; + + numcomps = (int)image->numcomps; + + if (numcomps != 3) { + fprintf(stderr, "%s:%d:\n\tnumcomps %d not handled. Quitting.\n", + __FILE__, __LINE__, numcomps); + return; + } + if (!are_comps_same_dimensions(image)) { + fprintf(stderr, + "%s:%d:\n\tcomponents are not all of the same dimension. Quitting.\n", + __FILE__, __LINE__); + return; + } + + row = (int*)image->icc_profile_buf; + enumcs = row[0]; + + if (enumcs == 14) { /* CIELab */ + int *L, *a, *b, *red, *green, *blue; + int *src0, *src1, *src2, *dst0, *dst1, *dst2; + double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2; + double minL, maxL, mina, maxa, minb, maxb; + unsigned int default_type; + unsigned int i, max; + cmsHPROFILE in, out; + cmsHTRANSFORM transform; + cmsUInt16Number RGB[3]; + cmsCIELab Lab; + + in = cmsCreateLab4Profile(NULL); + if (in == NULL) { + return; + } + out = cmsCreate_sRGBProfile(); + if (out == NULL) { + cmsCloseProfile(in); + return; + } + transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, + INTENT_PERCEPTUAL, 0); + +#ifdef OPJ_HAVE_LIBLCMS2 + cmsCloseProfile(in); + cmsCloseProfile(out); +#endif + if (transform == NULL) { +#ifdef OPJ_HAVE_LIBLCMS1 + cmsCloseProfile(in); + cmsCloseProfile(out); +#endif + return; + } + new_space = OPJ_CLRSPC_SRGB; + + prec0 = (double)image->comps[0].prec; + prec1 = (double)image->comps[1].prec; + prec2 = (double)image->comps[2].prec; + + default_type = (unsigned int)row[1]; + + if (default_type == 0x44454600) { /* DEF : default */ + rl = 100; + ra = 170; + rb = 200; + ol = 0; + oa = pow(2, prec1 - 1); + ob = pow(2, prec2 - 2) + pow(2, prec2 - 3); + } else { + rl = row[2]; + ra = row[4]; + rb = row[6]; + ol = row[3]; + oa = row[5]; + ob = row[7]; + } + + L = src0 = image->comps[0].data; + a = src1 = image->comps[1].data; + b = src2 = image->comps[2].data; + + max = image->comps[0].w * image->comps[0].h; + + red = dst0 = (int*)opj_image_data_alloc(max * sizeof(int)); + green = dst1 = (int*)opj_image_data_alloc(max * sizeof(int)); + blue = dst2 = (int*)opj_image_data_alloc(max * sizeof(int)); + + if (red == NULL || green == NULL || blue == NULL) { + goto fails; + } + + minL = -(rl * ol) / (pow(2, prec0) - 1); + maxL = minL + rl; + + mina = -(ra * oa) / (pow(2, prec1) - 1); + maxa = mina + ra; + + minb = -(rb * ob) / (pow(2, prec2) - 1); + maxb = minb + rb; + + for (i = 0; i < max; ++i) { + Lab.L = minL + (double)(*L) * (maxL - minL) / (pow(2, prec0) - 1); + ++L; + Lab.a = mina + (double)(*a) * (maxa - mina) / (pow(2, prec1) - 1); + ++a; + Lab.b = minb + (double)(*b) * (maxb - minb) / (pow(2, prec2) - 1); + ++b; + + cmsDoTransform(transform, &Lab, RGB, 1); + + *red++ = RGB[0]; + *green++ = RGB[1]; + *blue++ = RGB[2]; + } + cmsDeleteTransform(transform); +#ifdef OPJ_HAVE_LIBLCMS1 + cmsCloseProfile(in); + cmsCloseProfile(out); +#endif + opj_image_data_free(src0); + image->comps[0].data = dst0; + opj_image_data_free(src1); + image->comps[1].data = dst1; + opj_image_data_free(src2); + image->comps[2].data = dst2; + + image->color_space = new_space; + image->comps[0].prec = 16; + image->comps[1].prec = 16; + image->comps[2].prec = 16; + + return; + +fails: + cmsDeleteTransform(transform); +#ifdef OPJ_HAVE_LIBLCMS1 + cmsCloseProfile(in); + cmsCloseProfile(out); +#endif + if (red) { + opj_image_data_free(red); + } + if (green) { + opj_image_data_free(green); + } + if (blue) { + opj_image_data_free(blue); + } + return; + } + + fprintf(stderr, "%s:%d:\n\tenumCS %d not handled. Ignoring.\n", __FILE__, + __LINE__, enumcs); +}/* color_cielab_to_rgb() */ + +#endif /* OPJ_HAVE_LIBLCMS2 || OPJ_HAVE_LIBLCMS1 */ + +void color_cmyk_to_rgb(opj_image_t *image) +{ + float C, M, Y, K; + float sC, sM, sY, sK; + unsigned int w, h, max, i; + + w = image->comps[0].w; + h = image->comps[0].h; + + if ( + (image->numcomps < 4) + || (image->comps[0].dx != image->comps[1].dx) || + (image->comps[0].dx != image->comps[2].dx) || + (image->comps[0].dx != image->comps[3].dx) + || (image->comps[0].dy != image->comps[1].dy) || + (image->comps[0].dy != image->comps[2].dy) || + (image->comps[0].dy != image->comps[3].dy) + ) { + fprintf(stderr, "%s:%d:color_cmyk_to_rgb\n\tCAN NOT CONVERT\n", __FILE__, + __LINE__); + return; + } + + max = w * h; + + sC = 1.0F / (float)((1 << image->comps[0].prec) - 1); + sM = 1.0F / (float)((1 << image->comps[1].prec) - 1); + sY = 1.0F / (float)((1 << image->comps[2].prec) - 1); + sK = 1.0F / (float)((1 << image->comps[3].prec) - 1); + + for (i = 0; i < max; ++i) { + /* CMYK values from 0 to 1 */ + C = (float)(image->comps[0].data[i]) * sC; + M = (float)(image->comps[1].data[i]) * sM; + Y = (float)(image->comps[2].data[i]) * sY; + K = (float)(image->comps[3].data[i]) * sK; + + /* Invert all CMYK values */ + C = 1.0F - C; + M = 1.0F - M; + Y = 1.0F - Y; + K = 1.0F - K; + + /* CMYK -> RGB : RGB results from 0 to 255 */ + image->comps[0].data[i] = (int)(255.0F * C * K); /* R */ + image->comps[1].data[i] = (int)(255.0F * M * K); /* G */ + image->comps[2].data[i] = (int)(255.0F * Y * K); /* B */ + } + + opj_image_data_free(image->comps[3].data); + image->comps[3].data = NULL; + image->comps[0].prec = 8; + image->comps[1].prec = 8; + image->comps[2].prec = 8; + image->numcomps -= 1; + image->color_space = OPJ_CLRSPC_SRGB; + + for (i = 3; i < image->numcomps; ++i) { + memcpy(&(image->comps[i]), &(image->comps[i + 1]), sizeof(image->comps[i])); + } + +}/* color_cmyk_to_rgb() */ + +/* + * This code has been adopted from sjpx_openjpeg.c of ghostscript + */ +void color_esycc_to_rgb(opj_image_t *image) +{ + int y, cb, cr, sign1, sign2, val; + unsigned int w, h, max, i; + int flip_value = (1 << (image->comps[0].prec - 1)); + int max_value = (1 << image->comps[0].prec) - 1; + + if ( + (image->numcomps < 3) + || (image->comps[0].dx != image->comps[1].dx) || + (image->comps[0].dx != image->comps[2].dx) + || (image->comps[0].dy != image->comps[1].dy) || + (image->comps[0].dy != image->comps[2].dy) + ) { + fprintf(stderr, "%s:%d:color_esycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__, + __LINE__); + return; + } + + w = image->comps[0].w; + h = image->comps[0].h; + + sign1 = (int)image->comps[1].sgnd; + sign2 = (int)image->comps[2].sgnd; + + max = w * h; + + for (i = 0; i < max; ++i) { + + y = image->comps[0].data[i]; + cb = image->comps[1].data[i]; + cr = image->comps[2].data[i]; + + if (!sign1) { + cb -= flip_value; + } + if (!sign2) { + cr -= flip_value; + } + + val = (int) + ((float)y - (float)0.0000368 * (float)cb + + (float)1.40199 * (float)cr + (float)0.5); + + if (val > max_value) { + val = max_value; + } else if (val < 0) { + val = 0; + } + image->comps[0].data[i] = val; + + val = (int) + ((float)1.0003 * (float)y - (float)0.344125 * (float)cb + - (float)0.7141128 * (float)cr + (float)0.5); + + if (val > max_value) { + val = max_value; + } else if (val < 0) { + val = 0; + } + image->comps[1].data[i] = val; + + val = (int) + ((float)0.999823 * (float)y + (float)1.77204 * (float)cb + - (float)0.000008 * (float)cr + (float)0.5); + + if (val > max_value) { + val = max_value; + } else if (val < 0) { + val = 0; + } + image->comps[2].data[i] = val; + } + image->color_space = OPJ_CLRSPC_SRGB; + +}/* color_esycc_to_rgb() */ diff --git a/src/bin/common/color.h b/src/bin/common/color.h new file mode 100644 index 0000000..2479254 --- /dev/null +++ b/src/bin/common/color.h @@ -0,0 +1,47 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _OPJ_COLOR_H_ +#define _OPJ_COLOR_H_ + +extern void color_sycc_to_rgb(opj_image_t *img); +extern void color_apply_icc_profile(opj_image_t *image); +extern void color_cielab_to_rgb(opj_image_t *image); + +extern void color_cmyk_to_rgb(opj_image_t *image); +extern void color_esycc_to_rgb(opj_image_t *image); +#endif /* _OPJ_COLOR_H_ */ diff --git a/src/bin/common/format_defs.h b/src/bin/common/format_defs.h new file mode 100644 index 0000000..1985b54 --- /dev/null +++ b/src/bin/common/format_defs.h @@ -0,0 +1,55 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _OPJ_FORMAT_DEFS_H_ +#define _OPJ_FORMAT_DEFS_H_ + +#define J2K_CFMT 0 +#define JP2_CFMT 1 +#define JPT_CFMT 2 + +#define PXM_DFMT 10 +#define PGX_DFMT 11 +#define BMP_DFMT 12 +#define YUV_DFMT 13 +#define TIF_DFMT 14 +#define RAW_DFMT 15 /* MSB / Big Endian */ +#define TGA_DFMT 16 +#define PNG_DFMT 17 +#define RAWL_DFMT 18 /* LSB / Little Endian */ + +#endif /* _OPJ_FORMAT_DEFS_H_ */ diff --git a/src/bin/common/opj_apps_config.h.cmake.in b/src/bin/common/opj_apps_config.h.cmake.in new file mode 100644 index 0000000..5e60690 --- /dev/null +++ b/src/bin/common/opj_apps_config.h.cmake.in @@ -0,0 +1,15 @@ +#include "opj_config_private.h" + +/* create opj_apps_config.h for CMake */ + +#cmakedefine OPJ_HAVE_LIBPNG @HAVE_LIBPNG@ +#cmakedefine OPJ_HAVE_PNG_H @HAVE_PNG_H@ +#cmakedefine OPJ_HAVE_LIBTIFF @HAVE_LIBTIFF@ +#cmakedefine OPJ_HAVE_TIFF_H @HAVE_TIFF_H@ + +#cmakedefine OPJ_HAVE_LIBLCMS1 +#cmakedefine OPJ_HAVE_LIBLCMS2 +#cmakedefine OPJ_HAVE_LCMS1_H +#cmakedefine OPJ_HAVE_LCMS2_H + + diff --git a/src/bin/common/opj_getopt.c b/src/bin/common/opj_getopt.c new file mode 100644 index 0000000..11ccfc5 --- /dev/null +++ b/src/bin/common/opj_getopt.c @@ -0,0 +1,277 @@ +/* + * The copyright in this software is being made available under the 3-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* last review : october 29th, 2002 */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)opj_getopt.c 8.3 (Berkeley) 4/27/95"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include "opj_getopt.h" + +int opj_opterr = 1, /* if error message should be printed */ + opj_optind = 1, /* index into parent argv vector */ + opj_optopt, /* character checked for validity */ + opj_optreset; /* reset getopt */ +char *opj_optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +static char EMSG[] = {""}; + +/* As this class remembers its values from one Java call to the other, reset the values before each use */ +void opj_reset_options_reading(void) +{ + opj_opterr = 1; + opj_optind = 1; +} + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int opj_getopt(int nargc, char *const *nargv, const char *ostr) +{ +# define __progname nargv[0] + static char *place = EMSG; /* option letter processing */ + const char *oli = NULL; /* option letter list index */ + + if (opj_optreset || !*place) { /* update scanning pointer */ + opj_optreset = 0; + if (opj_optind >= nargc || *(place = nargv[opj_optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++opj_optind; + place = EMSG; + return (-1); + } + } /* option letter okay? */ + if ((opj_optopt = (int) * place++) == (int) ':' || + !(oli = strchr(ostr, opj_optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (opj_optopt == (int) '-') { + return (-1); + } + if (!*place) { + ++opj_optind; + } + if (opj_opterr && *ostr != ':') { + fprintf(stderr, + "%s: illegal option -- %c\n", __progname, opj_optopt); + return (BADCH); + } + } + if (*++oli != ':') { /* don't need argument */ + opj_optarg = NULL; + if (!*place) { + ++opj_optind; + } + } else { /* need an argument */ + if (*place) { /* no white space */ + opj_optarg = place; + } else if (nargc <= ++opj_optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') { + return (BADARG); + } + if (opj_opterr) { + fprintf(stderr, + "%s: option requires an argument -- %c\n", + __progname, opj_optopt); + return (BADCH); + } + } else { /* white space */ + opj_optarg = nargv[opj_optind]; + } + place = EMSG; + ++opj_optind; + } + return (opj_optopt); /* dump back option letter */ +} + + +int opj_getopt_long(int argc, char * const argv[], const char *optstring, + const opj_option_t *longopts, int totlen) +{ + static int lastidx, lastofs; + const char *tmp; + int i, len; + char param = 1; + +again: + if (opj_optind >= argc || !argv[opj_optind] || *argv[opj_optind] != '-') { + return -1; + } + + if (argv[opj_optind][0] == '-' && argv[opj_optind][1] == 0) { + if (opj_optind >= (argc - 1)) { /* no more input parameters */ + param = 0; + } else { /* more input parameters */ + if (argv[opj_optind + 1][0] == '-') { + param = 0; /* Missing parameter after '-' */ + } else { + param = 2; + } + } + } + + if (param == 0) { + ++opj_optind; + return (BADCH); + } + + if (argv[opj_optind][0] == '-') { /* long option */ + char* arg; + const opj_option_t* o; + o = longopts; + len = sizeof(longopts[0]); + + if (param > 1) { + if (opj_optind + 1 >= argc) { + return -1; + } + arg = argv[opj_optind + 1]; + opj_optind++; + } else { + arg = argv[opj_optind] + 1; + } + + if (strlen(arg) > 1) { + for (i = 0; i < totlen; i = i + len, o++) { + if (!strcmp(o->name, arg)) { /* match */ + if (o->has_arg == 0) { + if ((argv[opj_optind + 1]) && (!(argv[opj_optind + 1][0] == '-'))) { + fprintf(stderr, "%s: option does not require an argument. Ignoring %s\n", arg, + argv[opj_optind + 1]); + ++opj_optind; + } + } else { + opj_optarg = argv[opj_optind + 1]; + if (opj_optarg) { + if (opj_optarg[0] == + '-') { /* Has read next input parameter: No arg for current parameter */ + if (opj_opterr) { + fprintf(stderr, "%s: option requires an argument\n", arg); + return (BADCH); + } + } + } + if (!opj_optarg && o->has_arg == 1) { /* no argument there */ + if (opj_opterr) { + fprintf(stderr, "%s: option requires an argument \n", arg); + return (BADCH); + } + } + ++opj_optind; + } + ++opj_optind; + if (o->flag) { + *(o->flag) = o->val; + } else { + return o->val; + } + return 0; + } + }/*(end for)String not found in the list*/ + fprintf(stderr, "Invalid option %s\n", arg); + ++opj_optind; + return (BADCH); + } else { /*Single character input parameter*/ + if (*optstring == ':') { + return ':'; + } + if (lastidx != opj_optind) { + lastidx = opj_optind; + lastofs = 0; + } + opj_optopt = argv[opj_optind][lastofs + 1]; + if ((tmp = strchr(optstring, opj_optopt))) { /*Found input parameter in list*/ + if (*tmp == 0) { /* apparently, we looked for \0, i.e. end of argument */ + ++opj_optind; + goto again; + } + if (tmp[1] == ':') { /* argument expected */ + if (tmp[2] == ':' || + argv[opj_optind][lastofs + 2]) { /* "-foo", return "oo" as opj_optarg */ + if (!*(opj_optarg = argv[opj_optind] + lastofs + 2)) { + opj_optarg = 0; + } + goto found; + } + opj_optarg = argv[opj_optind + 1]; + if (opj_optarg) { + if (opj_optarg[0] == + '-') { /* Has read next input parameter: No arg for current parameter */ + if (opj_opterr) { + fprintf(stderr, "%s: option requires an argument\n", arg); + ++opj_optind; + return (BADCH); + } + } + } + if (!opj_optarg) { /* missing argument */ + if (opj_opterr) { + fprintf(stderr, "%s: option requires an argument\n", arg); + ++opj_optind; + return (BADCH); + } + } + ++opj_optind; + } else {/*Argument not expected*/ + ++lastofs; + return opj_optopt; + } +found: + ++opj_optind; + return opj_optopt; + } else { /* not found */ + fprintf(stderr, "Invalid option %s\n", arg); + ++opj_optind; + return (BADCH); + }/*end of not found*/ + + }/* end of single character*/ + }/*end '-'*/ + fprintf(stderr, "Invalid option\n"); + ++opj_optind; + return (BADCH);; +}/*end function*/ diff --git a/src/bin/common/opj_getopt.h b/src/bin/common/opj_getopt.h new file mode 100644 index 0000000..18ac24d --- /dev/null +++ b/src/bin/common/opj_getopt.h @@ -0,0 +1,28 @@ +/* last review : october 29th, 2002 */ + +#ifndef _GETOPT_H_ +#define _GETOPT_H_ + +typedef struct opj_option { + const char *name; + int has_arg; + int *flag; + int val; +} opj_option_t; + +#define NO_ARG 0 +#define REQ_ARG 1 +#define OPT_ARG 2 + +extern int opj_opterr; +extern int opj_optind; +extern int opj_optopt; +extern int opj_optreset; +extern char *opj_optarg; + +extern int opj_getopt(int nargc, char *const *nargv, const char *ostr); +extern int opj_getopt_long(int argc, char * const argv[], const char *optstring, + const opj_option_t *longopts, int totlen); +extern void opj_reset_options_reading(void); + +#endif /* _GETOPT_H_ */ diff --git a/src/bin/common/opj_string.h b/src/bin/common/opj_string.h new file mode 100644 index 0000000..f704a8c --- /dev/null +++ b/src/bin/common/opj_string.h @@ -0,0 +1,72 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2015, Matthieu Darbois + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef OPJ_STRING_H +#define OPJ_STRING_H + +#include +#include + +/* strnlen is not standard, strlen_s is C11... */ +/* keep in mind there still is a buffer read overflow possible */ +static size_t opj_strnlen_s(const char *src, size_t max_len) +{ + size_t len; + + if (src == NULL) { + return 0U; + } + for (len = 0U; (*src != '\0') && (len < max_len); src++, len++); + return len; +} + +/* should be equivalent to C11 function except for the handler */ +/* keep in mind there still is a buffer read overflow possible */ +static int opj_strcpy_s(char* dst, size_t dst_size, const char* src) +{ + size_t src_len = 0U; + if ((dst == NULL) || (dst_size == 0U)) { + return EINVAL; + } + if (src == NULL) { + dst[0] = '\0'; + return EINVAL; + } + src_len = opj_strnlen_s(src, dst_size); + if (src_len >= dst_size) { + return ERANGE; + } + memcpy(dst, src, src_len); + dst[src_len] = '\0'; + return 0; +} + +#endif /* OPJ_STRING_H */ diff --git a/src/bin/jp2/CMakeLists.txt b/src/bin/jp2/CMakeLists.txt new file mode 100644 index 0000000..4d4bd95 --- /dev/null +++ b/src/bin/jp2/CMakeLists.txt @@ -0,0 +1,88 @@ +# Build the demo app, small examples + +# First thing define the common source: +set(common_SRCS + convert.c + convert.h + convertbmp.c + index.c + index.h + ${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c + ${OPENJPEG_SOURCE_DIR}/src/bin/common/color.h + ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c + ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.h + ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_string.h + ) + +if(OPJ_HAVE_LIBTIFF) + list(APPEND common_SRCS converttif.c) +endif() +if(OPJ_HAVE_LIBPNG) + list(APPEND common_SRCS convertpng.c) +endif() + +# Headers file are located here: +include_directories( + ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h + ${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h + ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2 + ${OPENJPEG_SOURCE_DIR}/src/bin/common + ${LCMS_INCLUDE_DIRNAME} + ${Z_INCLUDE_DIRNAME} + ${PNG_INCLUDE_DIRNAME} + ${TIFF_INCLUDE_DIRNAME} + ) + +if(WIN32) + if(BUILD_SHARED_LIBS) + add_definitions(-DOPJ_EXPORTS) + else() + add_definitions(-DOPJ_STATIC) + endif() +endif() + +# Loop over all executables: +foreach(exe opj_decompress opj_compress opj_dump) + add_executable(${exe} ${exe}.c ${common_SRCS}) + if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12") + target_compile_options(${exe} PRIVATE ${OPENJP2_COMPILE_OPTIONS}) + endif() + target_link_libraries(${exe} ${OPENJPEG_LIBRARY_NAME} + ${PNG_LIBNAME} ${TIFF_LIBNAME} ${LCMS_LIBNAME} + ) + # To support universal exe: + if(ZLIB_FOUND AND APPLE) + target_link_libraries(${exe} z) + else(ZLIB_FOUND AND APPLE) + target_link_libraries(${exe} ${Z_LIBNAME}) + endif() + + # On unix you need to link to the math library: + if(UNIX) + target_link_libraries(${exe} m) + IF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + target_link_libraries(${exe} rt) + endif() + endif() + # Install exe + install(TARGETS ${exe} + EXPORT OpenJPEGTargets + DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications + ) + if(OPJ_USE_DSYMUTIL) + add_custom_command(TARGET ${exe} POST_BUILD + COMMAND "dsymutil" "$" + COMMENT "dsymutil $" + DEPENDS ${exe}) + endif() +endforeach() + +if(BUILD_DOC) +# Install man pages +install( + FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_compress.1 + ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_decompress.1 + ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_dump.1 + DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man1) +# +endif() diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c new file mode 100644 index 0000000..e670cd8 --- /dev/null +++ b/src/bin/jp2/convert.c @@ -0,0 +1,2623 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include "opj_apps_config.h" + +#include +#include +#include +#include +#include + +#include "openjpeg.h" +#include "convert.h" + +/* + * Get logarithm of an integer and round downwards. + * + * log2(a) + */ +static int int_floorlog2(int a) +{ + int l; + for (l = 0; a > 1; l++) { + a >>= 1; + } + return l; +} + +/* Component precision scaling */ +void clip_component(opj_image_comp_t* component, OPJ_UINT32 precision) +{ + OPJ_SIZE_T i; + OPJ_SIZE_T len; + OPJ_UINT32 umax = (OPJ_UINT32)((OPJ_INT32) - 1); + + len = (OPJ_SIZE_T)component->w * (OPJ_SIZE_T)component->h; + if (precision < 32) { + umax = (1U << precision) - 1U; + } + + if (component->sgnd) { + OPJ_INT32* l_data = component->data; + OPJ_INT32 max = (OPJ_INT32)(umax / 2U); + OPJ_INT32 min = -max - 1; + for (i = 0; i < len; ++i) { + if (l_data[i] > max) { + l_data[i] = max; + } else if (l_data[i] < min) { + l_data[i] = min; + } + } + } else { + OPJ_UINT32* l_data = (OPJ_UINT32*)component->data; + for (i = 0; i < len; ++i) { + if (l_data[i] > umax) { + l_data[i] = umax; + } + } + } + component->prec = precision; +} + +/* Component precision scaling */ +static void scale_component_up(opj_image_comp_t* component, + OPJ_UINT32 precision) +{ + OPJ_SIZE_T i, len; + + len = (OPJ_SIZE_T)component->w * (OPJ_SIZE_T)component->h; + if (component->sgnd) { + OPJ_INT64 newMax = (OPJ_INT64)(1U << (precision - 1)); + OPJ_INT64 oldMax = (OPJ_INT64)(1U << (component->prec - 1)); + OPJ_INT32* l_data = component->data; + for (i = 0; i < len; ++i) { + l_data[i] = (OPJ_INT32)(((OPJ_INT64)l_data[i] * newMax) / oldMax); + } + } else { + OPJ_UINT64 newMax = (OPJ_UINT64)((1U << precision) - 1U); + OPJ_UINT64 oldMax = (OPJ_UINT64)((1U << component->prec) - 1U); + OPJ_UINT32* l_data = (OPJ_UINT32*)component->data; + for (i = 0; i < len; ++i) { + l_data[i] = (OPJ_UINT32)(((OPJ_UINT64)l_data[i] * newMax) / oldMax); + } + } + component->prec = precision; + component->bpp = precision; +} +void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision) +{ + int shift; + OPJ_SIZE_T i, len; + + if (component->prec == precision) { + return; + } + if (component->prec < precision) { + scale_component_up(component, precision); + return; + } + shift = (int)(component->prec - precision); + len = (OPJ_SIZE_T)component->w * (OPJ_SIZE_T)component->h; + if (component->sgnd) { + OPJ_INT32* l_data = component->data; + for (i = 0; i < len; ++i) { + l_data[i] >>= shift; + } + } else { + OPJ_UINT32* l_data = (OPJ_UINT32*)component->data; + for (i = 0; i < len; ++i) { + l_data[i] >>= shift; + } + } + component->bpp = precision; + component->prec = precision; +} + + +/* planar / interleaved conversions */ +/* used by PNG/TIFF */ +static void convert_32s_C1P1(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, + OPJ_SIZE_T length) +{ + memcpy(pDst[0], pSrc, length * sizeof(OPJ_INT32)); +} +static void convert_32s_C2P2(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + OPJ_INT32* pDst0 = pDst[0]; + OPJ_INT32* pDst1 = pDst[1]; + + for (i = 0; i < length; i++) { + pDst0[i] = pSrc[2 * i + 0]; + pDst1[i] = pSrc[2 * i + 1]; + } +} +static void convert_32s_C3P3(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + OPJ_INT32* pDst0 = pDst[0]; + OPJ_INT32* pDst1 = pDst[1]; + OPJ_INT32* pDst2 = pDst[2]; + + for (i = 0; i < length; i++) { + pDst0[i] = pSrc[3 * i + 0]; + pDst1[i] = pSrc[3 * i + 1]; + pDst2[i] = pSrc[3 * i + 2]; + } +} +static void convert_32s_C4P4(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + OPJ_INT32* pDst0 = pDst[0]; + OPJ_INT32* pDst1 = pDst[1]; + OPJ_INT32* pDst2 = pDst[2]; + OPJ_INT32* pDst3 = pDst[3]; + + for (i = 0; i < length; i++) { + pDst0[i] = pSrc[4 * i + 0]; + pDst1[i] = pSrc[4 * i + 1]; + pDst2[i] = pSrc[4 * i + 2]; + pDst3[i] = pSrc[4 * i + 3]; + } +} +const convert_32s_CXPX convert_32s_CXPX_LUT[5] = { + NULL, + convert_32s_C1P1, + convert_32s_C2P2, + convert_32s_C3P3, + convert_32s_C4P4 +}; + +static void convert_32s_P1C1(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length, OPJ_INT32 adjust) +{ + OPJ_SIZE_T i; + const OPJ_INT32* pSrc0 = pSrc[0]; + + for (i = 0; i < length; i++) { + pDst[i] = pSrc0[i] + adjust; + } +} +static void convert_32s_P2C2(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length, OPJ_INT32 adjust) +{ + OPJ_SIZE_T i; + const OPJ_INT32* pSrc0 = pSrc[0]; + const OPJ_INT32* pSrc1 = pSrc[1]; + + for (i = 0; i < length; i++) { + pDst[2 * i + 0] = pSrc0[i] + adjust; + pDst[2 * i + 1] = pSrc1[i] + adjust; + } +} +static void convert_32s_P3C3(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length, OPJ_INT32 adjust) +{ + OPJ_SIZE_T i; + const OPJ_INT32* pSrc0 = pSrc[0]; + const OPJ_INT32* pSrc1 = pSrc[1]; + const OPJ_INT32* pSrc2 = pSrc[2]; + + for (i = 0; i < length; i++) { + pDst[3 * i + 0] = pSrc0[i] + adjust; + pDst[3 * i + 1] = pSrc1[i] + adjust; + pDst[3 * i + 2] = pSrc2[i] + adjust; + } +} +static void convert_32s_P4C4(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length, OPJ_INT32 adjust) +{ + OPJ_SIZE_T i; + const OPJ_INT32* pSrc0 = pSrc[0]; + const OPJ_INT32* pSrc1 = pSrc[1]; + const OPJ_INT32* pSrc2 = pSrc[2]; + const OPJ_INT32* pSrc3 = pSrc[3]; + + for (i = 0; i < length; i++) { + pDst[4 * i + 0] = pSrc0[i] + adjust; + pDst[4 * i + 1] = pSrc1[i] + adjust; + pDst[4 * i + 2] = pSrc2[i] + adjust; + pDst[4 * i + 3] = pSrc3[i] + adjust; + } +} +const convert_32s_PXCX convert_32s_PXCX_LUT[5] = { + NULL, + convert_32s_P1C1, + convert_32s_P2C2, + convert_32s_P3C3, + convert_32s_P4C4 +}; + +/* bit depth conversions */ +/* used by PNG/TIFF up to 8bpp */ +static void convert_1u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 val = *pSrc++; + pDst[i + 0] = (OPJ_INT32)(val >> 7); + pDst[i + 1] = (OPJ_INT32)((val >> 6) & 0x1U); + pDst[i + 2] = (OPJ_INT32)((val >> 5) & 0x1U); + pDst[i + 3] = (OPJ_INT32)((val >> 4) & 0x1U); + pDst[i + 4] = (OPJ_INT32)((val >> 3) & 0x1U); + pDst[i + 5] = (OPJ_INT32)((val >> 2) & 0x1U); + pDst[i + 6] = (OPJ_INT32)((val >> 1) & 0x1U); + pDst[i + 7] = (OPJ_INT32)(val & 0x1U); + } + if (length & 7U) { + OPJ_UINT32 val = *pSrc++; + length = length & 7U; + pDst[i + 0] = (OPJ_INT32)(val >> 7); + + if (length > 1U) { + pDst[i + 1] = (OPJ_INT32)((val >> 6) & 0x1U); + if (length > 2U) { + pDst[i + 2] = (OPJ_INT32)((val >> 5) & 0x1U); + if (length > 3U) { + pDst[i + 3] = (OPJ_INT32)((val >> 4) & 0x1U); + if (length > 4U) { + pDst[i + 4] = (OPJ_INT32)((val >> 3) & 0x1U); + if (length > 5U) { + pDst[i + 5] = (OPJ_INT32)((val >> 2) & 0x1U); + if (length > 6U) { + pDst[i + 6] = (OPJ_INT32)((val >> 1) & 0x1U); + } + } + } + } + } + } + } +} +static void convert_2u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i += 4U) { + OPJ_UINT32 val = *pSrc++; + pDst[i + 0] = (OPJ_INT32)(val >> 6); + pDst[i + 1] = (OPJ_INT32)((val >> 4) & 0x3U); + pDst[i + 2] = (OPJ_INT32)((val >> 2) & 0x3U); + pDst[i + 3] = (OPJ_INT32)(val & 0x3U); + } + if (length & 3U) { + OPJ_UINT32 val = *pSrc++; + length = length & 3U; + pDst[i + 0] = (OPJ_INT32)(val >> 6); + + if (length > 1U) { + pDst[i + 1] = (OPJ_INT32)((val >> 4) & 0x3U); + if (length > 2U) { + pDst[i + 2] = (OPJ_INT32)((val >> 2) & 0x3U); + + } + } + } +} +static void convert_4u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)1U); i += 2U) { + OPJ_UINT32 val = *pSrc++; + pDst[i + 0] = (OPJ_INT32)(val >> 4); + pDst[i + 1] = (OPJ_INT32)(val & 0xFU); + } + if (length & 1U) { + OPJ_UINT8 val = *pSrc++; + pDst[i + 0] = (OPJ_INT32)(val >> 4); + } +} +static void convert_6u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i += 4U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + pDst[i + 0] = (OPJ_INT32)(val0 >> 2); + pDst[i + 1] = (OPJ_INT32)(((val0 & 0x3U) << 4) | (val1 >> 4)); + pDst[i + 2] = (OPJ_INT32)(((val1 & 0xFU) << 2) | (val2 >> 6)); + pDst[i + 3] = (OPJ_INT32)(val2 & 0x3FU); + + } + if (length & 3U) { + OPJ_UINT32 val0 = *pSrc++; + length = length & 3U; + pDst[i + 0] = (OPJ_INT32)(val0 >> 2); + + if (length > 1U) { + OPJ_UINT32 val1 = *pSrc++; + pDst[i + 1] = (OPJ_INT32)(((val0 & 0x3U) << 4) | (val1 >> 4)); + if (length > 2U) { + OPJ_UINT32 val2 = *pSrc++; + pDst[i + 2] = (OPJ_INT32)(((val1 & 0xFU) << 2) | (val2 >> 6)); + } + } + } +} +static void convert_8u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; i++) { + pDst[i] = pSrc[i]; + } +} +const convert_XXx32s_C1R convert_XXu32s_C1R_LUT[9] = { + NULL, + convert_1u32s_C1R, + convert_2u32s_C1R, + NULL, + convert_4u32s_C1R, + NULL, + convert_6u32s_C1R, + NULL, + convert_8u32s_C1R +}; + + +static void convert_32s1u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i + 4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i + 5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i + 6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i + 7]; + + *pDst++ = (OPJ_BYTE)((src0 << 7) | (src1 << 6) | (src2 << 5) | (src3 << 4) | + (src4 << 3) | (src5 << 2) | (src6 << 1) | src7); + } + + if (length & 7U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = 0U; + OPJ_UINT32 src2 = 0U; + OPJ_UINT32 src3 = 0U; + OPJ_UINT32 src4 = 0U; + OPJ_UINT32 src5 = 0U; + OPJ_UINT32 src6 = 0U; + length = length & 7U; + + if (length > 1U) { + src1 = (OPJ_UINT32)pSrc[i + 1]; + if (length > 2U) { + src2 = (OPJ_UINT32)pSrc[i + 2]; + if (length > 3U) { + src3 = (OPJ_UINT32)pSrc[i + 3]; + if (length > 4U) { + src4 = (OPJ_UINT32)pSrc[i + 4]; + if (length > 5U) { + src5 = (OPJ_UINT32)pSrc[i + 5]; + if (length > 6U) { + src6 = (OPJ_UINT32)pSrc[i + 6]; + } + } + } + } + } + } + *pDst++ = (OPJ_BYTE)((src0 << 7) | (src1 << 6) | (src2 << 5) | (src3 << 4) | + (src4 << 3) | (src5 << 2) | (src6 << 1)); + } +} + +static void convert_32s2u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i += 4U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + + *pDst++ = (OPJ_BYTE)((src0 << 6) | (src1 << 4) | (src2 << 2) | src3); + } + + if (length & 3U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = 0U; + OPJ_UINT32 src2 = 0U; + length = length & 3U; + + if (length > 1U) { + src1 = (OPJ_UINT32)pSrc[i + 1]; + if (length > 2U) { + src2 = (OPJ_UINT32)pSrc[i + 2]; + } + } + *pDst++ = (OPJ_BYTE)((src0 << 6) | (src1 << 4) | (src2 << 2)); + } +} + +static void convert_32s4u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)1U); i += 2U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + + *pDst++ = (OPJ_BYTE)((src0 << 4) | src1); + } + + if (length & 1U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + *pDst++ = (OPJ_BYTE)((src0 << 4)); + } +} + +static void convert_32s6u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i += 4U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + + *pDst++ = (OPJ_BYTE)((src0 << 2) | (src1 >> 4)); + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 2)); + *pDst++ = (OPJ_BYTE)(((src2 & 0x3U) << 6) | src3); + } + + if (length & 3U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = 0U; + OPJ_UINT32 src2 = 0U; + length = length & 3U; + + if (length > 1U) { + src1 = (OPJ_UINT32)pSrc[i + 1]; + if (length > 2U) { + src2 = (OPJ_UINT32)pSrc[i + 2]; + } + } + *pDst++ = (OPJ_BYTE)((src0 << 2) | (src1 >> 4)); + if (length > 1U) { + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 2)); + if (length > 2U) { + *pDst++ = (OPJ_BYTE)(((src2 & 0x3U) << 6)); + } + } + } +} +static void convert_32s8u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; ++i) { + pDst[i] = (OPJ_BYTE)pSrc[i]; + } +} +const convert_32sXXx_C1R convert_32sXXu_C1R_LUT[9] = { + NULL, + convert_32s1u_C1R, + convert_32s2u_C1R, + NULL, + convert_32s4u_C1R, + NULL, + convert_32s6u_C1R, + NULL, + convert_32s8u_C1R +}; + +/* -->> -->> -->> -->> + + TGA IMAGE FORMAT + + <<-- <<-- <<-- <<-- */ + +#ifdef INFORMATION_ONLY +/* TGA header definition. */ +struct tga_header { + unsigned char id_length; /* Image id field length */ + unsigned char colour_map_type; /* Colour map type */ + unsigned char image_type; /* Image type */ + /* + ** Colour map specification + */ + unsigned short colour_map_index; /* First entry index */ + unsigned short colour_map_length; /* Colour map length */ + unsigned char colour_map_entry_size; /* Colour map entry size */ + /* + ** Image specification + */ + unsigned short x_origin; /* x origin of image */ + unsigned short y_origin; /* u origin of image */ + unsigned short image_width; /* Image width */ + unsigned short image_height; /* Image height */ + unsigned char pixel_depth; /* Pixel depth */ + unsigned char image_desc; /* Image descriptor */ +}; +#endif /* INFORMATION_ONLY */ + +/* Returns a ushort from a little-endian serialized value */ +static unsigned short get_tga_ushort(const unsigned char *data) +{ + return (unsigned short)(data[0] | (data[1] << 8)); +} + +#define TGA_HEADER_SIZE 18 + +static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel, + unsigned int *width, unsigned int *height, int *flip_image) +{ + int palette_size; + unsigned char tga[TGA_HEADER_SIZE]; + unsigned char id_len, /*cmap_type,*/ image_type; + unsigned char pixel_depth, image_desc; + unsigned short /*cmap_index,*/ cmap_len, cmap_entry_size; + unsigned short /*x_origin, y_origin,*/ image_w, image_h; + + if (!bits_per_pixel || !width || !height || !flip_image) { + return 0; + } + + if (fread(tga, TGA_HEADER_SIZE, 1, fp) != 1) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + return 0 ; + } + id_len = tga[0]; + /*cmap_type = tga[1];*/ + image_type = tga[2]; + /*cmap_index = get_tga_ushort(&tga[3]);*/ + cmap_len = get_tga_ushort(&tga[5]); + cmap_entry_size = tga[7]; + + +#if 0 + x_origin = get_tga_ushort(&tga[8]); + y_origin = get_tga_ushort(&tga[10]); +#endif + image_w = get_tga_ushort(&tga[12]); + image_h = get_tga_ushort(&tga[14]); + pixel_depth = tga[16]; + image_desc = tga[17]; + + *bits_per_pixel = (unsigned int)pixel_depth; + *width = (unsigned int)image_w; + *height = (unsigned int)image_h; + + /* Ignore tga identifier, if present ... */ + if (id_len) { + unsigned char *id = (unsigned char *) malloc(id_len); + if (id == 0) { + fprintf(stderr, "tga_readheader: memory out\n"); + return 0; + } + if (!fread(id, id_len, 1, fp)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + free(id); + return 0 ; + } + free(id); + } + + /* Test for compressed formats ... not yet supported ... + // Note :- 9 - RLE encoded palettized. + // 10 - RLE encoded RGB. */ + if (image_type > 8) { + fprintf(stderr, "Sorry, compressed tga files are not currently supported.\n"); + return 0 ; + } + + *flip_image = !(image_desc & 32); + + /* Palettized formats are not yet supported, skip over the palette, if present ... */ + palette_size = cmap_len * (cmap_entry_size / 8); + + if (palette_size > 0) { + fprintf(stderr, "File contains a palette - not yet supported."); + fseek(fp, palette_size, SEEK_CUR); + } + return 1; +} + +#ifdef OPJ_BIG_ENDIAN + +static INLINE OPJ_UINT16 swap16(OPJ_UINT16 x) +{ + return (OPJ_UINT16)(((x & 0x00ffU) << 8) | ((x & 0xff00U) >> 8)); +} + +#endif + +static int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height, + OPJ_BOOL flip_image) +{ + OPJ_UINT16 image_w, image_h, us0; + unsigned char uc0, image_type; + unsigned char pixel_depth, image_desc; + + if (!bits_per_pixel || !width || !height) { + return 0; + } + + pixel_depth = 0; + + if (bits_per_pixel < 256) { + pixel_depth = (unsigned char)bits_per_pixel; + } else { + fprintf(stderr, "ERROR: Wrong bits per pixel inside tga_header"); + return 0; + } + uc0 = 0; + + if (fwrite(&uc0, 1, 1, fp) != 1) { + goto fails; /* id_length */ + } + if (fwrite(&uc0, 1, 1, fp) != 1) { + goto fails; /* colour_map_type */ + } + + image_type = 2; /* Uncompressed. */ + if (fwrite(&image_type, 1, 1, fp) != 1) { + goto fails; + } + + us0 = 0; + if (fwrite(&us0, 2, 1, fp) != 1) { + goto fails; /* colour_map_index */ + } + if (fwrite(&us0, 2, 1, fp) != 1) { + goto fails; /* colour_map_length */ + } + if (fwrite(&uc0, 1, 1, fp) != 1) { + goto fails; /* colour_map_entry_size */ + } + + if (fwrite(&us0, 2, 1, fp) != 1) { + goto fails; /* x_origin */ + } + if (fwrite(&us0, 2, 1, fp) != 1) { + goto fails; /* y_origin */ + } + + image_w = (unsigned short)width; + image_h = (unsigned short) height; + +#ifndef OPJ_BIG_ENDIAN + if (fwrite(&image_w, 2, 1, fp) != 1) { + goto fails; + } + if (fwrite(&image_h, 2, 1, fp) != 1) { + goto fails; + } +#else + image_w = swap16(image_w); + image_h = swap16(image_h); + if (fwrite(&image_w, 2, 1, fp) != 1) { + goto fails; + } + if (fwrite(&image_h, 2, 1, fp) != 1) { + goto fails; + } +#endif + + if (fwrite(&pixel_depth, 1, 1, fp) != 1) { + goto fails; + } + + image_desc = 8; /* 8 bits per component. */ + + if (flip_image) { + image_desc |= 32; + } + if (fwrite(&image_desc, 1, 1, fp) != 1) { + goto fails; + } + + return 1; + +fails: + fputs("\nwrite_tgaheader: write ERROR\n", stderr); + return 0; +} + +opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) +{ + FILE *f; + opj_image_t *image; + unsigned int image_width, image_height, pixel_bit_depth; + unsigned int x, y; + int flip_image = 0; + opj_image_cmptparm_t cmptparm[4]; /* maximum 4 components */ + int numcomps; + OPJ_COLOR_SPACE color_space; + OPJ_BOOL mono ; + OPJ_BOOL save_alpha; + int subsampling_dx, subsampling_dy; + int i; + + f = fopen(filename, "rb"); + if (!f) { + fprintf(stderr, "Failed to open %s for reading !!\n", filename); + return 0; + } + + if (!tga_readheader(f, &pixel_bit_depth, &image_width, &image_height, + &flip_image)) { + fclose(f); + return NULL; + } + + /* We currently only support 24 & 32 bit tga's ... */ + if (!((pixel_bit_depth == 24) || (pixel_bit_depth == 32))) { + fclose(f); + return NULL; + } + + /* initialize image components */ + memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); + + mono = (pixel_bit_depth == 8) || + (pixel_bit_depth == 16); /* Mono with & without alpha. */ + save_alpha = (pixel_bit_depth == 16) || + (pixel_bit_depth == 32); /* Mono with alpha, or RGB with alpha */ + + if (mono) { + color_space = OPJ_CLRSPC_GRAY; + numcomps = save_alpha ? 2 : 1; + } else { + numcomps = save_alpha ? 4 : 3; + color_space = OPJ_CLRSPC_SRGB; + } + + /* If the declared file size is > 10 MB, check that the file is big */ + /* enough to avoid excessive memory allocations */ + if (image_height != 0 && + image_width > 10000000U / image_height / (OPJ_UINT32)numcomps) { + char ch; + OPJ_UINT64 expected_file_size = + (OPJ_UINT64)image_width * image_height * (OPJ_UINT32)numcomps; + long curpos = ftell(f); + if (expected_file_size > (OPJ_UINT64)INT_MAX) { + expected_file_size = (OPJ_UINT64)INT_MAX; + } + fseek(f, (long)expected_file_size - 1, SEEK_SET); + if (fread(&ch, 1, 1, f) != 1) { + fclose(f); + return NULL; + } + fseek(f, curpos, SEEK_SET); + } + + subsampling_dx = parameters->subsampling_dx; + subsampling_dy = parameters->subsampling_dy; + + for (i = 0; i < numcomps; i++) { + cmptparm[i].prec = 8; + cmptparm[i].bpp = 8; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[i].w = image_width; + cmptparm[i].h = image_height; + } + + /* create the image */ + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); + + if (!image) { + fclose(f); + return NULL; + } + + + /* set image offset and reference grid */ + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = !image->x0 ? (OPJ_UINT32)(image_width - 1) * + (OPJ_UINT32)subsampling_dx + 1 : image->x0 + (OPJ_UINT32)(image_width - 1) * + (OPJ_UINT32)subsampling_dx + 1; + image->y1 = !image->y0 ? (OPJ_UINT32)(image_height - 1) * + (OPJ_UINT32)subsampling_dy + 1 : image->y0 + (OPJ_UINT32)(image_height - 1) * + (OPJ_UINT32)subsampling_dy + 1; + + /* set image data */ + for (y = 0; y < image_height; y++) { + int index; + + if (flip_image) { + index = (int)((image_height - y - 1) * image_width); + } else { + index = (int)(y * image_width); + } + + if (numcomps == 3) { + for (x = 0; x < image_width; x++) { + unsigned char r, g, b; + + if (!fread(&b, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + if (!fread(&g, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + if (!fread(&r, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + + image->comps[0].data[index] = r; + image->comps[1].data[index] = g; + image->comps[2].data[index] = b; + index++; + } + } else if (numcomps == 4) { + for (x = 0; x < image_width; x++) { + unsigned char r, g, b, a; + if (!fread(&b, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + if (!fread(&g, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + if (!fread(&r, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + if (!fread(&a, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + + image->comps[0].data[index] = r; + image->comps[1].data[index] = g; + image->comps[2].data[index] = b; + image->comps[3].data[index] = a; + index++; + } + } else { + fprintf(stderr, "Currently unsupported bit depth : %s\n", filename); + } + } + fclose(f); + return image; +} + +int imagetotga(opj_image_t * image, const char *outfile) +{ + int width, height, bpp, x, y; + OPJ_BOOL write_alpha; + unsigned int i; + int adjustR, adjustG = 0, adjustB = 0, fails; + unsigned int alpha_channel; + float r, g, b, a; + unsigned char value; + float scale; + FILE *fdest; + size_t res; + fails = 1; + + fdest = fopen(outfile, "wb"); + if (!fdest) { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); + return 1; + } + + for (i = 0; i < image->numcomps - 1; i++) { + if ((image->comps[0].dx != image->comps[i + 1].dx) + || (image->comps[0].dy != image->comps[i + 1].dy) + || (image->comps[0].prec != image->comps[i + 1].prec) + || (image->comps[0].sgnd != image->comps[i + 1].sgnd)) { + fclose(fdest); + fprintf(stderr, + "Unable to create a tga file with such J2K image charateristics.\n"); + return 1; + } + } + + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; + + /* Mono with alpha, or RGB with alpha. */ + write_alpha = (image->numcomps == 2) || (image->numcomps == 4); + + /* Write TGA header */ + bpp = write_alpha ? 32 : 24; + + if (!tga_writeheader(fdest, bpp, width, height, OPJ_TRUE)) { + goto fin; + } + + alpha_channel = image->numcomps - 1; + + scale = 255.0f / (float)((1 << image->comps[0].prec) - 1); + + adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + if (image->numcomps >= 3) { + adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + } + + for (y = 0; y < height; y++) { + unsigned int index = (unsigned int)(y * width); + + for (x = 0; x < width; x++, index++) { + r = (float)(image->comps[0].data[index] + adjustR); + + if (image->numcomps > 2) { + g = (float)(image->comps[1].data[index] + adjustG); + b = (float)(image->comps[2].data[index] + adjustB); + } else { + /* Greyscale ... */ + g = r; + b = r; + } + + /* TGA format writes BGR ... */ + if (b > 255.) { + b = 255.; + } else if (b < 0.) { + b = 0.; + } + value = (unsigned char)(b * scale); + res = fwrite(&value, 1, 1, fdest); + + if (res < 1) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + goto fin; + } + if (g > 255.) { + g = 255.; + } else if (g < 0.) { + g = 0.; + } + value = (unsigned char)(g * scale); + res = fwrite(&value, 1, 1, fdest); + + if (res < 1) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + goto fin; + } + if (r > 255.) { + r = 255.; + } else if (r < 0.) { + r = 0.; + } + value = (unsigned char)(r * scale); + res = fwrite(&value, 1, 1, fdest); + + if (res < 1) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + goto fin; + } + + if (write_alpha) { + a = (float)(image->comps[alpha_channel].data[index]); + if (a > 255.) { + a = 255.; + } else if (a < 0.) { + a = 0.; + } + value = (unsigned char)(a * scale); + res = fwrite(&value, 1, 1, fdest); + + if (res < 1) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + goto fin; + } + } + } + } + fails = 0; +fin: + fclose(fdest); + + return fails; +} + +/* -->> -->> -->> -->> + +PGX IMAGE FORMAT + +<<-- <<-- <<-- <<-- */ + + +static unsigned char readuchar(FILE * f) +{ + unsigned char c1; + if (!fread(&c1, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + return c1; +} + +static unsigned short readushort(FILE * f, int bigendian) +{ + unsigned char c1, c2; + if (!fread(&c1, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if (!fread(&c2, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if (bigendian) { + return (unsigned short)((c1 << 8) + c2); + } else { + return (unsigned short)((c2 << 8) + c1); + } +} + +static unsigned int readuint(FILE * f, int bigendian) +{ + unsigned char c1, c2, c3, c4; + if (!fread(&c1, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if (!fread(&c2, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if (!fread(&c3, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if (!fread(&c4, 1, 1, f)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if (bigendian) { + return (unsigned int)(c1 << 24) + (unsigned int)(c2 << 16) + (unsigned int)( + c3 << 8) + c4; + } else { + return (unsigned int)(c4 << 24) + (unsigned int)(c3 << 16) + (unsigned int)( + c2 << 8) + c1; + } +} + +opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) +{ + FILE *f = NULL; + int w, h, prec; + int i, numcomps, max; + OPJ_COLOR_SPACE color_space; + opj_image_cmptparm_t cmptparm; /* maximum of 1 component */ + opj_image_t * image = NULL; + int adjustS, ushift, dshift, force8; + OPJ_UINT64 expected_file_size; + + char endian1, endian2, sign; + char signtmp[32]; + + char temp[32]; + int bigendian; + opj_image_comp_t *comp = NULL; + + numcomps = 1; + color_space = OPJ_CLRSPC_GRAY; + + memset(&cmptparm, 0, sizeof(opj_image_cmptparm_t)); + + max = 0; + + f = fopen(filename, "rb"); + if (!f) { + fprintf(stderr, "Failed to open %s for reading !\n", filename); + return NULL; + } + + fseek(f, 0, SEEK_SET); + if (fscanf(f, "PG%31[ \t]%c%c%31[ \t+-]%d%31[ \t]%d%31[ \t]%d", temp, &endian1, + &endian2, signtmp, &prec, temp, &w, temp, &h) != 9) { + fclose(f); + fprintf(stderr, + "ERROR: Failed to read the right number of element from the fscanf() function!\n"); + return NULL; + } + + i = 0; + sign = '+'; + while (signtmp[i] != '\0') { + if (signtmp[i] == '-') { + sign = '-'; + } + i++; + } + + fgetc(f); + if (endian1 == 'M' && endian2 == 'L') { + bigendian = 1; + } else if (endian2 == 'M' && endian1 == 'L') { + bigendian = 0; + } else { + fclose(f); + fprintf(stderr, "Bad pgx header, please check input file\n"); + return NULL; + } + + if (w < 1 || h < 1 || prec < 1 || prec > 31) { + fclose(f); + fprintf(stderr, "Bad pgx header, please check input file\n"); + return NULL; + } + + expected_file_size = + (OPJ_UINT64)w * (OPJ_UINT64)h * (prec > 16 ? 4 : prec > 8 ? 2 : 1); + if (expected_file_size > 10000000U) { + char ch; + long curpos = ftell(f); + if (expected_file_size > (OPJ_UINT64)INT_MAX) { + expected_file_size = (OPJ_UINT64)INT_MAX; + } + fseek(f, (long)expected_file_size - 1, SEEK_SET); + if (fread(&ch, 1, 1, f) != 1) { + fprintf(stderr, "File too short\n"); + fclose(f); + return NULL; + } + fseek(f, curpos, SEEK_SET); + } + + /* initialize image component */ + + cmptparm.x0 = (OPJ_UINT32)parameters->image_offset_x0; + cmptparm.y0 = (OPJ_UINT32)parameters->image_offset_y0; + cmptparm.w = !cmptparm.x0 ? (OPJ_UINT32)((w - 1) * parameters->subsampling_dx + + 1) : cmptparm.x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)parameters->subsampling_dx + + 1; + cmptparm.h = !cmptparm.y0 ? (OPJ_UINT32)((h - 1) * parameters->subsampling_dy + + 1) : cmptparm.y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)parameters->subsampling_dy + + 1; + + if (sign == '-') { + cmptparm.sgnd = 1; + } else { + cmptparm.sgnd = 0; + } + if (prec < 8) { + force8 = 1; + ushift = 8 - prec; + dshift = prec - ushift; + if (cmptparm.sgnd) { + adjustS = (1 << (prec - 1)); + } else { + adjustS = 0; + } + cmptparm.sgnd = 0; + prec = 8; + } else { + ushift = dshift = force8 = adjustS = 0; + } + + cmptparm.prec = (OPJ_UINT32)prec; + cmptparm.bpp = (OPJ_UINT32)prec; + cmptparm.dx = (OPJ_UINT32)parameters->subsampling_dx; + cmptparm.dy = (OPJ_UINT32)parameters->subsampling_dy; + + /* create the image */ + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm, color_space); + if (!image) { + fclose(f); + return NULL; + } + /* set image offset and reference grid */ + image->x0 = cmptparm.x0; + image->y0 = cmptparm.x0; + image->x1 = cmptparm.w; + image->y1 = cmptparm.h; + + /* set image data */ + + comp = &image->comps[0]; + + for (i = 0; i < w * h; i++) { + int v; + if (force8) { + v = readuchar(f) + adjustS; + v = (v << ushift) + (v >> dshift); + comp->data[i] = (unsigned char)v; + + if (v > max) { + max = v; + } + + continue; + } + if (comp->prec == 8) { + if (!comp->sgnd) { + v = readuchar(f); + } else { + v = (char) readuchar(f); + } + } else if (comp->prec <= 16) { + if (!comp->sgnd) { + v = readushort(f, bigendian); + } else { + v = (short) readushort(f, bigendian); + } + } else { + if (!comp->sgnd) { + v = (int)readuint(f, bigendian); + } else { + v = (int) readuint(f, bigendian); + } + } + if (v > max) { + max = v; + } + comp->data[i] = v; + } + fclose(f); + comp->bpp = (OPJ_UINT32)int_floorlog2(max) + 1; + + return image; +} + +#define CLAMP(x,a,b) ((x) < (a) ? (a) : ((x) > (b) ? (b) : (x))) + +static INLINE int clamp(const int value, const int prec, const int sgnd) +{ + if (sgnd) { + if (prec <= 8) { + return CLAMP(value, -128, 127); + } else if (prec <= 16) { + return CLAMP(value, -32768, 32767); + } else { + return CLAMP(value, -2147483647 - 1, 2147483647); + } + } else { + if (prec <= 8) { + return CLAMP(value, 0, 255); + } else if (prec <= 16) { + return CLAMP(value, 0, 65535); + } else { + return value; /*CLAMP(value,0,4294967295);*/ + } + } +} + +int imagetopgx(opj_image_t * image, const char *outfile) +{ + int w, h; + int i, j, fails = 1; + unsigned int compno; + FILE *fdest = NULL; + + for (compno = 0; compno < image->numcomps; compno++) { + opj_image_comp_t *comp = &image->comps[compno]; + char bname[256]; /* buffer for name */ + char *name = bname; /* pointer */ + int nbytes = 0; + size_t res; + const size_t olen = strlen(outfile); + const size_t dotpos = olen - 4; + const size_t total = dotpos + 1 + 1 + 4; /* '-' + '[1-3]' + '.pgx' */ + + if (outfile[dotpos] != '.') { + /* `pgx` was recognized but there is no dot at expected position */ + fprintf(stderr, "ERROR -> Impossible happen."); + goto fin; + } + if (total > 256) { + name = (char*)malloc(total + 1); + if (name == NULL) { + fprintf(stderr, "imagetopgx: memory out\n"); + goto fin; + } + } + strncpy(name, outfile, dotpos); + sprintf(name + dotpos, "_%u.pgx", compno); + fdest = fopen(name, "wb"); + /* don't need name anymore */ + + if (!fdest) { + + fprintf(stderr, "ERROR -> failed to open %s for writing\n", name); + if (total > 256) { + free(name); + } + goto fin; + } + + w = (int)image->comps[compno].w; + h = (int)image->comps[compno].h; + + fprintf(fdest, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+', comp->prec, + w, h); + + if (comp->prec <= 8) { + nbytes = 1; + } else if (comp->prec <= 16) { + nbytes = 2; + } else { + nbytes = 4; + } + + if (nbytes == 1) { + unsigned char* line_buffer = malloc((size_t)w); + if (line_buffer == NULL) { + fprintf(stderr, "Out of memory"); + if (total > 256) { + free(name); + } + goto fin; + } + for (j = 0; j < h; j++) { + if (comp->prec == 8 && comp->sgnd == 0) { + for (i = 0; i < w; i++) { + line_buffer[i] = (unsigned char)CLAMP(image->comps[compno].data[j * w + i], 0, + 255); + } + } else { + for (i = 0; i < w; i++) { + line_buffer[i] = (unsigned char) + clamp(image->comps[compno].data[j * w + i], + (int)comp->prec, (int)comp->sgnd); + } + } + res = fwrite(line_buffer, 1, (size_t)w, fdest); + if (res != (size_t)w) { + fprintf(stderr, "failed to write %d bytes for %s\n", w, name); + if (total > 256) { + free(name); + } + free(line_buffer); + goto fin; + } + } + free(line_buffer); + } else { + + for (i = 0; i < w * h; i++) { + /* FIXME: clamp func is being called within a loop */ + const int val = clamp(image->comps[compno].data[i], + (int)comp->prec, (int)comp->sgnd); + + for (j = nbytes - 1; j >= 0; j--) { + int v = (int)(val >> (j * 8)); + unsigned char byte = (unsigned char)v; + res = fwrite(&byte, 1, 1, fdest); + + if (res < 1) { + fprintf(stderr, "failed to write 1 byte for %s\n", name); + if (total > 256) { + free(name); + } + goto fin; + } + } + } + } + + if (total > 256) { + free(name); + } + fclose(fdest); + fdest = NULL; + } + fails = 0; +fin: + if (fdest) { + fclose(fdest); + } + + return fails; +} + +/* -->> -->> -->> -->> + +PNM IMAGE FORMAT + +<<-- <<-- <<-- <<-- */ + +struct pnm_header { + int width, height, maxval, depth, format; + char rgb, rgba, gray, graya, bw; + char ok; +}; + +static char *skip_white(char *s) +{ + if (s != NULL) { + while (*s) { + if (*s == '\n' || *s == '\r') { + return NULL; + } + if (isspace(*s)) { + ++s; + continue; + } + return s; + } + } + return NULL; +} + +static char *skip_int(char *start, int *out_n) +{ + char *s; + char c; + + *out_n = 0; + + s = skip_white(start); + if (s == NULL) { + return NULL; + } + start = s; + + while (*s) { + if (!isdigit(*s)) { + break; + } + ++s; + } + c = *s; + *s = 0; + *out_n = atoi(start); + *s = c; + return s; +} + +static char *skip_idf(char *start, char out_idf[256]) +{ + char *s; + char c; + + s = skip_white(start); + if (s == NULL) { + return NULL; + } + start = s; + + while (*s) { + if (isalpha(*s) || *s == '_') { + ++s; + continue; + } + break; + } + c = *s; + *s = 0; + strncpy(out_idf, start, 255); + *s = c; + return s; +} + +static void read_pnm_header(FILE *reader, struct pnm_header *ph) +{ + int format, end, ttype; + char idf[256], type[256]; + char line[256]; + + if (fgets(line, 250, reader) == NULL) { + fprintf(stderr, "\nWARNING: fgets return a NULL value"); + return; + } + + if (line[0] != 'P') { + fprintf(stderr, "read_pnm_header:PNM:magic P missing\n"); + return; + } + format = atoi(line + 1); + if (format < 1 || format > 7) { + fprintf(stderr, "read_pnm_header:magic format %d invalid\n", format); + return; + } + ph->format = format; + ttype = end = 0; + + while (fgets(line, 250, reader)) { + char *s; + int allow_null = 0; + + if (*line == '#') { + continue; + } + + s = line; + + if (format == 7) { + s = skip_idf(s, idf); + + if (s == NULL || *s == 0) { + return; + } + + if (strcmp(idf, "ENDHDR") == 0) { + end = 1; + break; + } + if (strcmp(idf, "WIDTH") == 0) { + s = skip_int(s, &ph->width); + if (s == NULL || *s == 0) { + return; + } + + continue; + } + if (strcmp(idf, "HEIGHT") == 0) { + s = skip_int(s, &ph->height); + if (s == NULL || *s == 0) { + return; + } + + continue; + } + if (strcmp(idf, "DEPTH") == 0) { + s = skip_int(s, &ph->depth); + if (s == NULL || *s == 0) { + return; + } + + continue; + } + if (strcmp(idf, "MAXVAL") == 0) { + s = skip_int(s, &ph->maxval); + if (s == NULL || *s == 0) { + return; + } + + continue; + } + if (strcmp(idf, "TUPLTYPE") == 0) { + s = skip_idf(s, type); + if (s == NULL || *s == 0) { + return; + } + + if (strcmp(type, "BLACKANDWHITE") == 0) { + ph->bw = 1; + ttype = 1; + continue; + } + if (strcmp(type, "GRAYSCALE") == 0) { + ph->gray = 1; + ttype = 1; + continue; + } + if (strcmp(type, "GRAYSCALE_ALPHA") == 0) { + ph->graya = 1; + ttype = 1; + continue; + } + if (strcmp(type, "RGB") == 0) { + ph->rgb = 1; + ttype = 1; + continue; + } + if (strcmp(type, "RGB_ALPHA") == 0) { + ph->rgba = 1; + ttype = 1; + continue; + } + fprintf(stderr, "read_pnm_header:unknown P7 TUPLTYPE %s\n", type); + return; + } + fprintf(stderr, "read_pnm_header:unknown P7 idf %s\n", idf); + return; + } /* if(format == 7) */ + + /* Here format is in range [1,6] */ + if (ph->width == 0) { + s = skip_int(s, &ph->width); + if ((s == NULL) || (*s == 0) || (ph->width < 1)) { + return; + } + allow_null = 1; + } + if (ph->height == 0) { + s = skip_int(s, &ph->height); + if ((s == NULL) && allow_null) { + continue; + } + if ((s == NULL) || (*s == 0) || (ph->height < 1)) { + return; + } + if (format == 1 || format == 4) { + break; + } + allow_null = 1; + } + /* here, format is in P2, P3, P5, P6 */ + s = skip_int(s, &ph->maxval); + if ((s == NULL) && allow_null) { + continue; + } + if ((s == NULL) || (*s == 0)) { + return; + } + break; + }/* while(fgets( ) */ + if (format == 2 || format == 3 || format > 4) { + if (ph->maxval < 1 || ph->maxval > 65535) { + return; + } + } + if (ph->width < 1 || ph->height < 1) { + return; + } + + if (format == 7) { + if (!end) { + fprintf(stderr, "read_pnm_header:P7 without ENDHDR\n"); + return; + } + if (ph->depth < 1 || ph->depth > 4) { + return; + } + + if (ttype) { + ph->ok = 1; + } + } else { + ph->ok = 1; + if (format == 1 || format == 4) { + ph->maxval = 255; + } + } +} + +static int has_prec(int val) +{ + if (val < 2) { + return 1; + } + if (val < 4) { + return 2; + } + if (val < 8) { + return 3; + } + if (val < 16) { + return 4; + } + if (val < 32) { + return 5; + } + if (val < 64) { + return 6; + } + if (val < 128) { + return 7; + } + if (val < 256) { + return 8; + } + if (val < 512) { + return 9; + } + if (val < 1024) { + return 10; + } + if (val < 2048) { + return 11; + } + if (val < 4096) { + return 12; + } + if (val < 8192) { + return 13; + } + if (val < 16384) { + return 14; + } + if (val < 32768) { + return 15; + } + return 16; +} + +opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) +{ + int subsampling_dx = parameters->subsampling_dx; + int subsampling_dy = parameters->subsampling_dy; + + FILE *fp = NULL; + int i, compno, numcomps, w, h, prec, format; + OPJ_COLOR_SPACE color_space; + opj_image_cmptparm_t cmptparm[4]; /* RGBA: max. 4 components */ + opj_image_t * image = NULL; + struct pnm_header header_info; + + if ((fp = fopen(filename, "rb")) == NULL) { + fprintf(stderr, "pnmtoimage:Failed to open %s for reading!\n", filename); + return NULL; + } + memset(&header_info, 0, sizeof(struct pnm_header)); + + read_pnm_header(fp, &header_info); + + if (!header_info.ok) { + fclose(fp); + return NULL; + } + + if (header_info.width == 0 + || header_info.height == 0 + || (header_info.format == 7 && header_info.depth == 0)) { + fclose(fp); + return NULL; + } + + /* This limitation could be removed by making sure to use size_t below */ + if (header_info.height != 0 && + header_info.width > INT_MAX / header_info.height) { + fprintf(stderr, "pnmtoimage:Image %dx%d too big!\n", + header_info.width, header_info.height); + fclose(fp); + return NULL; + } + + format = header_info.format; + + switch (format) { + case 1: /* ascii bitmap */ + case 4: /* raw bitmap */ + numcomps = 1; + break; + + case 2: /* ascii greymap */ + case 5: /* raw greymap */ + numcomps = 1; + break; + + case 3: /* ascii pixmap */ + case 6: /* raw pixmap */ + numcomps = 3; + break; + + case 7: /* arbitrary map */ + numcomps = header_info.depth; + break; + + default: + fclose(fp); + return NULL; + } + if (numcomps < 3) { + color_space = OPJ_CLRSPC_GRAY; /* GRAY, GRAYA */ + } else { + color_space = OPJ_CLRSPC_SRGB; /* RGB, RGBA */ + } + + prec = has_prec(header_info.maxval); + + if (prec < 8) { + prec = 8; + } + + w = header_info.width; + h = header_info.height; + subsampling_dx = parameters->subsampling_dx; + subsampling_dy = parameters->subsampling_dy; + + memset(&cmptparm[0], 0, (size_t)numcomps * sizeof(opj_image_cmptparm_t)); + + for (i = 0; i < numcomps; i++) { + cmptparm[i].prec = (OPJ_UINT32)prec; + cmptparm[i].bpp = (OPJ_UINT32)prec; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[i].w = (OPJ_UINT32)w; + cmptparm[i].h = (OPJ_UINT32)h; + } + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); + + if (!image) { + fclose(fp); + return NULL; + } + + /* set image offset and reference grid */ + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = (OPJ_UINT32)(parameters->image_offset_x0 + (w - 1) * subsampling_dx + + 1); + image->y1 = (OPJ_UINT32)(parameters->image_offset_y0 + (h - 1) * subsampling_dy + + 1); + + if ((format == 2) || (format == 3)) { /* ascii pixmap */ + unsigned int index; + + for (i = 0; i < w * h; i++) { + for (compno = 0; compno < numcomps; compno++) { + index = 0; + if (fscanf(fp, "%u", &index) != 1) { + fprintf(stderr, "Missing data. Quitting.\n"); + opj_image_destroy(image); + fclose(fp); + return NULL; + } + + image->comps[compno].data[i] = (OPJ_INT32)(index * 255) / header_info.maxval; + } + } + } else if ((format == 5) + || (format == 6) + || ((format == 7) + && (header_info.gray || header_info.graya + || header_info.rgb || header_info.rgba))) { /* binary pixmap */ + unsigned char c0, c1, one; + + one = (prec < 9); + + for (i = 0; i < w * h; i++) { + for (compno = 0; compno < numcomps; compno++) { + if (!fread(&c0, 1, 1, fp)) { + fprintf(stderr, "Missing data. Quitting.\n"); + opj_image_destroy(image); + fclose(fp); + return NULL; + } + if (one) { + image->comps[compno].data[i] = c0; + } else { + if (!fread(&c1, 1, 1, fp)) { + fprintf(stderr, "Missing data. Quitting.\n"); + opj_image_destroy(image); + fclose(fp); + return NULL; + } + /* netpbm: */ + image->comps[compno].data[i] = ((c0 << 8) | c1); + } + } + } + } else if (format == 1) { /* ascii bitmap */ + for (i = 0; i < w * h; i++) { + unsigned int index; + + if (fscanf(fp, "%u", &index) != 1) { + fprintf(stderr, "Missing data. Quitting.\n"); + opj_image_destroy(image); + fclose(fp); + return NULL; + } + + image->comps[0].data[i] = (index ? 0 : 255); + } + } else if (format == 4) { + int x, y, bit; + int uc; + + i = 0; + for (y = 0; y < h; ++y) { + bit = -1; + uc = 0; + + for (x = 0; x < w; ++x) { + if (bit == -1) { + bit = 7; + uc = getc(fp); + if (uc == EOF) { + fprintf(stderr, "Missing data. Quitting.\n"); + opj_image_destroy(image); + fclose(fp); + return NULL; + } + } + image->comps[0].data[i] = ((((unsigned char)uc >> bit) & 1) ? 0 : 255); + --bit; + ++i; + } + } + } else if ((format == 7 && header_info.bw)) { /*MONO*/ + unsigned char uc; + + for (i = 0; i < w * h; ++i) { + if (!fread(&uc, 1, 1, fp)) { + fprintf(stderr, "Missing data. Quitting.\n"); + opj_image_destroy(image); + fclose(fp); + return NULL; + } + image->comps[0].data[i] = (uc & 1) ? 0 : 255; + } + } + fclose(fp); + + return image; +}/* pnmtoimage() */ + +static int are_comps_similar(opj_image_t * image) +{ + unsigned int i; + for (i = 1; i < image->numcomps; i++) { + if (image->comps[0].dx != image->comps[i].dx || + image->comps[0].dy != image->comps[i].dy || + (i <= 2 && + (image->comps[0].prec != image->comps[i].prec || + image->comps[0].sgnd != image->comps[i].sgnd))) { + return OPJ_FALSE; + } + } + return OPJ_TRUE; +} + + +int imagetopnm(opj_image_t * image, const char *outfile, int force_split) +{ + int *red, *green, *blue, *alpha; + int wr, hr, max; + int i; + unsigned int compno, ncomp; + int adjustR, adjustG, adjustB, adjustA; + int fails, two, want_gray, has_alpha, triple; + int prec, v; + FILE *fdest = NULL; + const char *tmp = outfile; + char *destname; + + alpha = NULL; + + if ((prec = (int)image->comps[0].prec) > 16) { + fprintf(stderr, "%s:%d:imagetopnm\n\tprecision %d is larger than 16" + "\n\t: refused.\n", __FILE__, __LINE__, prec); + return 1; + } + two = has_alpha = 0; + fails = 1; + ncomp = image->numcomps; + + while (*tmp) { + ++tmp; + } + tmp -= 2; + want_gray = (*tmp == 'g' || *tmp == 'G'); + ncomp = image->numcomps; + + if (want_gray) { + ncomp = 1; + } + + if ((force_split == 0) && ncomp >= 2 && + are_comps_similar(image)) { + fdest = fopen(outfile, "wb"); + + if (!fdest) { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); + return fails; + } + two = (prec > 8); + triple = (ncomp > 2); + wr = (int)image->comps[0].w; + hr = (int)image->comps[0].h; + max = (1 << prec) - 1; + has_alpha = (ncomp == 4 || ncomp == 2); + + red = image->comps[0].data; + + if (triple) { + green = image->comps[1].data; + blue = image->comps[2].data; + } else { + green = blue = NULL; + } + + if (has_alpha) { + const char *tt = (triple ? "RGB_ALPHA" : "GRAYSCALE_ALPHA"); + + fprintf(fdest, "P7\n# OpenJPEG-%s\nWIDTH %d\nHEIGHT %d\nDEPTH %u\n" + "MAXVAL %d\nTUPLTYPE %s\nENDHDR\n", opj_version(), + wr, hr, ncomp, max, tt); + alpha = image->comps[ncomp - 1].data; + adjustA = (image->comps[ncomp - 1].sgnd ? + 1 << (image->comps[ncomp - 1].prec - 1) : 0); + } else { + fprintf(fdest, "P6\n# OpenJPEG-%s\n%d %d\n%d\n", + opj_version(), wr, hr, max); + adjustA = 0; + } + adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + + if (triple) { + adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + } else { + adjustG = adjustB = 0; + } + + for (i = 0; i < wr * hr; ++i) { + if (two) { + v = *red + adjustR; + ++red; + if (v > 65535) { + v = 65535; + } else if (v < 0) { + v = 0; + } + + /* netpbm: */ + fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v); + + if (triple) { + v = *green + adjustG; + ++green; + if (v > 65535) { + v = 65535; + } else if (v < 0) { + v = 0; + } + + /* netpbm: */ + fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v); + + v = *blue + adjustB; + ++blue; + if (v > 65535) { + v = 65535; + } else if (v < 0) { + v = 0; + } + + /* netpbm: */ + fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v); + + }/* if(triple) */ + + if (has_alpha) { + v = *alpha + adjustA; + ++alpha; + if (v > 65535) { + v = 65535; + } else if (v < 0) { + v = 0; + } + + /* netpbm: */ + fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v); + } + continue; + + } /* if(two) */ + + /* prec <= 8: */ + v = *red++; + if (v > 255) { + v = 255; + } else if (v < 0) { + v = 0; + } + + fprintf(fdest, "%c", (unsigned char)v); + if (triple) { + v = *green++; + if (v > 255) { + v = 255; + } else if (v < 0) { + v = 0; + } + + fprintf(fdest, "%c", (unsigned char)v); + v = *blue++; + if (v > 255) { + v = 255; + } else if (v < 0) { + v = 0; + } + + fprintf(fdest, "%c", (unsigned char)v); + } + if (has_alpha) { + v = *alpha++; + if (v > 255) { + v = 255; + } else if (v < 0) { + v = 0; + } + + fprintf(fdest, "%c", (unsigned char)v); + } + } /* for(i */ + + fclose(fdest); + return 0; + } + + /* YUV or MONO: */ + + if (image->numcomps > ncomp) { + fprintf(stderr, "WARNING -> [PGM file] Only the first component\n"); + fprintf(stderr, " is written to the file\n"); + } + destname = (char*)malloc(strlen(outfile) + 8); + if (destname == NULL) { + fprintf(stderr, "imagetopnm: memory out\n"); + return 1; + } + for (compno = 0; compno < ncomp; compno++) { + if (ncomp > 1) { + /*sprintf(destname, "%d.%s", compno, outfile);*/ + const size_t olen = strlen(outfile); + const size_t dotpos = olen - 4; + + strncpy(destname, outfile, dotpos); + sprintf(destname + dotpos, "_%u.pgm", compno); + } else { + sprintf(destname, "%s", outfile); + } + + fdest = fopen(destname, "wb"); + if (!fdest) { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", destname); + free(destname); + return 1; + } + wr = (int)image->comps[compno].w; + hr = (int)image->comps[compno].h; + prec = (int)image->comps[compno].prec; + max = (1 << prec) - 1; + + fprintf(fdest, "P5\n#OpenJPEG-%s\n%d %d\n%d\n", + opj_version(), wr, hr, max); + + red = image->comps[compno].data; + if (!red) { + fclose(fdest); + continue; + } + + adjustR = + (image->comps[compno].sgnd ? 1 << (image->comps[compno].prec - 1) : 0); + + if (prec > 8) { + for (i = 0; i < wr * hr; i++) { + v = *red + adjustR; + ++red; + if (v > 65535) { + v = 65535; + } else if (v < 0) { + v = 0; + } + + /* netpbm: */ + fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v); + + if (has_alpha) { + v = *alpha++; + if (v > 65535) { + v = 65535; + } else if (v < 0) { + v = 0; + } + + /* netpbm: */ + fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v); + } + }/* for(i */ + } else { /* prec <= 8 */ + for (i = 0; i < wr * hr; ++i) { + v = *red + adjustR; + ++red; + if (v > 255) { + v = 255; + } else if (v < 0) { + v = 0; + } + + fprintf(fdest, "%c", (unsigned char)v); + } + } + fclose(fdest); + } /* for (compno */ + free(destname); + + return 0; +}/* imagetopnm() */ + +/* -->> -->> -->> -->> + + RAW IMAGE FORMAT + + <<-- <<-- <<-- <<-- */ +static opj_image_t* rawtoimage_common(const char *filename, + opj_cparameters_t *parameters, raw_cparameters_t *raw_cp, OPJ_BOOL big_endian) +{ + int subsampling_dx = parameters->subsampling_dx; + int subsampling_dy = parameters->subsampling_dy; + + FILE *f = NULL; + int i, compno, numcomps, w, h; + OPJ_COLOR_SPACE color_space; + opj_image_cmptparm_t *cmptparm; + opj_image_t * image = NULL; + unsigned short ch; + + if ((!(raw_cp->rawWidth & raw_cp->rawHeight & raw_cp->rawComp & + raw_cp->rawBitDepth)) == 0) { + fprintf(stderr, "\nError: invalid raw image parameters\n"); + fprintf(stderr, "Please use the Format option -F:\n"); + fprintf(stderr, + "-F ,,,,{s,u}@x:...:x\n"); + fprintf(stderr, + "If subsampling is omitted, 1x1 is assumed for all components\n"); + fprintf(stderr, + "Example: -i image.raw -o image.j2k -F 512,512,3,8,u@1x1:2x2:2x2\n"); + fprintf(stderr, " for raw 512x512 image with 4:2:0 subsampling\n"); + fprintf(stderr, "Aborting.\n"); + return NULL; + } + + f = fopen(filename, "rb"); + if (!f) { + fprintf(stderr, "Failed to open %s for reading !!\n", filename); + fprintf(stderr, "Aborting\n"); + return NULL; + } + numcomps = raw_cp->rawComp; + + /* FIXME ADE at this point, tcp_mct has not been properly set in calling function */ + if (numcomps == 1) { + color_space = OPJ_CLRSPC_GRAY; + } else if ((numcomps >= 3) && (parameters->tcp_mct == 0)) { + color_space = OPJ_CLRSPC_SYCC; + } else if ((numcomps >= 3) && (parameters->tcp_mct != 2)) { + color_space = OPJ_CLRSPC_SRGB; + } else { + color_space = OPJ_CLRSPC_UNKNOWN; + } + w = raw_cp->rawWidth; + h = raw_cp->rawHeight; + cmptparm = (opj_image_cmptparm_t*) calloc((OPJ_UINT32)numcomps, + sizeof(opj_image_cmptparm_t)); + if (!cmptparm) { + fprintf(stderr, "Failed to allocate image components parameters !!\n"); + fprintf(stderr, "Aborting\n"); + fclose(f); + return NULL; + } + /* initialize image components */ + for (i = 0; i < numcomps; i++) { + cmptparm[i].prec = (OPJ_UINT32)raw_cp->rawBitDepth; + cmptparm[i].bpp = (OPJ_UINT32)raw_cp->rawBitDepth; + cmptparm[i].sgnd = (OPJ_UINT32)raw_cp->rawSigned; + cmptparm[i].dx = (OPJ_UINT32)(subsampling_dx * raw_cp->rawComps[i].dx); + cmptparm[i].dy = (OPJ_UINT32)(subsampling_dy * raw_cp->rawComps[i].dy); + cmptparm[i].w = (OPJ_UINT32)w; + cmptparm[i].h = (OPJ_UINT32)h; + } + /* create the image */ + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); + free(cmptparm); + if (!image) { + fclose(f); + return NULL; + } + /* set image offset and reference grid */ + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = (OPJ_UINT32)parameters->image_offset_x0 + (OPJ_UINT32)(w - 1) * + (OPJ_UINT32)subsampling_dx + 1; + image->y1 = (OPJ_UINT32)parameters->image_offset_y0 + (OPJ_UINT32)(h - 1) * + (OPJ_UINT32)subsampling_dy + 1; + + if (raw_cp->rawBitDepth <= 8) { + unsigned char value = 0; + for (compno = 0; compno < numcomps; compno++) { + int nloop = (w * h) / (raw_cp->rawComps[compno].dx * + raw_cp->rawComps[compno].dy); + for (i = 0; i < nloop; i++) { + if (!fread(&value, 1, 1, f)) { + fprintf(stderr, "Error reading raw file. End of file probably reached.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + image->comps[compno].data[i] = raw_cp->rawSigned ? (char)value : value; + } + } + } else if (raw_cp->rawBitDepth <= 16) { + unsigned short value; + for (compno = 0; compno < numcomps; compno++) { + int nloop = (w * h) / (raw_cp->rawComps[compno].dx * + raw_cp->rawComps[compno].dy); + for (i = 0; i < nloop; i++) { + unsigned char temp1; + unsigned char temp2; + if (!fread(&temp1, 1, 1, f)) { + fprintf(stderr, "Error reading raw file. End of file probably reached.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + if (!fread(&temp2, 1, 1, f)) { + fprintf(stderr, "Error reading raw file. End of file probably reached.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + if (big_endian) { + value = (unsigned short)((temp1 << 8) + temp2); + } else { + value = (unsigned short)((temp2 << 8) + temp1); + } + image->comps[compno].data[i] = raw_cp->rawSigned ? (short)value : value; + } + } + } else { + fprintf(stderr, + "OpenJPEG cannot encode raw components with bit depth higher than 16 bits.\n"); + opj_image_destroy(image); + fclose(f); + return NULL; + } + + if (fread(&ch, 1, 1, f)) { + fprintf(stderr, "Warning. End of raw file not reached... processing anyway\n"); + } + fclose(f); + + return image; +} + +opj_image_t* rawltoimage(const char *filename, opj_cparameters_t *parameters, + raw_cparameters_t *raw_cp) +{ + return rawtoimage_common(filename, parameters, raw_cp, OPJ_FALSE); +} + +opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, + raw_cparameters_t *raw_cp) +{ + return rawtoimage_common(filename, parameters, raw_cp, OPJ_TRUE); +} + +static int imagetoraw_common(opj_image_t * image, const char *outfile, + OPJ_BOOL big_endian) +{ + FILE *rawFile = NULL; + size_t res; + unsigned int compno, numcomps; + int w, h, fails; + int line, row, curr, mask; + int *ptr; + unsigned char uc; + (void)big_endian; + + if ((image->numcomps * image->x1 * image->y1) == 0) { + fprintf(stderr, "\nError: invalid raw image parameters\n"); + return 1; + } + + numcomps = image->numcomps; + + if (numcomps > 4) { + numcomps = 4; + } + + for (compno = 1; compno < numcomps; ++compno) { + if (image->comps[0].dx != image->comps[compno].dx) { + break; + } + if (image->comps[0].dy != image->comps[compno].dy) { + break; + } + if (image->comps[0].prec != image->comps[compno].prec) { + break; + } + if (image->comps[0].sgnd != image->comps[compno].sgnd) { + break; + } + } + if (compno != numcomps) { + fprintf(stderr, + "imagetoraw_common: All components shall have the same subsampling, same bit depth, same sign.\n"); + fprintf(stderr, "\tAborting\n"); + return 1; + } + + rawFile = fopen(outfile, "wb"); + if (!rawFile) { + fprintf(stderr, "Failed to open %s for writing !!\n", outfile); + return 1; + } + + fails = 1; + fprintf(stdout, "Raw image characteristics: %d components\n", image->numcomps); + + for (compno = 0; compno < image->numcomps; compno++) { + fprintf(stdout, "Component %u characteristics: %dx%dx%d %s\n", compno, + image->comps[compno].w, + image->comps[compno].h, image->comps[compno].prec, + image->comps[compno].sgnd == 1 ? "signed" : "unsigned"); + + w = (int)image->comps[compno].w; + h = (int)image->comps[compno].h; + + if (image->comps[compno].prec <= 8) { + if (image->comps[compno].sgnd == 1) { + mask = (1 << image->comps[compno].prec) - 1; + ptr = image->comps[compno].data; + for (line = 0; line < h; line++) { + for (row = 0; row < w; row++) { + curr = *ptr; + if (curr > 127) { + curr = 127; + } else if (curr < -128) { + curr = -128; + } + uc = (unsigned char)(curr & mask); + res = fwrite(&uc, 1, 1, rawFile); + if (res < 1) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + goto fin; + } + ptr++; + } + } + } else if (image->comps[compno].sgnd == 0) { + mask = (1 << image->comps[compno].prec) - 1; + ptr = image->comps[compno].data; + for (line = 0; line < h; line++) { + for (row = 0; row < w; row++) { + curr = *ptr; + if (curr > 255) { + curr = 255; + } else if (curr < 0) { + curr = 0; + } + uc = (unsigned char)(curr & mask); + res = fwrite(&uc, 1, 1, rawFile); + if (res < 1) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + goto fin; + } + ptr++; + } + } + } + } else if (image->comps[compno].prec <= 16) { + if (image->comps[compno].sgnd == 1) { + union { + signed short val; + signed char vals[2]; + } uc16; + mask = (1 << image->comps[compno].prec) - 1; + ptr = image->comps[compno].data; + for (line = 0; line < h; line++) { + for (row = 0; row < w; row++) { + curr = *ptr; + if (curr > 32767) { + curr = 32767; + } else if (curr < -32768) { + curr = -32768; + } + uc16.val = (signed short)(curr & mask); + res = fwrite(uc16.vals, 1, 2, rawFile); + if (res < 2) { + fprintf(stderr, "failed to write 2 byte for %s\n", outfile); + goto fin; + } + ptr++; + } + } + } else if (image->comps[compno].sgnd == 0) { + union { + unsigned short val; + unsigned char vals[2]; + } uc16; + mask = (1 << image->comps[compno].prec) - 1; + ptr = image->comps[compno].data; + for (line = 0; line < h; line++) { + for (row = 0; row < w; row++) { + curr = *ptr; + if (curr > 65535) { + curr = 65535; + } else if (curr < 0) { + curr = 0; + } + uc16.val = (unsigned short)(curr & mask); + res = fwrite(uc16.vals, 1, 2, rawFile); + if (res < 2) { + fprintf(stderr, "failed to write 2 byte for %s\n", outfile); + goto fin; + } + ptr++; + } + } + } + } else if (image->comps[compno].prec <= 32) { + fprintf(stderr, "More than 16 bits per component not handled yet\n"); + goto fin; + } else { + fprintf(stderr, "Error: invalid precision: %d\n", image->comps[compno].prec); + goto fin; + } + } + fails = 0; +fin: + fclose(rawFile); + return fails; +} + +int imagetoraw(opj_image_t * image, const char *outfile) +{ + return imagetoraw_common(image, outfile, OPJ_TRUE); +} + +int imagetorawl(opj_image_t * image, const char *outfile) +{ + return imagetoraw_common(image, outfile, OPJ_FALSE); +} + diff --git a/src/bin/jp2/convert.h b/src/bin/jp2/convert.h new file mode 100644 index 0000000..61439d4 --- /dev/null +++ b/src/bin/jp2/convert.h @@ -0,0 +1,126 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __J2K_CONVERT_H +#define __J2K_CONVERT_H + +/**@name RAW component encoding parameters */ +/*@{*/ +typedef struct raw_comp_cparameters { + /** subsampling in X direction */ + int dx; + /** subsampling in Y direction */ + int dy; + /*@}*/ +} raw_comp_cparameters_t; + +/**@name RAW image encoding parameters */ +/*@{*/ +typedef struct raw_cparameters { + /** width of the raw image */ + int rawWidth; + /** height of the raw image */ + int rawHeight; + /** number of components of the raw image */ + int rawComp; + /** bit depth of the raw image */ + int rawBitDepth; + /** signed/unsigned raw image */ + OPJ_BOOL rawSigned; + /** raw components parameters */ + raw_comp_cparameters_t *rawComps; + /*@}*/ +} raw_cparameters_t; + +/* Component precision clipping */ +void clip_component(opj_image_comp_t* component, OPJ_UINT32 precision); +/* Component precision scaling */ +void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision); + +/* planar / interleaved conversions */ +typedef void (* convert_32s_CXPX)(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, + OPJ_SIZE_T length); +extern const convert_32s_CXPX convert_32s_CXPX_LUT[5]; +typedef void (* convert_32s_PXCX)(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length, OPJ_INT32 adjust); +extern const convert_32s_PXCX convert_32s_PXCX_LUT[5]; +/* bit depth conversions */ +typedef void (* convert_XXx32s_C1R)(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length); +extern const convert_XXx32s_C1R convert_XXu32s_C1R_LUT[9]; /* up to 8bpp */ +typedef void (* convert_32sXXx_C1R)(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length); +extern const convert_32sXXx_C1R convert_32sXXu_C1R_LUT[9]; /* up to 8bpp */ + + +/* TGA conversion */ +opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters); +int imagetotga(opj_image_t * image, const char *outfile); + +/* BMP conversion */ +opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters); +int imagetobmp(opj_image_t *image, const char *outfile); + +/* TIFF conversion*/ +opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters); +int imagetotif(opj_image_t *image, const char *outfile); +/** +Load a single image component encoded in PGX file format +@param filename Name of the PGX file to load +@param parameters *List ?* +@return Returns a greyscale image if successful, returns NULL otherwise +*/ +opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters); +int imagetopgx(opj_image_t *image, const char *outfile); + +opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters); +int imagetopnm(opj_image_t *image, const char *outfile, int force_split); + +/* RAW conversion */ +int imagetoraw(opj_image_t * image, const char *outfile); +int imagetorawl(opj_image_t * image, const char *outfile); +opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, + raw_cparameters_t *raw_cp); +opj_image_t* rawltoimage(const char *filename, opj_cparameters_t *parameters, + raw_cparameters_t *raw_cp); + +/* PNG conversion*/ +extern int imagetopng(opj_image_t *image, const char *write_idf); +extern opj_image_t* pngtoimage(const char *filename, + opj_cparameters_t *parameters); + +#endif /* __J2K_CONVERT_H */ + diff --git a/src/bin/jp2/convertbmp.c b/src/bin/jp2/convertbmp.c new file mode 100644 index 0000000..0af52f8 --- /dev/null +++ b/src/bin/jp2/convertbmp.c @@ -0,0 +1,1135 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include "opj_apps_config.h" + +#include +#include +#include +#include + +#include "openjpeg.h" +#include "convert.h" + +typedef struct { + OPJ_UINT16 bfType; /* 'BM' for Bitmap (19776) */ + OPJ_UINT32 bfSize; /* Size of the file */ + OPJ_UINT16 bfReserved1; /* Reserved : 0 */ + OPJ_UINT16 bfReserved2; /* Reserved : 0 */ + OPJ_UINT32 bfOffBits; /* Offset */ +} OPJ_BITMAPFILEHEADER; + +typedef struct { + OPJ_UINT32 biSize; /* Size of the structure in bytes */ + OPJ_UINT32 biWidth; /* Width of the image in pixels */ + OPJ_UINT32 biHeight; /* Height of the image in pixels */ + OPJ_UINT16 biPlanes; /* 1 */ + OPJ_UINT16 biBitCount; /* Number of color bits by pixels */ + OPJ_UINT32 biCompression; /* Type of encoding 0: none 1: RLE8 2: RLE4 */ + OPJ_UINT32 biSizeImage; /* Size of the image in bytes */ + OPJ_UINT32 biXpelsPerMeter; /* Horizontal (X) resolution in pixels/meter */ + OPJ_UINT32 biYpelsPerMeter; /* Vertical (Y) resolution in pixels/meter */ + OPJ_UINT32 biClrUsed; /* Number of color used in the image (0: ALL) */ + OPJ_UINT32 biClrImportant; /* Number of important color (0: ALL) */ + OPJ_UINT32 biRedMask; /* Red channel bit mask */ + OPJ_UINT32 biGreenMask; /* Green channel bit mask */ + OPJ_UINT32 biBlueMask; /* Blue channel bit mask */ + OPJ_UINT32 biAlphaMask; /* Alpha channel bit mask */ + OPJ_UINT32 biColorSpaceType; /* Color space type */ + OPJ_UINT8 biColorSpaceEP[36]; /* Color space end points */ + OPJ_UINT32 biRedGamma; /* Red channel gamma */ + OPJ_UINT32 biGreenGamma; /* Green channel gamma */ + OPJ_UINT32 biBlueGamma; /* Blue channel gamma */ + OPJ_UINT32 biIntent; /* Intent */ + OPJ_UINT32 biIccProfileData; /* ICC profile data */ + OPJ_UINT32 biIccProfileSize; /* ICC profile size */ + OPJ_UINT32 biReserved; /* Reserved */ +} OPJ_BITMAPINFOHEADER; + +static void opj_applyLUT8u_8u32s_C1R( + OPJ_UINT8 const* pSrc, OPJ_INT32 srcStride, + OPJ_INT32* pDst, OPJ_INT32 dstStride, + OPJ_UINT8 const* pLUT, + OPJ_UINT32 width, OPJ_UINT32 height) +{ + OPJ_UINT32 y; + + for (y = height; y != 0U; --y) { + OPJ_UINT32 x; + + for (x = 0; x < width; x++) { + pDst[x] = (OPJ_INT32)pLUT[pSrc[x]]; + } + pSrc += srcStride; + pDst += dstStride; + } +} + +static void opj_applyLUT8u_8u32s_C1P3R( + OPJ_UINT8 const* pSrc, OPJ_INT32 srcStride, + OPJ_INT32* const* pDst, OPJ_INT32 const* pDstStride, + OPJ_UINT8 const* const* pLUT, + OPJ_UINT32 width, OPJ_UINT32 height) +{ + OPJ_UINT32 y; + OPJ_INT32* pR = pDst[0]; + OPJ_INT32* pG = pDst[1]; + OPJ_INT32* pB = pDst[2]; + OPJ_UINT8 const* pLUT_R = pLUT[0]; + OPJ_UINT8 const* pLUT_G = pLUT[1]; + OPJ_UINT8 const* pLUT_B = pLUT[2]; + + for (y = height; y != 0U; --y) { + OPJ_UINT32 x; + + for (x = 0; x < width; x++) { + OPJ_UINT8 idx = pSrc[x]; + pR[x] = (OPJ_INT32)pLUT_R[idx]; + pG[x] = (OPJ_INT32)pLUT_G[idx]; + pB[x] = (OPJ_INT32)pLUT_B[idx]; + } + pSrc += srcStride; + pR += pDstStride[0]; + pG += pDstStride[1]; + pB += pDstStride[2]; + } +} + +static void bmp24toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, + opj_image_t* image) +{ + int index; + OPJ_UINT32 width, height; + OPJ_UINT32 x, y; + const OPJ_UINT8 *pSrc = NULL; + + width = image->comps[0].w; + height = image->comps[0].h; + + index = 0; + pSrc = pData + (height - 1U) * stride; + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + image->comps[0].data[index] = (OPJ_INT32)pSrc[3 * x + 2]; /* R */ + image->comps[1].data[index] = (OPJ_INT32)pSrc[3 * x + 1]; /* G */ + image->comps[2].data[index] = (OPJ_INT32)pSrc[3 * x + 0]; /* B */ + index++; + } + pSrc -= stride; + } +} + +static void bmp_mask_get_shift_and_prec(OPJ_UINT32 mask, OPJ_UINT32* shift, + OPJ_UINT32* prec) +{ + OPJ_UINT32 l_shift, l_prec; + + l_shift = l_prec = 0U; + + if (mask != 0U) { + while ((mask & 1U) == 0U) { + mask >>= 1; + l_shift++; + } + while (mask & 1U) { + mask >>= 1; + l_prec++; + } + } + *shift = l_shift; + *prec = l_prec; +} + +static void bmpmask32toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, + opj_image_t* image, OPJ_UINT32 redMask, OPJ_UINT32 greenMask, + OPJ_UINT32 blueMask, OPJ_UINT32 alphaMask) +{ + int index; + OPJ_UINT32 width, height; + OPJ_UINT32 x, y; + const OPJ_UINT8 *pSrc = NULL; + OPJ_BOOL hasAlpha; + OPJ_UINT32 redShift, redPrec; + OPJ_UINT32 greenShift, greenPrec; + OPJ_UINT32 blueShift, bluePrec; + OPJ_UINT32 alphaShift, alphaPrec; + + width = image->comps[0].w; + height = image->comps[0].h; + + hasAlpha = image->numcomps > 3U; + + bmp_mask_get_shift_and_prec(redMask, &redShift, &redPrec); + bmp_mask_get_shift_and_prec(greenMask, &greenShift, &greenPrec); + bmp_mask_get_shift_and_prec(blueMask, &blueShift, &bluePrec); + bmp_mask_get_shift_and_prec(alphaMask, &alphaShift, &alphaPrec); + + image->comps[0].bpp = redPrec; + image->comps[0].prec = redPrec; + image->comps[1].bpp = greenPrec; + image->comps[1].prec = greenPrec; + image->comps[2].bpp = bluePrec; + image->comps[2].prec = bluePrec; + if (hasAlpha) { + image->comps[3].bpp = alphaPrec; + image->comps[3].prec = alphaPrec; + } + + index = 0; + pSrc = pData + (height - 1U) * stride; + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + OPJ_UINT32 value = 0U; + + value |= ((OPJ_UINT32)pSrc[4 * x + 0]) << 0; + value |= ((OPJ_UINT32)pSrc[4 * x + 1]) << 8; + value |= ((OPJ_UINT32)pSrc[4 * x + 2]) << 16; + value |= ((OPJ_UINT32)pSrc[4 * x + 3]) << 24; + + image->comps[0].data[index] = (OPJ_INT32)((value & redMask) >> + redShift); /* R */ + image->comps[1].data[index] = (OPJ_INT32)((value & greenMask) >> + greenShift); /* G */ + image->comps[2].data[index] = (OPJ_INT32)((value & blueMask) >> + blueShift); /* B */ + if (hasAlpha) { + image->comps[3].data[index] = (OPJ_INT32)((value & alphaMask) >> + alphaShift); /* A */ + } + index++; + } + pSrc -= stride; + } +} + +static void bmpmask16toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, + opj_image_t* image, OPJ_UINT32 redMask, OPJ_UINT32 greenMask, + OPJ_UINT32 blueMask, OPJ_UINT32 alphaMask) +{ + int index; + OPJ_UINT32 width, height; + OPJ_UINT32 x, y; + const OPJ_UINT8 *pSrc = NULL; + OPJ_BOOL hasAlpha; + OPJ_UINT32 redShift, redPrec; + OPJ_UINT32 greenShift, greenPrec; + OPJ_UINT32 blueShift, bluePrec; + OPJ_UINT32 alphaShift, alphaPrec; + + width = image->comps[0].w; + height = image->comps[0].h; + + hasAlpha = image->numcomps > 3U; + + bmp_mask_get_shift_and_prec(redMask, &redShift, &redPrec); + bmp_mask_get_shift_and_prec(greenMask, &greenShift, &greenPrec); + bmp_mask_get_shift_and_prec(blueMask, &blueShift, &bluePrec); + bmp_mask_get_shift_and_prec(alphaMask, &alphaShift, &alphaPrec); + + image->comps[0].bpp = redPrec; + image->comps[0].prec = redPrec; + image->comps[1].bpp = greenPrec; + image->comps[1].prec = greenPrec; + image->comps[2].bpp = bluePrec; + image->comps[2].prec = bluePrec; + if (hasAlpha) { + image->comps[3].bpp = alphaPrec; + image->comps[3].prec = alphaPrec; + } + + index = 0; + pSrc = pData + (height - 1U) * stride; + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + OPJ_UINT32 value = 0U; + + value |= ((OPJ_UINT32)pSrc[2 * x + 0]) << 0; + value |= ((OPJ_UINT32)pSrc[2 * x + 1]) << 8; + + image->comps[0].data[index] = (OPJ_INT32)((value & redMask) >> + redShift); /* R */ + image->comps[1].data[index] = (OPJ_INT32)((value & greenMask) >> + greenShift); /* G */ + image->comps[2].data[index] = (OPJ_INT32)((value & blueMask) >> + blueShift); /* B */ + if (hasAlpha) { + image->comps[3].data[index] = (OPJ_INT32)((value & alphaMask) >> + alphaShift); /* A */ + } + index++; + } + pSrc -= stride; + } +} + +static opj_image_t* bmp8toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, + opj_image_t* image, OPJ_UINT8 const* const* pLUT) +{ + OPJ_UINT32 width, height; + const OPJ_UINT8 *pSrc = NULL; + + width = image->comps[0].w; + height = image->comps[0].h; + + pSrc = pData + (height - 1U) * stride; + if (image->numcomps == 1U) { + opj_applyLUT8u_8u32s_C1R(pSrc, -(OPJ_INT32)stride, image->comps[0].data, + (OPJ_INT32)width, pLUT[0], width, height); + } else { + OPJ_INT32* pDst[3]; + OPJ_INT32 pDstStride[3]; + + pDst[0] = image->comps[0].data; + pDst[1] = image->comps[1].data; + pDst[2] = image->comps[2].data; + pDstStride[0] = (OPJ_INT32)width; + pDstStride[1] = (OPJ_INT32)width; + pDstStride[2] = (OPJ_INT32)width; + opj_applyLUT8u_8u32s_C1P3R(pSrc, -(OPJ_INT32)stride, pDst, pDstStride, pLUT, + width, height); + } + return image; +} + +static OPJ_BOOL bmp_read_file_header(FILE* IN, OPJ_BITMAPFILEHEADER* header) +{ + header->bfType = (OPJ_UINT16)getc(IN); + header->bfType |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); + + if (header->bfType != 19778) { + fprintf(stderr, "Error, not a BMP file!\n"); + return OPJ_FALSE; + } + + /* FILE HEADER */ + /* ------------- */ + header->bfSize = (OPJ_UINT32)getc(IN); + header->bfSize |= (OPJ_UINT32)getc(IN) << 8; + header->bfSize |= (OPJ_UINT32)getc(IN) << 16; + header->bfSize |= (OPJ_UINT32)getc(IN) << 24; + + header->bfReserved1 = (OPJ_UINT16)getc(IN); + header->bfReserved1 |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); + + header->bfReserved2 = (OPJ_UINT16)getc(IN); + header->bfReserved2 |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); + + header->bfOffBits = (OPJ_UINT32)getc(IN); + header->bfOffBits |= (OPJ_UINT32)getc(IN) << 8; + header->bfOffBits |= (OPJ_UINT32)getc(IN) << 16; + header->bfOffBits |= (OPJ_UINT32)getc(IN) << 24; + return OPJ_TRUE; +} +static OPJ_BOOL bmp_read_info_header(FILE* IN, OPJ_BITMAPINFOHEADER* header) +{ + memset(header, 0, sizeof(*header)); + /* INFO HEADER */ + /* ------------- */ + header->biSize = (OPJ_UINT32)getc(IN); + header->biSize |= (OPJ_UINT32)getc(IN) << 8; + header->biSize |= (OPJ_UINT32)getc(IN) << 16; + header->biSize |= (OPJ_UINT32)getc(IN) << 24; + + switch (header->biSize) { + case 12U: /* BITMAPCOREHEADER */ + case 40U: /* BITMAPINFOHEADER */ + case 52U: /* BITMAPV2INFOHEADER */ + case 56U: /* BITMAPV3INFOHEADER */ + case 108U: /* BITMAPV4HEADER */ + case 124U: /* BITMAPV5HEADER */ + break; + default: + fprintf(stderr, "Error, unknown BMP header size %d\n", header->biSize); + return OPJ_FALSE; + } + + header->biWidth = (OPJ_UINT32)getc(IN); + header->biWidth |= (OPJ_UINT32)getc(IN) << 8; + header->biWidth |= (OPJ_UINT32)getc(IN) << 16; + header->biWidth |= (OPJ_UINT32)getc(IN) << 24; + + header->biHeight = (OPJ_UINT32)getc(IN); + header->biHeight |= (OPJ_UINT32)getc(IN) << 8; + header->biHeight |= (OPJ_UINT32)getc(IN) << 16; + header->biHeight |= (OPJ_UINT32)getc(IN) << 24; + + header->biPlanes = (OPJ_UINT16)getc(IN); + header->biPlanes |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); + + header->biBitCount = (OPJ_UINT16)getc(IN); + header->biBitCount |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); + if (header->biBitCount == 0) { + fprintf(stderr, "Error, invalid biBitCount %d\n", 0); + return OPJ_FALSE; + } + + if (header->biSize >= 40U) { + header->biCompression = (OPJ_UINT32)getc(IN); + header->biCompression |= (OPJ_UINT32)getc(IN) << 8; + header->biCompression |= (OPJ_UINT32)getc(IN) << 16; + header->biCompression |= (OPJ_UINT32)getc(IN) << 24; + + header->biSizeImage = (OPJ_UINT32)getc(IN); + header->biSizeImage |= (OPJ_UINT32)getc(IN) << 8; + header->biSizeImage |= (OPJ_UINT32)getc(IN) << 16; + header->biSizeImage |= (OPJ_UINT32)getc(IN) << 24; + + header->biXpelsPerMeter = (OPJ_UINT32)getc(IN); + header->biXpelsPerMeter |= (OPJ_UINT32)getc(IN) << 8; + header->biXpelsPerMeter |= (OPJ_UINT32)getc(IN) << 16; + header->biXpelsPerMeter |= (OPJ_UINT32)getc(IN) << 24; + + header->biYpelsPerMeter = (OPJ_UINT32)getc(IN); + header->biYpelsPerMeter |= (OPJ_UINT32)getc(IN) << 8; + header->biYpelsPerMeter |= (OPJ_UINT32)getc(IN) << 16; + header->biYpelsPerMeter |= (OPJ_UINT32)getc(IN) << 24; + + header->biClrUsed = (OPJ_UINT32)getc(IN); + header->biClrUsed |= (OPJ_UINT32)getc(IN) << 8; + header->biClrUsed |= (OPJ_UINT32)getc(IN) << 16; + header->biClrUsed |= (OPJ_UINT32)getc(IN) << 24; + + header->biClrImportant = (OPJ_UINT32)getc(IN); + header->biClrImportant |= (OPJ_UINT32)getc(IN) << 8; + header->biClrImportant |= (OPJ_UINT32)getc(IN) << 16; + header->biClrImportant |= (OPJ_UINT32)getc(IN) << 24; + } + + if (header->biSize >= 56U) { + header->biRedMask = (OPJ_UINT32)getc(IN); + header->biRedMask |= (OPJ_UINT32)getc(IN) << 8; + header->biRedMask |= (OPJ_UINT32)getc(IN) << 16; + header->biRedMask |= (OPJ_UINT32)getc(IN) << 24; + + if (!header->biRedMask) { + fprintf(stderr, "Error, invalid red mask value %d\n", header->biRedMask); + return OPJ_FALSE; + } + + header->biGreenMask = (OPJ_UINT32)getc(IN); + header->biGreenMask |= (OPJ_UINT32)getc(IN) << 8; + header->biGreenMask |= (OPJ_UINT32)getc(IN) << 16; + header->biGreenMask |= (OPJ_UINT32)getc(IN) << 24; + + if (!header->biGreenMask) { + fprintf(stderr, "Error, invalid green mask value %d\n", header->biGreenMask); + return OPJ_FALSE; + } + + header->biBlueMask = (OPJ_UINT32)getc(IN); + header->biBlueMask |= (OPJ_UINT32)getc(IN) << 8; + header->biBlueMask |= (OPJ_UINT32)getc(IN) << 16; + header->biBlueMask |= (OPJ_UINT32)getc(IN) << 24; + + if (!header->biBlueMask) { + fprintf(stderr, "Error, invalid blue mask value %d\n", header->biBlueMask); + return OPJ_FALSE; + } + + header->biAlphaMask = (OPJ_UINT32)getc(IN); + header->biAlphaMask |= (OPJ_UINT32)getc(IN) << 8; + header->biAlphaMask |= (OPJ_UINT32)getc(IN) << 16; + header->biAlphaMask |= (OPJ_UINT32)getc(IN) << 24; + } + + if (header->biSize >= 108U) { + header->biColorSpaceType = (OPJ_UINT32)getc(IN); + header->biColorSpaceType |= (OPJ_UINT32)getc(IN) << 8; + header->biColorSpaceType |= (OPJ_UINT32)getc(IN) << 16; + header->biColorSpaceType |= (OPJ_UINT32)getc(IN) << 24; + + if (fread(&(header->biColorSpaceEP), 1U, sizeof(header->biColorSpaceEP), + IN) != sizeof(header->biColorSpaceEP)) { + fprintf(stderr, "Error, can't read BMP header\n"); + return OPJ_FALSE; + } + + header->biRedGamma = (OPJ_UINT32)getc(IN); + header->biRedGamma |= (OPJ_UINT32)getc(IN) << 8; + header->biRedGamma |= (OPJ_UINT32)getc(IN) << 16; + header->biRedGamma |= (OPJ_UINT32)getc(IN) << 24; + + header->biGreenGamma = (OPJ_UINT32)getc(IN); + header->biGreenGamma |= (OPJ_UINT32)getc(IN) << 8; + header->biGreenGamma |= (OPJ_UINT32)getc(IN) << 16; + header->biGreenGamma |= (OPJ_UINT32)getc(IN) << 24; + + header->biBlueGamma = (OPJ_UINT32)getc(IN); + header->biBlueGamma |= (OPJ_UINT32)getc(IN) << 8; + header->biBlueGamma |= (OPJ_UINT32)getc(IN) << 16; + header->biBlueGamma |= (OPJ_UINT32)getc(IN) << 24; + } + + if (header->biSize >= 124U) { + header->biIntent = (OPJ_UINT32)getc(IN); + header->biIntent |= (OPJ_UINT32)getc(IN) << 8; + header->biIntent |= (OPJ_UINT32)getc(IN) << 16; + header->biIntent |= (OPJ_UINT32)getc(IN) << 24; + + header->biIccProfileData = (OPJ_UINT32)getc(IN); + header->biIccProfileData |= (OPJ_UINT32)getc(IN) << 8; + header->biIccProfileData |= (OPJ_UINT32)getc(IN) << 16; + header->biIccProfileData |= (OPJ_UINT32)getc(IN) << 24; + + header->biIccProfileSize = (OPJ_UINT32)getc(IN); + header->biIccProfileSize |= (OPJ_UINT32)getc(IN) << 8; + header->biIccProfileSize |= (OPJ_UINT32)getc(IN) << 16; + header->biIccProfileSize |= (OPJ_UINT32)getc(IN) << 24; + + header->biReserved = (OPJ_UINT32)getc(IN); + header->biReserved |= (OPJ_UINT32)getc(IN) << 8; + header->biReserved |= (OPJ_UINT32)getc(IN) << 16; + header->biReserved |= (OPJ_UINT32)getc(IN) << 24; + } + return OPJ_TRUE; +} + +static OPJ_BOOL bmp_read_raw_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride, + OPJ_UINT32 width, OPJ_UINT32 height) +{ + OPJ_ARG_NOT_USED(width); + + if (fread(pData, sizeof(OPJ_UINT8), stride * height, IN) != (stride * height)) { + fprintf(stderr, + "\nError: fread return a number of element different from the expected.\n"); + return OPJ_FALSE; + } + return OPJ_TRUE; +} + +static OPJ_BOOL bmp_read_rle8_data(FILE* IN, OPJ_UINT8* pData, + OPJ_UINT32 stride, OPJ_UINT32 width, OPJ_UINT32 height) +{ + OPJ_UINT32 x, y, written; + OPJ_UINT8 *pix; + const OPJ_UINT8 *beyond; + + beyond = pData + stride * height; + pix = pData; + + x = y = written = 0U; + while (y < height) { + int c = getc(IN); + if (c == EOF) { + return OPJ_FALSE; + } + + if (c) { + int j, c1_int; + OPJ_UINT8 c1; + + c1_int = getc(IN); + if (c1_int == EOF) { + return OPJ_FALSE; + } + c1 = (OPJ_UINT8)c1_int; + + for (j = 0; (j < c) && (x < width) && + ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) { + *pix = c1; + written++; + } + } else { + c = getc(IN); + if (c == EOF) { + return OPJ_FALSE; + } + + if (c == 0x00) { /* EOL */ + x = 0; + ++y; + pix = pData + y * stride + x; + } else if (c == 0x01) { /* EOP */ + break; + } else if (c == 0x02) { /* MOVE by dxdy */ + c = getc(IN); + if (c == EOF) { + return OPJ_FALSE; + } + x += (OPJ_UINT32)c; + c = getc(IN); + if (c == EOF) { + return OPJ_FALSE; + } + y += (OPJ_UINT32)c; + pix = pData + y * stride + x; + } else { /* 03 .. 255 */ + int j; + for (j = 0; (j < c) && (x < width) && + ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) { + int c1_int; + OPJ_UINT8 c1; + c1_int = getc(IN); + if (c1_int == EOF) { + return OPJ_FALSE; + } + c1 = (OPJ_UINT8)c1_int; + *pix = c1; + written++; + } + if ((OPJ_UINT32)c & 1U) { /* skip padding byte */ + c = getc(IN); + if (c == EOF) { + return OPJ_FALSE; + } + } + } + } + }/* while() */ + + if (written != width * height) { + fprintf(stderr, "warning, image's actual size does not match advertized one\n"); + return OPJ_FALSE; + } + + return OPJ_TRUE; +} + +static OPJ_BOOL bmp_read_rle4_data(FILE* IN, OPJ_UINT8* pData, + OPJ_UINT32 stride, OPJ_UINT32 width, OPJ_UINT32 height) +{ + OPJ_UINT32 x, y; + OPJ_UINT8 *pix; + const OPJ_UINT8 *beyond; + + beyond = pData + stride * height; + pix = pData; + x = y = 0U; + while (y < height) { + int c = getc(IN); + if (c == EOF) { + break; + } + + if (c) { /* encoded mode */ + int j; + OPJ_UINT8 c1 = (OPJ_UINT8)getc(IN); + + for (j = 0; (j < c) && (x < width) && + ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) { + *pix = (OPJ_UINT8)((j & 1) ? (c1 & 0x0fU) : ((c1 >> 4) & 0x0fU)); + } + } else { /* absolute mode */ + c = getc(IN); + if (c == EOF) { + break; + } + + if (c == 0x00) { /* EOL */ + x = 0; + y++; + pix = pData + y * stride; + } else if (c == 0x01) { /* EOP */ + break; + } else if (c == 0x02) { /* MOVE by dxdy */ + c = getc(IN); + x += (OPJ_UINT32)c; + c = getc(IN); + y += (OPJ_UINT32)c; + pix = pData + y * stride + x; + } else { /* 03 .. 255 : absolute mode */ + int j; + OPJ_UINT8 c1 = 0U; + + for (j = 0; (j < c) && (x < width) && + ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) { + if ((j & 1) == 0) { + c1 = (OPJ_UINT8)getc(IN); + } + *pix = (OPJ_UINT8)((j & 1) ? (c1 & 0x0fU) : ((c1 >> 4) & 0x0fU)); + } + if (((c & 3) == 1) || ((c & 3) == 2)) { /* skip padding byte */ + getc(IN); + } + } + } + } /* while(y < height) */ + return OPJ_TRUE; +} + +opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) +{ + opj_image_cmptparm_t cmptparm[4]; /* maximum of 4 components */ + OPJ_UINT8 lut_R[256], lut_G[256], lut_B[256]; + OPJ_UINT8 const* pLUT[3]; + opj_image_t * image = NULL; + FILE *IN; + OPJ_BITMAPFILEHEADER File_h; + OPJ_BITMAPINFOHEADER Info_h; + OPJ_UINT32 i, palette_len, numcmpts = 1U; + OPJ_BOOL l_result = OPJ_FALSE; + OPJ_UINT8* pData = NULL; + OPJ_UINT32 stride; + + pLUT[0] = lut_R; + pLUT[1] = lut_G; + pLUT[2] = lut_B; + + IN = fopen(filename, "rb"); + if (!IN) { + fprintf(stderr, "Failed to open %s for reading !!\n", filename); + return NULL; + } + + if (!bmp_read_file_header(IN, &File_h)) { + fclose(IN); + return NULL; + } + if (!bmp_read_info_header(IN, &Info_h)) { + fclose(IN); + return NULL; + } + + /* Load palette */ + if (Info_h.biBitCount <= 8U) { + memset(&lut_R[0], 0, sizeof(lut_R)); + memset(&lut_G[0], 0, sizeof(lut_G)); + memset(&lut_B[0], 0, sizeof(lut_B)); + + palette_len = Info_h.biClrUsed; + if ((palette_len == 0U) && (Info_h.biBitCount <= 8U)) { + palette_len = (1U << Info_h.biBitCount); + } + if (palette_len > 256U) { + palette_len = 256U; + } + if (palette_len > 0U) { + OPJ_UINT8 has_color = 0U; + for (i = 0U; i < palette_len; i++) { + lut_B[i] = (OPJ_UINT8)getc(IN); + lut_G[i] = (OPJ_UINT8)getc(IN); + lut_R[i] = (OPJ_UINT8)getc(IN); + (void)getc(IN); /* padding */ + has_color |= (lut_B[i] ^ lut_G[i]) | (lut_G[i] ^ lut_R[i]); + } + if (has_color) { + numcmpts = 3U; + } + } + } else { + numcmpts = 3U; + if ((Info_h.biCompression == 3) && (Info_h.biAlphaMask != 0U)) { + numcmpts++; + } + } + + if (Info_h.biWidth == 0 || Info_h.biHeight == 0) { + fclose(IN); + return NULL; + } + + if (Info_h.biBitCount > (((OPJ_UINT32) - 1) - 31) / Info_h.biWidth) { + fclose(IN); + return NULL; + } + stride = ((Info_h.biWidth * Info_h.biBitCount + 31U) / 32U) * + 4U; /* rows are aligned on 32bits */ + if (Info_h.biBitCount == 4 && + Info_h.biCompression == 2) { /* RLE 4 gets decoded as 8 bits data for now... */ + if (8 > (((OPJ_UINT32) - 1) - 31) / Info_h.biWidth) { + fclose(IN); + return NULL; + } + stride = ((Info_h.biWidth * 8U + 31U) / 32U) * 4U; + } + + if (stride > ((OPJ_UINT32) - 1) / sizeof(OPJ_UINT8) / Info_h.biHeight) { + fclose(IN); + return NULL; + } + pData = (OPJ_UINT8 *) calloc(1, sizeof(OPJ_UINT8) * stride * Info_h.biHeight); + if (pData == NULL) { + fclose(IN); + return NULL; + } + /* Place the cursor at the beginning of the image information */ + fseek(IN, 0, SEEK_SET); + fseek(IN, (long)File_h.bfOffBits, SEEK_SET); + + switch (Info_h.biCompression) { + case 0: + case 3: + /* read raw data */ + l_result = bmp_read_raw_data(IN, pData, stride, Info_h.biWidth, + Info_h.biHeight); + break; + case 1: + /* read rle8 data */ + l_result = bmp_read_rle8_data(IN, pData, stride, Info_h.biWidth, + Info_h.biHeight); + break; + case 2: + /* read rle4 data */ + l_result = bmp_read_rle4_data(IN, pData, stride, Info_h.biWidth, + Info_h.biHeight); + break; + default: + fprintf(stderr, "Unsupported BMP compression\n"); + l_result = OPJ_FALSE; + break; + } + if (!l_result) { + free(pData); + fclose(IN); + return NULL; + } + + /* create the image */ + memset(&cmptparm[0], 0, sizeof(cmptparm)); + for (i = 0; i < 4U; i++) { + cmptparm[i].prec = 8; + cmptparm[i].bpp = 8; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = (OPJ_UINT32)parameters->subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)parameters->subsampling_dy; + cmptparm[i].w = Info_h.biWidth; + cmptparm[i].h = Info_h.biHeight; + } + + image = opj_image_create(numcmpts, &cmptparm[0], + (numcmpts == 1U) ? OPJ_CLRSPC_GRAY : OPJ_CLRSPC_SRGB); + if (!image) { + fclose(IN); + free(pData); + return NULL; + } + if (numcmpts == 4U) { + image->comps[3].alpha = 1; + } + + /* set image offset and reference grid */ + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = image->x0 + (Info_h.biWidth - 1U) * (OPJ_UINT32) + parameters->subsampling_dx + 1U; + image->y1 = image->y0 + (Info_h.biHeight - 1U) * (OPJ_UINT32) + parameters->subsampling_dy + 1U; + + /* Read the data */ + if (Info_h.biBitCount == 24 && Info_h.biCompression == 0) { /*RGB */ + bmp24toimage(pData, stride, image); + } else if (Info_h.biBitCount == 8 && + Info_h.biCompression == 0) { /* RGB 8bpp Indexed */ + bmp8toimage(pData, stride, image, pLUT); + } else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) { /*RLE8*/ + bmp8toimage(pData, stride, image, pLUT); + } else if (Info_h.biBitCount == 4 && Info_h.biCompression == 2) { /*RLE4*/ + bmp8toimage(pData, stride, image, + pLUT); /* RLE 4 gets decoded as 8 bits data for now */ + } else if (Info_h.biBitCount == 32 && Info_h.biCompression == 0) { /* RGBX */ + bmpmask32toimage(pData, stride, image, 0x00FF0000U, 0x0000FF00U, 0x000000FFU, + 0x00000000U); + } else if (Info_h.biBitCount == 32 && Info_h.biCompression == 3) { /* bitmask */ + if ((Info_h.biRedMask == 0U) && (Info_h.biGreenMask == 0U) && + (Info_h.biBlueMask == 0U)) { + Info_h.biRedMask = 0x00FF0000U; + Info_h.biGreenMask = 0x0000FF00U; + Info_h.biBlueMask = 0x000000FFU; + } + bmpmask32toimage(pData, stride, image, Info_h.biRedMask, Info_h.biGreenMask, + Info_h.biBlueMask, Info_h.biAlphaMask); + } else if (Info_h.biBitCount == 16 && Info_h.biCompression == 0) { /* RGBX */ + bmpmask16toimage(pData, stride, image, 0x7C00U, 0x03E0U, 0x001FU, 0x0000U); + } else if (Info_h.biBitCount == 16 && Info_h.biCompression == 3) { /* bitmask */ + if ((Info_h.biRedMask == 0U) && (Info_h.biGreenMask == 0U) && + (Info_h.biBlueMask == 0U)) { + Info_h.biRedMask = 0xF800U; + Info_h.biGreenMask = 0x07E0U; + Info_h.biBlueMask = 0x001FU; + } + bmpmask16toimage(pData, stride, image, Info_h.biRedMask, Info_h.biGreenMask, + Info_h.biBlueMask, Info_h.biAlphaMask); + } else { + opj_image_destroy(image); + image = NULL; + fprintf(stderr, + "Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n", + Info_h.biBitCount); + } + free(pData); + fclose(IN); + return image; +} + +int imagetobmp(opj_image_t * image, const char *outfile) +{ + int w, h; + int i, pad; + FILE *fdest = NULL; + int adjustR, adjustG, adjustB; + + if (image->comps[0].prec < 8) { + fprintf(stderr, "imagetobmp: Unsupported precision: %d\n", + image->comps[0].prec); + return 1; + } + if (image->numcomps >= 3 && image->comps[0].dx == image->comps[1].dx + && image->comps[1].dx == image->comps[2].dx + && image->comps[0].dy == image->comps[1].dy + && image->comps[1].dy == image->comps[2].dy + && image->comps[0].prec == image->comps[1].prec + && image->comps[1].prec == image->comps[2].prec + && image->comps[0].sgnd == image->comps[1].sgnd + && image->comps[1].sgnd == image->comps[2].sgnd) { + + /* -->> -->> -->> -->> + 24 bits color + <<-- <<-- <<-- <<-- */ + + fdest = fopen(outfile, "wb"); + if (!fdest) { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); + return 1; + } + + w = (int)image->comps[0].w; + h = (int)image->comps[0].h; + + fprintf(fdest, "BM"); + + /* FILE HEADER */ + /* ------------- */ + fprintf(fdest, "%c%c%c%c", + (OPJ_UINT8)(h * w * 3 + 3 * h * (w % 2) + 54) & 0xff, + (OPJ_UINT8)((h * w * 3 + 3 * h * (w % 2) + 54) >> 8) & 0xff, + (OPJ_UINT8)((h * w * 3 + 3 * h * (w % 2) + 54) >> 16) & 0xff, + (OPJ_UINT8)((h * w * 3 + 3 * h * (w % 2) + 54) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, + ((0) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (54) & 0xff, ((54) >> 8) & 0xff, ((54) >> 16) & 0xff, + ((54) >> 24) & 0xff); + + /* INFO HEADER */ + /* ------------- */ + fprintf(fdest, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, + ((40) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (OPJ_UINT8)((w) & 0xff), + (OPJ_UINT8)((w) >> 8) & 0xff, + (OPJ_UINT8)((w) >> 16) & 0xff, + (OPJ_UINT8)((w) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (OPJ_UINT8)((h) & 0xff), + (OPJ_UINT8)((h) >> 8) & 0xff, + (OPJ_UINT8)((h) >> 16) & 0xff, + (OPJ_UINT8)((h) >> 24) & 0xff); + fprintf(fdest, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff); + fprintf(fdest, "%c%c", (24) & 0xff, ((24) >> 8) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, + ((0) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (OPJ_UINT8)(3 * h * w + 3 * h * (w % 2)) & 0xff, + (OPJ_UINT8)((h * w * 3 + 3 * h * (w % 2)) >> 8) & 0xff, + (OPJ_UINT8)((h * w * 3 + 3 * h * (w % 2)) >> 16) & 0xff, + (OPJ_UINT8)((h * w * 3 + 3 * h * (w % 2)) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, + ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, + ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, + ((0) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, + ((0) >> 24) & 0xff); + + if (image->comps[0].prec > 8) { + adjustR = (int)image->comps[0].prec - 8; + printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", + image->comps[0].prec); + } else { + adjustR = 0; + } + if (image->comps[1].prec > 8) { + adjustG = (int)image->comps[1].prec - 8; + printf("BMP CONVERSION: Truncating component 1 from %d bits to 8 bits\n", + image->comps[1].prec); + } else { + adjustG = 0; + } + if (image->comps[2].prec > 8) { + adjustB = (int)image->comps[2].prec - 8; + printf("BMP CONVERSION: Truncating component 2 from %d bits to 8 bits\n", + image->comps[2].prec); + } else { + adjustB = 0; + } + + for (i = 0; i < w * h; i++) { + OPJ_UINT8 rc, gc, bc; + int r, g, b; + + r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; + r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + if (adjustR > 0) { + r = ((r >> adjustR) + ((r >> (adjustR - 1)) % 2)); + } + if (r > 255) { + r = 255; + } else if (r < 0) { + r = 0; + } + rc = (OPJ_UINT8)r; + + g = image->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; + g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + if (adjustG > 0) { + g = ((g >> adjustG) + ((g >> (adjustG - 1)) % 2)); + } + if (g > 255) { + g = 255; + } else if (g < 0) { + g = 0; + } + gc = (OPJ_UINT8)g; + + b = image->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; + b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + if (adjustB > 0) { + b = ((b >> adjustB) + ((b >> (adjustB - 1)) % 2)); + } + if (b > 255) { + b = 255; + } else if (b < 0) { + b = 0; + } + bc = (OPJ_UINT8)b; + + fprintf(fdest, "%c%c%c", bc, gc, rc); + + if ((i + 1) % w == 0) { + for (pad = ((3 * w) % 4) ? (4 - (3 * w) % 4) : 0; pad > 0; pad--) { /* ADD */ + fprintf(fdest, "%c", 0); + } + } + } + fclose(fdest); + } else { /* Gray-scale */ + + /* -->> -->> -->> -->> + 8 bits non code (Gray scale) + <<-- <<-- <<-- <<-- */ + + fdest = fopen(outfile, "wb"); + if (!fdest) { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); + return 1; + } + if (image->numcomps > 1) { + fprintf(stderr, "imagetobmp: only first component of %d is used.\n", + image->numcomps); + } + w = (int)image->comps[0].w; + h = (int)image->comps[0].h; + + fprintf(fdest, "BM"); + + /* FILE HEADER */ + /* ------------- */ + fprintf(fdest, "%c%c%c%c", (OPJ_UINT8)(h * w + 54 + 1024 + h * (w % 2)) & 0xff, + (OPJ_UINT8)((h * w + 54 + 1024 + h * (w % 2)) >> 8) & 0xff, + (OPJ_UINT8)((h * w + 54 + 1024 + h * (w % 2)) >> 16) & 0xff, + (OPJ_UINT8)((h * w + 54 + 1024 + w * (w % 2)) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, + ((0) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (54 + 1024) & 0xff, ((54 + 1024) >> 8) & 0xff, + ((54 + 1024) >> 16) & 0xff, + ((54 + 1024) >> 24) & 0xff); + + /* INFO HEADER */ + /* ------------- */ + fprintf(fdest, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, + ((40) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (OPJ_UINT8)((w) & 0xff), + (OPJ_UINT8)((w) >> 8) & 0xff, + (OPJ_UINT8)((w) >> 16) & 0xff, + (OPJ_UINT8)((w) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (OPJ_UINT8)((h) & 0xff), + (OPJ_UINT8)((h) >> 8) & 0xff, + (OPJ_UINT8)((h) >> 16) & 0xff, + (OPJ_UINT8)((h) >> 24) & 0xff); + fprintf(fdest, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff); + fprintf(fdest, "%c%c", (8) & 0xff, ((8) >> 8) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, + ((0) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (OPJ_UINT8)(h * w + h * (w % 2)) & 0xff, + (OPJ_UINT8)((h * w + h * (w % 2)) >> 8) & 0xff, + (OPJ_UINT8)((h * w + h * (w % 2)) >> 16) & 0xff, + (OPJ_UINT8)((h * w + h * (w % 2)) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, + ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, + ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, + ((256) >> 16) & 0xff, ((256) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, + ((256) >> 16) & 0xff, ((256) >> 24) & 0xff); + + if (image->comps[0].prec > 8) { + adjustR = (int)image->comps[0].prec - 8; + printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", + image->comps[0].prec); + } else { + adjustR = 0; + } + + for (i = 0; i < 256; i++) { + fprintf(fdest, "%c%c%c%c", i, i, i, 0); + } + + for (i = 0; i < w * h; i++) { + int r; + + r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; + r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + if (adjustR > 0) { + r = ((r >> adjustR) + ((r >> (adjustR - 1)) % 2)); + } + if (r > 255) { + r = 255; + } else if (r < 0) { + r = 0; + } + + fprintf(fdest, "%c", (OPJ_UINT8)r); + + if ((i + 1) % w == 0) { + for (pad = (w % 4) ? (4 - w % 4) : 0; pad > 0; pad--) { /* ADD */ + fprintf(fdest, "%c", 0); + } + } + } + fclose(fdest); + } + + return 0; +} diff --git a/src/bin/jp2/convertpng.c b/src/bin/jp2/convertpng.c new file mode 100644 index 0000000..44d985f --- /dev/null +++ b/src/bin/jp2/convertpng.c @@ -0,0 +1,517 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * Copyright (c) 2015, Matthieu Darbois + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include "opj_apps_config.h" + +#include +#include +#include +#include + +#include +#include + +#include "openjpeg.h" +#include "convert.h" + +#define PNG_MAGIC "\x89PNG\x0d\x0a\x1a\x0a" +#define MAGIC_SIZE 8 +/* PNG allows bits per sample: 1, 2, 4, 8, 16 */ + + +static void convert_16u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; i++) { + OPJ_INT32 val0 = *pSrc++; + OPJ_INT32 val1 = *pSrc++; + pDst[i] = val0 << 8 | val1; + } +} + +opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) +{ + png_structp png = NULL; + png_infop info = NULL; + double gamma; + int bit_depth, interlace_type, compression_type, filter_type; + OPJ_UINT32 i; + png_uint_32 width, height = 0U; + int color_type; + FILE *reader = NULL; + OPJ_BYTE** rows = NULL; + OPJ_INT32* row32s = NULL; + /* j2k: */ + opj_image_t *image = NULL; + opj_image_cmptparm_t cmptparm[4]; + OPJ_UINT32 nr_comp; + OPJ_BYTE sigbuf[8]; + convert_XXx32s_C1R cvtXXTo32s = NULL; + convert_32s_CXPX cvtCxToPx = NULL; + OPJ_INT32* planes[4]; + + if ((reader = fopen(read_idf, "rb")) == NULL) { + fprintf(stderr, "pngtoimage: can not open %s\n", read_idf); + return NULL; + } + + if (fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE + || memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) { + fprintf(stderr, "pngtoimage: %s is no valid PNG file\n", read_idf); + goto fin; + } + + if ((png = png_create_read_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL)) == NULL) { + goto fin; + } + if ((info = png_create_info_struct(png)) == NULL) { + goto fin; + } + + if (setjmp(png_jmpbuf(png))) { + goto fin; + } + + png_init_io(png, reader); + png_set_sig_bytes(png, MAGIC_SIZE); + + png_read_info(png, info); + + if (png_get_IHDR(png, info, &width, &height, + &bit_depth, &color_type, &interlace_type, + &compression_type, &filter_type) == 0) { + goto fin; + } + + /* png_set_expand(): + * expand paletted images to RGB, expand grayscale images of + * less than 8-bit depth to 8-bit depth, and expand tRNS chunks + * to alpha channels. + */ + if (color_type == PNG_COLOR_TYPE_PALETTE) { + png_set_expand(png); + } + + if (png_get_valid(png, info, PNG_INFO_tRNS)) { + png_set_expand(png); + } + /* We might wan't to expand background */ + /* + if(png_get_valid(png, info, PNG_INFO_bKGD)) { + png_color_16p bgnd; + png_get_bKGD(png, info, &bgnd); + png_set_background(png, bgnd, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); + } + */ + + if (!png_get_gAMA(png, info, &gamma)) { + gamma = 1.0; + } + + /* we're not displaying but converting, screen gamma == 1.0 */ + png_set_gamma(png, 1.0, gamma); + + png_read_update_info(png, info); + + color_type = png_get_color_type(png, info); + + switch (color_type) { + case PNG_COLOR_TYPE_GRAY: + nr_comp = 1; + break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + nr_comp = 2; + break; + case PNG_COLOR_TYPE_RGB: + nr_comp = 3; + break; + case PNG_COLOR_TYPE_RGB_ALPHA: + nr_comp = 4; + break; + default: + fprintf(stderr, "pngtoimage: colortype %d is not supported\n", color_type); + goto fin; + } + cvtCxToPx = convert_32s_CXPX_LUT[nr_comp]; + bit_depth = png_get_bit_depth(png, info); + + switch (bit_depth) { + case 1: + case 2: + case 4: + case 8: + cvtXXTo32s = convert_XXu32s_C1R_LUT[bit_depth]; + break; + case 16: /* 16 bpp is specific to PNG */ + cvtXXTo32s = convert_16u32s_C1R; + break; + default: + fprintf(stderr, "pngtoimage: bit depth %d is not supported\n", bit_depth); + goto fin; + } + + + rows = (OPJ_BYTE**)calloc(height + 1, sizeof(OPJ_BYTE*)); + if (rows == NULL) { + fprintf(stderr, "pngtoimage: memory out\n"); + goto fin; + } + for (i = 0; i < height; ++i) { + rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png, info)); + if (rows[i] == NULL) { + fprintf(stderr, "pngtoimage: memory out\n"); + goto fin; + } + } + png_read_image(png, rows); + + /* Create image */ + memset(cmptparm, 0, sizeof(cmptparm)); + for (i = 0; i < nr_comp; ++i) { + cmptparm[i].prec = (OPJ_UINT32)bit_depth; + /* bits_per_pixel: 8 or 16 */ + cmptparm[i].bpp = (OPJ_UINT32)bit_depth; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy; + cmptparm[i].w = (OPJ_UINT32)width; + cmptparm[i].h = (OPJ_UINT32)height; + } + + image = opj_image_create(nr_comp, &cmptparm[0], + (nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY); + if (image == NULL) { + goto fin; + } + image->x0 = (OPJ_UINT32)params->image_offset_x0; + image->y0 = (OPJ_UINT32)params->image_offset_y0; + image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32) + params->subsampling_dx + 1 + image->x0); + image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32) + params->subsampling_dy + 1 + image->y0); + + row32s = (OPJ_INT32 *)malloc((size_t)width * nr_comp * sizeof(OPJ_INT32)); + if (row32s == NULL) { + goto fin; + } + + /* Set alpha channel */ + image->comps[nr_comp - 1U].alpha = 1U - (nr_comp & 1U); + + for (i = 0; i < nr_comp; i++) { + planes[i] = image->comps[i].data; + } + + for (i = 0; i < height; ++i) { + cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp); + cvtCxToPx(row32s, planes, width); + planes[0] += width; + planes[1] += width; + planes[2] += width; + planes[3] += width; + } +fin: + if (rows) { + for (i = 0; i < height; ++i) + if (rows[i]) { + free(rows[i]); + } + free(rows); + } + if (row32s) { + free(row32s); + } + if (png) { + png_destroy_read_struct(&png, &info, NULL); + } + + fclose(reader); + + return image; + +}/* pngtoimage() */ + + +static void convert_32s16u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; i++) { + OPJ_UINT32 val = (OPJ_UINT32)pSrc[i]; + *pDst++ = (OPJ_BYTE)(val >> 8); + *pDst++ = (OPJ_BYTE)val; + } +} +int imagetopng(opj_image_t * image, const char *write_idf) +{ + FILE * volatile writer = NULL; + png_structp png = NULL; + png_infop info = NULL; + png_bytep volatile row_buf = NULL; + int nr_comp, color_type; + volatile int prec; + png_color_8 sig_bit; + OPJ_INT32 const* planes[4]; + int i; + OPJ_INT32* volatile buffer32s = NULL; + + volatile int fails = 1; + + memset(&sig_bit, 0, sizeof(sig_bit)); + prec = (int)image->comps[0].prec; + planes[0] = image->comps[0].data; + nr_comp = (int)image->numcomps; + + if (nr_comp > 4) { + nr_comp = 4; + } + for (i = 1; i < nr_comp; ++i) { + if (image->comps[0].dx != image->comps[i].dx) { + break; + } + if (image->comps[0].dy != image->comps[i].dy) { + break; + } + if (image->comps[0].prec != image->comps[i].prec) { + break; + } + if (image->comps[0].sgnd != image->comps[i].sgnd) { + break; + } + planes[i] = image->comps[i].data; + } + if (i != nr_comp) { + fprintf(stderr, + "imagetopng: All components shall have the same subsampling, same bit depth, same sign.\n"); + fprintf(stderr, "\tAborting\n"); + return 1; + } + for (i = 0; i < nr_comp; ++i) { + clip_component(&(image->comps[i]), image->comps[0].prec); + } + if (prec > 8 && prec < 16) { + for (i = 0; i < nr_comp; ++i) { + scale_component(&(image->comps[i]), 16); + } + prec = 16; + } else if (prec < 8 && nr_comp > 1) { /* GRAY_ALPHA, RGB, RGB_ALPHA */ + for (i = 0; i < nr_comp; ++i) { + scale_component(&(image->comps[i]), 8); + } + prec = 8; + } else if ((prec > 1) && (prec < 8) && ((prec == 6) || + ((prec & 1) == 1))) { /* GRAY with non native precision */ + if ((prec == 5) || (prec == 6)) { + prec = 8; + } else { + prec++; + } + for (i = 0; i < nr_comp; ++i) { + scale_component(&(image->comps[i]), (OPJ_UINT32)prec); + } + } + + if (prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) { + fprintf(stderr, "imagetopng: can not create %s\n\twrong bit_depth %d\n", + write_idf, prec); + return fails; + } + + writer = fopen(write_idf, "wb"); + + if (writer == NULL) { + return fails; + } + + /* Create and initialize the png_struct with the desired error handler + * functions. If you want to use the default stderr and longjump method, + * you can supply NULL for the last three parameters. We also check that + * the library version is compatible with the one used at compile time, + * in case we are using dynamically linked libraries. REQUIRED. + */ + png = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); + /*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */ + + if (png == NULL) { + goto fin; + } + + /* Allocate/initialize the image information data. REQUIRED + */ + info = png_create_info_struct(png); + + if (info == NULL) { + goto fin; + } + + /* Set error handling. REQUIRED if you are not supplying your own + * error handling functions in the png_create_write_struct() call. + */ + if (setjmp(png_jmpbuf(png))) { + goto fin; + } + + /* I/O initialization functions is REQUIRED + */ + png_init_io(png, writer); + + /* Set the image information here. Width and height are up to 2^31, + * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on + * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY, + * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, + * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or + * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST + * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. + * REQUIRED + * + * ERRORS: + * + * color_type == PNG_COLOR_TYPE_PALETTE && bit_depth > 8 + * color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8 + * color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8 + * color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8 + * + */ + png_set_compression_level(png, Z_BEST_COMPRESSION); + + if (nr_comp >= 3) { /* RGB(A) */ + color_type = PNG_COLOR_TYPE_RGB; + sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec; + } else { /* GRAY(A) */ + color_type = PNG_COLOR_TYPE_GRAY; + sig_bit.gray = (png_byte)prec; + } + if ((nr_comp & 1) == 0) { /* ALPHA */ + color_type |= PNG_COLOR_MASK_ALPHA; + sig_bit.alpha = (png_byte)prec; + } + + png_set_IHDR(png, info, image->comps[0].w, image->comps[0].h, prec, color_type, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + png_set_sBIT(png, info, &sig_bit); + /* png_set_gamma(png, 2.2, 1./2.2); */ + /* png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); */ + png_write_info(png, info); + + /* setup conversion */ + { + OPJ_SIZE_T rowStride; + png_size_t png_row_size; + + png_row_size = png_get_rowbytes(png, info); + rowStride = ((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * + (OPJ_SIZE_T)prec + 7U) / 8U; + if (rowStride != (OPJ_SIZE_T)png_row_size) { + fprintf(stderr, "Invalid PNG row size\n"); + goto fin; + } + row_buf = (png_bytep)malloc(png_row_size); + if (row_buf == NULL) { + fprintf(stderr, "Can't allocate memory for PNG row\n"); + goto fin; + } + buffer32s = (OPJ_INT32*)malloc((OPJ_SIZE_T)image->comps[0].w * + (OPJ_SIZE_T)nr_comp * sizeof(OPJ_INT32)); + if (buffer32s == NULL) { + fprintf(stderr, "Can't allocate memory for interleaved 32s row\n"); + goto fin; + } + } + + /* convert */ + { + OPJ_SIZE_T width = image->comps[0].w; + OPJ_UINT32 y; + convert_32s_PXCX cvtPxToCx = convert_32s_PXCX_LUT[nr_comp]; + convert_32sXXx_C1R cvt32sToPack = NULL; + OPJ_INT32 adjust = image->comps[0].sgnd ? 1 << (prec - 1) : 0; + png_bytep row_buf_cpy = row_buf; + OPJ_INT32* buffer32s_cpy = buffer32s; + + switch (prec) { + case 1: + case 2: + case 4: + case 8: + cvt32sToPack = convert_32sXXu_C1R_LUT[prec]; + break; + case 16: + cvt32sToPack = convert_32s16u_C1R; + break; + default: + /* never here */ + break; + } + + for (y = 0; y < image->comps[0].h; ++y) { + cvtPxToCx(planes, buffer32s_cpy, width, adjust); + cvt32sToPack(buffer32s_cpy, row_buf_cpy, width * (OPJ_SIZE_T)nr_comp); + png_write_row(png, row_buf_cpy); + planes[0] += width; + planes[1] += width; + planes[2] += width; + planes[3] += width; + } + } + + png_write_end(png, info); + + fails = 0; + +fin: + if (png) { + png_destroy_write_struct(&png, &info); + } + if (row_buf) { + free(row_buf); + } + if (buffer32s) { + free(buffer32s); + } + fclose(writer); + + if (fails) { + (void)remove(write_idf); /* ignore return value */ + } + + return fails; +}/* imagetopng() */ diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c new file mode 100644 index 0000000..6714d69 --- /dev/null +++ b/src/bin/jp2/converttif.c @@ -0,0 +1,1508 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * Copyright (c) 2015, Matthieu Darbois + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include "opj_apps_config.h" + +#include +#include +#include +#include +#include + +#ifndef OPJ_HAVE_LIBTIFF +# error OPJ_HAVE_LIBTIFF_NOT_DEFINED +#endif /* OPJ_HAVE_LIBTIFF */ + +#include +#include "openjpeg.h" +#include "convert.h" +#include "opj_inttypes.h" + +/* -->> -->> -->> -->> + + TIFF IMAGE FORMAT + + <<-- <<-- <<-- <<-- */ +#define PUTBITS2(s, nb) \ + trailing <<= remaining; \ + trailing |= (unsigned int)((s) >> (nb - remaining)); \ + *pDst++ = (OPJ_BYTE)trailing; \ + trailing = (unsigned int)((s) & ((1U << (nb - remaining)) - 1U)); \ + if (nb >= (remaining + 8)) { \ + *pDst++ = (OPJ_BYTE)(trailing >> (nb - (remaining + 8))); \ + trailing &= (unsigned int)((1U << (nb - (remaining + 8))) - 1U); \ + remaining += 16 - nb; \ + } else { \ + remaining += 8 - nb; \ + } + +#define PUTBITS(s, nb) \ + if (nb >= remaining) { \ + PUTBITS2(s, nb) \ + } else { \ + trailing <<= nb; \ + trailing |= (unsigned int)(s); \ + remaining -= nb; \ + } +#define FLUSHBITS() \ + if (remaining != 8) { \ + trailing <<= remaining; \ + *pDst++ = (OPJ_BYTE)trailing; \ + } + +static void tif_32sto3u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i + 4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i + 5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i + 6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i + 7]; + + *pDst++ = (OPJ_BYTE)((src0 << 5) | (src1 << 2) | (src2 >> 1)); + *pDst++ = (OPJ_BYTE)((src2 << 7) | (src3 << 4) | (src4 << 1) | (src5 >> 2)); + *pDst++ = (OPJ_BYTE)((src5 << 6) | (src6 << 3) | (src7)); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS((OPJ_UINT32)pSrc[i + 0], 3) + if (length > 1U) { + PUTBITS((OPJ_UINT32)pSrc[i + 1], 3) + if (length > 2U) { + PUTBITS((OPJ_UINT32)pSrc[i + 2], 3) + if (length > 3U) { + PUTBITS((OPJ_UINT32)pSrc[i + 3], 3) + if (length > 4U) { + PUTBITS((OPJ_UINT32)pSrc[i + 4], 3) + if (length > 5U) { + PUTBITS((OPJ_UINT32)pSrc[i + 5], 3) + if (length > 6U) { + PUTBITS((OPJ_UINT32)pSrc[i + 6], 3) + } + } + } + } + } + } + FLUSHBITS() + } +} + +static void tif_32sto5u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i + 4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i + 5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i + 6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i + 7]; + + *pDst++ = (OPJ_BYTE)((src0 << 3) | (src1 >> 2)); + *pDst++ = (OPJ_BYTE)((src1 << 6) | (src2 << 1) | (src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 1)); + *pDst++ = (OPJ_BYTE)((src4 << 7) | (src5 << 2) | (src6 >> 3)); + *pDst++ = (OPJ_BYTE)((src6 << 5) | (src7)); + + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS((OPJ_UINT32)pSrc[i + 0], 5) + if (length > 1U) { + PUTBITS((OPJ_UINT32)pSrc[i + 1], 5) + if (length > 2U) { + PUTBITS((OPJ_UINT32)pSrc[i + 2], 5) + if (length > 3U) { + PUTBITS((OPJ_UINT32)pSrc[i + 3], 5) + if (length > 4U) { + PUTBITS((OPJ_UINT32)pSrc[i + 4], 5) + if (length > 5U) { + PUTBITS((OPJ_UINT32)pSrc[i + 5], 5) + if (length > 6U) { + PUTBITS((OPJ_UINT32)pSrc[i + 6], 5) + } + } + } + } + } + } + FLUSHBITS() + } +} + +static void tif_32sto7u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i + 4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i + 5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i + 6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i + 7]; + + *pDst++ = (OPJ_BYTE)((src0 << 1) | (src1 >> 6)); + *pDst++ = (OPJ_BYTE)((src1 << 2) | (src2 >> 5)); + *pDst++ = (OPJ_BYTE)((src2 << 3) | (src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 3)); + *pDst++ = (OPJ_BYTE)((src4 << 5) | (src5 >> 2)); + *pDst++ = (OPJ_BYTE)((src5 << 6) | (src6 >> 1)); + *pDst++ = (OPJ_BYTE)((src6 << 7) | (src7)); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS((OPJ_UINT32)pSrc[i + 0], 7) + if (length > 1U) { + PUTBITS((OPJ_UINT32)pSrc[i + 1], 7) + if (length > 2U) { + PUTBITS((OPJ_UINT32)pSrc[i + 2], 7) + if (length > 3U) { + PUTBITS((OPJ_UINT32)pSrc[i + 3], 7) + if (length > 4U) { + PUTBITS((OPJ_UINT32)pSrc[i + 4], 7) + if (length > 5U) { + PUTBITS((OPJ_UINT32)pSrc[i + 5], 7) + if (length > 6U) { + PUTBITS((OPJ_UINT32)pSrc[i + 6], 7) + } + } + } + } + } + } + FLUSHBITS() + } +} + +static void tif_32sto9u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i + 4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i + 5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i + 6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i + 7]; + + *pDst++ = (OPJ_BYTE)((src0 >> 1)); + *pDst++ = (OPJ_BYTE)((src0 << 7) | (src1 >> 2)); + *pDst++ = (OPJ_BYTE)((src1 << 6) | (src2 >> 3)); + *pDst++ = (OPJ_BYTE)((src2 << 5) | (src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 5)); + *pDst++ = (OPJ_BYTE)((src4 << 3) | (src5 >> 6)); + *pDst++ = (OPJ_BYTE)((src5 << 2) | (src6 >> 7)); + *pDst++ = (OPJ_BYTE)((src6 << 1) | (src7 >> 8)); + *pDst++ = (OPJ_BYTE)(src7); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS2((OPJ_UINT32)pSrc[i + 0], 9) + if (length > 1U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 1], 9) + if (length > 2U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 2], 9) + if (length > 3U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 3], 9) + if (length > 4U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 4], 9) + if (length > 5U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 5], 9) + if (length > 6U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 6], 9) + } + } + } + } + } + } + FLUSHBITS() + } +} + +static void tif_32sto10u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i += 4U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + + *pDst++ = (OPJ_BYTE)(src0 >> 2); + *pDst++ = (OPJ_BYTE)(((src0 & 0x3U) << 6) | (src1 >> 4)); + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 6)); + *pDst++ = (OPJ_BYTE)(((src2 & 0x3FU) << 2) | (src3 >> 8)); + *pDst++ = (OPJ_BYTE)(src3); + } + + if (length & 3U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = 0U; + OPJ_UINT32 src2 = 0U; + length = length & 3U; + + if (length > 1U) { + src1 = (OPJ_UINT32)pSrc[i + 1]; + if (length > 2U) { + src2 = (OPJ_UINT32)pSrc[i + 2]; + } + } + *pDst++ = (OPJ_BYTE)(src0 >> 2); + *pDst++ = (OPJ_BYTE)(((src0 & 0x3U) << 6) | (src1 >> 4)); + if (length > 1U) { + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 6)); + if (length > 2U) { + *pDst++ = (OPJ_BYTE)(((src2 & 0x3FU) << 2)); + } + } + } +} +static void tif_32sto11u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i + 4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i + 5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i + 6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i + 7]; + + *pDst++ = (OPJ_BYTE)((src0 >> 3)); + *pDst++ = (OPJ_BYTE)((src0 << 5) | (src1 >> 6)); + *pDst++ = (OPJ_BYTE)((src1 << 2) | (src2 >> 9)); + *pDst++ = (OPJ_BYTE)((src2 >> 1)); + *pDst++ = (OPJ_BYTE)((src2 << 7) | (src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 7)); + *pDst++ = (OPJ_BYTE)((src4 << 1) | (src5 >> 10)); + *pDst++ = (OPJ_BYTE)((src5 >> 2)); + *pDst++ = (OPJ_BYTE)((src5 << 6) | (src6 >> 5)); + *pDst++ = (OPJ_BYTE)((src6 << 3) | (src7 >> 8)); + *pDst++ = (OPJ_BYTE)(src7); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS2((OPJ_UINT32)pSrc[i + 0], 11) + if (length > 1U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 1], 11) + if (length > 2U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 2], 11) + if (length > 3U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 3], 11) + if (length > 4U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 4], 11) + if (length > 5U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 5], 11) + if (length > 6U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 6], 11) + } + } + } + } + } + } + FLUSHBITS() + } +} +static void tif_32sto12u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)1U); i += 2U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + + *pDst++ = (OPJ_BYTE)(src0 >> 4); + *pDst++ = (OPJ_BYTE)(((src0 & 0xFU) << 4) | (src1 >> 8)); + *pDst++ = (OPJ_BYTE)(src1); + } + + if (length & 1U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + *pDst++ = (OPJ_BYTE)(src0 >> 4); + *pDst++ = (OPJ_BYTE)(((src0 & 0xFU) << 4)); + } +} +static void tif_32sto13u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i + 4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i + 5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i + 6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i + 7]; + + *pDst++ = (OPJ_BYTE)((src0 >> 5)); + *pDst++ = (OPJ_BYTE)((src0 << 3) | (src1 >> 10)); + *pDst++ = (OPJ_BYTE)((src1 >> 2)); + *pDst++ = (OPJ_BYTE)((src1 << 6) | (src2 >> 7)); + *pDst++ = (OPJ_BYTE)((src2 << 1) | (src3 >> 12)); + *pDst++ = (OPJ_BYTE)((src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 9)); + *pDst++ = (OPJ_BYTE)((src4 >> 1)); + *pDst++ = (OPJ_BYTE)((src4 << 7) | (src5 >> 6)); + *pDst++ = (OPJ_BYTE)((src5 << 2) | (src6 >> 11)); + *pDst++ = (OPJ_BYTE)((src6 >> 3)); + *pDst++ = (OPJ_BYTE)((src6 << 5) | (src7 >> 8)); + *pDst++ = (OPJ_BYTE)(src7); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS2((OPJ_UINT32)pSrc[i + 0], 13) + if (length > 1U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 1], 13) + if (length > 2U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 2], 13) + if (length > 3U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 3], 13) + if (length > 4U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 4], 13) + if (length > 5U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 5], 13) + if (length > 6U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 6], 13) + } + } + } + } + } + } + FLUSHBITS() + } +} +static void tif_32sto14u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i += 4U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + + *pDst++ = (OPJ_BYTE)(src0 >> 6); + *pDst++ = (OPJ_BYTE)(((src0 & 0x3FU) << 2) | (src1 >> 12)); + *pDst++ = (OPJ_BYTE)(src1 >> 4); + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 10)); + *pDst++ = (OPJ_BYTE)(src2 >> 2); + *pDst++ = (OPJ_BYTE)(((src2 & 0x3U) << 6) | (src3 >> 8)); + *pDst++ = (OPJ_BYTE)(src3); + } + + if (length & 3U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = 0U; + OPJ_UINT32 src2 = 0U; + length = length & 3U; + + if (length > 1U) { + src1 = (OPJ_UINT32)pSrc[i + 1]; + if (length > 2U) { + src2 = (OPJ_UINT32)pSrc[i + 2]; + } + } + *pDst++ = (OPJ_BYTE)(src0 >> 6); + *pDst++ = (OPJ_BYTE)(((src0 & 0x3FU) << 2) | (src1 >> 12)); + if (length > 1U) { + *pDst++ = (OPJ_BYTE)(src1 >> 4); + *pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 10)); + if (length > 2U) { + *pDst++ = (OPJ_BYTE)(src2 >> 2); + *pDst++ = (OPJ_BYTE)(((src2 & 0x3U) << 6)); + } + } + } +} +static void tif_32sto15u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i + 0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i + 1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i + 2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i + 3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i + 4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i + 5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i + 6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i + 7]; + + *pDst++ = (OPJ_BYTE)((src0 >> 7)); + *pDst++ = (OPJ_BYTE)((src0 << 1) | (src1 >> 14)); + *pDst++ = (OPJ_BYTE)((src1 >> 6)); + *pDst++ = (OPJ_BYTE)((src1 << 2) | (src2 >> 13)); + *pDst++ = (OPJ_BYTE)((src2 >> 5)); + *pDst++ = (OPJ_BYTE)((src2 << 3) | (src3 >> 12)); + *pDst++ = (OPJ_BYTE)((src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 11)); + *pDst++ = (OPJ_BYTE)((src4 >> 3)); + *pDst++ = (OPJ_BYTE)((src4 << 5) | (src5 >> 10)); + *pDst++ = (OPJ_BYTE)((src5 >> 2)); + *pDst++ = (OPJ_BYTE)((src5 << 6) | (src6 >> 9)); + *pDst++ = (OPJ_BYTE)((src6 >> 1)); + *pDst++ = (OPJ_BYTE)((src6 << 7) | (src7 >> 8)); + *pDst++ = (OPJ_BYTE)(src7); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS2((OPJ_UINT32)pSrc[i + 0], 15) + if (length > 1U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 1], 15) + if (length > 2U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 2], 15) + if (length > 3U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 3], 15) + if (length > 4U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 4], 15) + if (length > 5U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 5], 15) + if (length > 6U) { + PUTBITS2((OPJ_UINT32)pSrc[i + 6], 15) + } + } + } + } + } + } + FLUSHBITS() + } +} +static void tif_32sto16u(const OPJ_INT32* pSrc, OPJ_UINT16* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; ++i) { + pDst[i] = (OPJ_UINT16)pSrc[i]; + } +} + +int imagetotif(opj_image_t * image, const char *outfile) +{ + TIFF *tif; + tdata_t buf; + uint32 width, height; + uint16 bps, tiPhoto; + int adjust, sgnd; + int64_t strip_size, rowStride, TIFF_MAX; + OPJ_UINT32 i, numcomps; + OPJ_INT32* buffer32s = NULL; + OPJ_INT32 const* planes[4]; + convert_32s_PXCX cvtPxToCx = NULL; + convert_32sXXx_C1R cvt32sToTif = NULL; + + bps = (uint16)image->comps[0].prec; + planes[0] = image->comps[0].data; + + numcomps = image->numcomps; + + if (image->color_space == OPJ_CLRSPC_CMYK) { + if (numcomps < 4U) { + fprintf(stderr, + "imagetotif: CMYK images shall be composed of at least 4 planes.\n"); + fprintf(stderr, "\tAborting\n"); + return 1; + } + tiPhoto = PHOTOMETRIC_SEPARATED; + if (numcomps > 4U) { + numcomps = 4U; /* Alpha not supported */ + } + } else if (numcomps > 2U) { + tiPhoto = PHOTOMETRIC_RGB; + if (numcomps > 4U) { + numcomps = 4U; + } + } else { + tiPhoto = PHOTOMETRIC_MINISBLACK; + } + for (i = 1U; i < numcomps; ++i) { + if (image->comps[0].dx != image->comps[i].dx) { + break; + } + if (image->comps[0].dy != image->comps[i].dy) { + break; + } + if (image->comps[0].prec != image->comps[i].prec) { + break; + } + if (image->comps[0].sgnd != image->comps[i].sgnd) { + break; + } + planes[i] = image->comps[i].data; + } + if (i != numcomps) { + fprintf(stderr, + "imagetotif: All components shall have the same subsampling, same bit depth.\n"); + fprintf(stderr, "\tAborting\n"); + return 1; + } + + if (bps > 16) { + bps = 0; + } + if (bps == 0) { + fprintf(stderr, "imagetotif: Bits=%d, Only 1 to 16 bits implemented\n", bps); + fprintf(stderr, "\tAborting\n"); + return 1; + } + tif = TIFFOpen(outfile, "wb"); + if (!tif) { + fprintf(stderr, "imagetotif:failed to open %s for writing\n", outfile); + return 1; + } + for (i = 0U; i < numcomps; ++i) { + clip_component(&(image->comps[i]), image->comps[0].prec); + } + cvtPxToCx = convert_32s_PXCX_LUT[numcomps]; + switch (bps) { + case 1: + case 2: + case 4: + case 6: + case 8: + cvt32sToTif = convert_32sXXu_C1R_LUT[bps]; + break; + case 3: + cvt32sToTif = tif_32sto3u; + break; + case 5: + cvt32sToTif = tif_32sto5u; + break; + case 7: + cvt32sToTif = tif_32sto7u; + break; + case 9: + cvt32sToTif = tif_32sto9u; + break; + case 10: + cvt32sToTif = tif_32sto10u; + break; + case 11: + cvt32sToTif = tif_32sto11u; + break; + case 12: + cvt32sToTif = tif_32sto12u; + break; + case 13: + cvt32sToTif = tif_32sto13u; + break; + case 14: + cvt32sToTif = tif_32sto14u; + break; + case 15: + cvt32sToTif = tif_32sto15u; + break; + case 16: + cvt32sToTif = (convert_32sXXx_C1R)tif_32sto16u; + break; + default: + /* never here */ + break; + } + sgnd = (int)image->comps[0].sgnd; + adjust = sgnd ? (int)(1 << (image->comps[0].prec - 1)) : 0; + width = (uint32)image->comps[0].w; + height = (uint32)image->comps[0].h; + + TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); + TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (uint16)numcomps); + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps); + TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); + TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, tiPhoto); + TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1); + if (sizeof(tsize_t) == 4) { + TIFF_MAX = INT_MAX; + } else { + TIFF_MAX = UINT_MAX; + } + strip_size = (int64_t)TIFFStripSize(tif); + + if ((int64_t)width > (int64_t)(TIFF_MAX / numcomps) || + (int64_t)(width * numcomps) > (int64_t)(TIFF_MAX / bps) || + (int64_t)(width * numcomps) > (int64_t)(TIFF_MAX / (int64_t)sizeof( + OPJ_INT32))) { + fprintf(stderr, "Buffer overflow\n"); + TIFFClose(tif); + return 1; + } + rowStride = (int64_t)((width * numcomps * bps + 7U) / 8U); + if (rowStride != strip_size) { + fprintf(stderr, "Invalid TIFF strip size\n"); + TIFFClose(tif); + return 1; + } + buf = malloc((OPJ_SIZE_T)strip_size); + if (buf == NULL) { + TIFFClose(tif); + return 1; + } + buffer32s = (OPJ_INT32 *)malloc(sizeof(OPJ_INT32) * width * numcomps); + if (buffer32s == NULL) { + _TIFFfree(buf); + TIFFClose(tif); + return 1; + } + + for (i = 0; i < image->comps[0].h; ++i) { + cvtPxToCx(planes, buffer32s, (OPJ_SIZE_T)width, adjust); + cvt32sToTif(buffer32s, (OPJ_BYTE *)buf, (OPJ_SIZE_T)width * numcomps); + (void)TIFFWriteEncodedStrip(tif, i, (void*)buf, (tsize_t)strip_size); + planes[0] += width; + planes[1] += width; + planes[2] += width; + planes[3] += width; + } + _TIFFfree((void*)buf); + TIFFClose(tif); + free(buffer32s); + + return 0; +}/* imagetotif() */ + +#define GETBITS(dest, nb) { \ + int needed = (nb); \ + unsigned int dst = 0U; \ + if (available == 0) { \ + val = *pSrc++; \ + available = 8; \ + } \ + while (needed > available) { \ + dst |= val & ((1U << available) - 1U); \ + needed -= available; \ + dst <<= needed; \ + val = *pSrc++; \ + available = 8; \ + } \ + dst |= (val >> (available - needed)) & ((1U << needed) - 1U); \ + available -= needed; \ + dest = (OPJ_INT32)dst; \ +} + +static void tif_3uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + + pDst[i + 0] = (OPJ_INT32)((val0 >> 5)); + pDst[i + 1] = (OPJ_INT32)(((val0 & 0x1FU) >> 2)); + pDst[i + 2] = (OPJ_INT32)(((val0 & 0x3U) << 1) | (val1 >> 7)); + pDst[i + 3] = (OPJ_INT32)(((val1 & 0x7FU) >> 4)); + pDst[i + 4] = (OPJ_INT32)(((val1 & 0xFU) >> 1)); + pDst[i + 5] = (OPJ_INT32)(((val1 & 0x1U) << 2) | (val2 >> 6)); + pDst[i + 6] = (OPJ_INT32)(((val2 & 0x3FU) >> 3)); + pDst[i + 7] = (OPJ_INT32)(((val2 & 0x7U))); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i + 0], 3) + + if (length > 1U) { + GETBITS(pDst[i + 1], 3) + if (length > 2U) { + GETBITS(pDst[i + 2], 3) + if (length > 3U) { + GETBITS(pDst[i + 3], 3) + if (length > 4U) { + GETBITS(pDst[i + 4], 3) + if (length > 5U) { + GETBITS(pDst[i + 5], 3) + if (length > 6U) { + GETBITS(pDst[i + 6], 3) + } + } + } + } + } + } + } +} +static void tif_5uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + + pDst[i + 0] = (OPJ_INT32)((val0 >> 3)); + pDst[i + 1] = (OPJ_INT32)(((val0 & 0x7U) << 2) | (val1 >> 6)); + pDst[i + 2] = (OPJ_INT32)(((val1 & 0x3FU) >> 1)); + pDst[i + 3] = (OPJ_INT32)(((val1 & 0x1U) << 4) | (val2 >> 4)); + pDst[i + 4] = (OPJ_INT32)(((val2 & 0xFU) << 1) | (val3 >> 7)); + pDst[i + 5] = (OPJ_INT32)(((val3 & 0x7FU) >> 2)); + pDst[i + 6] = (OPJ_INT32)(((val3 & 0x3U) << 3) | (val4 >> 5)); + pDst[i + 7] = (OPJ_INT32)(((val4 & 0x1FU))); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i + 0], 5) + + if (length > 1U) { + GETBITS(pDst[i + 1], 5) + if (length > 2U) { + GETBITS(pDst[i + 2], 5) + if (length > 3U) { + GETBITS(pDst[i + 3], 5) + if (length > 4U) { + GETBITS(pDst[i + 4], 5) + if (length > 5U) { + GETBITS(pDst[i + 5], 5) + if (length > 6U) { + GETBITS(pDst[i + 6], 5) + } + } + } + } + } + } + } +} +static void tif_7uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + + pDst[i + 0] = (OPJ_INT32)((val0 >> 1)); + pDst[i + 1] = (OPJ_INT32)(((val0 & 0x1U) << 6) | (val1 >> 2)); + pDst[i + 2] = (OPJ_INT32)(((val1 & 0x3U) << 5) | (val2 >> 3)); + pDst[i + 3] = (OPJ_INT32)(((val2 & 0x7U) << 4) | (val3 >> 4)); + pDst[i + 4] = (OPJ_INT32)(((val3 & 0xFU) << 3) | (val4 >> 5)); + pDst[i + 5] = (OPJ_INT32)(((val4 & 0x1FU) << 2) | (val5 >> 6)); + pDst[i + 6] = (OPJ_INT32)(((val5 & 0x3FU) << 1) | (val6 >> 7)); + pDst[i + 7] = (OPJ_INT32)(((val6 & 0x7FU))); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i + 0], 7) + + if (length > 1U) { + GETBITS(pDst[i + 1], 7) + if (length > 2U) { + GETBITS(pDst[i + 2], 7) + if (length > 3U) { + GETBITS(pDst[i + 3], 7) + if (length > 4U) { + GETBITS(pDst[i + 4], 7) + if (length > 5U) { + GETBITS(pDst[i + 5], 7) + if (length > 6U) { + GETBITS(pDst[i + 6], 7) + } + } + } + } + } + } + } +} +static void tif_9uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + OPJ_UINT32 val7 = *pSrc++; + OPJ_UINT32 val8 = *pSrc++; + + pDst[i + 0] = (OPJ_INT32)((val0 << 1) | (val1 >> 7)); + pDst[i + 1] = (OPJ_INT32)(((val1 & 0x7FU) << 2) | (val2 >> 6)); + pDst[i + 2] = (OPJ_INT32)(((val2 & 0x3FU) << 3) | (val3 >> 5)); + pDst[i + 3] = (OPJ_INT32)(((val3 & 0x1FU) << 4) | (val4 >> 4)); + pDst[i + 4] = (OPJ_INT32)(((val4 & 0xFU) << 5) | (val5 >> 3)); + pDst[i + 5] = (OPJ_INT32)(((val5 & 0x7U) << 6) | (val6 >> 2)); + pDst[i + 6] = (OPJ_INT32)(((val6 & 0x3U) << 7) | (val7 >> 1)); + pDst[i + 7] = (OPJ_INT32)(((val7 & 0x1U) << 8) | (val8)); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i + 0], 9) + + if (length > 1U) { + GETBITS(pDst[i + 1], 9) + if (length > 2U) { + GETBITS(pDst[i + 2], 9) + if (length > 3U) { + GETBITS(pDst[i + 3], 9) + if (length > 4U) { + GETBITS(pDst[i + 4], 9) + if (length > 5U) { + GETBITS(pDst[i + 5], 9) + if (length > 6U) { + GETBITS(pDst[i + 6], 9) + } + } + } + } + } + } + } +} +static void tif_10uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i += 4U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + + pDst[i + 0] = (OPJ_INT32)((val0 << 2) | (val1 >> 6)); + pDst[i + 1] = (OPJ_INT32)(((val1 & 0x3FU) << 4) | (val2 >> 4)); + pDst[i + 2] = (OPJ_INT32)(((val2 & 0xFU) << 6) | (val3 >> 2)); + pDst[i + 3] = (OPJ_INT32)(((val3 & 0x3U) << 8) | val4); + + } + if (length & 3U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + length = length & 3U; + pDst[i + 0] = (OPJ_INT32)((val0 << 2) | (val1 >> 6)); + + if (length > 1U) { + OPJ_UINT32 val2 = *pSrc++; + pDst[i + 1] = (OPJ_INT32)(((val1 & 0x3FU) << 4) | (val2 >> 4)); + if (length > 2U) { + OPJ_UINT32 val3 = *pSrc++; + pDst[i + 2] = (OPJ_INT32)(((val2 & 0xFU) << 6) | (val3 >> 2)); + } + } + } +} +static void tif_11uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + OPJ_UINT32 val7 = *pSrc++; + OPJ_UINT32 val8 = *pSrc++; + OPJ_UINT32 val9 = *pSrc++; + OPJ_UINT32 val10 = *pSrc++; + + pDst[i + 0] = (OPJ_INT32)((val0 << 3) | (val1 >> 5)); + pDst[i + 1] = (OPJ_INT32)(((val1 & 0x1FU) << 6) | (val2 >> 2)); + pDst[i + 2] = (OPJ_INT32)(((val2 & 0x3U) << 9) | (val3 << 1) | (val4 >> 7)); + pDst[i + 3] = (OPJ_INT32)(((val4 & 0x7FU) << 4) | (val5 >> 4)); + pDst[i + 4] = (OPJ_INT32)(((val5 & 0xFU) << 7) | (val6 >> 1)); + pDst[i + 5] = (OPJ_INT32)(((val6 & 0x1U) << 10) | (val7 << 2) | (val8 >> 6)); + pDst[i + 6] = (OPJ_INT32)(((val8 & 0x3FU) << 5) | (val9 >> 3)); + pDst[i + 7] = (OPJ_INT32)(((val9 & 0x7U) << 8) | (val10)); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i + 0], 11) + + if (length > 1U) { + GETBITS(pDst[i + 1], 11) + if (length > 2U) { + GETBITS(pDst[i + 2], 11) + if (length > 3U) { + GETBITS(pDst[i + 3], 11) + if (length > 4U) { + GETBITS(pDst[i + 4], 11) + if (length > 5U) { + GETBITS(pDst[i + 5], 11) + if (length > 6U) { + GETBITS(pDst[i + 6], 11) + } + } + } + } + } + } + } +} +static void tif_12uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)1U); i += 2U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + + pDst[i + 0] = (OPJ_INT32)((val0 << 4) | (val1 >> 4)); + pDst[i + 1] = (OPJ_INT32)(((val1 & 0xFU) << 8) | val2); + } + if (length & 1U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + pDst[i + 0] = (OPJ_INT32)((val0 << 4) | (val1 >> 4)); + } +} +static void tif_13uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + OPJ_UINT32 val7 = *pSrc++; + OPJ_UINT32 val8 = *pSrc++; + OPJ_UINT32 val9 = *pSrc++; + OPJ_UINT32 val10 = *pSrc++; + OPJ_UINT32 val11 = *pSrc++; + OPJ_UINT32 val12 = *pSrc++; + + pDst[i + 0] = (OPJ_INT32)((val0 << 5) | (val1 >> 3)); + pDst[i + 1] = (OPJ_INT32)(((val1 & 0x7U) << 10) | (val2 << 2) | (val3 >> 6)); + pDst[i + 2] = (OPJ_INT32)(((val3 & 0x3FU) << 7) | (val4 >> 1)); + pDst[i + 3] = (OPJ_INT32)(((val4 & 0x1U) << 12) | (val5 << 4) | (val6 >> 4)); + pDst[i + 4] = (OPJ_INT32)(((val6 & 0xFU) << 9) | (val7 << 1) | (val8 >> 7)); + pDst[i + 5] = (OPJ_INT32)(((val8 & 0x7FU) << 6) | (val9 >> 2)); + pDst[i + 6] = (OPJ_INT32)(((val9 & 0x3U) << 11) | (val10 << 3) | (val11 >> 5)); + pDst[i + 7] = (OPJ_INT32)(((val11 & 0x1FU) << 8) | (val12)); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i + 0], 13) + + if (length > 1U) { + GETBITS(pDst[i + 1], 13) + if (length > 2U) { + GETBITS(pDst[i + 2], 13) + if (length > 3U) { + GETBITS(pDst[i + 3], 13) + if (length > 4U) { + GETBITS(pDst[i + 4], 13) + if (length > 5U) { + GETBITS(pDst[i + 5], 13) + if (length > 6U) { + GETBITS(pDst[i + 6], 13) + } + } + } + } + } + } + } +} +static void tif_14uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i += 4U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + + pDst[i + 0] = (OPJ_INT32)((val0 << 6) | (val1 >> 2)); + pDst[i + 1] = (OPJ_INT32)(((val1 & 0x3U) << 12) | (val2 << 4) | (val3 >> 4)); + pDst[i + 2] = (OPJ_INT32)(((val3 & 0xFU) << 10) | (val4 << 2) | (val5 >> 6)); + pDst[i + 3] = (OPJ_INT32)(((val5 & 0x3FU) << 8) | val6); + + } + if (length & 3U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + length = length & 3U; + pDst[i + 0] = (OPJ_INT32)((val0 << 6) | (val1 >> 2)); + + if (length > 1U) { + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + pDst[i + 1] = (OPJ_INT32)(((val1 & 0x3U) << 12) | (val2 << 4) | (val3 >> 4)); + if (length > 2U) { + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + pDst[i + 2] = (OPJ_INT32)(((val3 & 0xFU) << 10) | (val4 << 2) | (val5 >> 6)); + } + } + } +} +static void tif_15uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + OPJ_UINT32 val7 = *pSrc++; + OPJ_UINT32 val8 = *pSrc++; + OPJ_UINT32 val9 = *pSrc++; + OPJ_UINT32 val10 = *pSrc++; + OPJ_UINT32 val11 = *pSrc++; + OPJ_UINT32 val12 = *pSrc++; + OPJ_UINT32 val13 = *pSrc++; + OPJ_UINT32 val14 = *pSrc++; + + pDst[i + 0] = (OPJ_INT32)((val0 << 7) | (val1 >> 1)); + pDst[i + 1] = (OPJ_INT32)(((val1 & 0x1U) << 14) | (val2 << 6) | (val3 >> 2)); + pDst[i + 2] = (OPJ_INT32)(((val3 & 0x3U) << 13) | (val4 << 5) | (val5 >> 3)); + pDst[i + 3] = (OPJ_INT32)(((val5 & 0x7U) << 12) | (val6 << 4) | (val7 >> 4)); + pDst[i + 4] = (OPJ_INT32)(((val7 & 0xFU) << 11) | (val8 << 3) | (val9 >> 5)); + pDst[i + 5] = (OPJ_INT32)(((val9 & 0x1FU) << 10) | (val10 << 2) | (val11 >> 6)); + pDst[i + 6] = (OPJ_INT32)(((val11 & 0x3FU) << 9) | (val12 << 1) | (val13 >> 7)); + pDst[i + 7] = (OPJ_INT32)(((val13 & 0x7FU) << 8) | (val14)); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i + 0], 15) + + if (length > 1U) { + GETBITS(pDst[i + 1], 15) + if (length > 2U) { + GETBITS(pDst[i + 2], 15) + if (length > 3U) { + GETBITS(pDst[i + 3], 15) + if (length > 4U) { + GETBITS(pDst[i + 4], 15) + if (length > 5U) { + GETBITS(pDst[i + 5], 15) + if (length > 6U) { + GETBITS(pDst[i + 6], 15) + } + } + } + } + } + } + } +} + +/* seems that libtiff decodes this to machine endianness */ +static void tif_16uto32s(const OPJ_UINT16* pSrc, OPJ_INT32* pDst, + OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < length; i++) { + pDst[i] = pSrc[i]; + } +} + +/* + * libtiff/tif_getimage.c : 1,2,4,8,16 bitspersample accepted + * CINEMA : 12 bit precision + */ +opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) +{ + int subsampling_dx = parameters->subsampling_dx; + int subsampling_dy = parameters->subsampling_dy; + TIFF *tif; + tdata_t buf; + tstrip_t strip; + int64_t strip_size, rowStride, TIFF_MAX; + int j, currentPlane, numcomps = 0, w, h; + OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_UNKNOWN; + opj_image_cmptparm_t cmptparm[4]; /* RGBA */ + opj_image_t *image = NULL; + uint16 tiBps, tiPhoto, tiSf, tiSpp, tiPC; + uint32 tiWidth, tiHeight; + OPJ_BOOL is_cinema = OPJ_IS_CINEMA(parameters->rsiz); + convert_XXx32s_C1R cvtTifTo32s = NULL; + convert_32s_CXPX cvtCxToPx = NULL; + OPJ_INT32* buffer32s = NULL; + OPJ_INT32* planes[4]; + + tif = TIFFOpen(filename, "r"); + + if (!tif) { + fprintf(stderr, "tiftoimage:Failed to open %s for reading\n", filename); + return 0; + } + tiBps = tiPhoto = tiSf = tiSpp = tiPC = 0; + tiWidth = tiHeight = 0; + + TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &tiWidth); + TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &tiHeight); + TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &tiBps); + TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &tiSf); + TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &tiSpp); + TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &tiPhoto); + TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &tiPC); + w = (int)tiWidth; + h = (int)tiHeight; + + if (tiSpp == 0 || tiSpp > 4) { /* should be 1 ... 4 */ + fprintf(stderr, "tiftoimage: Bad value for samples per pixel == %d.\n" + "\tAborting.\n", tiSpp); + TIFFClose(tif); + return NULL; + } + if (tiBps > 16U || tiBps == 0) { + fprintf(stderr, "tiftoimage: Bad values for Bits == %d.\n" + "\tMax. 16 Bits are allowed here.\n\tAborting.\n", tiBps); + TIFFClose(tif); + return NULL; + } + if (tiPhoto != PHOTOMETRIC_MINISBLACK && tiPhoto != PHOTOMETRIC_RGB) { + fprintf(stderr, + "tiftoimage: Bad color format %d.\n\tOnly RGB(A) and GRAY(A) has been implemented\n\tAborting.\n", + (int) tiPhoto); + TIFFClose(tif); + return NULL; + } + if (tiWidth == 0 || tiHeight == 0) { + fprintf(stderr, "tiftoimage: Bad values for width(%u) " + "and/or height(%u)\n\tAborting.\n", tiWidth, tiHeight); + TIFFClose(tif); + return NULL; + } + w = (int)tiWidth; + h = (int)tiHeight; + + switch (tiBps) { + case 1: + case 2: + case 4: + case 6: + case 8: + cvtTifTo32s = convert_XXu32s_C1R_LUT[tiBps]; + break; + /* others are specific to TIFF */ + case 3: + cvtTifTo32s = tif_3uto32s; + break; + case 5: + cvtTifTo32s = tif_5uto32s; + break; + case 7: + cvtTifTo32s = tif_7uto32s; + break; + case 9: + cvtTifTo32s = tif_9uto32s; + break; + case 10: + cvtTifTo32s = tif_10uto32s; + break; + case 11: + cvtTifTo32s = tif_11uto32s; + break; + case 12: + cvtTifTo32s = tif_12uto32s; + break; + case 13: + cvtTifTo32s = tif_13uto32s; + break; + case 14: + cvtTifTo32s = tif_14uto32s; + break; + case 15: + cvtTifTo32s = tif_15uto32s; + break; + case 16: + cvtTifTo32s = (convert_XXx32s_C1R)tif_16uto32s; + break; + default: + /* never here */ + break; + } + + /* initialize image components */ + memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); + + if ((tiPhoto == PHOTOMETRIC_RGB) && (is_cinema) && (tiBps != 12U)) { + fprintf(stdout, "WARNING:\n" + "Input image bitdepth is %d bits\n" + "TIF conversion has automatically rescaled to 12-bits\n" + "to comply with cinema profiles.\n", + tiBps); + } else { + is_cinema = 0U; + } + + numcomps = tiSpp; + if (tiPhoto == PHOTOMETRIC_RGB) { /* RGB(A) */ + color_space = OPJ_CLRSPC_SRGB; + } else if (tiPhoto == PHOTOMETRIC_MINISBLACK) { /* GRAY(A) */ + color_space = OPJ_CLRSPC_GRAY; + } + + cvtCxToPx = convert_32s_CXPX_LUT[numcomps]; + if (tiPC == PLANARCONFIG_SEPARATE) { + cvtCxToPx = convert_32s_CXPX_LUT[1]; /* override */ + tiSpp = 1U; /* consider only one sample per plane */ + } + + for (j = 0; j < numcomps; j++) { + cmptparm[j].prec = tiBps; + cmptparm[j].bpp = tiBps; + cmptparm[j].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[j].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[j].w = (OPJ_UINT32)w; + cmptparm[j].h = (OPJ_UINT32)h; + } + + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); + if (!image) { + TIFFClose(tif); + return NULL; + } + /* set image offset and reference grid */ + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = !image->x0 ? (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1 : + image->x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1; + if (image->x1 <= image->x0) { + fprintf(stderr, "tiftoimage: Bad value for image->x1(%d) vs. " + "image->x0(%d)\n\tAborting.\n", image->x1, image->x0); + TIFFClose(tif); + opj_image_destroy(image); + return NULL; + } + image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 : + image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; + if (image->y1 <= image->y0) { + fprintf(stderr, "tiftoimage: Bad value for image->y1(%d) vs. " + "image->y0(%d)\n\tAborting.\n", image->y1, image->y0); + TIFFClose(tif); + opj_image_destroy(image); + return NULL; + } + + for (j = 0; j < numcomps; j++) { + planes[j] = image->comps[j].data; + } + image->comps[numcomps - 1].alpha = (OPJ_UINT16)(1 - (numcomps & 1)); + + strip_size = (int64_t)TIFFStripSize(tif); + + buf = malloc((OPJ_SIZE_T)strip_size); + if (buf == NULL) { + TIFFClose(tif); + opj_image_destroy(image); + return NULL; + } + if (sizeof(tsize_t) == 4) { + TIFF_MAX = INT_MAX; + } else { + TIFF_MAX = UINT_MAX; + } + if ((int64_t)tiWidth > (int64_t)(TIFF_MAX / tiSpp) || + (int64_t)(tiWidth * tiSpp) > (int64_t)(TIFF_MAX / tiBps) || + (int64_t)(tiWidth * tiSpp) > (int64_t)(TIFF_MAX / (int64_t)sizeof(OPJ_INT32))) { + fprintf(stderr, "Buffer overflow\n"); + _TIFFfree(buf); + TIFFClose(tif); + opj_image_destroy(image); + return NULL; + } + + rowStride = (int64_t)((tiWidth * tiSpp * tiBps + 7U) / 8U); + buffer32s = (OPJ_INT32 *)malloc(sizeof(OPJ_INT32) * tiWidth * tiSpp); + if (buffer32s == NULL) { + _TIFFfree(buf); + TIFFClose(tif); + opj_image_destroy(image); + return NULL; + } + + strip = 0; + currentPlane = 0; + do { + planes[0] = image->comps[currentPlane].data; /* to manage planar data */ + h = (int)tiHeight; + /* Read the Image components */ + for (; (h > 0) && (strip < TIFFNumberOfStrips(tif)); strip++) { + const OPJ_UINT8 *dat8; + int64_t ssize; + + ssize = (int64_t)TIFFReadEncodedStrip(tif, strip, buf, (tsize_t)strip_size); + + if (ssize < 1 || ssize > strip_size) { + fprintf(stderr, "tiftoimage: Bad value for ssize(%" PRId64 ") " + "vs. strip_size(%" PRId64 ").\n\tAborting.\n", ssize, strip_size); + _TIFFfree(buf); + _TIFFfree(buffer32s); + TIFFClose(tif); + opj_image_destroy(image); + return NULL; + } + dat8 = (const OPJ_UINT8*)buf; + + while (ssize >= rowStride) { + cvtTifTo32s(dat8, buffer32s, (OPJ_SIZE_T)w * tiSpp); + cvtCxToPx(buffer32s, planes, (OPJ_SIZE_T)w); + planes[0] += w; + planes[1] += w; + planes[2] += w; + planes[3] += w; + dat8 += rowStride; + ssize -= rowStride; + h--; + } + } + currentPlane++; + } while ((tiPC == PLANARCONFIG_SEPARATE) && (currentPlane < numcomps)); + + free(buffer32s); + _TIFFfree(buf); + TIFFClose(tif); + + if (is_cinema) { + for (j = 0; j < numcomps; ++j) { + scale_component(&(image->comps[j]), 12); + } + + } + return image; + +}/* tiftoimage() */ + diff --git a/src/bin/jp2/index.c b/src/bin/jp2/index.c new file mode 100644 index 0000000..3eae2f9 --- /dev/null +++ b/src/bin/jp2/index.c @@ -0,0 +1,456 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include "openjpeg.h" +#include "index.h" +#include "opj_inttypes.h" + +/* ------------------------------------------------------------------------------------ */ + +/** +Write a structured index to a file +@param cstr_info Codestream information +@param index Index filename +@return Returns 0 if successful, returns 1 otherwise +*/ +int write_index_file(opj_codestream_info_t *cstr_info, char *index) +{ + int tileno, compno, layno, resno, precno, pack_nb, x, y; + FILE *stream = NULL; + double total_disto = 0; + /* UniPG>> */ + int tilepartno; + char disto_on, numpix_on; + +#ifdef USE_JPWL + if (!strcmp(index, JPWL_PRIVATEINDEX_NAME)) { + return 0; + } +#endif /* USE_JPWL */ + /* <tile[0].distotile > 0.0) { + disto_on = 1; + } else { + disto_on = 0; + } + + if (cstr_info->tile[0].numpix) { + numpix_on = 1; + } else { + numpix_on = 0; + } + + fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h); + fprintf(stream, "%d\n", cstr_info->prog); + fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y); + fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th); + fprintf(stream, "%d\n", cstr_info->numcomps); + fprintf(stream, "%d\n", cstr_info->numlayers); + fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */ + + for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) { + fprintf(stream, "[%d,%d] ", + (1 << cstr_info->tile[0].pdx[resno]), + (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */ + } + + fprintf(stream, "\n"); + /* UniPG>> */ + fprintf(stream, "%d\n", cstr_info->main_head_start); + /* <main_head_end); + fprintf(stream, "%d\n", cstr_info->codestream_size); + + fprintf(stream, "\nINFO ON TILES\n"); + fprintf(stream, "tileno start_pos end_hd end_tile nbparts"); + if (disto_on) { + fprintf(stream, " disto"); + } + if (numpix_on) { + fprintf(stream, " nbpix"); + } + if (disto_on && numpix_on) { + fprintf(stream, " disto/nbpix"); + } + fprintf(stream, "\n"); + + for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { + fprintf(stream, "%4d %9d %9d %9d %9d", + cstr_info->tile[tileno].tileno, + cstr_info->tile[tileno].start_pos, + cstr_info->tile[tileno].end_header, + cstr_info->tile[tileno].end_pos, + cstr_info->tile[tileno].num_tps); + if (disto_on) { + fprintf(stream, " %9e", cstr_info->tile[tileno].distotile); + } + if (numpix_on) { + fprintf(stream, " %9d", cstr_info->tile[tileno].numpix); + } + if (disto_on && numpix_on) { + fprintf(stream, " %9e", cstr_info->tile[tileno].distotile / + cstr_info->tile[tileno].numpix); + } + fprintf(stream, "\n"); + } + + for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { + OPJ_OFF_T start_pos, end_ph_pos, end_pos; + double disto = 0; + int max_numdecompos = 0; + pack_nb = 0; + + for (compno = 0; compno < cstr_info->numcomps; compno++) { + if (max_numdecompos < cstr_info->numdecompos[compno]) { + max_numdecompos = cstr_info->numdecompos[compno]; + } + } + + fprintf(stream, "\nTILE %d DETAILS\n", tileno); + fprintf(stream, + "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n"); + for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++) + fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n", + tilepartno, tileno, + cstr_info->tile[tileno].tp[tilepartno].tp_start_pack, + cstr_info->tile[tileno].tp[tilepartno].tp_numpacks, + cstr_info->tile[tileno].tp[tilepartno].tp_start_pos, + cstr_info->tile[tileno].tp[tilepartno].tp_end_header, + cstr_info->tile[tileno].tp[tilepartno].tp_end_pos + ); + + if (cstr_info->prog == OPJ_LRCP) { /* LRCP */ + fprintf(stream, + "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos"); + if (disto_on) { + fprintf(stream, " disto"); + } + fprintf(stream, "\n"); + + for (layno = 0; layno < cstr_info->numlayers; layno++) { + for (resno = 0; resno < max_numdecompos + 1; resno++) { + for (compno = 0; compno < cstr_info->numcomps; compno++) { + int prec_max; + if (resno > cstr_info->numdecompos[compno]) { + break; + } + prec_max = cstr_info->tile[tileno].pw[resno] * + cstr_info->tile[tileno].ph[resno]; + for (precno = 0; precno < prec_max; precno++) { + start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; + end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; + end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; + disto = cstr_info->tile[tileno].packet[pack_nb].disto; + fprintf(stream, "%4d %6d %7d %5d %6d %6d %6" PRId64 " %6" PRId64 " %7" + PRId64, + pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos); + if (disto_on) { + fprintf(stream, " %8e", disto); + } + fprintf(stream, "\n"); + total_disto += disto; + pack_nb++; + } + } + } + } + } /* LRCP */ + + else if (cstr_info->prog == OPJ_RLCP) { /* RLCP */ + fprintf(stream, + "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n"); + if (disto_on) { + fprintf(stream, " disto"); + } + fprintf(stream, "\n"); + + for (resno = 0; resno < max_numdecompos + 1; resno++) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { + for (compno = 0; compno < cstr_info->numcomps; compno++) { + int prec_max; + if (resno > cstr_info->numdecompos[compno]) { + break; + } + prec_max = cstr_info->tile[tileno].pw[resno] * + cstr_info->tile[tileno].ph[resno]; + for (precno = 0; precno < prec_max; precno++) { + start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; + end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; + end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; + disto = cstr_info->tile[tileno].packet[pack_nb].disto; + fprintf(stream, "%4d %6d %5d %7d %6d %6d %9" PRId64 " %9" PRId64 " %7" PRId64, + pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos); + if (disto_on) { + fprintf(stream, " %8e", disto); + } + fprintf(stream, "\n"); + total_disto += disto; + pack_nb++; + } + } + } + } + } /* RLCP */ + + else if (cstr_info->prog == OPJ_RPCL) { /* RPCL */ + + fprintf(stream, + "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos"); + if (disto_on) { + fprintf(stream, " disto"); + } + fprintf(stream, "\n"); + + for (resno = 0; resno < max_numdecompos + 1; resno++) { + int numprec = cstr_info->tile[tileno].pw[resno] * + cstr_info->tile[tileno].ph[resno]; + for (precno = 0; precno < numprec; precno++) { + /* I suppose components have same XRsiz, YRsiz */ + int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno / + (float)cstr_info->tw) * cstr_info->tw * cstr_info->tile_x; + int y0 = cstr_info->tile_Ox + (int)floor((float)tileno / + (float)cstr_info->tw) * cstr_info->tile_y; + int x1 = x0 + cstr_info->tile_x; + int y1 = y0 + cstr_info->tile_y; + for (compno = 0; compno < cstr_info->numcomps; compno++) { + int pcnx = cstr_info->tile[tileno].pw[resno]; + int pcx = (int) pow(2, cstr_info->tile[tileno].pdx[resno] + + cstr_info->numdecompos[compno] - resno); + int pcy = (int) pow(2, cstr_info->tile[tileno].pdy[resno] + + cstr_info->numdecompos[compno] - resno); + int precno_x = precno - (int) floor((float)precno / (float)pcnx) * pcnx; + int precno_y = (int) floor((float)precno / (float)pcnx); + if (resno > cstr_info->numdecompos[compno]) { + break; + } + for (y = y0; y < y1; y++) { + if (precno_y * pcy == y) { + for (x = x0; x < x1; x++) { + if (precno_x * pcx == x) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { + start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; + end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; + end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; + disto = cstr_info->tile[tileno].packet[pack_nb].disto; + fprintf(stream, "%4d %6d %5d %6d %6d %7d %9" PRId64 " %9" PRId64 " %7" PRId64, + pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos); + if (disto_on) { + fprintf(stream, " %8e", disto); + } + fprintf(stream, "\n"); + total_disto += disto; + pack_nb++; + } + } + }/* x = x0..x1 */ + } + } /* y = y0..y1 */ + } /* precno */ + } /* compno */ + } /* resno */ + } /* RPCL */ + + else if (cstr_info->prog == OPJ_PCRL) { /* PCRL */ + /* I suppose components have same XRsiz, YRsiz */ + int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno / + (float)cstr_info->tw) * cstr_info->tw * cstr_info->tile_x; + int y0 = cstr_info->tile_Ox + (int)floor((float)tileno / + (float)cstr_info->tw) * cstr_info->tile_y; + int x1 = x0 + cstr_info->tile_x; + int y1 = y0 + cstr_info->tile_y; + + /* Count the maximum number of precincts */ + int max_numprec = 0; + for (resno = 0; resno < max_numdecompos + 1; resno++) { + int numprec = cstr_info->tile[tileno].pw[resno] * + cstr_info->tile[tileno].ph[resno]; + if (numprec > max_numprec) { + max_numprec = numprec; + } + } + + fprintf(stream, + "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos"); + if (disto_on) { + fprintf(stream, " disto"); + } + fprintf(stream, "\n"); + + for (precno = 0; precno < max_numprec; precno++) { + for (compno = 0; compno < cstr_info->numcomps; compno++) { + for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { + int numprec = cstr_info->tile[tileno].pw[resno] * + cstr_info->tile[tileno].ph[resno]; + int pcnx = cstr_info->tile[tileno].pw[resno]; + int pcx = (int) pow(2, cstr_info->tile[tileno].pdx[resno] + + cstr_info->numdecompos[compno] - resno); + int pcy = (int) pow(2, cstr_info->tile[tileno].pdy[resno] + + cstr_info->numdecompos[compno] - resno); + int precno_x = precno - (int) floor((float)precno / (float)pcnx) * pcnx; + int precno_y = (int) floor((float)precno / (float)pcnx); + if (precno >= numprec) { + continue; + } + for (y = y0; y < y1; y++) { + if (precno_y * pcy == y) { + for (x = x0; x < x1; x++) { + if (precno_x * pcx == x) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { + start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; + end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; + end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; + disto = cstr_info->tile[tileno].packet[pack_nb].disto; + fprintf(stream, "%4d %6d %6d %6d %5d %7d %9" PRId64 " %9" PRId64 " %7" PRId64, + pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos); + if (disto_on) { + fprintf(stream, " %8e", disto); + } + fprintf(stream, "\n"); + total_disto += disto; + pack_nb++; + } + } + }/* x = x0..x1 */ + } + } /* y = y0..y1 */ + } /* resno */ + } /* compno */ + } /* precno */ + } /* PCRL */ + + else { /* CPRL */ + /* Count the maximum number of precincts */ + int max_numprec = 0; + for (resno = 0; resno < max_numdecompos + 1; resno++) { + int numprec = cstr_info->tile[tileno].pw[resno] * + cstr_info->tile[tileno].ph[resno]; + if (numprec > max_numprec) { + max_numprec = numprec; + } + } + + fprintf(stream, + "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos"); + if (disto_on) { + fprintf(stream, " disto"); + } + fprintf(stream, "\n"); + + for (compno = 0; compno < cstr_info->numcomps; compno++) { + /* I suppose components have same XRsiz, YRsiz */ + int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno / + (float)cstr_info->tw) * cstr_info->tw * cstr_info->tile_x; + int y0 = cstr_info->tile_Ox + (int)floor((float)tileno / + (float)cstr_info->tw) * cstr_info->tile_y; + int x1 = x0 + cstr_info->tile_x; + int y1 = y0 + cstr_info->tile_y; + + for (precno = 0; precno < max_numprec; precno++) { + for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { + int numprec = cstr_info->tile[tileno].pw[resno] * + cstr_info->tile[tileno].ph[resno]; + int pcnx = cstr_info->tile[tileno].pw[resno]; + int pcx = (int) pow(2, cstr_info->tile[tileno].pdx[resno] + + cstr_info->numdecompos[compno] - resno); + int pcy = (int) pow(2, cstr_info->tile[tileno].pdy[resno] + + cstr_info->numdecompos[compno] - resno); + int precno_x = precno - (int) floor((float)precno / (float)pcnx) * pcnx; + int precno_y = (int) floor((float)precno / (float)pcnx); + if (precno >= numprec) { + continue; + } + + for (y = y0; y < y1; y++) { + if (precno_y * pcy == y) { + for (x = x0; x < x1; x++) { + if (precno_x * pcx == x) { + for (layno = 0; layno < cstr_info->numlayers; layno++) { + start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; + end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; + end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; + disto = cstr_info->tile[tileno].packet[pack_nb].disto; + fprintf(stream, "%4d %6d %6d %6d %5d %7d %9" PRId64 " %9" PRId64 " %7" PRId64, + pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos); + if (disto_on) { + fprintf(stream, " %8e", disto); + } + fprintf(stream, "\n"); + total_disto += disto; + pack_nb++; + } + } + }/* x = x0..x1 */ + } + } /* y = y0..y1 */ + } /* resno */ + } /* precno */ + } /* compno */ + } /* CPRL */ + } /* tileno */ + + if (disto_on) { + fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */ + fprintf(stream, "%.8e\n", total_disto); /* SE totale */ + } + /* UniPG>> */ + /* print the markers' list */ + if (cstr_info->marknum) { + fprintf(stream, "\nMARKER LIST\n"); + fprintf(stream, "%d\n", cstr_info->marknum); + fprintf(stream, "type\tstart_pos length\n"); + for (x = 0; x < cstr_info->marknum; x++) { + fprintf(stream, "%X\t%9" PRId64 " %9d\n", cstr_info->marker[x].type, + cstr_info->marker[x].pos, cstr_info->marker[x].len); + } + } + /* < + * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France + * Copyright (c) 2012, CS Systemes d'Information, France + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include "windirent.h" +#else +#include +#endif /* _WIN32 */ + +#ifdef _WIN32 +#include +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#else +#include +#include +#include +#include +#endif /* _WIN32 */ + +#include "opj_apps_config.h" +#include "openjpeg.h" +#include "opj_getopt.h" +#include "convert.h" +#include "index.h" + +#include "format_defs.h" +#include "opj_string.h" + +typedef struct dircnt { + /** Buffer for holding images read from Directory*/ + char *filename_buf; + /** Pointer to the buffer*/ + char **filename; +} dircnt_t; + +typedef struct img_folder { + /** The directory path of the folder containing input images*/ + char *imgdirpath; + /** Output format*/ + char *out_format; + /** Enable option*/ + char set_imgdir; + /** Enable Cod Format for output*/ + char set_out_format; +} img_fol_t; + +static void encode_help_display(void) +{ + fprintf(stdout, + "\nThis is the opj_compress utility from the OpenJPEG project.\n" + "It compresses various image formats with the JPEG 2000 algorithm.\n" + "It has been compiled against openjp2 library v%s.\n\n", opj_version()); + + fprintf(stdout, "Default encoding options:\n"); + fprintf(stdout, "-------------------------\n"); + fprintf(stdout, "\n"); + fprintf(stdout, " * Lossless\n"); + fprintf(stdout, " * 1 tile\n"); + fprintf(stdout, " * RGB->YCC conversion if at least 3 components\n"); + fprintf(stdout, " * Size of precinct : 2^15 x 2^15 (means 1 precinct)\n"); + fprintf(stdout, " * Size of code-block : 64 x 64\n"); + fprintf(stdout, " * Number of resolutions: 6\n"); + fprintf(stdout, " * No SOP marker in the codestream\n"); + fprintf(stdout, " * No EPH marker in the codestream\n"); + fprintf(stdout, " * No sub-sampling in x or y direction\n"); + fprintf(stdout, " * No mode switch activated\n"); + fprintf(stdout, " * Progression order: LRCP\n"); +#ifdef FIXME_INDEX + fprintf(stdout, " * No index file\n"); +#endif /* FIXME_INDEX */ + fprintf(stdout, " * No ROI upshifted\n"); + fprintf(stdout, " * No offset of the origin of the image\n"); + fprintf(stdout, " * No offset of the origin of the tiles\n"); + fprintf(stdout, " * Reversible DWT 5-3\n"); + /* UniPG>> */ +#ifdef USE_JPWL + fprintf(stdout, " * No JPWL protection\n"); +#endif /* USE_JPWL */ + /* <\n"); + fprintf(stdout, " Input file\n"); + fprintf(stdout, + " Known extensions are \n"); + fprintf(stdout, " If used, '-o ' must be provided\n"); + fprintf(stdout, "-o \n"); + fprintf(stdout, " Output file (accepted extensions are j2k or jp2).\n"); + fprintf(stdout, "-ImgDir \n"); + fprintf(stdout, " Image file Directory path (example ../Images) \n"); + fprintf(stdout, " When using this option -OutFor must be used\n"); + fprintf(stdout, "-OutFor \n"); + fprintf(stdout, " Output format for compressed files.\n"); + fprintf(stdout, " Required only if -ImgDir is used\n"); + fprintf(stdout, + "-F ,,,,{s,u}@x:...:x\n"); + fprintf(stdout, " Characteristics of the raw input image\n"); + fprintf(stdout, + " If subsampling is omitted, 1x1 is assumed for all components\n"); + fprintf(stdout, " Example: -F 512,512,3,8,u@1x1:2x2:2x2\n"); + fprintf(stdout, + " for raw 512x512 image with 4:2:0 subsampling\n"); + fprintf(stdout, " Required only if RAW or RAWL input file is provided.\n"); + fprintf(stdout, "\n"); + fprintf(stdout, "Optional Parameters:\n"); + fprintf(stdout, "\n"); + fprintf(stdout, "-h\n"); + fprintf(stdout, " Display the help information.\n"); + fprintf(stdout, "-r ,,...\n"); + fprintf(stdout, " Different compression ratios for successive layers.\n"); + fprintf(stdout, + " The rate specified for each quality level is the desired\n"); + fprintf(stdout, " compression factor (use 1 for lossless)\n"); + fprintf(stdout, " Decreasing ratios required.\n"); + fprintf(stdout, " Example: -r 20,10,1 means \n"); + fprintf(stdout, " quality layer 1: compress 20x, \n"); + fprintf(stdout, " quality layer 2: compress 10x \n"); + fprintf(stdout, " quality layer 3: compress lossless\n"); + fprintf(stdout, " Options -r and -q cannot be used together.\n"); + fprintf(stdout, "-q ,,,...\n"); + fprintf(stdout, " Different psnr for successive layers (-q 30,40,50).\n"); + fprintf(stdout, " Increasing PSNR values required, except 0 which can\n"); + fprintf(stdout, " be used for the last layer to indicate it is lossless.\n"); + fprintf(stdout, " Options -r and -q cannot be used together.\n"); + fprintf(stdout, "-n \n"); + fprintf(stdout, " Number of resolutions.\n"); + fprintf(stdout, + " It corresponds to the number of DWT decompositions +1. \n"); + fprintf(stdout, " Default: 6.\n"); + fprintf(stdout, "-b ,\n"); + fprintf(stdout, + " Code-block size. The dimension must respect the constraint \n"); + fprintf(stdout, + " defined in the JPEG-2000 standard (no dimension smaller than 4 \n"); + fprintf(stdout, + " or greater than 1024, no code-block with more than 4096 coefficients).\n"); + fprintf(stdout, " The maximum value authorized is 64x64. \n"); + fprintf(stdout, " Default: 64x64.\n"); + fprintf(stdout, + "-c [,],[,],...\n"); + fprintf(stdout, " Precinct size. Values specified must be power of 2. \n"); + fprintf(stdout, + " Multiple records may be supplied, in which case the first record refers\n"); + fprintf(stdout, + " to the highest resolution level and subsequent records to lower \n"); + fprintf(stdout, + " resolution levels. The last specified record is halved successively for each \n"); + fprintf(stdout, " remaining lower resolution levels.\n"); + fprintf(stdout, " Default: 2^15x2^15 at each resolution.\n"); + fprintf(stdout, "-t ,\n"); + fprintf(stdout, " Tile size.\n"); + fprintf(stdout, + " Default: the dimension of the whole image, thus only one tile.\n"); + fprintf(stdout, "-p \n"); + fprintf(stdout, " Progression order.\n"); + fprintf(stdout, " Default: LRCP.\n"); + fprintf(stdout, "-s \n"); + fprintf(stdout, " Subsampling factor.\n"); + fprintf(stdout, " Subsampling bigger than 2 can produce error\n"); + fprintf(stdout, " Default: no subsampling.\n"); + fprintf(stdout, + "-POC //...\n"); + fprintf(stdout, " Progression order change.\n"); + fprintf(stdout, + " The syntax of a progression order change is the following:\n"); + fprintf(stdout, + " T=,,,,,\n"); + fprintf(stdout, " Example: -POC T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL\n"); + fprintf(stdout, "-SOP\n"); + fprintf(stdout, " Write SOP marker before each packet.\n"); + fprintf(stdout, "-EPH\n"); + fprintf(stdout, " Write EPH marker after each header packet.\n"); + fprintf(stdout, "-M \n"); + fprintf(stdout, " Mode switch.\n"); + fprintf(stdout, " [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n"); + fprintf(stdout, " 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)]\n"); + fprintf(stdout, " Indicate multiple modes by adding their values.\n"); + fprintf(stdout, + " Example: RESTART(4) + RESET(2) + SEGMARK(32) => -M 38\n"); + fprintf(stdout, "-TP \n"); + fprintf(stdout, " Divide packets of every tile into tile-parts.\n"); + fprintf(stdout, + " Division is made by grouping Resolutions (R), Layers (L)\n"); + fprintf(stdout, " or Components (C).\n"); +#ifdef FIXME_INDEX + fprintf(stdout, "-x \n"); + fprintf(stdout, " Create an index file.\n"); +#endif /*FIXME_INDEX*/ + fprintf(stdout, "-ROI c=,U=\n"); + fprintf(stdout, " Quantization indices upshifted for a component. \n"); + fprintf(stdout, + " Warning: This option does not implement the usual ROI (Region of Interest).\n"); + fprintf(stdout, + " It should be understood as a 'Component of Interest'. It offers the \n"); + fprintf(stdout, + " possibility to upshift the value of a component during quantization step.\n"); + fprintf(stdout, + " The value after c= is the component number [0, 1, 2, ...] and the value \n"); + fprintf(stdout, + " after U= is the value of upshifting. U must be in the range [0, 37].\n"); + fprintf(stdout, "-d \n"); + fprintf(stdout, " Offset of the origin of the image.\n"); + fprintf(stdout, "-T \n"); + fprintf(stdout, " Offset of the origin of the tiles.\n"); + fprintf(stdout, "-I\n"); + fprintf(stdout, " Use the irreversible DWT 9-7.\n"); + fprintf(stdout, "-mct <0|1|2>\n"); + fprintf(stdout, + " Explicitly specifies if a Multiple Component Transform has to be used.\n"); + fprintf(stdout, " 0: no MCT ; 1: RGB->YCC conversion ; 2: custom MCT.\n"); + fprintf(stdout, + " If custom MCT, \"-m\" option has to be used (see hereunder).\n"); + fprintf(stdout, + " By default, RGB->YCC conversion is used if there are 3 components or more,\n"); + fprintf(stdout, " no conversion otherwise.\n"); + fprintf(stdout, "-m \n"); + fprintf(stdout, + " Use array-based MCT, values are coma separated, line by line\n"); + fprintf(stdout, + " No specific separators between lines, no space allowed between values.\n"); + fprintf(stdout, + " If this option is used, it automatically sets \"-mct\" option to 2.\n"); + fprintf(stdout, "-cinema2K <24|48>\n"); + fprintf(stdout, " Digital Cinema 2K profile compliant codestream.\n"); + fprintf(stdout, + " Need to specify the frames per second for a 2K resolution.\n"); + fprintf(stdout, " Only 24 or 48 fps are currently allowed.\n"); + fprintf(stdout, "-cinema4K\n"); + fprintf(stdout, " Digital Cinema 4K profile compliant codestream.\n"); + fprintf(stdout, " Frames per second not required. Default value is 24fps.\n"); + fprintf(stdout, "-jpip\n"); + fprintf(stdout, " Write jpip codestream index box in JP2 output file.\n"); + fprintf(stdout, " Currently supports only RPCL order.\n"); + fprintf(stdout, "-C \n"); + fprintf(stdout, " Add in the comment marker segment.\n"); + /* UniPG>> */ +#ifdef USE_JPWL + fprintf(stdout, "-W \n"); + fprintf(stdout, " Adoption of JPWL (Part 11) capabilities (-W params)\n"); + fprintf(stdout, + " The field can be written and repeated in any order:\n"); + fprintf(stdout, " [h<=type>,s<=method>,a=,...\n"); + fprintf(stdout, " ...,z=,g=,p<=type>]\n"); + fprintf(stdout, + " h selects the header error protection (EPB): 'type' can be\n"); + fprintf(stdout, + " [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n"); + fprintf(stdout, + " if 'tilepart' is absent, it is for main and tile headers\n"); + fprintf(stdout, " if 'tilepart' is present, it applies from that tile\n"); + fprintf(stdout, + " onwards, up to the next h<> spec, or to the last tilepart\n"); + fprintf(stdout, " in the codestream (max. %d specs)\n", + JPWL_MAX_NO_TILESPECS); + fprintf(stdout, + " p selects the packet error protection (EEP/UEP with EPBs)\n"); + fprintf(stdout, " to be applied to raw data: 'type' can be\n"); + fprintf(stdout, + " [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n"); + fprintf(stdout, + " if 'tilepart:pack' is absent, it is from tile 0, packet 0\n"); + fprintf(stdout, + " if 'tilepart:pack' is present, it applies from that tile\n"); + fprintf(stdout, + " and that packet onwards, up to the next packet spec\n"); + fprintf(stdout, + " or to the last packet in the last tilepart in the stream\n"); + fprintf(stdout, " (max. %d specs)\n", JPWL_MAX_NO_PACKSPECS); + fprintf(stdout, + " s enables sensitivity data insertion (ESD): 'method' can be\n"); + fprintf(stdout, + " [-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR\n"); + fprintf(stdout, " 4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED]\n"); + fprintf(stdout, " if 'tilepart' is absent, it is for main header only\n"); + fprintf(stdout, " if 'tilepart' is present, it applies from that tile\n"); + fprintf(stdout, + " onwards, up to the next s<> spec, or to the last tilepart\n"); + fprintf(stdout, " in the codestream (max. %d specs)\n", + JPWL_MAX_NO_TILESPECS); + fprintf(stdout, " g determines the addressing mode: can be\n"); + fprintf(stdout, " [0=PACKET 1=BYTE RANGE 2=PACKET RANGE]\n"); + fprintf(stdout, + " a determines the size of data addressing: can be\n"); + fprintf(stdout, + " 2/4 bytes (small/large codestreams). If not set, auto-mode\n"); + fprintf(stdout, + " z determines the size of sensitivity values: can be\n"); + fprintf(stdout, + " 1/2 bytes, for the transformed pseudo-floating point value\n"); + fprintf(stdout, " ex.:\n"); + fprintf(stdout, + " h,h0=64,h3=16,h5=32,p0=78,p0:24=56,p1,p3:0=0,p3:20=32,s=0,\n"); + fprintf(stdout, " s0=6,s3=-1,a=0,g=1,z=1\n"); + fprintf(stdout, " means\n"); + fprintf(stdout, + " predefined EPB in MH, rs(64,32) from TPH 0 to TPH 2,\n"); + fprintf(stdout, + " CRC-16 in TPH 3 and TPH 4, CRC-32 in remaining TPHs,\n"); + fprintf(stdout, " UEP rs(78,32) for packets 0 to 23 of tile 0,\n"); + fprintf(stdout, + " UEP rs(56,32) for packs. 24 to the last of tilepart 0,\n"); + fprintf(stdout, " UEP rs default for packets of tilepart 1,\n"); + fprintf(stdout, " no UEP for packets 0 to 19 of tilepart 3,\n"); + fprintf(stdout, + " UEP CRC-32 for packs. 20 of tilepart 3 to last tilepart,\n"); + fprintf(stdout, " relative sensitivity ESD for MH,\n"); + fprintf(stdout, + " TSE ESD from TPH 0 to TPH 2, byte range with automatic\n"); + fprintf(stdout, + " size of addresses and 1 byte for each sensitivity value\n"); + fprintf(stdout, " ex.:\n"); + fprintf(stdout, " h,s,p\n"); + fprintf(stdout, " means\n"); + fprintf(stdout, + " default protection to headers (MH and TPHs) as well as\n"); + fprintf(stdout, " data packets, one ESD in MH\n"); + fprintf(stdout, + " N.B.: use the following recommendations when specifying\n"); + fprintf(stdout, " the JPWL parameters list\n"); + fprintf(stdout, + " - when you use UEP, always pair the 'p' option with 'h'\n"); +#endif /* USE_JPWL */ + /* <d_name) == 0 || strcmp("..", content->d_name) == 0) { + continue; + } + num_images++; + } + closedir(dir); + return num_images; +} + +static int load_images(dircnt_t *dirptr, char *imgdirpath) +{ + DIR *dir; + struct dirent* content; + int i = 0; + + /*Reading the input images from given input directory*/ + + dir = opendir(imgdirpath); + if (!dir) { + fprintf(stderr, "Could not open Folder %s\n", imgdirpath); + return 1; + } else { + fprintf(stderr, "Folder opened successfully\n"); + } + + while ((content = readdir(dir)) != NULL) { + if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) { + continue; + } + + strcpy(dirptr->filename[i], content->d_name); + i++; + } + closedir(dir); + return 0; +} + +static int get_file_format(char *filename) +{ + unsigned int i; + static const char *extension[] = { + "pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc" + }; + static const int format[] = { + PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, J2K_CFMT, J2K_CFMT + }; + char * ext = strrchr(filename, '.'); + if (ext == NULL) { + return -1; + } + ext++; + for (i = 0; i < sizeof(format) / sizeof(*format); i++) { + if (strcasecmp(ext, extension[i]) == 0) { + return format[i]; + } + } + return -1; +} + +static char * get_file_name(char *name) +{ + char *fname = strtok(name, "."); + return fname; +} + +static char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol, + opj_cparameters_t *parameters) +{ + char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN], + outfilename[OPJ_PATH_LEN], temp_ofname[OPJ_PATH_LEN]; + char *temp_p, temp1[OPJ_PATH_LEN] = ""; + + strcpy(image_filename, dirptr->filename[imageno]); + fprintf(stderr, "File Number %d \"%s\"\n", imageno, image_filename); + parameters->decod_format = get_file_format(image_filename); + if (parameters->decod_format == -1) { + return 1; + } + sprintf(infilename, "%s/%s", img_fol->imgdirpath, image_filename); + if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), + infilename) != 0) { + return 1; + } + + /*Set output file*/ + strcpy(temp_ofname, get_file_name(image_filename)); + while ((temp_p = strtok(NULL, ".")) != NULL) { + strcat(temp_ofname, temp1); + sprintf(temp1, ".%s", temp_p); + } + if (img_fol->set_out_format == 1) { + sprintf(outfilename, "%s/%s.%s", img_fol->imgdirpath, temp_ofname, + img_fol->out_format); + if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), + outfilename) != 0) { + return 1; + } + } + return 0; +} + +/* ------------------------------------------------------------------------------------ */ + +static int parse_cmdline_encoder(int argc, char **argv, + opj_cparameters_t *parameters, + img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename, + size_t indexfilename_size) +{ + OPJ_UINT32 i, j; + int totlen, c; + opj_option_t long_option[] = { + {"cinema2K", REQ_ARG, NULL, 'w'}, + {"cinema4K", NO_ARG, NULL, 'y'}, + {"ImgDir", REQ_ARG, NULL, 'z'}, + {"TP", REQ_ARG, NULL, 'u'}, + {"SOP", NO_ARG, NULL, 'S'}, + {"EPH", NO_ARG, NULL, 'E'}, + {"OutFor", REQ_ARG, NULL, 'O'}, + {"POC", REQ_ARG, NULL, 'P'}, + {"ROI", REQ_ARG, NULL, 'R'}, + {"jpip", NO_ARG, NULL, 'J'}, + {"mct", REQ_ARG, NULL, 'Y'} + }; + + /* parse the command line */ + const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:" +#ifdef USE_JPWL + "W:" +#endif /* USE_JPWL */ + "h"; + + totlen = sizeof(long_option); + img_fol->set_out_format = 0; + raw_cp->rawWidth = 0; + + do { + c = opj_getopt_long(argc, argv, optlist, long_option, totlen); + if (c == -1) { + break; + } + switch (c) { + case 'i': { /* input file */ + char *infile = opj_optarg; + parameters->decod_format = get_file_format(infile); + switch (parameters->decod_format) { + case PGX_DFMT: + case PXM_DFMT: + case BMP_DFMT: + case TIF_DFMT: + case RAW_DFMT: + case RAWL_DFMT: + case TGA_DFMT: + case PNG_DFMT: + break; + default: + fprintf(stderr, + "[ERROR] Unknown input file format: %s \n" + " Known file formats are *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga\n", + infile); + return 1; + } + if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) { + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'o': { /* output file */ + char *outfile = opj_optarg; + parameters->cod_format = get_file_format(outfile); + switch (parameters->cod_format) { + case J2K_CFMT: + case JP2_CFMT: + break; + default: + fprintf(stderr, + "Unknown output format image %s [only *.j2k, *.j2c or *.jp2]!! \n", outfile); + return 1; + } + if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), + outfile) != 0) { + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + case 'O': { /* output format */ + char outformat[50]; + char *of = opj_optarg; + sprintf(outformat, ".%s", of); + img_fol->set_out_format = 1; + parameters->cod_format = get_file_format(outformat); + switch (parameters->cod_format) { + case J2K_CFMT: + case JP2_CFMT: + img_fol->out_format = opj_optarg; + break; + default: + fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n"); + return 1; + } + } + break; + + + /* ----------------------------------------------------- */ + + + case 'r': { /* rates rates/distorsion */ + char *s = opj_optarg; + parameters->tcp_numlayers = 0; + while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == + 1) { + parameters->tcp_numlayers++; + while (*s && *s != ',') { + s++; + } + if (!*s) { + break; + } + s++; + } + parameters->cp_disto_alloc = 1; + } + break; + + /* ----------------------------------------------------- */ + + + case 'F': { /* Raw image format parameters */ + OPJ_BOOL wrong = OPJ_FALSE; + char *substr1; + char *substr2; + char *sep; + char signo; + int width, height, bitdepth, ncomp; + OPJ_UINT32 len; + OPJ_BOOL raw_signed = OPJ_FALSE; + substr2 = strchr(opj_optarg, '@'); + if (substr2 == NULL) { + len = (OPJ_UINT32) strlen(opj_optarg); + } else { + len = (OPJ_UINT32)(substr2 - opj_optarg); + substr2++; /* skip '@' character */ + } + substr1 = (char*) malloc((len + 1) * sizeof(char)); + if (substr1 == NULL) { + return 1; + } + memcpy(substr1, opj_optarg, len); + substr1[len] = '\0'; + if (sscanf(substr1, "%d,%d,%d,%d,%c", &width, &height, &ncomp, &bitdepth, + &signo) == 5) { + if (signo == 's') { + raw_signed = OPJ_TRUE; + } else if (signo == 'u') { + raw_signed = OPJ_FALSE; + } else { + wrong = OPJ_TRUE; + } + } else { + wrong = OPJ_TRUE; + } + if (!wrong) { + int compno; + int lastdx = 1; + int lastdy = 1; + raw_cp->rawWidth = width; + raw_cp->rawHeight = height; + raw_cp->rawComp = ncomp; + raw_cp->rawBitDepth = bitdepth; + raw_cp->rawSigned = raw_signed; + raw_cp->rawComps = (raw_comp_cparameters_t*) malloc(((OPJ_UINT32)( + ncomp)) * sizeof(raw_comp_cparameters_t)); + if (raw_cp->rawComps == NULL) { + free(substr1); + return 1; + } + for (compno = 0; compno < ncomp && !wrong; compno++) { + if (substr2 == NULL) { + raw_cp->rawComps[compno].dx = lastdx; + raw_cp->rawComps[compno].dy = lastdy; + } else { + int dx, dy; + sep = strchr(substr2, ':'); + if (sep == NULL) { + if (sscanf(substr2, "%dx%d", &dx, &dy) == 2) { + lastdx = dx; + lastdy = dy; + raw_cp->rawComps[compno].dx = dx; + raw_cp->rawComps[compno].dy = dy; + substr2 = NULL; + } else { + wrong = OPJ_TRUE; + } + } else { + if (sscanf(substr2, "%dx%d:%s", &dx, &dy, substr2) == 3) { + raw_cp->rawComps[compno].dx = dx; + raw_cp->rawComps[compno].dy = dy; + } else { + wrong = OPJ_TRUE; + } + } + } + } + } + free(substr1); + if (wrong) { + fprintf(stderr, "\nError: invalid raw image parameters\n"); + fprintf(stderr, "Please use the Format option -F:\n"); + fprintf(stderr, + "-F ,,,,{s,u}@x:...:x\n"); + fprintf(stderr, + "If subsampling is omitted, 1x1 is assumed for all components\n"); + fprintf(stderr, + "Example: -i image.raw -o image.j2k -F 512,512,3,8,u@1x1:2x2:2x2\n"); + fprintf(stderr, " for raw 512x512 image with 4:2:0 subsampling\n"); + fprintf(stderr, "Aborting.\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'q': { /* add fixed_quality */ + char *s = opj_optarg; + while (sscanf(s, "%f", ¶meters->tcp_distoratio[parameters->tcp_numlayers]) + == 1) { + parameters->tcp_numlayers++; + while (*s && *s != ',') { + s++; + } + if (!*s) { + break; + } + s++; + } + parameters->cp_fixed_quality = 1; + } + break; + + /* dda */ + /* ----------------------------------------------------- */ + + case 'f': { /* mod fixed_quality (before : -q) */ + int *row = NULL, *col = NULL; + OPJ_UINT32 numlayers = 0, numresolution = 0, matrix_width = 0; + + char *s = opj_optarg; + sscanf(s, "%u", &numlayers); + s++; + if (numlayers > 9) { + s++; + } + + parameters->tcp_numlayers = (int)numlayers; + numresolution = (OPJ_UINT32)parameters->numresolution; + matrix_width = numresolution * 3; + parameters->cp_matrice = (int *) malloc(sizeof(int) * numlayers * matrix_width); + if (parameters->cp_matrice == NULL) { + return 1; + } + s = s + 2; + + for (i = 0; i < numlayers; i++) { + row = ¶meters->cp_matrice[i * matrix_width]; + col = row; + parameters->tcp_rates[i] = 1; + sscanf(s, "%d,", &col[0]); + s += 2; + if (col[0] > 9) { + s++; + } + col[1] = 0; + col[2] = 0; + for (j = 1; j < numresolution; j++) { + col += 3; + sscanf(s, "%d,%d,%d", &col[0], &col[1], &col[2]); + s += 6; + if (col[0] > 9) { + s++; + } + if (col[1] > 9) { + s++; + } + if (col[2] > 9) { + s++; + } + } + if (i < numlayers - 1) { + s++; + } + } + parameters->cp_fixed_alloc = 1; + } + break; + + /* ----------------------------------------------------- */ + + case 't': { /* tiles */ + sscanf(opj_optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy); + parameters->tile_size_on = OPJ_TRUE; + } + break; + + /* ----------------------------------------------------- */ + + case 'n': { /* resolution */ + sscanf(opj_optarg, "%d", ¶meters->numresolution); + } + break; + + /* ----------------------------------------------------- */ + case 'c': { /* precinct dimension */ + char sep; + int res_spec = 0; + + char *s = opj_optarg; + int ret; + do { + sep = 0; + ret = sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec], + ¶meters->prch_init[res_spec], &sep); + if (!(ret == 2 && sep == 0) && !(ret == 3 && sep == ',')) { + fprintf(stderr, "\nError: could not parse precinct dimension: '%s' %x\n", s, + sep); + fprintf(stderr, "Example: -i lena.raw -o lena.j2k -c [128,128],[128,128]\n"); + return 1; + } + parameters->csty |= 0x01; + res_spec++; + s = strpbrk(s, "]") + 2; + } while (sep == ','); + parameters->res_spec = res_spec; + } + break; + + /* ----------------------------------------------------- */ + + case 'b': { /* code-block dimension */ + int cblockw_init = 0, cblockh_init = 0; + sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init); + if (cblockw_init > 1024 || cblockw_init < 4 || + cblockh_init > 1024 || cblockh_init < 4 || + cblockw_init * cblockh_init > 4096) { + fprintf(stderr, + "!! Size of code_block error (option -b) !!\n\nRestriction :\n" + " * width*height<=4096\n * 4<=width,height<= 1024\n\n"); + return 1; + } + parameters->cblockw_init = cblockw_init; + parameters->cblockh_init = cblockh_init; + } + break; + + /* ----------------------------------------------------- */ + + case 'x': { /* creation of index file */ + if (opj_strcpy_s(indexfilename, indexfilename_size, opj_optarg) != 0) { + return 1; + } + /* FIXME ADE INDEX >> */ + fprintf(stderr, + "[WARNING] Index file generation is currently broken.\n" + " '-x' option ignored.\n"); + /* << FIXME ADE INDEX */ + } + break; + + /* ----------------------------------------------------- */ + + case 'p': { /* progression order */ + char progression[4]; + + strncpy(progression, opj_optarg, 4); + parameters->prog_order = give_progression(progression); + if (parameters->prog_order == -1) { + fprintf(stderr, "Unrecognized progression order " + "[LRCP, RLCP, RPCL, PCRL, CPRL] !!\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 's': { /* subsampling factor */ + if (sscanf(opj_optarg, "%d,%d", ¶meters->subsampling_dx, + ¶meters->subsampling_dy) != 2) { + fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'd': { /* coordonnate of the reference grid */ + if (sscanf(opj_optarg, "%d,%d", ¶meters->image_offset_x0, + ¶meters->image_offset_y0) != 2) { + fprintf(stderr, "-d 'coordonnate of the reference grid' argument " + "error !! [-d x0,y0]\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'h': /* display an help description */ + encode_help_display(); + return 1; + + /* ----------------------------------------------------- */ + + case 'P': { /* POC */ + int numpocs = 0; /* number of progression order change (POC) default 0 */ + opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */ + + char *s = opj_optarg; + POC = parameters->POC; + + while (sscanf(s, "T%u=%u,%u,%u,%u,%u,%4s", &POC[numpocs].tile, + &POC[numpocs].resno0, &POC[numpocs].compno0, + &POC[numpocs].layno1, &POC[numpocs].resno1, + &POC[numpocs].compno1, POC[numpocs].progorder) == 7) { + POC[numpocs].prg1 = give_progression(POC[numpocs].progorder); + numpocs++; + while (*s && *s != '/') { + s++; + } + if (!*s) { + break; + } + s++; + } + parameters->numpocs = (OPJ_UINT32)numpocs; + } + break; + + /* ------------------------------------------------------ */ + + case 'S': { /* SOP marker */ + parameters->csty |= 0x02; + } + break; + + /* ------------------------------------------------------ */ + + case 'E': { /* EPH marker */ + parameters->csty |= 0x04; + } + break; + + /* ------------------------------------------------------ */ + + case 'M': { /* Mode switch pas tous au point !! */ + int value = 0; + if (sscanf(opj_optarg, "%d", &value) == 1) { + for (i = 0; i <= 5; i++) { + int cache = value & (1 << i); + if (cache) { + parameters->mode |= (1 << i); + } + } + } + } + break; + + /* ------------------------------------------------------ */ + + case 'R': { /* ROI */ + if (sscanf(opj_optarg, "c=%d,U=%d", ¶meters->roi_compno, + ¶meters->roi_shift) != 2) { + fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n"); + return 1; + } + } + break; + + /* ------------------------------------------------------ */ + + case 'T': { /* Tile offset */ + if (sscanf(opj_optarg, "%d,%d", ¶meters->cp_tx0, + ¶meters->cp_ty0) != 2) { + fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]"); + return 1; + } + } + break; + + /* ------------------------------------------------------ */ + + case 'C': { /* add a comment */ + parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1); + if (parameters->cp_comment) { + strcpy(parameters->cp_comment, opj_optarg); + } + } + break; + + + /* ------------------------------------------------------ */ + + case 'I': { /* reversible or not */ + parameters->irreversible = 1; + } + break; + + /* ------------------------------------------------------ */ + + case 'u': { /* Tile part generation*/ + parameters->tp_flag = opj_optarg[0]; + parameters->tp_on = 1; + } + break; + + /* ------------------------------------------------------ */ + + case 'z': { /* Image Directory path */ + img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); + if (img_fol->imgdirpath == NULL) { + return 1; + } + strcpy(img_fol->imgdirpath, opj_optarg); + img_fol->set_imgdir = 1; + } + break; + + /* ------------------------------------------------------ */ + + case 'w': { /* Digital Cinema 2K profile compliance*/ + int fps = 0; + sscanf(opj_optarg, "%d", &fps); + if (fps == 24) { + parameters->rsiz = OPJ_PROFILE_CINEMA_2K; + parameters->max_comp_size = OPJ_CINEMA_24_COMP; + parameters->max_cs_size = OPJ_CINEMA_24_CS; + } else if (fps == 48) { + parameters->rsiz = OPJ_PROFILE_CINEMA_2K; + parameters->max_comp_size = OPJ_CINEMA_48_COMP; + parameters->max_cs_size = OPJ_CINEMA_48_CS; + } else { + fprintf(stderr, "Incorrect value!! must be 24 or 48\n"); + return 1; + } + fprintf(stdout, "CINEMA 2K profile activated\n" + "Other options specified could be overridden\n"); + + } + break; + + /* ------------------------------------------------------ */ + + case 'y': { /* Digital Cinema 4K profile compliance*/ + parameters->rsiz = OPJ_PROFILE_CINEMA_4K; + fprintf(stdout, "CINEMA 4K profile activated\n" + "Other options specified could be overridden\n"); + } + break; + + /* ------------------------------------------------------ */ + + case 'Y': { /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/ + int mct_mode = 0; + sscanf(opj_optarg, "%d", &mct_mode); + if (mct_mode < 0 || mct_mode > 2) { + fprintf(stderr, + "MCT incorrect value!! Current accepted values are 0, 1 or 2.\n"); + return 1; + } + parameters->tcp_mct = (char) mct_mode; + } + break; + + /* ------------------------------------------------------ */ + + + case 'm': { /* mct input file */ + char *lFilename = opj_optarg; + char *lMatrix; + char *lCurrentPtr ; + float *lCurrentDoublePtr; + float *lSpace; + int *l_int_ptr; + int lNbComp = 0, lTotalComp, lMctComp, i2; + size_t lStrLen, lStrFread; + + /* Open file */ + FILE * lFile = fopen(lFilename, "r"); + if (lFile == NULL) { + return 1; + } + + /* Set size of file and read its content*/ + fseek(lFile, 0, SEEK_END); + lStrLen = (size_t)ftell(lFile); + fseek(lFile, 0, SEEK_SET); + lMatrix = (char *) malloc(lStrLen + 1); + if (lMatrix == NULL) { + fclose(lFile); + return 1; + } + lStrFread = fread(lMatrix, 1, lStrLen, lFile); + fclose(lFile); + if (lStrLen != lStrFread) { + free(lMatrix); + return 1; + } + + lMatrix[lStrLen] = 0; + lCurrentPtr = lMatrix; + + /* replace ',' by 0 */ + while (*lCurrentPtr != 0) { + if (*lCurrentPtr == ' ') { + *lCurrentPtr = 0; + ++lNbComp; + } + ++lCurrentPtr; + } + ++lNbComp; + lCurrentPtr = lMatrix; + + lNbComp = (int)(sqrt(4 * lNbComp + 1) / 2. - 0.5); + lMctComp = lNbComp * lNbComp; + lTotalComp = lMctComp + lNbComp; + lSpace = (float *) malloc((size_t)lTotalComp * sizeof(float)); + if (lSpace == NULL) { + free(lMatrix); + return 1; + } + lCurrentDoublePtr = lSpace; + for (i2 = 0; i2 < lMctComp; ++i2) { + lStrLen = strlen(lCurrentPtr) + 1; + *lCurrentDoublePtr++ = (float) atof(lCurrentPtr); + lCurrentPtr += lStrLen; + } + + l_int_ptr = (int*) lCurrentDoublePtr; + for (i2 = 0; i2 < lNbComp; ++i2) { + lStrLen = strlen(lCurrentPtr) + 1; + *l_int_ptr++ = atoi(lCurrentPtr); + lCurrentPtr += lStrLen; + } + + /* TODO should not be here ! */ + opj_set_MCT(parameters, lSpace, (int *)(lSpace + lMctComp), + (OPJ_UINT32)lNbComp); + + /* Free memory*/ + free(lSpace); + free(lMatrix); + } + break; + + + /* ------------------------------------------------------ */ + + /* UniPG>> */ +#ifdef USE_JPWL + /* ------------------------------------------------------ */ + + case 'W': { /* JPWL capabilities switched on */ + char *token = NULL; + int hprot, pprot, sens, addr, size, range; + + /* we need to enable indexing */ + if (!indexfilename || !*indexfilename) { + if (opj_strcpy_s(indexfilename, indexfilename_size, + JPWL_PRIVATEINDEX_NAME) != 0) { + return 1; + } + } + + /* search for different protection methods */ + + /* break the option in comma points and parse the result */ + token = strtok(opj_optarg, ","); + while (token != NULL) { + + /* search header error protection method */ + if (*token == 'h') { + + static int tile = 0, tilespec = 0, lasttileno = 0; + + hprot = 1; /* predefined method */ + + if (sscanf(token, "h=%d", &hprot) == 1) { + /* Main header, specified */ + if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) || + ((hprot >= 37) && (hprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid main header protection method h = %d\n", + hprot); + return 1; + } + parameters->jpwl_hprot_MH = hprot; + + } else if (sscanf(token, "h%d=%d", &tile, &hprot) == 2) { + /* Tile part header, specified */ + if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) || + ((hprot >= 37) && (hprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid tile part header protection method h = %d\n", + hprot); + return 1; + } + if (tile < 0) { + fprintf(stderr, + "ERROR -> invalid tile part number on protection method t = %d\n", tile); + return 1; + } + if (tilespec < JPWL_MAX_NO_TILESPECS) { + parameters->jpwl_hprot_TPH_tileno[tilespec] = lasttileno = tile; + parameters->jpwl_hprot_TPH[tilespec++] = hprot; + } + + } else if (sscanf(token, "h%d", &tile) == 1) { + /* Tile part header, unspecified */ + if (tile < 0) { + fprintf(stderr, + "ERROR -> invalid tile part number on protection method t = %d\n", tile); + return 1; + } + if (tilespec < JPWL_MAX_NO_TILESPECS) { + parameters->jpwl_hprot_TPH_tileno[tilespec] = lasttileno = tile; + parameters->jpwl_hprot_TPH[tilespec++] = hprot; + } + + + } else if (!strcmp(token, "h")) { + /* Main header, unspecified */ + parameters->jpwl_hprot_MH = hprot; + + } else { + fprintf(stderr, "ERROR -> invalid protection method selection = %s\n", token); + return 1; + }; + + } + + /* search packet error protection method */ + if (*token == 'p') { + + static int pack = 0, tile = 0, packspec = 0; + + pprot = 1; /* predefined method */ + + if (sscanf(token, "p=%d", &pprot) == 1) { + /* Method for all tiles and all packets */ + if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || + ((pprot >= 37) && (pprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid default packet protection method p = %d\n", + pprot); + return 1; + } + parameters->jpwl_pprot_tileno[0] = 0; + parameters->jpwl_pprot_packno[0] = 0; + parameters->jpwl_pprot[0] = pprot; + + } else if (sscanf(token, "p%d=%d", &tile, &pprot) == 2) { + /* method specified from that tile on */ + if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || + ((pprot >= 37) && (pprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); + return 1; + } + if (tile < 0) { + fprintf(stderr, + "ERROR -> invalid tile part number on protection method p = %d\n", tile); + return 1; + } + if (packspec < JPWL_MAX_NO_PACKSPECS) { + parameters->jpwl_pprot_tileno[packspec] = tile; + parameters->jpwl_pprot_packno[packspec] = 0; + parameters->jpwl_pprot[packspec++] = pprot; + } + + } else if (sscanf(token, "p%d:%d=%d", &tile, &pack, &pprot) == 3) { + /* method fully specified from that tile and that packet on */ + if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || + ((pprot >= 37) && (pprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); + return 1; + } + if (tile < 0) { + fprintf(stderr, + "ERROR -> invalid tile part number on protection method p = %d\n", tile); + return 1; + } + if (pack < 0) { + fprintf(stderr, "ERROR -> invalid packet number on protection method p = %d\n", + pack); + return 1; + } + if (packspec < JPWL_MAX_NO_PACKSPECS) { + parameters->jpwl_pprot_tileno[packspec] = tile; + parameters->jpwl_pprot_packno[packspec] = pack; + parameters->jpwl_pprot[packspec++] = pprot; + } + + } else if (sscanf(token, "p%d:%d", &tile, &pack) == 2) { + /* default method from that tile and that packet on */ + if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || + ((pprot >= 37) && (pprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); + return 1; + } + if (tile < 0) { + fprintf(stderr, + "ERROR -> invalid tile part number on protection method p = %d\n", tile); + return 1; + } + if (pack < 0) { + fprintf(stderr, "ERROR -> invalid packet number on protection method p = %d\n", + pack); + return 1; + } + if (packspec < JPWL_MAX_NO_PACKSPECS) { + parameters->jpwl_pprot_tileno[packspec] = tile; + parameters->jpwl_pprot_packno[packspec] = pack; + parameters->jpwl_pprot[packspec++] = pprot; + } + + } else if (sscanf(token, "p%d", &tile) == 1) { + /* default from a tile on */ + if (tile < 0) { + fprintf(stderr, + "ERROR -> invalid tile part number on protection method p = %d\n", tile); + return 1; + } + if (packspec < JPWL_MAX_NO_PACKSPECS) { + parameters->jpwl_pprot_tileno[packspec] = tile; + parameters->jpwl_pprot_packno[packspec] = 0; + parameters->jpwl_pprot[packspec++] = pprot; + } + + + } else if (!strcmp(token, "p")) { + /* all default */ + parameters->jpwl_pprot_tileno[0] = 0; + parameters->jpwl_pprot_packno[0] = 0; + parameters->jpwl_pprot[0] = pprot; + + } else { + fprintf(stderr, "ERROR -> invalid protection method selection = %s\n", token); + return 1; + }; + + } + + /* search sensitivity method */ + if (*token == 's') { + + static int tile = 0, tilespec = 0, lasttileno = 0; + + sens = 0; /* predefined: relative error */ + + if (sscanf(token, "s=%d", &sens) == 1) { + /* Main header, specified */ + if ((sens < -1) || (sens > 7)) { + fprintf(stderr, "ERROR -> invalid main header sensitivity method s = %d\n", + sens); + return 1; + } + parameters->jpwl_sens_MH = sens; + + } else if (sscanf(token, "s%d=%d", &tile, &sens) == 2) { + /* Tile part header, specified */ + if ((sens < -1) || (sens > 7)) { + fprintf(stderr, "ERROR -> invalid tile part header sensitivity method s = %d\n", + sens); + return 1; + } + if (tile < 0) { + fprintf(stderr, + "ERROR -> invalid tile part number on sensitivity method t = %d\n", tile); + return 1; + } + if (tilespec < JPWL_MAX_NO_TILESPECS) { + parameters->jpwl_sens_TPH_tileno[tilespec] = lasttileno = tile; + parameters->jpwl_sens_TPH[tilespec++] = sens; + } + + } else if (sscanf(token, "s%d", &tile) == 1) { + /* Tile part header, unspecified */ + if (tile < 0) { + fprintf(stderr, + "ERROR -> invalid tile part number on sensitivity method t = %d\n", tile); + return 1; + } + if (tilespec < JPWL_MAX_NO_TILESPECS) { + parameters->jpwl_sens_TPH_tileno[tilespec] = lasttileno = tile; + parameters->jpwl_sens_TPH[tilespec++] = hprot; + } + + } else if (!strcmp(token, "s")) { + /* Main header, unspecified */ + parameters->jpwl_sens_MH = sens; + + } else { + fprintf(stderr, "ERROR -> invalid sensitivity method selection = %s\n", token); + return 1; + }; + + parameters->jpwl_sens_size = 2; /* 2 bytes for default size */ + } + + /* search addressing size */ + if (*token == 'a') { + + + addr = 0; /* predefined: auto */ + + if (sscanf(token, "a=%d", &addr) == 1) { + /* Specified */ + if ((addr != 0) && (addr != 2) && (addr != 4)) { + fprintf(stderr, "ERROR -> invalid addressing size a = %d\n", addr); + return 1; + } + parameters->jpwl_sens_addr = addr; + + } else if (!strcmp(token, "a")) { + /* default */ + parameters->jpwl_sens_addr = addr; /* auto for default size */ + + } else { + fprintf(stderr, "ERROR -> invalid addressing selection = %s\n", token); + return 1; + }; + + } + + /* search sensitivity size */ + if (*token == 'z') { + + + size = 1; /* predefined: 1 byte */ + + if (sscanf(token, "z=%d", &size) == 1) { + /* Specified */ + if ((size != 0) && (size != 1) && (size != 2)) { + fprintf(stderr, "ERROR -> invalid sensitivity size z = %d\n", size); + return 1; + } + parameters->jpwl_sens_size = size; + + } else if (!strcmp(token, "a")) { + /* default */ + parameters->jpwl_sens_size = size; /* 1 for default size */ + + } else { + fprintf(stderr, "ERROR -> invalid size selection = %s\n", token); + return 1; + }; + + } + + /* search range method */ + if (*token == 'g') { + + + range = 0; /* predefined: 0 (packet) */ + + if (sscanf(token, "g=%d", &range) == 1) { + /* Specified */ + if ((range < 0) || (range > 3)) { + fprintf(stderr, "ERROR -> invalid sensitivity range method g = %d\n", range); + return 1; + } + parameters->jpwl_sens_range = range; + + } else if (!strcmp(token, "g")) { + /* default */ + parameters->jpwl_sens_range = range; + + } else { + fprintf(stderr, "ERROR -> invalid range selection = %s\n", token); + return 1; + }; + + } + + /* next token or bust */ + token = strtok(NULL, ","); + }; + + + /* some info */ + fprintf(stdout, "Info: JPWL capabilities enabled\n"); + parameters->jpwl_epc_on = OPJ_TRUE; + + } + break; +#endif /* USE_JPWL */ + /* <jpip_on = OPJ_TRUE; + } + break; + /* ------------------------------------------------------ */ + + + default: + fprintf(stderr, "[WARNING] An invalid option has been ignored\n"); + break; + } + } while (c != -1); + + if (img_fol->set_imgdir == 1) { + if (!(parameters->infile[0] == 0)) { + fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together !!\n"); + return 1; + } + if (img_fol->set_out_format == 0) { + fprintf(stderr, + "[ERROR] When -ImgDir is used, -OutFor must be used !!\n"); + fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n"); + return 1; + } + if (!((parameters->outfile[0] == 0))) { + fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together !!\n"); + fprintf(stderr, "Specify OutputFormat using -OutFor !!\n"); + return 1; + } + } else { + if ((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { + fprintf(stderr, "[ERROR] Required parameters are missing\n" + "Example: %s -i image.pgm -o image.j2k\n", argv[0]); + fprintf(stderr, " Help: %s -h\n", argv[0]); + return 1; + } + } + + if ((parameters->decod_format == RAW_DFMT && raw_cp->rawWidth == 0) + || (parameters->decod_format == RAWL_DFMT && raw_cp->rawWidth == 0)) { + fprintf(stderr, "[ERROR] invalid raw image parameters\n"); + fprintf(stderr, "Please use the Format option -F:\n"); + fprintf(stderr, + "-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); + fprintf(stderr, "Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); + fprintf(stderr, "Aborting\n"); + return 1; + } + + if ((parameters->cp_disto_alloc || parameters->cp_fixed_alloc || + parameters->cp_fixed_quality) + && (!(parameters->cp_disto_alloc ^ parameters->cp_fixed_alloc ^ + parameters->cp_fixed_quality))) { + fprintf(stderr, "[ERROR] options -r -q and -f cannot be used together !!\n"); + return 1; + } /* mod fixed_quality */ + + + /* if no rate entered, lossless by default */ + /* Note: post v2.2.0, this is no longer necessary, but for released */ + /* versions at the time of writing, this is needed to avoid crashes */ + if (parameters->tcp_numlayers == 0) { + parameters->tcp_rates[0] = 0; + parameters->tcp_numlayers++; + parameters->cp_disto_alloc = 1; + } + + if ((parameters->cp_tx0 > parameters->image_offset_x0) || + (parameters->cp_ty0 > parameters->image_offset_y0)) { + fprintf(stderr, + "[ERROR] Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n", + parameters->cp_tx0, parameters->image_offset_x0, parameters->cp_ty0, + parameters->image_offset_y0); + return 1; + } + + for (i = 0; i < parameters->numpocs; i++) { + if (parameters->POC[i].prg == -1) { + fprintf(stderr, + "Unrecognized progression order in option -P (POC n %d) [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n", + i + 1); + } + } + + /* If subsampled image is provided, automatically disable MCT */ + if (((parameters->decod_format == RAW_DFMT) || + (parameters->decod_format == RAWL_DFMT)) + && (((raw_cp->rawComp > 1) && ((raw_cp->rawComps[1].dx > 1) || + (raw_cp->rawComps[1].dy > 1))) + || ((raw_cp->rawComp > 2) && ((raw_cp->rawComps[2].dx > 1) || + (raw_cp->rawComps[2].dy > 1))) + )) { + parameters->tcp_mct = 0; + } + + return 0; + +} + +/* -------------------------------------------------------------------------- */ + +/** +sample error debug callback expecting no client object +*/ +static void error_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[ERROR] %s", msg); +} +/** +sample warning debug callback expecting no client object +*/ +static void warning_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[WARNING] %s", msg); +} +/** +sample debug callback expecting no client object +*/ +static void info_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[INFO] %s", msg); +} + +OPJ_FLOAT64 opj_clock(void) +{ +#ifdef _WIN32 + /* _WIN32: use QueryPerformance (very accurate) */ + LARGE_INTEGER freq, t ; + /* freq is the clock speed of the CPU */ + QueryPerformanceFrequency(&freq) ; + /* cout << "freq = " << ((double) freq.QuadPart) << endl; */ + /* t is the high resolution performance counter (see MSDN) */ + QueryPerformanceCounter(& t) ; + return freq.QuadPart ? ((OPJ_FLOAT64) t.QuadPart / (OPJ_FLOAT64) freq.QuadPart) + : 0 ; +#else + /* Unix or Linux: use resource usage */ + struct rusage t; + OPJ_FLOAT64 procTime; + /* (1) Get the rusage data structure at this moment (man getrusage) */ + getrusage(0, &t); + /* (2) What is the elapsed time ? - CPU time = User time + System time */ + /* (2a) Get the seconds */ + procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec); + /* (2b) More precisely! Get the microseconds part ! */ + return (procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * + 1e-6) ; +#endif +} + + +/* -------------------------------------------------------------------------- */ +/** + * OPJ_COMPRESS MAIN + */ +/* -------------------------------------------------------------------------- */ +int main(int argc, char **argv) +{ + + opj_cparameters_t parameters; /* compression parameters */ + + opj_stream_t *l_stream = 00; + opj_codec_t* l_codec = 00; + opj_image_t *image = NULL; + raw_cparameters_t raw_cp; + OPJ_SIZE_T num_compressed_files = 0; + + char indexfilename[OPJ_PATH_LEN]; /* index file name */ + + unsigned int i, num_images, imageno; + img_fol_t img_fol; + dircnt_t *dirptr = NULL; + + int ret = 0; + + OPJ_BOOL bSuccess; + OPJ_BOOL bUseTiles = OPJ_FALSE; /* OPJ_TRUE */ + OPJ_UINT32 l_nb_tiles = 4; + OPJ_FLOAT64 t = opj_clock(); + + /* set encoding parameters to default values */ + opj_set_default_encoder_parameters(¶meters); + + /* Initialize indexfilename and img_fol */ + *indexfilename = 0; + memset(&img_fol, 0, sizeof(img_fol_t)); + + /* raw_cp initialization */ + raw_cp.rawBitDepth = 0; + raw_cp.rawComp = 0; + raw_cp.rawComps = 0; + raw_cp.rawHeight = 0; + raw_cp.rawSigned = 0; + raw_cp.rawWidth = 0; + + /* parse input and get user encoding parameters */ + parameters.tcp_mct = (char) + 255; /* This will be set later according to the input image or the provided option */ + if (parse_cmdline_encoder(argc, argv, ¶meters, &img_fol, &raw_cp, + indexfilename, sizeof(indexfilename)) == 1) { + ret = 1; + goto fin; + } + + /* Read directory if necessary */ + if (img_fol.set_imgdir == 1) { + num_images = get_num_images(img_fol.imgdirpath); + dirptr = (dircnt_t*)malloc(sizeof(dircnt_t)); + if (dirptr) { + dirptr->filename_buf = (char*)malloc(num_images * OPJ_PATH_LEN * sizeof( + char)); /* Stores at max 10 image file names*/ + dirptr->filename = (char**) malloc(num_images * sizeof(char*)); + if (!dirptr->filename_buf) { + ret = 0; + goto fin; + } + for (i = 0; i < num_images; i++) { + dirptr->filename[i] = dirptr->filename_buf + i * OPJ_PATH_LEN; + } + } + if (load_images(dirptr, img_fol.imgdirpath) == 1) { + ret = 0; + goto fin; + } + if (num_images == 0) { + fprintf(stdout, "Folder is empty\n"); + ret = 0; + goto fin; + } + } else { + num_images = 1; + } + /*Encoding image one by one*/ + for (imageno = 0; imageno < num_images; imageno++) { + image = NULL; + fprintf(stderr, "\n"); + + if (img_fol.set_imgdir == 1) { + if (get_next_file((int)imageno, dirptr, &img_fol, ¶meters)) { + fprintf(stderr, "skipping file...\n"); + continue; + } + } + + switch (parameters.decod_format) { + case PGX_DFMT: + break; + case PXM_DFMT: + break; + case BMP_DFMT: + break; + case TIF_DFMT: + break; + case RAW_DFMT: + case RAWL_DFMT: + break; + case TGA_DFMT: + break; + case PNG_DFMT: + break; + default: + fprintf(stderr, "skipping file...\n"); + continue; + } + + /* decode the source image */ + /* ----------------------- */ + + switch (parameters.decod_format) { + case PGX_DFMT: + image = pgxtoimage(parameters.infile, ¶meters); + if (!image) { + fprintf(stderr, "Unable to load pgx file\n"); + ret = 1; + goto fin; + } + break; + + case PXM_DFMT: + image = pnmtoimage(parameters.infile, ¶meters); + if (!image) { + fprintf(stderr, "Unable to load pnm file\n"); + ret = 1; + goto fin; + } + break; + + case BMP_DFMT: + image = bmptoimage(parameters.infile, ¶meters); + if (!image) { + fprintf(stderr, "Unable to load bmp file\n"); + ret = 1; + goto fin; + } + break; + +#ifdef OPJ_HAVE_LIBTIFF + case TIF_DFMT: + image = tiftoimage(parameters.infile, ¶meters); + if (!image) { + fprintf(stderr, "Unable to load tiff file\n"); + ret = 1; + goto fin; + } + break; +#endif /* OPJ_HAVE_LIBTIFF */ + + case RAW_DFMT: + image = rawtoimage(parameters.infile, ¶meters, &raw_cp); + if (!image) { + fprintf(stderr, "Unable to load raw file\n"); + ret = 1; + goto fin; + } + break; + + case RAWL_DFMT: + image = rawltoimage(parameters.infile, ¶meters, &raw_cp); + if (!image) { + fprintf(stderr, "Unable to load raw file\n"); + ret = 1; + goto fin; + } + break; + + case TGA_DFMT: + image = tgatoimage(parameters.infile, ¶meters); + if (!image) { + fprintf(stderr, "Unable to load tga file\n"); + ret = 1; + goto fin; + } + break; + +#ifdef OPJ_HAVE_LIBPNG + case PNG_DFMT: + image = pngtoimage(parameters.infile, ¶meters); + if (!image) { + fprintf(stderr, "Unable to load png file\n"); + ret = 1; + goto fin; + } + break; +#endif /* OPJ_HAVE_LIBPNG */ + } + + /* Can happen if input file is TIFF or PNG + * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined + */ + if (!image) { + fprintf(stderr, "Unable to load file: got no image\n"); + ret = 1; + goto fin; + } + + /* Decide if MCT should be used */ + if (parameters.tcp_mct == (char) + 255) { /* mct mode has not been set in commandline */ + parameters.tcp_mct = (image->numcomps >= 3) ? 1 : 0; + } else { /* mct mode has been set in commandline */ + if ((parameters.tcp_mct == 1) && (image->numcomps < 3)) { + fprintf(stderr, "RGB->YCC conversion cannot be used:\n"); + fprintf(stderr, "Input image has less than 3 components\n"); + ret = 1; + goto fin; + } + if ((parameters.tcp_mct == 2) && (!parameters.mct_data)) { + fprintf(stderr, "Custom MCT has been set but no array-based MCT\n"); + fprintf(stderr, "has been provided. Aborting.\n"); + ret = 1; + goto fin; + } + } + + /* encode the destination image */ + /* ---------------------------- */ + + switch (parameters.cod_format) { + case J2K_CFMT: { /* JPEG-2000 codestream */ + /* Get a decoder handle */ + l_codec = opj_create_compress(OPJ_CODEC_J2K); + break; + } + case JP2_CFMT: { /* JPEG 2000 compressed image data */ + /* Get a decoder handle */ + l_codec = opj_create_compress(OPJ_CODEC_JP2); + break; + } + default: + fprintf(stderr, "skipping file..\n"); + opj_stream_destroy(l_stream); + continue; + } + + /* catch events using our callbacks and give a local context */ + opj_set_info_handler(l_codec, info_callback, 00); + opj_set_warning_handler(l_codec, warning_callback, 00); + opj_set_error_handler(l_codec, error_callback, 00); + + if (bUseTiles) { + parameters.cp_tx0 = 0; + parameters.cp_ty0 = 0; + parameters.tile_size_on = OPJ_TRUE; + parameters.cp_tdx = 512; + parameters.cp_tdy = 512; + } + if (! opj_setup_encoder(l_codec, ¶meters, image)) { + fprintf(stderr, "failed to encode image: opj_setup_encoder\n"); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + ret = 1; + goto fin; + } + + /* open a byte stream for writing and allocate memory for all tiles */ + l_stream = opj_stream_create_default_file_stream(parameters.outfile, OPJ_FALSE); + if (! l_stream) { + ret = 1; + goto fin; + } + + /* encode the image */ + bSuccess = opj_start_compress(l_codec, image, l_stream); + if (!bSuccess) { + fprintf(stderr, "failed to encode image: opj_start_compress\n"); + } + if (bSuccess && bUseTiles) { + OPJ_BYTE *l_data; + OPJ_UINT32 l_data_size = 512 * 512 * 3; + l_data = (OPJ_BYTE*) calloc(1, l_data_size); + if (l_data == NULL) { + ret = 1; + goto fin; + } + for (i = 0; i < l_nb_tiles; ++i) { + if (! opj_write_tile(l_codec, i, l_data, l_data_size, l_stream)) { + fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n", + i); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + ret = 1; + goto fin; + } + } + free(l_data); + } else { + bSuccess = bSuccess && opj_encode(l_codec, l_stream); + if (!bSuccess) { + fprintf(stderr, "failed to encode image: opj_encode\n"); + } + } + bSuccess = bSuccess && opj_end_compress(l_codec, l_stream); + if (!bSuccess) { + fprintf(stderr, "failed to encode image: opj_end_compress\n"); + } + + if (!bSuccess) { + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + fprintf(stderr, "failed to encode image\n"); + remove(parameters.outfile); + ret = 1; + goto fin; + } + + num_compressed_files++; + fprintf(stdout, "[INFO] Generated outfile %s\n", parameters.outfile); + /* close and free the byte stream */ + opj_stream_destroy(l_stream); + + /* free remaining compression structures */ + opj_destroy_codec(l_codec); + + /* free image data */ + opj_image_destroy(image); + + } + + t = opj_clock() - t; + if (num_compressed_files) { + fprintf(stdout, "encode time: %d ms \n", + (int)((t * 1000.0) / (OPJ_FLOAT64)num_compressed_files)); + } + + ret = 0; + +fin: + if (parameters.cp_comment) { + free(parameters.cp_comment); + } + if (parameters.cp_matrice) { + free(parameters.cp_matrice); + } + if (raw_cp.rawComps) { + free(raw_cp.rawComps); + } + if (img_fol.imgdirpath) { + free(img_fol.imgdirpath); + } + if (dirptr) { + if (dirptr->filename_buf) { + free(dirptr->filename_buf); + } + if (dirptr->filename) { + free(dirptr->filename); + } + free(dirptr); + } + return ret; +} diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c new file mode 100644 index 0000000..4b9583b --- /dev/null +++ b/src/bin/jp2/opj_decompress.c @@ -0,0 +1,1813 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2014, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux + * Copyright (c) 2003-2014, Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR + * Copyright (c) 2012, CS Systemes d'Information, France + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include "opj_apps_config.h" + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include "windirent.h" +#else +#include +#endif /* _WIN32 */ + +#ifdef _WIN32 +#include +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#else +#include +#include +#include +#include +#endif /* _WIN32 */ + +#include "openjpeg.h" +#include "opj_getopt.h" +#include "convert.h" +#include "index.h" + +#ifdef OPJ_HAVE_LIBLCMS2 +#include +#endif +#ifdef OPJ_HAVE_LIBLCMS1 +#include +#endif +#include "color.h" + +#include "format_defs.h" +#include "opj_string.h" + +typedef struct dircnt { + /** Buffer for holding images read from Directory*/ + char *filename_buf; + /** Pointer to the buffer*/ + char **filename; +} dircnt_t; + + +typedef struct img_folder { + /** The directory path of the folder containing input images*/ + char *imgdirpath; + /** Output format*/ + const char *out_format; + /** Enable option*/ + char set_imgdir; + /** Enable Cod Format for output*/ + char set_out_format; + +} img_fol_t; + +typedef enum opj_prec_mode { + OPJ_PREC_MODE_CLIP, + OPJ_PREC_MODE_SCALE +} opj_precision_mode; + +typedef struct opj_prec { + OPJ_UINT32 prec; + opj_precision_mode mode; +} opj_precision; + +typedef struct opj_decompress_params { + /** core library parameters */ + opj_dparameters_t core; + + /** input file name */ + char infile[OPJ_PATH_LEN]; + /** output file name */ + char outfile[OPJ_PATH_LEN]; + /** input file format 0: J2K, 1: JP2, 2: JPT */ + int decod_format; + /** output file format 0: PGX, 1: PxM, 2: BMP */ + int cod_format; + /** index file name */ + char indexfilename[OPJ_PATH_LEN]; + + /** Decoding area left boundary */ + OPJ_UINT32 DA_x0; + /** Decoding area right boundary */ + OPJ_UINT32 DA_x1; + /** Decoding area up boundary */ + OPJ_UINT32 DA_y0; + /** Decoding area bottom boundary */ + OPJ_UINT32 DA_y1; + /** Verbose mode */ + OPJ_BOOL m_verbose; + + /** tile number of the decoded tile */ + OPJ_UINT32 tile_index; + /** Nb of tile to decode */ + OPJ_UINT32 nb_tile_to_decode; + + opj_precision* precision; + OPJ_UINT32 nb_precision; + + /* force output colorspace to RGB */ + int force_rgb; + /* upsample components according to their dx/dy values */ + int upsample; + /* split output components to different files */ + int split_pnm; + /** number of threads */ + int num_threads; + /* Quiet */ + int quiet; + /** number of components to decode */ + OPJ_UINT32 numcomps; + /** indices of components to decode */ + OPJ_UINT32* comps_indices; +} opj_decompress_parameters; + +/* -------------------------------------------------------------------------- */ +/* Declarations */ +int get_num_images(char *imgdirpath); +int load_images(dircnt_t *dirptr, char *imgdirpath); +int get_file_format(const char *filename); +char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol, + opj_decompress_parameters *parameters); +static int infile_format(const char *fname); + +int parse_cmdline_decoder(int argc, char **argv, + opj_decompress_parameters *parameters, img_fol_t *img_fol); +int parse_DA_values(char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, + unsigned int *DA_x1, unsigned int *DA_y1); + +static opj_image_t* convert_gray_to_rgb(opj_image_t* original); + +/* -------------------------------------------------------------------------- */ +static void decode_help_display(void) +{ + fprintf(stdout, + "\nThis is the opj_decompress utility from the OpenJPEG project.\n" + "It decompresses JPEG 2000 codestreams to various image formats.\n" + "It has been compiled against openjp2 library v%s.\n\n", opj_version()); + + fprintf(stdout, "Parameters:\n" + "-----------\n" + "\n" + " -ImgDir \n" + " Image file Directory path \n" + " -OutFor \n" + " REQUIRED only if -ImgDir is used\n" + " Output format for decompressed images.\n"); + fprintf(stdout, " -i \n" + " REQUIRED only if an Input image directory is not specified\n" + " Currently accepts J2K-files, JP2-files and JPT-files. The file type\n" + " is identified based on its suffix.\n"); + fprintf(stdout, " -o \n" + " REQUIRED\n" + " Currently accepts formats specified above (see OutFor option)\n" + " Binary data is written to the file (not ascii). If a PGX\n" + " filename is given, there will be as many output files as there are\n" + " components: an indice starting from 0 will then be appended to the\n" + " output filename, just before the \"pgx\" extension. If a PGM filename\n" + " is given and there are more than one component, only the first component\n" + " will be written to the file.\n"); + fprintf(stdout, " -r \n" + " Set the number of highest resolution levels to be discarded. The\n" + " image resolution is effectively divided by 2 to the power of the\n" + " number of discarded levels. The reduce factor is limited by the\n" + " smallest total number of decomposition levels among tiles.\n" + " -l \n" + " Set the maximum number of quality layers to decode. If there are\n" + " less quality layers than the specified number, all the quality layers\n" + " are decoded.\n"); + fprintf(stdout, " -x \n" + " Create an index file *.Idx (-x index_name.Idx) \n" + " -d \n" + " OPTIONAL\n" + " Decoding area\n" + " By default all the image is decoded.\n" + " -t \n" + " OPTIONAL\n" + " Set the tile number of the decoded tile. Follow the JPEG2000 convention from left-up to bottom-up\n" + " By default all tiles are decoded.\n"); + fprintf(stdout, " -p [C|S][,[C|S][,...]]\n" + " OPTIONAL\n" + " Force the precision (bit depth) of components.\n"); + fprintf(stdout, + " There shall be at least 1 value. Theres no limit on the number of values (comma separated, last values ignored if too much values).\n" + " If there are less values than components, the last value is used for remaining components.\n" + " If 'C' is specified (default), values are clipped.\n" + " If 'S' is specified, values are scaled.\n" + " A 0 value can be specified (meaning original bit depth).\n"); + fprintf(stdout, " -c first_comp_index[,second_comp_index][,...]\n" + " OPTIONAL\n" + " To limit the number of components to decoded.\n" + " Component indices are numbered starting at 0.\n"); + fprintf(stdout, " -force-rgb\n" + " Force output image colorspace to RGB\n" + " -upsample\n" + " Downsampled components will be upsampled to image size\n" + " -split-pnm\n" + " Split output components to different files when writing to PNM\n"); + if (opj_has_thread_support()) { + fprintf(stdout, " -threads \n" + " Number of threads to use for decoding or ALL_CPUS for all available cores.\n"); + } + fprintf(stdout, " -quiet\n" + " Disable output from the library and other output.\n"); + /* UniPG>> */ +#ifdef USE_JPWL + fprintf(stdout, " -W \n" + " Activates the JPWL correction capability, if the codestream complies.\n" + " Options can be a comma separated list of tokens:\n" + " c, c=numcomps\n" + " numcomps is the number of expected components in the codestream\n" + " (search of first EPB rely upon this, default is %d)\n", + JPWL_EXPECTED_COMPONENTS); +#endif /* USE_JPWL */ + /* <precision) { + free(parameters->precision); + parameters->precision = NULL; + } + parameters->nb_precision = 0U; + + for (;;) { + int prec; + char mode; + char comma; + int count; + + count = sscanf(l_remaining, "%d%c%c", &prec, &mode, &comma); + if (count == 1) { + mode = 'C'; + count++; + } + if ((count == 2) || (mode == ',')) { + if (mode == ',') { + mode = 'C'; + } + comma = ','; + count = 3; + } + if (count == 3) { + if ((prec < 1) || (prec > 32)) { + fprintf(stderr, "Invalid precision %d in precision option %s\n", prec, option); + l_result = OPJ_FALSE; + break; + } + if ((mode != 'C') && (mode != 'S')) { + fprintf(stderr, "Invalid precision mode %c in precision option %s\n", mode, + option); + l_result = OPJ_FALSE; + break; + } + if (comma != ',') { + fprintf(stderr, "Invalid character %c in precision option %s\n", comma, option); + l_result = OPJ_FALSE; + break; + } + + if (parameters->precision == NULL) { + /* first one */ + parameters->precision = (opj_precision *)malloc(sizeof(opj_precision)); + if (parameters->precision == NULL) { + fprintf(stderr, "Could not allocate memory for precision option\n"); + l_result = OPJ_FALSE; + break; + } + } else { + OPJ_UINT32 l_new_size = parameters->nb_precision + 1U; + opj_precision* l_new; + + if (l_new_size == 0U) { + fprintf(stderr, "Could not allocate memory for precision option\n"); + l_result = OPJ_FALSE; + break; + } + + l_new = (opj_precision *)realloc(parameters->precision, + l_new_size * sizeof(opj_precision)); + if (l_new == NULL) { + fprintf(stderr, "Could not allocate memory for precision option\n"); + l_result = OPJ_FALSE; + break; + } + parameters->precision = l_new; + } + + parameters->precision[parameters->nb_precision].prec = (OPJ_UINT32)prec; + switch (mode) { + case 'C': + parameters->precision[parameters->nb_precision].mode = OPJ_PREC_MODE_CLIP; + break; + case 'S': + parameters->precision[parameters->nb_precision].mode = OPJ_PREC_MODE_SCALE; + break; + default: + break; + } + parameters->nb_precision++; + + l_remaining = strchr(l_remaining, ','); + if (l_remaining == NULL) { + break; + } + l_remaining += 1; + } else { + fprintf(stderr, "Could not parse precision option %s\n", option); + l_result = OPJ_FALSE; + break; + } + } + + return l_result; +} + +/* -------------------------------------------------------------------------- */ + +int get_num_images(char *imgdirpath) +{ + DIR *dir; + struct dirent* content; + int num_images = 0; + + /*Reading the input images from given input directory*/ + + dir = opendir(imgdirpath); + if (!dir) { + fprintf(stderr, "Could not open Folder %s\n", imgdirpath); + return 0; + } + + while ((content = readdir(dir)) != NULL) { + if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) { + continue; + } + num_images++; + } + closedir(dir); + return num_images; +} + +/* -------------------------------------------------------------------------- */ +int load_images(dircnt_t *dirptr, char *imgdirpath) +{ + DIR *dir; + struct dirent* content; + int i = 0; + + /*Reading the input images from given input directory*/ + + dir = opendir(imgdirpath); + if (!dir) { + fprintf(stderr, "Could not open Folder %s\n", imgdirpath); + return 1; + } else { + fprintf(stderr, "Folder opened successfully\n"); + } + + while ((content = readdir(dir)) != NULL) { + if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) { + continue; + } + + strcpy(dirptr->filename[i], content->d_name); + i++; + } + closedir(dir); + return 0; +} + +/* -------------------------------------------------------------------------- */ +int get_file_format(const char *filename) +{ + unsigned int i; + static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; + static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; + const char * ext = strrchr(filename, '.'); + if (ext == NULL) { + return -1; + } + ext++; + if (*ext) { + for (i = 0; i < sizeof(format) / sizeof(*format); i++) { + if (strcasecmp(ext, extension[i]) == 0) { + return format[i]; + } + } + } + + return -1; +} + +#ifdef _WIN32 +const char* path_separator = "\\"; +#else +const char* path_separator = "/"; +#endif + +/* -------------------------------------------------------------------------- */ +char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol, + opj_decompress_parameters *parameters) +{ + char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN], + outfilename[OPJ_PATH_LEN], temp_ofname[OPJ_PATH_LEN]; + char *temp_p, temp1[OPJ_PATH_LEN] = ""; + + strcpy(image_filename, dirptr->filename[imageno]); + fprintf(stderr, "File Number %d \"%s\"\n", imageno, image_filename); + sprintf(infilename, "%s%s%s", img_fol->imgdirpath, path_separator, + image_filename); + parameters->decod_format = infile_format(infilename); + if (parameters->decod_format == -1) { + return 1; + } + if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), + infilename) != 0) { + return 1; + } + + /*Set output file*/ + strcpy(temp_ofname, strtok(image_filename, ".")); + while ((temp_p = strtok(NULL, ".")) != NULL) { + strcat(temp_ofname, temp1); + sprintf(temp1, ".%s", temp_p); + } + if (img_fol->set_out_format == 1) { + sprintf(outfilename, "%s/%s.%s", img_fol->imgdirpath, temp_ofname, + img_fol->out_format); + if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), + outfilename) != 0) { + return 1; + } + } + return 0; +} + +/* -------------------------------------------------------------------------- */ +#define JP2_RFC3745_MAGIC "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a" +#define JP2_MAGIC "\x0d\x0a\x87\x0a" +/* position 45: "\xff\x52" */ +#define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51" + +static int infile_format(const char *fname) +{ + FILE *reader; + const char *s, *magic_s; + int ext_format, magic_format; + unsigned char buf[12]; + OPJ_SIZE_T l_nb_read; + + reader = fopen(fname, "rb"); + + if (reader == NULL) { + return -2; + } + + memset(buf, 0, 12); + l_nb_read = fread(buf, 1, 12, reader); + fclose(reader); + if (l_nb_read != 12) { + return -1; + } + + + + ext_format = get_file_format(fname); + + if (ext_format == JPT_CFMT) { + return JPT_CFMT; + } + + if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { + magic_format = JP2_CFMT; + magic_s = ".jp2"; + } else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) { + magic_format = J2K_CFMT; + magic_s = ".j2k or .jpc or .j2c"; + } else { + return -1; + } + + if (magic_format == ext_format) { + return ext_format; + } + + s = fname + strlen(fname) - 4; + + fputs("\n===========================================\n", stderr); + fprintf(stderr, "The extension of this file is incorrect.\n" + "FOUND %s. SHOULD BE %s\n", s, magic_s); + fputs("===========================================\n", stderr); + + return magic_format; +} + +/* -------------------------------------------------------------------------- */ +/** + * Parse the command line + */ +/* -------------------------------------------------------------------------- */ +int parse_cmdline_decoder(int argc, char **argv, + opj_decompress_parameters *parameters, img_fol_t *img_fol) +{ + /* parse the command line */ + int totlen, c; + opj_option_t long_option[] = { + {"ImgDir", REQ_ARG, NULL, 'y'}, + {"OutFor", REQ_ARG, NULL, 'O'}, + {"force-rgb", NO_ARG, NULL, 1}, + {"upsample", NO_ARG, NULL, 1}, + {"split-pnm", NO_ARG, NULL, 1}, + {"threads", REQ_ARG, NULL, 'T'}, + {"quiet", NO_ARG, NULL, 1}, + }; + + const char optlist[] = "i:o:r:l:x:d:t:p:c:" + + /* UniPG>> */ +#ifdef USE_JPWL + "W:" +#endif /* USE_JPWL */ + /* <force_rgb); + long_option[3].flag = &(parameters->upsample); + long_option[4].flag = &(parameters->split_pnm); + long_option[6].flag = &(parameters->quiet); + totlen = sizeof(long_option); + opj_reset_options_reading(); + img_fol->set_out_format = 0; + do { + c = opj_getopt_long(argc, argv, optlist, long_option, totlen); + if (c == -1) { + break; + } + switch (c) { + case 0: /* long opt with flag */ + break; + case 'i': { /* input file */ + char *infile = opj_optarg; + parameters->decod_format = infile_format(infile); + switch (parameters->decod_format) { + case J2K_CFMT: + break; + case JP2_CFMT: + break; + case JPT_CFMT: + break; + case -2: + fprintf(stderr, + "!! infile cannot be read: %s !!\n\n", + infile); + return 1; + default: + fprintf(stderr, + "[ERROR] Unknown input file format: %s \n" + " Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n", + infile); + return 1; + } + if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) { + fprintf(stderr, "[ERROR] Path is too long\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'o': { /* output file */ + char *outfile = opj_optarg; + parameters->cod_format = get_file_format(outfile); + switch (parameters->cod_format) { + case PGX_DFMT: + break; + case PXM_DFMT: + break; + case BMP_DFMT: + break; + case TIF_DFMT: + break; + case RAW_DFMT: + break; + case RAWL_DFMT: + break; + case TGA_DFMT: + break; + case PNG_DFMT: + break; + default: + fprintf(stderr, + "Unknown output format image %s [only *.png, *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!!\n", + outfile); + return 1; + } + if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), + outfile) != 0) { + fprintf(stderr, "[ERROR] Path is too long\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'O': { /* output format */ + char outformat[50]; + char *of = opj_optarg; + sprintf(outformat, ".%s", of); + img_fol->set_out_format = 1; + parameters->cod_format = get_file_format(outformat); + switch (parameters->cod_format) { + case PGX_DFMT: + img_fol->out_format = "pgx"; + break; + case PXM_DFMT: + img_fol->out_format = "ppm"; + break; + case BMP_DFMT: + img_fol->out_format = "bmp"; + break; + case TIF_DFMT: + img_fol->out_format = "tif"; + break; + case RAW_DFMT: + img_fol->out_format = "raw"; + break; + case RAWL_DFMT: + img_fol->out_format = "rawl"; + break; + case TGA_DFMT: + img_fol->out_format = "raw"; + break; + case PNG_DFMT: + img_fol->out_format = "png"; + break; + default: + fprintf(stderr, + "Unknown output format image %s [only *.png, *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!!\n", + outformat); + return 1; + break; + } + } + break; + + /* ----------------------------------------------------- */ + + + case 'r': { /* reduce option */ + sscanf(opj_optarg, "%u", &(parameters->core.cp_reduce)); + } + break; + + /* ----------------------------------------------------- */ + + + case 'l': { /* layering option */ + sscanf(opj_optarg, "%u", &(parameters->core.cp_layer)); + } + break; + + /* ----------------------------------------------------- */ + + case 'h': /* display an help description */ + decode_help_display(); + return 1; + + /* ----------------------------------------------------- */ + + case 'y': { /* Image Directory path */ + img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); + if (img_fol->imgdirpath == NULL) { + return 1; + } + strcpy(img_fol->imgdirpath, opj_optarg); + img_fol->set_imgdir = 1; + } + break; + + /* ----------------------------------------------------- */ + + case 'd': { /* Input decode ROI */ + size_t size_optarg = (size_t)strlen(opj_optarg) + 1U; + char *ROI_values = (char*) malloc(size_optarg); + if (ROI_values == NULL) { + fprintf(stderr, "[ERROR] Couldn't allocate memory\n"); + return 1; + } + ROI_values[0] = '\0'; + memcpy(ROI_values, opj_optarg, size_optarg); + /*printf("ROI_values = %s [%d / %d]\n", ROI_values, strlen(ROI_values), size_optarg ); */ + parse_DA_values(ROI_values, ¶meters->DA_x0, ¶meters->DA_y0, + ¶meters->DA_x1, ¶meters->DA_y1); + + free(ROI_values); + } + break; + + /* ----------------------------------------------------- */ + + case 't': { /* Input tile index */ + sscanf(opj_optarg, "%u", ¶meters->tile_index); + parameters->nb_tile_to_decode = 1; + } + break; + + /* ----------------------------------------------------- */ + + case 'x': { /* Creation of index file */ + if (opj_strcpy_s(parameters->indexfilename, sizeof(parameters->indexfilename), + opj_optarg) != 0) { + fprintf(stderr, "[ERROR] Path is too long\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + case 'p': { /* Force precision */ + if (!parse_precision(opj_optarg, parameters)) { + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + case 'c': { /* Componenets */ + const char* iter = opj_optarg; + while (1) { + parameters->numcomps ++; + parameters->comps_indices = (OPJ_UINT32*) realloc( + parameters->comps_indices, + parameters->numcomps * sizeof(OPJ_UINT32)); + parameters->comps_indices[parameters->numcomps - 1] = + (OPJ_UINT32) atoi(iter); + iter = strchr(iter, ','); + if (iter == NULL) { + break; + } + iter ++; + } + } + break; + /* ----------------------------------------------------- */ + + /* UniPG>> */ +#ifdef USE_JPWL + + case 'W': { /* activate JPWL correction */ + char *token = NULL; + + token = strtok(opj_optarg, ","); + while (token != NULL) { + + /* search expected number of components */ + if (*token == 'c') { + + static int compno; + + compno = JPWL_EXPECTED_COMPONENTS; /* predefined no. of components */ + + if (sscanf(token, "c=%d", &compno) == 1) { + /* Specified */ + if ((compno < 1) || (compno > 256)) { + fprintf(stderr, "ERROR -> invalid number of components c = %d\n", compno); + return 1; + } + parameters->jpwl_exp_comps = compno; + + } else if (!strcmp(token, "c")) { + /* default */ + parameters->jpwl_exp_comps = compno; /* auto for default size */ + + } else { + fprintf(stderr, "ERROR -> invalid components specified = %s\n", token); + return 1; + }; + } + + /* search maximum number of tiles */ + if (*token == 't') { + + static int tileno; + + tileno = JPWL_MAXIMUM_TILES; /* maximum no. of tiles */ + + if (sscanf(token, "t=%d", &tileno) == 1) { + /* Specified */ + if ((tileno < 1) || (tileno > JPWL_MAXIMUM_TILES)) { + fprintf(stderr, "ERROR -> invalid number of tiles t = %d\n", tileno); + return 1; + } + parameters->jpwl_max_tiles = tileno; + + } else if (!strcmp(token, "t")) { + /* default */ + parameters->jpwl_max_tiles = tileno; /* auto for default size */ + + } else { + fprintf(stderr, "ERROR -> invalid tiles specified = %s\n", token); + return 1; + }; + } + + /* next token or bust */ + token = strtok(NULL, ","); + }; + parameters->jpwl_correct = OPJ_TRUE; + if (!(parameter->quiet)) { + fprintf(stdout, "JPWL correction capability activated\n"); + fprintf(stdout, "- expecting %d components\n", parameters->jpwl_exp_comps); + } + } + break; +#endif /* USE_JPWL */ + /* <num_threads = opj_get_num_cpus(); + if (parameters->num_threads == 1) { + parameters->num_threads = 0; + } + } else { + sscanf(opj_optarg, "%d", ¶meters->num_threads); + } + } + break; + + /* ----------------------------------------------------- */ + + default: + fprintf(stderr, "[WARNING] An invalid option has been ignored.\n"); + break; + } + } while (c != -1); + + /* check for possible errors */ + if (img_fol->set_imgdir == 1) { + if (!(parameters->infile[0] == 0)) { + fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n"); + return 1; + } + if (img_fol->set_out_format == 0) { + fprintf(stderr, + "[ERROR] When -ImgDir is used, -OutFor must be used.\n"); + fprintf(stderr, "Only one format allowed.\n" + "Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n"); + return 1; + } + if (!((parameters->outfile[0] == 0))) { + fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together.\n"); + return 1; + } + } else { + if ((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { + fprintf(stderr, "[ERROR] Required parameters are missing\n" + "Example: %s -i image.j2k -o image.pgm\n", argv[0]); + fprintf(stderr, " Help: %s -h\n", argv[0]); + return 1; + } + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/** + * Parse decoding area input values + * separator = "," + */ +/* -------------------------------------------------------------------------- */ +int parse_DA_values(char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, + unsigned int *DA_x1, unsigned int *DA_y1) +{ + int it = 0; + int values[4]; + char delims[] = ","; + char *result = NULL; + result = strtok(inArg, delims); + + while ((result != NULL) && (it < 4)) { + values[it] = atoi(result); + result = strtok(NULL, delims); + it++; + } + + if (it != 4) { + return EXIT_FAILURE; + } else { + *DA_x0 = (OPJ_UINT32)values[0]; + *DA_y0 = (OPJ_UINT32)values[1]; + *DA_x1 = (OPJ_UINT32)values[2]; + *DA_y1 = (OPJ_UINT32)values[3]; + return EXIT_SUCCESS; + } +} + +OPJ_FLOAT64 opj_clock(void) +{ +#ifdef _WIN32 + /* _WIN32: use QueryPerformance (very accurate) */ + LARGE_INTEGER freq, t ; + /* freq is the clock speed of the CPU */ + QueryPerformanceFrequency(&freq) ; + /* cout << "freq = " << ((double) freq.QuadPart) << endl; */ + /* t is the high resolution performance counter (see MSDN) */ + QueryPerformanceCounter(& t) ; + return freq.QuadPart ? ((OPJ_FLOAT64)t.QuadPart / (OPJ_FLOAT64)freq.QuadPart) : + 0; +#elif defined(__linux) + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + return ((OPJ_FLOAT64)ts.tv_sec + (OPJ_FLOAT64)ts.tv_nsec * 1e-9); +#else + /* Unix : use resource usage */ + /* FIXME: this counts the total CPU time, instead of the user perceived time */ + struct rusage t; + OPJ_FLOAT64 procTime; + /* (1) Get the rusage data structure at this moment (man getrusage) */ + getrusage(0, &t); + /* (2) What is the elapsed time ? - CPU time = User time + System time */ + /* (2a) Get the seconds */ + procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec); + /* (2b) More precisely! Get the microseconds part ! */ + return (procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * + 1e-6) ; +#endif +} + +/* -------------------------------------------------------------------------- */ + +/** +sample error callback expecting a FILE* client object +*/ +static void error_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[ERROR] %s", msg); +} +/** +sample warning callback expecting a FILE* client object +*/ +static void warning_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[WARNING] %s", msg); +} +/** +sample debug callback expecting no client object +*/ +static void info_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[INFO] %s", msg); +} +/** +sample quiet callback expecting no client object +*/ +static void quiet_callback(const char *msg, void *client_data) +{ + (void)msg; + (void)client_data; +} + +static void set_default_parameters(opj_decompress_parameters* parameters) +{ + if (parameters) { + memset(parameters, 0, sizeof(opj_decompress_parameters)); + + /* default decoding parameters (command line specific) */ + parameters->decod_format = -1; + parameters->cod_format = -1; + + /* default decoding parameters (core) */ + opj_set_default_decoder_parameters(&(parameters->core)); + } +} + +static void destroy_parameters(opj_decompress_parameters* parameters) +{ + if (parameters) { + if (parameters->precision) { + free(parameters->precision); + parameters->precision = NULL; + } + + free(parameters->comps_indices); + parameters->comps_indices = NULL; + } +} + +/* -------------------------------------------------------------------------- */ + +static opj_image_t* convert_gray_to_rgb(opj_image_t* original) +{ + OPJ_UINT32 compno; + opj_image_t* l_new_image = NULL; + opj_image_cmptparm_t* l_new_components = NULL; + + l_new_components = (opj_image_cmptparm_t*)malloc((original->numcomps + 2U) * + sizeof(opj_image_cmptparm_t)); + if (l_new_components == NULL) { + fprintf(stderr, + "ERROR -> opj_decompress: failed to allocate memory for RGB image!\n"); + opj_image_destroy(original); + return NULL; + } + + l_new_components[0].bpp = l_new_components[1].bpp = l_new_components[2].bpp = + original->comps[0].bpp; + l_new_components[0].dx = l_new_components[1].dx = l_new_components[2].dx = + original->comps[0].dx; + l_new_components[0].dy = l_new_components[1].dy = l_new_components[2].dy = + original->comps[0].dy; + l_new_components[0].h = l_new_components[1].h = l_new_components[2].h = + original->comps[0].h; + l_new_components[0].w = l_new_components[1].w = l_new_components[2].w = + original->comps[0].w; + l_new_components[0].prec = l_new_components[1].prec = l_new_components[2].prec = + original->comps[0].prec; + l_new_components[0].sgnd = l_new_components[1].sgnd = l_new_components[2].sgnd = + original->comps[0].sgnd; + l_new_components[0].x0 = l_new_components[1].x0 = l_new_components[2].x0 = + original->comps[0].x0; + l_new_components[0].y0 = l_new_components[1].y0 = l_new_components[2].y0 = + original->comps[0].y0; + + for (compno = 1U; compno < original->numcomps; ++compno) { + l_new_components[compno + 2U].bpp = original->comps[compno].bpp; + l_new_components[compno + 2U].dx = original->comps[compno].dx; + l_new_components[compno + 2U].dy = original->comps[compno].dy; + l_new_components[compno + 2U].h = original->comps[compno].h; + l_new_components[compno + 2U].w = original->comps[compno].w; + l_new_components[compno + 2U].prec = original->comps[compno].prec; + l_new_components[compno + 2U].sgnd = original->comps[compno].sgnd; + l_new_components[compno + 2U].x0 = original->comps[compno].x0; + l_new_components[compno + 2U].y0 = original->comps[compno].y0; + } + + l_new_image = opj_image_create(original->numcomps + 2U, l_new_components, + OPJ_CLRSPC_SRGB); + free(l_new_components); + if (l_new_image == NULL) { + fprintf(stderr, + "ERROR -> opj_decompress: failed to allocate memory for RGB image!\n"); + opj_image_destroy(original); + return NULL; + } + + l_new_image->x0 = original->x0; + l_new_image->x1 = original->x1; + l_new_image->y0 = original->y0; + l_new_image->y1 = original->y1; + + l_new_image->comps[0].factor = l_new_image->comps[1].factor = + l_new_image->comps[2].factor = original->comps[0].factor; + l_new_image->comps[0].alpha = l_new_image->comps[1].alpha = + l_new_image->comps[2].alpha = original->comps[0].alpha; + l_new_image->comps[0].resno_decoded = l_new_image->comps[1].resno_decoded = + l_new_image->comps[2].resno_decoded = original->comps[0].resno_decoded; + + memcpy(l_new_image->comps[0].data, original->comps[0].data, + sizeof(OPJ_INT32) * original->comps[0].w * original->comps[0].h); + memcpy(l_new_image->comps[1].data, original->comps[0].data, + sizeof(OPJ_INT32) * original->comps[0].w * original->comps[0].h); + memcpy(l_new_image->comps[2].data, original->comps[0].data, + sizeof(OPJ_INT32) * original->comps[0].w * original->comps[0].h); + + for (compno = 1U; compno < original->numcomps; ++compno) { + l_new_image->comps[compno + 2U].factor = original->comps[compno].factor; + l_new_image->comps[compno + 2U].alpha = original->comps[compno].alpha; + l_new_image->comps[compno + 2U].resno_decoded = + original->comps[compno].resno_decoded; + memcpy(l_new_image->comps[compno + 2U].data, original->comps[compno].data, + sizeof(OPJ_INT32) * original->comps[compno].w * original->comps[compno].h); + } + opj_image_destroy(original); + return l_new_image; +} + +/* -------------------------------------------------------------------------- */ + +static opj_image_t* upsample_image_components(opj_image_t* original) +{ + opj_image_t* l_new_image = NULL; + opj_image_cmptparm_t* l_new_components = NULL; + OPJ_BOOL l_upsample_need = OPJ_FALSE; + OPJ_UINT32 compno; + + for (compno = 0U; compno < original->numcomps; ++compno) { + if (original->comps[compno].factor > 0U) { + fprintf(stderr, + "ERROR -> opj_decompress: -upsample not supported with reduction\n"); + opj_image_destroy(original); + return NULL; + } + if ((original->comps[compno].dx > 1U) || (original->comps[compno].dy > 1U)) { + l_upsample_need = OPJ_TRUE; + break; + } + } + if (!l_upsample_need) { + return original; + } + /* Upsample is needed */ + l_new_components = (opj_image_cmptparm_t*)malloc(original->numcomps * sizeof( + opj_image_cmptparm_t)); + if (l_new_components == NULL) { + fprintf(stderr, + "ERROR -> opj_decompress: failed to allocate memory for upsampled components!\n"); + opj_image_destroy(original); + return NULL; + } + + for (compno = 0U; compno < original->numcomps; ++compno) { + opj_image_cmptparm_t* l_new_cmp = &(l_new_components[compno]); + opj_image_comp_t* l_org_cmp = &(original->comps[compno]); + + l_new_cmp->bpp = l_org_cmp->bpp; + l_new_cmp->prec = l_org_cmp->prec; + l_new_cmp->sgnd = l_org_cmp->sgnd; + l_new_cmp->x0 = original->x0; + l_new_cmp->y0 = original->y0; + l_new_cmp->dx = 1; + l_new_cmp->dy = 1; + l_new_cmp->w = + l_org_cmp->w; /* should be original->x1 - original->x0 for dx==1 */ + l_new_cmp->h = + l_org_cmp->h; /* should be original->y1 - original->y0 for dy==0 */ + + if (l_org_cmp->dx > 1U) { + l_new_cmp->w = original->x1 - original->x0; + } + + if (l_org_cmp->dy > 1U) { + l_new_cmp->h = original->y1 - original->y0; + } + } + + l_new_image = opj_image_create(original->numcomps, l_new_components, + original->color_space); + free(l_new_components); + if (l_new_image == NULL) { + fprintf(stderr, + "ERROR -> opj_decompress: failed to allocate memory for upsampled components!\n"); + opj_image_destroy(original); + return NULL; + } + + l_new_image->x0 = original->x0; + l_new_image->x1 = original->x1; + l_new_image->y0 = original->y0; + l_new_image->y1 = original->y1; + + for (compno = 0U; compno < original->numcomps; ++compno) { + opj_image_comp_t* l_new_cmp = &(l_new_image->comps[compno]); + opj_image_comp_t* l_org_cmp = &(original->comps[compno]); + + l_new_cmp->factor = l_org_cmp->factor; + l_new_cmp->alpha = l_org_cmp->alpha; + l_new_cmp->resno_decoded = l_org_cmp->resno_decoded; + + if ((l_org_cmp->dx > 1U) || (l_org_cmp->dy > 1U)) { + const OPJ_INT32* l_src = l_org_cmp->data; + OPJ_INT32* l_dst = l_new_cmp->data; + OPJ_UINT32 y; + OPJ_UINT32 xoff, yoff; + + /* need to take into account dx & dy */ + xoff = l_org_cmp->dx * l_org_cmp->x0 - original->x0; + yoff = l_org_cmp->dy * l_org_cmp->y0 - original->y0; + if ((xoff >= l_org_cmp->dx) || (yoff >= l_org_cmp->dy)) { + fprintf(stderr, + "ERROR -> opj_decompress: Invalid image/component parameters found when upsampling\n"); + opj_image_destroy(original); + opj_image_destroy(l_new_image); + return NULL; + } + + for (y = 0U; y < yoff; ++y) { + memset(l_dst, 0U, l_new_cmp->w * sizeof(OPJ_INT32)); + l_dst += l_new_cmp->w; + } + + if (l_new_cmp->h > (l_org_cmp->dy - + 1U)) { /* check subtraction overflow for really small images */ + for (; y < l_new_cmp->h - (l_org_cmp->dy - 1U); y += l_org_cmp->dy) { + OPJ_UINT32 x, dy; + OPJ_UINT32 xorg; + + xorg = 0U; + for (x = 0U; x < xoff; ++x) { + l_dst[x] = 0; + } + if (l_new_cmp->w > (l_org_cmp->dx - + 1U)) { /* check subtraction overflow for really small images */ + for (; x < l_new_cmp->w - (l_org_cmp->dx - 1U); x += l_org_cmp->dx, ++xorg) { + OPJ_UINT32 dx; + for (dx = 0U; dx < l_org_cmp->dx; ++dx) { + l_dst[x + dx] = l_src[xorg]; + } + } + } + for (; x < l_new_cmp->w; ++x) { + l_dst[x] = l_src[xorg]; + } + l_dst += l_new_cmp->w; + + for (dy = 1U; dy < l_org_cmp->dy; ++dy) { + memcpy(l_dst, l_dst - l_new_cmp->w, l_new_cmp->w * sizeof(OPJ_INT32)); + l_dst += l_new_cmp->w; + } + l_src += l_org_cmp->w; + } + } + if (y < l_new_cmp->h) { + OPJ_UINT32 x; + OPJ_UINT32 xorg; + + xorg = 0U; + for (x = 0U; x < xoff; ++x) { + l_dst[x] = 0; + } + if (l_new_cmp->w > (l_org_cmp->dx - + 1U)) { /* check subtraction overflow for really small images */ + for (; x < l_new_cmp->w - (l_org_cmp->dx - 1U); x += l_org_cmp->dx, ++xorg) { + OPJ_UINT32 dx; + for (dx = 0U; dx < l_org_cmp->dx; ++dx) { + l_dst[x + dx] = l_src[xorg]; + } + } + } + for (; x < l_new_cmp->w; ++x) { + l_dst[x] = l_src[xorg]; + } + l_dst += l_new_cmp->w; + ++y; + for (; y < l_new_cmp->h; ++y) { + memcpy(l_dst, l_dst - l_new_cmp->w, l_new_cmp->w * sizeof(OPJ_INT32)); + l_dst += l_new_cmp->w; + } + } + } else { + memcpy(l_new_cmp->data, l_org_cmp->data, + sizeof(OPJ_INT32) * l_org_cmp->w * l_org_cmp->h); + } + } + opj_image_destroy(original); + return l_new_image; +} + +/* -------------------------------------------------------------------------- */ +/** + * OPJ_DECOMPRESS MAIN + */ +/* -------------------------------------------------------------------------- */ +int main(int argc, char **argv) +{ + opj_decompress_parameters parameters; /* decompression parameters */ + opj_image_t* image = NULL; + opj_stream_t *l_stream = NULL; /* Stream */ + opj_codec_t* l_codec = NULL; /* Handle to a decompressor */ + opj_codestream_index_t* cstr_index = NULL; + + OPJ_INT32 num_images, imageno; + img_fol_t img_fol; + dircnt_t *dirptr = NULL; + int failed = 0; + OPJ_FLOAT64 t, tCumulative = 0; + OPJ_UINT32 numDecompressedImages = 0; + OPJ_UINT32 cp_reduce; + + /* set decoding parameters to default values */ + set_default_parameters(¶meters); + + /* Initialize img_fol */ + memset(&img_fol, 0, sizeof(img_fol_t)); + + /* parse input and get user encoding parameters */ + if (parse_cmdline_decoder(argc, argv, ¶meters, &img_fol) == 1) { + failed = 1; + goto fin; + } + + cp_reduce = parameters.core.cp_reduce; + if (getenv("USE_OPJ_SET_DECODED_RESOLUTION_FACTOR") != NULL) { + /* For debugging/testing purposes, do not set the cp_reduce member */ + /* if USE_OPJ_SET_DECODED_RESOLUTION_FACTOR is defined, but used */ + /* the opj_set_decoded_resolution_factor() API instead */ + parameters.core.cp_reduce = 0; + } + + + /* Initialize reading of directory */ + if (img_fol.set_imgdir == 1) { + int it_image; + num_images = get_num_images(img_fol.imgdirpath); + + dirptr = (dircnt_t*)malloc(sizeof(dircnt_t)); + if (!dirptr) { + destroy_parameters(¶meters); + return EXIT_FAILURE; + } + /* Stores at max 10 image file names */ + dirptr->filename_buf = (char*)malloc(sizeof(char) * + (size_t)num_images * OPJ_PATH_LEN); + if (!dirptr->filename_buf) { + failed = 1; + goto fin; + } + + dirptr->filename = (char**) malloc((size_t)num_images * sizeof(char*)); + + if (!dirptr->filename) { + failed = 1; + goto fin; + } + for (it_image = 0; it_image < num_images; it_image++) { + dirptr->filename[it_image] = dirptr->filename_buf + it_image * OPJ_PATH_LEN; + } + + if (load_images(dirptr, img_fol.imgdirpath) == 1) { + failed = 1; + goto fin; + } + if (num_images == 0) { + fprintf(stderr, "Folder is empty\n"); + failed = 1; + goto fin; + } + } else { + num_images = 1; + } + + /*Decoding image one by one*/ + for (imageno = 0; imageno < num_images ; imageno++) { + + if (!parameters.quiet) { + fprintf(stderr, "\n"); + } + + if (img_fol.set_imgdir == 1) { + if (get_next_file(imageno, dirptr, &img_fol, ¶meters)) { + fprintf(stderr, "skipping file...\n"); + destroy_parameters(¶meters); + continue; + } + } + + /* read the input file and put it in memory */ + /* ---------------------------------------- */ + + l_stream = opj_stream_create_default_file_stream(parameters.infile, 1); + if (!l_stream) { + fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", + parameters.infile); + failed = 1; + goto fin; + } + + /* decode the JPEG2000 stream */ + /* ---------------------- */ + + switch (parameters.decod_format) { + case J2K_CFMT: { /* JPEG-2000 codestream */ + /* Get a decoder handle */ + l_codec = opj_create_decompress(OPJ_CODEC_J2K); + break; + } + case JP2_CFMT: { /* JPEG 2000 compressed image data */ + /* Get a decoder handle */ + l_codec = opj_create_decompress(OPJ_CODEC_JP2); + break; + } + case JPT_CFMT: { /* JPEG 2000, JPIP */ + /* Get a decoder handle */ + l_codec = opj_create_decompress(OPJ_CODEC_JPT); + break; + } + default: + fprintf(stderr, "skipping file..\n"); + destroy_parameters(¶meters); + opj_stream_destroy(l_stream); + continue; + } + + if (parameters.quiet) { + /* Set all callbacks to quiet */ + opj_set_info_handler(l_codec, quiet_callback, 00); + opj_set_warning_handler(l_codec, quiet_callback, 00); + opj_set_error_handler(l_codec, quiet_callback, 00); + } else { + /* catch events using our callbacks and give a local context */ + opj_set_info_handler(l_codec, info_callback, 00); + opj_set_warning_handler(l_codec, warning_callback, 00); + opj_set_error_handler(l_codec, error_callback, 00); + } + + + t = opj_clock(); + + /* Setup the decoder decoding parameters using user parameters */ + if (!opj_setup_decoder(l_codec, &(parameters.core))) { + fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n"); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + failed = 1; + goto fin; + } + + if (parameters.num_threads >= 1 && + !opj_codec_set_threads(l_codec, parameters.num_threads)) { + fprintf(stderr, "ERROR -> opj_decompress: failed to set number of threads\n"); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + failed = 1; + goto fin; + } + + /* Read the main header of the codestream and if necessary the JP2 boxes*/ + if (! opj_read_header(l_stream, l_codec, &image)) { + fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n"); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + failed = 1; + goto fin; + } + + if (parameters.numcomps) { + if (! opj_set_decoded_components(l_codec, + parameters.numcomps, + parameters.comps_indices, + OPJ_FALSE)) { + fprintf(stderr, + "ERROR -> opj_decompress: failed to set the component indices!\n"); + opj_destroy_codec(l_codec); + opj_stream_destroy(l_stream); + opj_image_destroy(image); + failed = 1; + goto fin; + } + } + + if (getenv("USE_OPJ_SET_DECODED_RESOLUTION_FACTOR") != NULL) { + /* For debugging/testing purposes, and also an illustration on how to */ + /* use the alternative API opj_set_decoded_resolution_factor() instead */ + /* of setting parameters.cp_reduce */ + if (! opj_set_decoded_resolution_factor(l_codec, cp_reduce)) { + fprintf(stderr, + "ERROR -> opj_decompress: failed to set the resolution factor tile!\n"); + opj_destroy_codec(l_codec); + opj_stream_destroy(l_stream); + opj_image_destroy(image); + failed = 1; + goto fin; + } + } + + if (!parameters.nb_tile_to_decode) { + if (getenv("SKIP_OPJ_SET_DECODE_AREA") != NULL && + parameters.DA_x0 == 0 && + parameters.DA_y0 == 0 && + parameters.DA_x1 == 0 && + parameters.DA_y1 == 0) { + /* For debugging/testing purposes, */ + /* do nothing if SKIP_OPJ_SET_DECODE_AREA env variable */ + /* is defined and no decoded area has been set */ + } + /* Optional if you want decode the entire image */ + else if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0, + (OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1, + (OPJ_INT32)parameters.DA_y1)) { + fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n"); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + failed = 1; + goto fin; + } + + /* Get the decoded image */ + if (!(opj_decode(l_codec, l_stream, image) && + opj_end_decompress(l_codec, l_stream))) { + fprintf(stderr, "ERROR -> opj_decompress: failed to decode image!\n"); + opj_destroy_codec(l_codec); + opj_stream_destroy(l_stream); + opj_image_destroy(image); + failed = 1; + goto fin; + } + } else { + if (!(parameters.DA_x0 == 0 && + parameters.DA_y0 == 0 && + parameters.DA_x1 == 0 && + parameters.DA_y1 == 0)) { + if (!(parameters.quiet)) { + fprintf(stderr, "WARNING: -d option ignored when used together with -t\n"); + } + } + + if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_index)) { + fprintf(stderr, "ERROR -> opj_decompress: failed to decode tile!\n"); + opj_destroy_codec(l_codec); + opj_stream_destroy(l_stream); + opj_image_destroy(image); + failed = 1; + goto fin; + } + if (!(parameters.quiet)) { + fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index); + } + } + + /* FIXME? Shouldn't that situation be considered as an error of */ + /* opj_decode() / opj_get_decoded_tile() ? */ + if (image->comps[0].data == NULL) { + fprintf(stderr, "ERROR -> opj_decompress: no image data!\n"); + opj_destroy_codec(l_codec); + opj_stream_destroy(l_stream); + opj_image_destroy(image); + failed = 1; + goto fin; + } + + tCumulative += opj_clock() - t; + numDecompressedImages++; + + /* Close the byte stream */ + opj_stream_destroy(l_stream); + + if (image->color_space != OPJ_CLRSPC_SYCC + && image->numcomps == 3 && image->comps[0].dx == image->comps[0].dy + && image->comps[1].dx != 1) { + image->color_space = OPJ_CLRSPC_SYCC; + } else if (image->numcomps <= 2) { + image->color_space = OPJ_CLRSPC_GRAY; + } + + if (image->color_space == OPJ_CLRSPC_SYCC) { + color_sycc_to_rgb(image); + } else if ((image->color_space == OPJ_CLRSPC_CMYK) && + (parameters.cod_format != TIF_DFMT)) { + color_cmyk_to_rgb(image); + } else if (image->color_space == OPJ_CLRSPC_EYCC) { + color_esycc_to_rgb(image); + } + + if (image->icc_profile_buf) { +#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) + if (image->icc_profile_len) { + color_apply_icc_profile(image); + } else { + color_cielab_to_rgb(image); + } +#endif + free(image->icc_profile_buf); + image->icc_profile_buf = NULL; + image->icc_profile_len = 0; + } + + /* Force output precision */ + /* ---------------------- */ + if (parameters.precision != NULL) { + OPJ_UINT32 compno; + for (compno = 0; compno < image->numcomps; ++compno) { + OPJ_UINT32 precno = compno; + OPJ_UINT32 prec; + + if (precno >= parameters.nb_precision) { + precno = parameters.nb_precision - 1U; + } + + prec = parameters.precision[precno].prec; + if (prec == 0) { + prec = image->comps[compno].prec; + } + + switch (parameters.precision[precno].mode) { + case OPJ_PREC_MODE_CLIP: + clip_component(&(image->comps[compno]), prec); + break; + case OPJ_PREC_MODE_SCALE: + scale_component(&(image->comps[compno]), prec); + break; + default: + break; + } + + } + } + + /* Upsample components */ + /* ------------------- */ + if (parameters.upsample) { + image = upsample_image_components(image); + if (image == NULL) { + fprintf(stderr, + "ERROR -> opj_decompress: failed to upsample image components!\n"); + opj_destroy_codec(l_codec); + failed = 1; + goto fin; + } + } + + /* Force RGB output */ + /* ---------------- */ + if (parameters.force_rgb) { + switch (image->color_space) { + case OPJ_CLRSPC_SRGB: + break; + case OPJ_CLRSPC_GRAY: + image = convert_gray_to_rgb(image); + break; + default: + fprintf(stderr, + "ERROR -> opj_decompress: don't know how to convert image to RGB colorspace!\n"); + opj_image_destroy(image); + image = NULL; + break; + } + if (image == NULL) { + fprintf(stderr, "ERROR -> opj_decompress: failed to convert to RGB image!\n"); + opj_destroy_codec(l_codec); + failed = 1; + goto fin; + } + } + + /* create output image */ + /* ------------------- */ + switch (parameters.cod_format) { + case PXM_DFMT: /* PNM PGM PPM */ + if (imagetopnm(image, parameters.outfile, parameters.split_pnm)) { + fprintf(stderr, "[ERROR] Outfile %s not generated\n", parameters.outfile); + failed = 1; + } else if (!(parameters.quiet)) { + fprintf(stdout, "[INFO] Generated Outfile %s\n", parameters.outfile); + } + break; + + case PGX_DFMT: /* PGX */ + if (imagetopgx(image, parameters.outfile)) { + fprintf(stderr, "[ERROR] Outfile %s not generated\n", parameters.outfile); + failed = 1; + } else if (!(parameters.quiet)) { + fprintf(stdout, "[INFO] Generated Outfile %s\n", parameters.outfile); + } + break; + + case BMP_DFMT: /* BMP */ + if (imagetobmp(image, parameters.outfile)) { + fprintf(stderr, "[ERROR] Outfile %s not generated\n", parameters.outfile); + failed = 1; + } else if (!(parameters.quiet)) { + fprintf(stdout, "[INFO] Generated Outfile %s\n", parameters.outfile); + } + break; +#ifdef OPJ_HAVE_LIBTIFF + case TIF_DFMT: /* TIFF */ + if (imagetotif(image, parameters.outfile)) { + fprintf(stderr, "[ERROR] Outfile %s not generated\n", parameters.outfile); + failed = 1; + } else if (!(parameters.quiet)) { + fprintf(stdout, "[INFO] Generated Outfile %s\n", parameters.outfile); + } + break; +#endif /* OPJ_HAVE_LIBTIFF */ + case RAW_DFMT: /* RAW */ + if (imagetoraw(image, parameters.outfile)) { + fprintf(stderr, "[ERROR] Error generating raw file. Outfile %s not generated\n", + parameters.outfile); + failed = 1; + } else if (!(parameters.quiet)) { + fprintf(stdout, "[INFO] Generated Outfile %s\n", parameters.outfile); + } + break; + + case RAWL_DFMT: /* RAWL */ + if (imagetorawl(image, parameters.outfile)) { + fprintf(stderr, + "[ERROR] Error generating rawl file. Outfile %s not generated\n", + parameters.outfile); + failed = 1; + } else if (!(parameters.quiet)) { + fprintf(stdout, "[INFO] Generated Outfile %s\n", parameters.outfile); + } + break; + + case TGA_DFMT: /* TGA */ + if (imagetotga(image, parameters.outfile)) { + fprintf(stderr, "[ERROR] Error generating tga file. Outfile %s not generated\n", + parameters.outfile); + failed = 1; + } else if (!(parameters.quiet)) { + fprintf(stdout, "[INFO] Generated Outfile %s\n", parameters.outfile); + } + break; +#ifdef OPJ_HAVE_LIBPNG + case PNG_DFMT: /* PNG */ + if (imagetopng(image, parameters.outfile)) { + fprintf(stderr, "[ERROR] Error generating png file. Outfile %s not generated\n", + parameters.outfile); + failed = 1; + } else if (!(parameters.quiet)) { + fprintf(stdout, "[INFO] Generated Outfile %s\n", parameters.outfile); + } + break; +#endif /* OPJ_HAVE_LIBPNG */ + /* Can happen if output file is TIFF or PNG + * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined + */ + default: + fprintf(stderr, "[ERROR] Outfile %s not generated\n", parameters.outfile); + failed = 1; + } + + /* free remaining structures */ + if (l_codec) { + opj_destroy_codec(l_codec); + } + + + /* free image data structure */ + opj_image_destroy(image); + + /* destroy the codestream index */ + opj_destroy_cstr_index(&cstr_index); + + if (failed) { + (void)remove(parameters.outfile); /* ignore return value */ + } + } +fin: + destroy_parameters(¶meters); + if (failed && img_fol.imgdirpath) { + free(img_fol.imgdirpath); + } + if (dirptr) { + if (dirptr->filename) { + free(dirptr->filename); + } + if (dirptr->filename_buf) { + free(dirptr->filename_buf); + } + free(dirptr); + } + if (numDecompressedImages && !failed && !(parameters.quiet)) { + fprintf(stdout, "decode time: %d ms\n", + (int)((tCumulative * 1000.0) / (OPJ_FLOAT64)numDecompressedImages)); + } + return failed ? EXIT_FAILURE : EXIT_SUCCESS; +} +/*end main()*/ diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c new file mode 100644 index 0000000..6e15fee --- /dev/null +++ b/src/bin/jp2/opj_dump.c @@ -0,0 +1,642 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2010, Mathieu Malaterre, GDCM + * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France + * Copyright (c) 2012, CS Systemes d'Information, France + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include "opj_config.h" + +#include +#include +#include +#include + +#ifdef _WIN32 +#include "windirent.h" +#else +#include +#endif /* _WIN32 */ + +#ifdef _WIN32 +#include +#else +#include +#define _stricmp strcasecmp +#define _strnicmp strncasecmp +#endif /* _WIN32 */ + +#include "openjpeg.h" +#include "opj_getopt.h" +#include "convert.h" +#include "index.h" + +#include "format_defs.h" +#include "opj_string.h" + +typedef struct dircnt { + /** Buffer for holding images read from Directory*/ + char *filename_buf; + /** Pointer to the buffer*/ + char **filename; +} dircnt_t; + + +typedef struct img_folder { + /** The directory path of the folder containing input images*/ + char *imgdirpath; + /** Output format*/ + const char *out_format; + /** Enable option*/ + char set_imgdir; + /** Enable Cod Format for output*/ + char set_out_format; + + int flag; +} img_fol_t; + +/* -------------------------------------------------------------------------- */ +/* Declarations */ +static int get_num_images(char *imgdirpath); +static int load_images(dircnt_t *dirptr, char *imgdirpath); +static int get_file_format(const char *filename); +static char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol, + opj_dparameters_t *parameters); +static int infile_format(const char *fname); + +static int parse_cmdline_decoder(int argc, char **argv, + opj_dparameters_t *parameters, img_fol_t *img_fol); + +/* -------------------------------------------------------------------------- */ +static void decode_help_display(void) +{ + fprintf(stdout, "\nThis is the opj_dump utility from the OpenJPEG project.\n" + "It dumps JPEG 2000 codestream info to stdout or a given file.\n" + "It has been compiled against openjp2 library v%s.\n\n", opj_version()); + + fprintf(stdout, "Parameters:\n"); + fprintf(stdout, "-----------\n"); + fprintf(stdout, "\n"); + fprintf(stdout, " -ImgDir \n"); + fprintf(stdout, " Image file Directory path \n"); + fprintf(stdout, " -i \n"); + fprintf(stdout, + " REQUIRED only if an Input image directory not specified\n"); + fprintf(stdout, + " Currently accepts J2K-files, JP2-files and JPT-files. The file type\n"); + fprintf(stdout, " is identified based on its suffix.\n"); + fprintf(stdout, " -o \n"); + fprintf(stdout, " OPTIONAL\n"); + fprintf(stdout, " Output file where file info will be dump.\n"); + fprintf(stdout, " By default it will be in the stdout.\n"); + fprintf(stdout, " -v "); /* FIXME WIP_MSD */ + fprintf(stdout, " OPTIONAL\n"); + fprintf(stdout, " Enable informative messages\n"); + fprintf(stdout, " By default verbose mode is off.\n"); + fprintf(stdout, "\n"); +} + +/* -------------------------------------------------------------------------- */ +static int get_num_images(char *imgdirpath) +{ + DIR *dir; + struct dirent* content; + int num_images = 0; + + /*Reading the input images from given input directory*/ + + dir = opendir(imgdirpath); + if (!dir) { + fprintf(stderr, "Could not open Folder %s\n", imgdirpath); + return 0; + } + + while ((content = readdir(dir)) != NULL) { + if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) { + continue; + } + num_images++; + } + closedir(dir); + return num_images; +} + +/* -------------------------------------------------------------------------- */ +static int load_images(dircnt_t *dirptr, char *imgdirpath) +{ + DIR *dir; + struct dirent* content; + int i = 0; + + /*Reading the input images from given input directory*/ + + dir = opendir(imgdirpath); + if (!dir) { + fprintf(stderr, "Could not open Folder %s\n", imgdirpath); + return 1; + } else { + fprintf(stderr, "Folder opened successfully\n"); + } + + while ((content = readdir(dir)) != NULL) { + if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) { + continue; + } + + strcpy(dirptr->filename[i], content->d_name); + i++; + } + closedir(dir); + return 0; +} + +/* -------------------------------------------------------------------------- */ +static int get_file_format(const char *filename) +{ + unsigned int i; + static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp", "tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; + static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; + const char *ext = strrchr(filename, '.'); + if (ext == NULL) { + return -1; + } + ext++; + if (ext) { + for (i = 0; i < sizeof(format) / sizeof(*format); i++) { + if (_strnicmp(ext, extension[i], 3) == 0) { + return format[i]; + } + } + } + + return -1; +} + +/* -------------------------------------------------------------------------- */ +static char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol, + opj_dparameters_t *parameters) +{ + char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN], + outfilename[OPJ_PATH_LEN], temp_ofname[OPJ_PATH_LEN]; + char *temp_p, temp1[OPJ_PATH_LEN] = ""; + + strcpy(image_filename, dirptr->filename[imageno]); + fprintf(stderr, "File Number %d \"%s\"\n", imageno, image_filename); + parameters->decod_format = get_file_format(image_filename); + if (parameters->decod_format == -1) { + return 1; + } + sprintf(infilename, "%s/%s", img_fol->imgdirpath, image_filename); + if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), + infilename) != 0) { + return 1; + } + + /*Set output file*/ + strcpy(temp_ofname, strtok(image_filename, ".")); + while ((temp_p = strtok(NULL, ".")) != NULL) { + strcat(temp_ofname, temp1); + sprintf(temp1, ".%s", temp_p); + } + if (img_fol->set_out_format == 1) { + sprintf(outfilename, "%s/%s.%s", img_fol->imgdirpath, temp_ofname, + img_fol->out_format); + if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), + outfilename) != 0) { + return 1; + } + } + return 0; +} + +/* -------------------------------------------------------------------------- */ +#define JP2_RFC3745_MAGIC "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a" +#define JP2_MAGIC "\x0d\x0a\x87\x0a" +/* position 45: "\xff\x52" */ +#define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51" + +static int infile_format(const char *fname) +{ + FILE *reader; + const char *s, *magic_s; + int ext_format, magic_format; + unsigned char buf[12]; + size_t l_nb_read; + + reader = fopen(fname, "rb"); + + if (reader == NULL) { + return -1; + } + + memset(buf, 0, 12); + l_nb_read = fread(buf, 1, 12, reader); + fclose(reader); + if (l_nb_read != 12) { + return -1; + } + + + + ext_format = get_file_format(fname); + + if (ext_format == JPT_CFMT) { + return JPT_CFMT; + } + + if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { + magic_format = JP2_CFMT; + magic_s = ".jp2"; + } else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) { + magic_format = J2K_CFMT; + magic_s = ".j2k or .jpc or .j2c"; + } else { + return -1; + } + + if (magic_format == ext_format) { + return ext_format; + } + + s = fname + strlen(fname) - 4; + + fputs("\n===========================================\n", stderr); + fprintf(stderr, "The extension of this file is incorrect.\n" + "FOUND %s. SHOULD BE %s\n", s, magic_s); + fputs("===========================================\n", stderr); + + return magic_format; +} +/* -------------------------------------------------------------------------- */ +/** + * Parse the command line + */ +/* -------------------------------------------------------------------------- */ +static int parse_cmdline_decoder(int argc, char **argv, + opj_dparameters_t *parameters, img_fol_t *img_fol) +{ + int totlen, c; + opj_option_t long_option[] = { + {"ImgDir", REQ_ARG, NULL, 'y'} + }; + const char optlist[] = "i:o:f:hv"; + + totlen = sizeof(long_option); + img_fol->set_out_format = 0; + do { + c = opj_getopt_long(argc, argv, optlist, long_option, totlen); + if (c == -1) { + break; + } + switch (c) { + case 'i': { /* input file */ + char *infile = opj_optarg; + parameters->decod_format = infile_format(infile); + switch (parameters->decod_format) { + case J2K_CFMT: + break; + case JP2_CFMT: + break; + case JPT_CFMT: + break; + default: + fprintf(stderr, + "[ERROR] Unknown input file format: %s \n" + " Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n", + infile); + return 1; + } + if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) { + fprintf(stderr, "[ERROR] Path is too long\n"); + return 1; + } + } + break; + + /* ------------------------------------------------------ */ + + case 'o': { /* output file */ + if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), + opj_optarg) != 0) { + fprintf(stderr, "[ERROR] Path is too long\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + case 'f': /* flag */ + img_fol->flag = atoi(opj_optarg); + break; + /* ----------------------------------------------------- */ + + case 'h': /* display an help description */ + decode_help_display(); + return 1; + + /* ------------------------------------------------------ */ + + case 'y': { /* Image Directory path */ + img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); + if (img_fol->imgdirpath == NULL) { + return 1; + } + strcpy(img_fol->imgdirpath, opj_optarg); + img_fol->set_imgdir = 1; + } + break; + + /* ----------------------------------------------------- */ + + case 'v': { /* Verbose mode */ + parameters->m_verbose = 1; + } + break; + + /* ----------------------------------------------------- */ + default: + fprintf(stderr, "[WARNING] An invalid option has been ignored.\n"); + break; + } + } while (c != -1); + + /* check for possible errors */ + if (img_fol->set_imgdir == 1) { + if (!(parameters->infile[0] == 0)) { + fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n"); + return 1; + } + if (img_fol->set_out_format == 0) { + fprintf(stderr, + "[ERROR] When -ImgDir is used, -OutFor must be used.\n"); + fprintf(stderr, "Only one format allowed.\n" + "Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n"); + return 1; + } + if (!(parameters->outfile[0] == 0)) { + fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together\n"); + return 1; + } + } else { + if (parameters->infile[0] == 0) { + fprintf(stderr, "[ERROR] Required parameter is missing\n"); + fprintf(stderr, "Example: %s -i image.j2k\n", argv[0]); + fprintf(stderr, " Help: %s -h\n", argv[0]); + return 1; + } + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ + +/** +sample error debug callback expecting no client object +*/ +static void error_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[ERROR] %s", msg); +} +/** +sample warning debug callback expecting no client object +*/ +static void warning_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[WARNING] %s", msg); +} +/** +sample debug callback expecting no client object +*/ +static void info_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[INFO] %s", msg); +} + +/* -------------------------------------------------------------------------- */ +/** + * OPJ_DUMP MAIN + */ +/* -------------------------------------------------------------------------- */ +int main(int argc, char *argv[]) +{ + FILE *fout = NULL; + + opj_dparameters_t parameters; /* Decompression parameters */ + opj_image_t* image = NULL; /* Image structure */ + opj_codec_t* l_codec = NULL; /* Handle to a decompressor */ + opj_stream_t *l_stream = NULL; /* Stream */ + opj_codestream_info_v2_t* cstr_info = NULL; + opj_codestream_index_t* cstr_index = NULL; + + OPJ_INT32 num_images, imageno; + img_fol_t img_fol; + dircnt_t *dirptr = NULL; + + /* Set decoding parameters to default values */ + opj_set_default_decoder_parameters(¶meters); + + /* Initialize img_fol */ + memset(&img_fol, 0, sizeof(img_fol_t)); + img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND; + + /* Parse input and get user encoding parameters */ + if (parse_cmdline_decoder(argc, argv, ¶meters, &img_fol) == 1) { + if (img_fol.imgdirpath) { + free(img_fol.imgdirpath); + } + + return EXIT_FAILURE; + } + + /* Initialize reading of directory */ + if (img_fol.set_imgdir == 1) { + int it_image; + num_images = get_num_images(img_fol.imgdirpath); + + dirptr = (dircnt_t*)malloc(sizeof(dircnt_t)); + if (!dirptr) { + return EXIT_FAILURE; + } + dirptr->filename_buf = (char*)malloc((size_t)num_images * OPJ_PATH_LEN * sizeof( + char)); /* Stores at max 10 image file names*/ + if (!dirptr->filename_buf) { + free(dirptr); + return EXIT_FAILURE; + } + dirptr->filename = (char**) malloc((size_t)num_images * sizeof(char*)); + + if (!dirptr->filename) { + goto fails; + } + + for (it_image = 0; it_image < num_images; it_image++) { + dirptr->filename[it_image] = dirptr->filename_buf + it_image * OPJ_PATH_LEN; + } + + if (load_images(dirptr, img_fol.imgdirpath) == 1) { + goto fails; + } + + if (num_images == 0) { + fprintf(stdout, "Folder is empty\n"); + goto fails; + } + } else { + num_images = 1; + } + + /* Try to open for writing the output file if necessary */ + if (parameters.outfile[0] != 0) { + fout = fopen(parameters.outfile, "w"); + if (!fout) { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile); + goto fails; + } + } else { + fout = stdout; + } + + /* Read the header of each image one by one */ + for (imageno = 0; imageno < num_images ; imageno++) { + + fprintf(stderr, "\n"); + + if (img_fol.set_imgdir == 1) { + if (get_next_file(imageno, dirptr, &img_fol, ¶meters)) { + fprintf(stderr, "skipping file...\n"); + continue; + } + } + + /* Read the input file and put it in memory */ + /* ---------------------------------------- */ + + l_stream = opj_stream_create_default_file_stream(parameters.infile, 1); + if (!l_stream) { + fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", + parameters.infile); + goto fails; + } + + /* Read the JPEG2000 stream */ + /* ------------------------ */ + + switch (parameters.decod_format) { + case J2K_CFMT: { /* JPEG-2000 codestream */ + /* Get a decoder handle */ + l_codec = opj_create_decompress(OPJ_CODEC_J2K); + break; + } + case JP2_CFMT: { /* JPEG 2000 compressed image data */ + /* Get a decoder handle */ + l_codec = opj_create_decompress(OPJ_CODEC_JP2); + break; + } + case JPT_CFMT: { /* JPEG 2000, JPIP */ + /* Get a decoder handle */ + l_codec = opj_create_decompress(OPJ_CODEC_JPT); + break; + } + default: + fprintf(stderr, "skipping file..\n"); + opj_stream_destroy(l_stream); + continue; + } + + /* catch events using our callbacks and give a local context */ + opj_set_info_handler(l_codec, info_callback, 00); + opj_set_warning_handler(l_codec, warning_callback, 00); + opj_set_error_handler(l_codec, error_callback, 00); + + parameters.flags |= OPJ_DPARAMETERS_DUMP_FLAG; + + /* Setup the decoder decoding parameters using user parameters */ + if (!opj_setup_decoder(l_codec, ¶meters)) { + fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n"); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + fclose(fout); + goto fails; + } + + /* Read the main header of the codestream and if necessary the JP2 boxes*/ + if (! opj_read_header(l_stream, l_codec, &image)) { + fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n"); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + fclose(fout); + goto fails; + } + + opj_dump_codec(l_codec, img_fol.flag, fout); + + cstr_info = opj_get_cstr_info(l_codec); + + cstr_index = opj_get_cstr_index(l_codec); + + /* close the byte stream */ + opj_stream_destroy(l_stream); + + /* free remaining structures */ + if (l_codec) { + opj_destroy_codec(l_codec); + } + + /* destroy the image header */ + opj_image_destroy(image); + + /* destroy the codestream index */ + opj_destroy_cstr_index(&cstr_index); + + /* destroy the codestream info */ + opj_destroy_cstr_info(&cstr_info); + + } + + /* Close the output file */ + fclose(fout); + + return EXIT_SUCCESS; + +fails: + if (dirptr) { + if (dirptr->filename) { + free(dirptr->filename); + } + if (dirptr->filename_buf) { + free(dirptr->filename_buf); + } + free(dirptr); + } + return EXIT_FAILURE; +} diff --git a/src/bin/jp2/windirent.h b/src/bin/jp2/windirent.h new file mode 100644 index 0000000..1950982 --- /dev/null +++ b/src/bin/jp2/windirent.h @@ -0,0 +1,683 @@ + +/* + * uce-dirent.h - operating system independent dirent implementation + * + * Copyright (C) 1998-2002 Toni Ronkko + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * ``Software''), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * + * May 28 1998, Toni Ronkko + * + * $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $ + * + * $Log: uce-dirent.h,v $ + * Revision 1.7 2002/05/13 10:48:35 tr + * embedded some source code directly to the header so that no source + * modules need to be included in the MS Visual C project using the + * interface, removed all the dependencies to other headers of the `uce' + * library so that the header can be made public + * + * Revision 1.6 2002/04/12 16:22:04 tr + * Unified Compiling Environment (UCE) replaced `std' library + * + * Revision 1.5 2001/07/20 16:33:40 tr + * moved to `std' library and re-named defines accordingly + * + * Revision 1.4 2001/07/10 16:47:18 tronkko + * revised comments + * + * Revision 1.3 2001/01/11 13:16:43 tr + * using ``uce-machine.h'' for finding out defines such as `FREEBSD' + * + * Revision 1.2 2000/10/08 16:00:41 tr + * copy of FreeBSD man page + * + * Revision 1.1 2000/07/10 05:53:16 tr + * Initial revision + * + * Revision 1.2 1998/07/19 18:29:14 tr + * Added error reporting capabilities and some asserts. + * + * Revision 1.1 1998/07/04 16:27:51 tr + * Initial revision + * + * + * MSVC 1.0 scans automatic dependencies incorrectly when your project + * contains this very header. The problem is that MSVC cannot handle + * include directives inside #if..#endif block those are never entered. + * Since this header ought to compile in many different operating systems, + * there had to be several conditional blocks that are compiled only in + * operating systems for what they were designed for. MSVC 1.0 cannot + * handle inclusion of sys/dir.h in a part that is compiled only in Apollo + * operating system. To fix the problem you need to insert DIR.H into + * SYSINCL.DAT located in MSVC\BIN directory and restart visual C++. + * Consult manuals for more informaton about the problem. + * + * Since many UNIX systems have dirent.h we assume to have one also. + * However, if your UNIX system does not have dirent.h you can download one + * for example at: http://ftp.uni-mannheim.de/ftp/GNU/dirent/dirent.tar.gz. + * You can also see if you have one of dirent.h, direct.h, dir.h, ndir.h, + * sys/dir.h and sys/ndir.h somewhere. Try defining HAVE_DIRENT_H, + * HAVE_DIRECT_H, HAVE_DIR_H, HAVE_NDIR_H, HAVE_SYS_DIR_H and + * HAVE_SYS_NDIR_H according to the files found. + */ +#ifndef DIRENT_H +#define DIRENT_H +#define DIRENT_H_INCLUDED + +/* find out platform */ +#if defined(MSDOS) /* MS-DOS */ +#elif defined(__MSDOS__) /* Turbo C/Borland */ +# define MSDOS +#elif defined(__DOS__) /* Watcom */ +# define MSDOS +#endif + +#if defined(WIN32) /* MS-Windows */ +#elif defined(__NT__) /* Watcom */ +# define WIN32 +#elif defined(_WIN32) /* Microsoft */ +# define WIN32 +#elif defined(__WIN32__) /* Borland */ +# define WIN32 +#endif + +/* + * See what kind of dirent interface we have unless autoconf has already + * determinated that. + */ +#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H) +# if defined(_MSC_VER) /* Microsoft C/C++ */ +/* no dirent.h */ +# elif defined(__MINGW32__) /* MinGW */ +/* no dirent.h */ +# elif defined(__BORLANDC__) /* Borland C/C++ */ +# define HAVE_DIRENT_H +# define VOID_CLOSEDIR +# elif defined(__TURBOC__) /* Borland Turbo C */ +/* no dirent.h */ +# elif defined(__WATCOMC__) /* Watcom C/C++ */ +# define HAVE_DIRECT_H +# elif defined(__apollo) /* Apollo */ +# define HAVE_SYS_DIR_H +# elif defined(__hpux) /* HP-UX */ +# define HAVE_DIRENT_H +# elif (defined(__alpha) || defined(__alpha__)) && !defined(__linux__) /* Alpha OSF1 */ +# error "not implemented" +# elif defined(__sgi) /* Silicon Graphics */ +# define HAVE_DIRENT_H +# elif defined(sun) || defined(__sun) /* Sun Solaris */ +# define HAVE_DIRENT_H +# elif defined(__FreeBSD__) /* FreeBSD */ +# define HAVE_DIRENT_H +# elif defined(__linux__) /* Linux */ +# define HAVE_DIRENT_H +# elif defined(__GNUC__) /* GNU C/C++ */ +# define HAVE_DIRENT_H +# else +# error "not implemented" +# endif +#endif + +/* include proper interface headers */ +#if defined(HAVE_DIRENT_H) +# include +# ifdef FREEBSD +# define NAMLEN(dp) ((int)((dp)->d_namlen)) +# else +# define NAMLEN(dp) ((int)(strlen((dp)->d_name))) +# endif + +#elif defined(HAVE_NDIR_H) +# include +# define NAMLEN(dp) ((int)((dp)->d_namlen)) + +#elif defined(HAVE_SYS_NDIR_H) +# include +# define NAMLEN(dp) ((int)((dp)->d_namlen)) + +#elif defined(HAVE_DIRECT_H) +# include +# define NAMLEN(dp) ((int)((dp)->d_namlen)) + +#elif defined(HAVE_DIR_H) +# include +# define NAMLEN(dp) ((int)((dp)->d_namlen)) + +#elif defined(HAVE_SYS_DIR_H) +# include +# include +# ifndef dirent +# define dirent direct +# endif +# define NAMLEN(dp) ((int)((dp)->d_namlen)) + +#elif defined(MSDOS) || defined(WIN32) + +/* figure out type of underlaying directory interface to be used */ +# if defined(WIN32) +# define DIRENT_WIN32_INTERFACE +# elif defined(MSDOS) +# define DIRENT_MSDOS_INTERFACE +# else +# error "missing native dirent interface" +# endif + +/*** WIN32 specifics ***/ +# if defined(DIRENT_WIN32_INTERFACE) +# include +# if !defined(DIRENT_MAXNAMLEN) +# define DIRENT_MAXNAMLEN (MAX_PATH) +# endif + + +/*** MS-DOS specifics ***/ +# elif defined(DIRENT_MSDOS_INTERFACE) +# include + +/* Borland defines file length macros in dir.h */ +# if defined(__BORLANDC__) +# include +# if !defined(DIRENT_MAXNAMLEN) +# define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT)) +# endif +# if !defined(_find_t) +# define _find_t find_t +# endif + +/* Turbo C defines ffblk structure in dir.h */ +# elif defined(__TURBOC__) +# include +# if !defined(DIRENT_MAXNAMLEN) +# define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT)) +# endif +# define DIRENT_USE_FFBLK + +/* MSVC */ +# elif defined(_MSC_VER) +# if !defined(DIRENT_MAXNAMLEN) +# define DIRENT_MAXNAMLEN (12) +# endif + +/* Watcom */ +# elif defined(__WATCOMC__) +# if !defined(DIRENT_MAXNAMLEN) +# if defined(__OS2__) || defined(__NT__) +# define DIRENT_MAXNAMLEN (255) +# else +# define DIRENT_MAXNAMLEN (12) +# endif +# endif + +# endif +# endif + +/*** generic MS-DOS and MS-Windows stuff ***/ +# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN) +# define NAME_MAX DIRENT_MAXNAMLEN +# endif +# if NAME_MAX < DIRENT_MAXNAMLEN +# error "assertion failed: NAME_MAX >= DIRENT_MAXNAMLEN" +# endif + + +/* + * Substitute for real dirent structure. Note that `d_name' field is a + * true character array although we have it copied in the implementation + * dependent data. We could save some memory if we had declared `d_name' + * as a pointer referring the name within implementation dependent data. + * We have not done that since some code may rely on sizeof(d_name) to be + * something other than four. Besides, directory entries are typically so + * small that it takes virtually no time to copy them from place to place. + */ +typedef struct dirent { + char d_name[NAME_MAX + 1]; + + /*** Operating system specific part ***/ +# if defined(DIRENT_WIN32_INTERFACE) /*WIN32*/ + WIN32_FIND_DATA data; +# elif defined(DIRENT_MSDOS_INTERFACE) /*MSDOS*/ +# if defined(DIRENT_USE_FFBLK) + struct ffblk data; +# else + struct _find_t data; +# endif +# endif +} dirent; + +/* DIR substitute structure containing directory name. The name is + * essential for the operation of ``rewinndir'' function. */ +typedef struct DIR { + char *dirname; /* directory being scanned */ + dirent current; /* current entry */ + int dirent_filled; /* is current un-processed? */ + + /*** Operating system specific part ***/ +# if defined(DIRENT_WIN32_INTERFACE) + HANDLE search_handle; +# elif defined(DIRENT_MSDOS_INTERFACE) +# endif +} DIR; + +# ifdef __cplusplus +extern "C" { +# endif + +/* supply prototypes for dirent functions */ +static DIR *opendir(const char *dirname); +static struct dirent *readdir(DIR *dirp); +static int closedir(DIR *dirp); +#ifdef unused +static void rewinddir(DIR *dirp); +#endif + +/* + * Implement dirent interface as static functions so that the user does not + * need to change his project in any way to use dirent function. With this + * it is sufficient to include this very header from source modules using + * dirent functions and the functions will be pulled in automatically. + */ +#include +#include +#include +#include +#include + +/* use ffblk instead of _find_t if requested */ +#if defined(DIRENT_USE_FFBLK) +# define _A_ARCH (FA_ARCH) +# define _A_HIDDEN (FA_HIDDEN) +# define _A_NORMAL (0) +# define _A_RDONLY (FA_RDONLY) +# define _A_SUBDIR (FA_DIREC) +# define _A_SYSTEM (FA_SYSTEM) +# define _A_VOLID (FA_LABEL) +# define _dos_findnext(dest) findnext(dest) +# define _dos_findfirst(name,flags,dest) findfirst(name,dest,flags) +#endif + +static int _initdir(DIR *p); +static const char *_getdirname(const struct dirent *dp); +static void _setdirname(struct DIR *dirp); + +/* + * + * open directory stream for reading + * DIR *opendir (const char *dirname); + * + * Open named directory stream for read and return pointer to the + * internal working area that is used for retrieving individual directory + * entries. The internal working area has no fields of your interest. + * + * Returns a pointer to the internal working area or NULL in case the + * directory stream could not be opened. Global `errno' variable will set + * in case of error as follows: + * + * + * [EACESS |Permission denied. + * [EMFILE |Too many open files used by the process. + * [ENFILE |Too many open files in system. + * [ENOENT |Directory does not exist. + * [ENOMEM |Insufficient memory. + * [ENOTDIR |dirname does not refer to directory. This value is not + * reliable on MS-DOS and MS-Windows platforms. Many + * implementations return ENOENT even when the name refers to a + * file.] + *
+ *
+ */ +static DIR *opendir(const char *dirname) +{ + DIR *dirp; + assert(dirname != NULL); + + dirp = (DIR*)malloc(sizeof(struct DIR)); + if (dirp != NULL) { + char *p; + + /* allocate room for directory name */ + dirp->dirname = (char*) malloc(strlen(dirname) + 1 + strlen("\\*.*")); + if (dirp->dirname == NULL) { + /* failed to duplicate directory name. errno set by malloc() */ + free(dirp); + return NULL; + } + /* Copy directory name while appending directory separator and "*.*". + * Directory separator is not appended if the name already ends with + * drive or directory separator. Directory separator is assumed to be + * '/' or '\' and drive separator is assumed to be ':'. */ + strcpy(dirp->dirname, dirname); + p = strchr(dirp->dirname, '\0'); + if (dirp->dirname < p && + *(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') { + strcpy(p++, "\\"); + } +# ifdef DIRENT_WIN32_INTERFACE + strcpy(p, "*"); /*scan files with and without extension in win32*/ +# else + strcpy(p, "*.*"); /*scan files with and without extension in DOS*/ +# endif + + /* open stream */ + if (_initdir(dirp) == 0) { + /* initialization failed */ + free(dirp->dirname); + free(dirp); + return NULL; + } + } + return dirp; +} + + +/* + * + * read a directory entry + * struct dirent *readdir (DIR *dirp); + * + * Read individual directory entry and return pointer to a structure + * containing the name of the entry. Individual directory entries returned + * include normal files, sub-directories, pseudo-directories "." and ".." + * and also volume labels, hidden files and system files in MS-DOS and + * MS-Windows. You might want to use stat(2) function to determinate which + * one are you dealing with. Many dirent implementations already contain + * equivalent information in dirent structure but you cannot depend on + * this. + * + * The dirent structure contains several system dependent fields that + * generally have no interest to you. The only interesting one is char + * d_name[] that is also portable across different systems. The d_name + * field contains the name of the directory entry without leading path. + * While d_name is portable across different systems the actual storage + * capacity of d_name varies from system to system and there is no portable + * way to find out it at compile time as different systems define the + * capacity of d_name with different macros and some systems do not define + * capacity at all (besides actual declaration of the field). If you really + * need to find out storage capacity of d_name then you might want to try + * NAME_MAX macro. The NAME_MAX is defined in POSIX standard although + * there are many MS-DOS and MS-Windows implementations those do not define + * it. There are also systems that declare d_name as "char d_name[1]" and + * then allocate suitable amount of memory at run-time. Thanks to Alain + * Decamps (Alain.Decamps@advalvas.be) for pointing it out to me. + * + * This all leads to the fact that it is difficult to allocate space + * for the directory names when the very same program is being compiled on + * number of operating systems. Therefore I suggest that you always + * allocate space for directory names dynamically. + * + * + * Returns a pointer to a structure containing name of the directory entry + * in `d_name' field or NULL if there was an error. In case of an error the + * global `errno' variable will set as follows: + * + * + * [EBADF |dir parameter refers to an invalid directory stream. This value + * is not set reliably on all implementations.] + *
+ *
+ */ +static struct dirent * +readdir(DIR *dirp) +{ + assert(dirp != NULL); + if (dirp == NULL) { + errno = EBADF; + return NULL; + } + +#if defined(DIRENT_WIN32_INTERFACE) + if (dirp->search_handle == INVALID_HANDLE_VALUE) { + /* directory stream was opened/rewound incorrectly or it ended normally */ + errno = EBADF; + return NULL; + } +#endif + + if (dirp->dirent_filled != 0) { + /* + * Directory entry has already been retrieved and there is no need to + * retrieve a new one. Directory entry will be retrieved in advance + * when the user calls readdir function for the first time. This is so + * because real dirent has separate functions for opening and reading + * the stream whereas Win32 and DOS dirents open the stream + * automatically when we retrieve the first file. Therefore, we have to + * save the first file when opening the stream and later we have to + * return the saved entry when the user tries to read the first entry. + */ + dirp->dirent_filled = 0; + } else { + /* fill in entry and return that */ +#if defined(DIRENT_WIN32_INTERFACE) + if (FindNextFile(dirp->search_handle, &dirp->current.data) == FALSE) { + /* Last file has been processed or an error occurred */ + FindClose(dirp->search_handle); + dirp->search_handle = INVALID_HANDLE_VALUE; + errno = ENOENT; + return NULL; + } + +# elif defined(DIRENT_MSDOS_INTERFACE) + if (_dos_findnext(&dirp->current.data) != 0) { + /* _dos_findnext and findnext will set errno to ENOENT when no + * more entries could be retrieved. */ + return NULL; + } +# endif + + _setdirname(dirp); + assert(dirp->dirent_filled == 0); + } + return &dirp->current; +} + + +/* + * + * close directory stream. + * int closedir (DIR *dirp); + * + * Close directory stream opened by the `opendir' function. Close of + * directory stream invalidates the DIR structure as well as previously read + * dirent entry. + * + * The function typically returns 0 on success and -1 on failure but + * the function may be declared to return void on same systems. At least + * Borland C/C++ and some UNIX implementations use void as a return type. + * The dirent wrapper tries to define VOID_CLOSEDIR whenever closedir is + * known to return nothing. The very same definition is made by the GNU + * autoconf if you happen to use it. + * + * The global `errno' variable will set to EBADF in case of error. + * + */ +static int +closedir(DIR *dirp) +{ + int retcode = 0; + + /* make sure that dirp points to legal structure */ + assert(dirp != NULL); + if (dirp == NULL) { + errno = EBADF; + return -1; + } + + /* free directory name and search handles */ + if (dirp->dirname != NULL) { + free(dirp->dirname); + } + +#if defined(DIRENT_WIN32_INTERFACE) + if (dirp->search_handle != INVALID_HANDLE_VALUE) { + if (FindClose(dirp->search_handle) == FALSE) { + /* Unknown error */ + retcode = -1; + errno = EBADF; + } + } +#endif + + /* clear dirp structure to make sure that it cannot be used anymore*/ + memset(dirp, 0, sizeof(*dirp)); +# if defined(DIRENT_WIN32_INTERFACE) + dirp->search_handle = INVALID_HANDLE_VALUE; +# endif + + free(dirp); + return retcode; +} + + +#ifdef unused +/* + * + * rewind directory stream to the beginning + * void rewinddir (DIR *dirp); + * + * Rewind directory stream to the beginning so that the next call of + * readdir() returns the very first directory entry again. However, note + * that next call of readdir() may not return the same directory entry as it + * did in first time. The directory stream may have been affected by newly + * created files. + * + * Almost every dirent implementation ensure that rewinddir will update + * the directory stream to reflect any changes made to the directory entries + * since the previous ``opendir'' or ``rewinddir'' call. Keep an eye on + * this if your program depends on the feature. I know at least one dirent + * implementation where you are required to close and re-open the stream to + * see the changes. + * + * Returns nothing. If something went wrong while rewinding, you will + * notice it later when you try to retrieve the first directory entry. + */ +static void +rewinddir(DIR *dirp) +{ + /* make sure that dirp is legal */ + assert(dirp != NULL); + if (dirp == NULL) { + errno = EBADF; + return; + } + assert(dirp->dirname != NULL); + + /* close previous stream */ +#if defined(DIRENT_WIN32_INTERFACE) + if (dirp->search_handle != INVALID_HANDLE_VALUE) { + if (FindClose(dirp->search_handle) == FALSE) { + /* Unknown error */ + errno = EBADF; + } + } +#endif + + /* re-open previous stream */ + if (_initdir(dirp) == 0) { + /* initialization failed but we cannot deal with error. User will notice + * error later when she tries to retrieve first directory enty. */ + /*EMPTY*/; + } +} +#endif + +/* + * Open native directory stream object and retrieve first file. + * Be sure to close previous stream before opening new one. + */ +static int +_initdir(DIR *dirp) +{ + assert(dirp != NULL); + assert(dirp->dirname != NULL); + dirp->dirent_filled = 0; + +# if defined(DIRENT_WIN32_INTERFACE) + /* Open stream and retrieve first file */ + dirp->search_handle = FindFirstFile(dirp->dirname, &dirp->current.data); + if (dirp->search_handle == INVALID_HANDLE_VALUE) { + /* something went wrong but we don't know what. GetLastError() could + * give us more information about the error, but then we should map + * the error code into errno. */ + errno = ENOENT; + return 0; + } + +# elif defined(DIRENT_MSDOS_INTERFACE) + if (_dos_findfirst(dirp->dirname, + _A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN, + &dirp->current.data) != 0) { + /* _dos_findfirst and findfirst will set errno to ENOENT when no + * more entries could be retrieved. */ + return 0; + } +# endif + + /* initialize DIR and it's first entry */ + _setdirname(dirp); + dirp->dirent_filled = 1; + return 1; +} + + +/* + * Return implementation dependent name of the current directory entry. + */ +static const char * +_getdirname(const struct dirent *dp) +{ +#if defined(DIRENT_WIN32_INTERFACE) + return dp->data.cFileName; + +#elif defined(DIRENT_USE_FFBLK) + return dp->data.ff_name; + +#else + return dp->data.name; +#endif +} + + +/* + * Copy name of implementation dependent directory entry to the d_name field. + */ +static void +_setdirname(struct DIR *dirp) +{ + /* make sure that d_name is long enough */ + assert(strlen(_getdirname(&dirp->current)) <= NAME_MAX); + + strncpy(dirp->current.d_name, + _getdirname(&dirp->current), + NAME_MAX); + dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/ +} + +# ifdef __cplusplus +} +# endif +# define NAMLEN(dp) ((int)(strlen((dp)->d_name))) + +#else +# error "missing dirent interface" +#endif + + +#endif /*DIRENT_H*/ diff --git a/src/bin/jp3d/CMakeLists.txt b/src/bin/jp3d/CMakeLists.txt new file mode 100644 index 0000000..3cac1a8 --- /dev/null +++ b/src/bin/jp3d/CMakeLists.txt @@ -0,0 +1,41 @@ +# Build the demo app, small examples + +# First thing define the common source: +set(common_SRCS + convert.c + ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c + ) + +# Headers file are located here: +include_directories( + ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h + ${OPENJPEG_SOURCE_DIR}/src/lib/openjp3d + ${LCMS_INCLUDE_DIRNAME} + ${OPENJPEG_SOURCE_DIR}/src/bin/common + ${Z_INCLUDE_DIRNAME} + ${PNG_INCLUDE_DIRNAME} + ${TIFF_INCLUDE_DIRNAME} + ) + +if(WIN32) + if(BUILD_SHARED_LIBS) + add_definitions(-DOPJ_EXPORTS) + else() + add_definitions(-DOPJ_STATIC) + endif() +endif() + +# Loop over all executables: +foreach(exe opj_jp3d_compress opj_jp3d_decompress) + add_executable(${exe} ${exe}.c ${common_SRCS}) + target_link_libraries(${exe} openjp3d) + # On unix you need to link to the math library: + if(UNIX) + target_link_libraries(${exe} m) + endif(UNIX) + # Install exe + install(TARGETS ${exe} + EXPORT OpenJP3DTargets + DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications + ) +endforeach() diff --git a/src/bin/jp3d/convert.c b/src/bin/jp3d/convert.c new file mode 100644 index 0000000..acad8f8 --- /dev/null +++ b/src/bin/jp3d/convert.c @@ -0,0 +1,1050 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include "openjp3d.h" +#ifdef _WIN32 +#include "windirent.h" +#else +#include +#endif /* _WIN32 */ + + + +void dump_volume(FILE *fd, opj_volume_t * vol) +{ + int compno; + fprintf(fd, "volume {\n"); + fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", vol->x0, vol->y0, + vol->z0, vol->x1, vol->y1, vol->z1); + fprintf(fd, " numcomps=%d\n", vol->numcomps); + for (compno = 0; compno < vol->numcomps; compno++) { + opj_volume_comp_t *comp = &vol->comps[compno]; + fprintf(fd, " comp %d {\n", compno); + fprintf(fd, " dx=%d, dy=%d, dz=%d\n", comp->dx, comp->dy, comp->dz); + fprintf(fd, " prec=%d\n", comp->prec); + fprintf(fd, " sgnd=%d\n", comp->sgnd); + fprintf(fd, " }\n"); + } + fprintf(fd, "}\n"); +} + +/* + * Get logarithm of an integer and round downwards. + * + * log2(a) + */ +static int int_floorlog2(int a) +{ + int l; + for (l = 0; a > 1; l++) { + a >>= 1; + } + return l; +} + +/* + * Divide an integer by a power of 2 and round upwards. + * + * a divided by 2^b + */ +static int int_ceildivpow2(int a, int b) +{ + return (a + (1 << b) - 1) >> b; +} + +/* + * Divide an integer and round upwards. + * + * a divided by b + */ +static int int_ceildiv(int a, int b) +{ + return (a + b - 1) / b; +} + + +/* -->> -->> -->> -->> + +PGX IMAGE FORMAT + +<<-- <<-- <<-- <<-- */ + + +unsigned char readuchar(FILE * f) +{ + unsigned char c1; + fread(&c1, 1, 1, f); + return c1; +} + +unsigned short readushort(FILE * f, int bigendian) +{ + unsigned char c1, c2; + fread(&c1, 1, 1, f); + fread(&c2, 1, 1, f); + if (bigendian) { + return (c1 << 8) + c2; + } else { + return (c2 << 8) + c1; + } +} + +unsigned int readuint(FILE * f, int bigendian) +{ + unsigned char c1, c2, c3, c4; + fread(&c1, 1, 1, f); + fread(&c2, 1, 1, f); + fread(&c3, 1, 1, f); + fread(&c4, 1, 1, f); + if (bigendian) { + return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4; + } else { + return (c4 << 24) + (c3 << 16) + (c2 << 8) + c1; + } +} +/*****************************************/ +static unsigned short ShortSwap(unsigned short v) +{ + unsigned char c1, c2; + c1 = v & 0xff; + c2 = (v >> 8) & 0xff; + return (c1 << 8) + c2; +} + +static unsigned int LongSwap(unsigned int i) +{ + unsigned char b1, b2, b3, b4; + b1 = i & 255; + b2 = (i >> 8) & 255; + b3 = (i >> 16) & 255; + b4 = (i >> 24) & 255; + return ((int)b1 << 24) + ((int)b2 << 16) + ((int)b3 << 8) + b4; +} +/*****************************************/ + +opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) +{ + + FILE *f = NULL; + int w, h, prec; + unsigned long offset; + int i, s, numcomps, maxvalue, sliceno, slicepos, maxslice = 0; + + OPJ_COLOR_SPACE color_space; + opj_volume_cmptparm_t cmptparm; /* maximum of 1 component */ + opj_volume_t * volume = NULL; + + char endian1, endian2, sign; + char signtmp[32]; + char temp[32]; + opj_volume_comp_t *comp = NULL; + + DIR *dirp; + struct dirent *direntp; + + char *tmp = NULL, *tmp2 = NULL, + *point = NULL, *pgx = NULL; + char tmpdirpath[MAX_PATH]; + char dirpath[MAX_PATH]; + char pattern[MAX_PATH]; + char pgxfiles[MAX_SLICES][MAX_PATH]; + int pgxslicepos[MAX_SLICES]; + char tmpno[3]; + + numcomps = 1; + color_space = CLRSPC_GRAY; + sliceno = 0; + maxvalue = 0; + memset(pgxfiles, 0, MAX_SLICES * MAX_PATH * sizeof(char)); + memset(&cmptparm, 0, sizeof(opj_volume_cmptparm_t)); + + /* Separación del caso de un único slice frente al de muchos */ + if ((tmp = strrchr(relpath, '-')) == NULL) { + /*fprintf(stdout,"[INFO] A volume of only one slice....\n");*/ + sliceno = 1; + maxslice = 1; + strcpy(pgxfiles[0], relpath); + + } else { + /*Fetch only the path */ + strcpy(tmpdirpath, relpath); + if ((tmp = strrchr(tmpdirpath, '/')) != NULL) { + tmp++; + *tmp = '\0'; + strcpy(dirpath, tmpdirpath); + } else { + strcpy(dirpath, "./"); + } + + /*Fetch the pattern of the volume slices*/ + if ((tmp = strrchr(relpath, '/')) != NULL) { + tmp++; + } else { + tmp = relpath; + } + if ((tmp2 = strrchr(tmp, '-')) != NULL) { + *tmp2 = '\0'; + } else { + fprintf(stdout, "[ERROR] tmp2 ha dado null. no ha encontrado el * %s %s", tmp, + relpath); + return NULL; + } + strcpy(pattern, tmp); + + dirp = opendir(dirpath); + if (dirp == NULL) { + fprintf(stdout, + "[ERROR] Infile must be a .pgx file or a directory that contain pgx files"); + return NULL; + } + + /*Read all .pgx files of directory */ + while ((direntp = readdir(dirp)) != NULL) { + /* Found a directory, but ignore . and .. */ + if (strcmp(".", direntp->d_name) == 0 || strcmp("..", direntp->d_name) == 0) { + continue; + } + + if (((pgx = strstr(direntp->d_name, pattern)) != NULL) && + ((tmp2 = strstr(direntp->d_name, ".pgx")) != NULL)) { + + strcpy(tmp, dirpath); + tmp = strcat(tmp, direntp->d_name); + + /*Obtenemos el index de la secuencia de slices*/ + if ((tmp2 = strpbrk(direntp->d_name, "0123456789")) == NULL) { + continue; + } + i = 0; + while (tmp2 != NULL) { + tmpno[i++] = *tmp2; + point = tmp2; + tmp2 = strpbrk(tmp2 + 1, "0123456789"); + } + tmpno[i] = '\0'; + + /*Comprobamos que no estamos leyendo algo raro como pattern.jp3d*/ + if ((point = strpbrk(point, ".")) == NULL) { + break; + } + /*Slicepos --> index de slice; Sliceno --> no de slices hasta el momento*/ + slicepos = atoi(tmpno); + pgxslicepos[sliceno] = slicepos - 1; + sliceno++; + if (slicepos > maxslice) { + maxslice = slicepos; + } + + /*Colocamos el slices en su posicion correspondiente*/ + strcpy(pgxfiles[slicepos - 1], tmp); + } + } + + }/* else if pattern*.pgx */ + + if (!sliceno) { + fprintf(stdout, + "[ERROR] No slices with this pattern founded !! Please check input volume name\n"); + return NULL; + } + /*if ( maxslice != sliceno) { + fprintf(stdout,"[ERROR] Slices are not sequentially numbered !! Please rename them accordingly\n"); + return NULL; + }*/ + + for (s = 0; s < sliceno; s++) { + int pos = maxslice == sliceno ? s : pgxslicepos[s]; + f = fopen(pgxfiles[pos], "rb"); + if (!f) { + fprintf(stdout, "[ERROR] Failed to open %s for reading !\n", pgxfiles[s]); + return NULL; + } + fprintf(stdout, "[INFO] Loading %s \n", pgxfiles[pos]); + + fseek(f, 0, SEEK_SET); + fscanf(f, "PG%31[ \t]%c%c%31[ \t+-]%d%31[ \t]%d%31[ \t]%d", temp, &endian1, + &endian2, signtmp, &prec, temp, &w, temp, &h); + + i = 0; + sign = '+'; + while (signtmp[i] != '\0') { + if (signtmp[i] == '-') { + sign = '-'; + } + i++; + } + + fgetc(f); + if (endian1 == 'M' && endian2 == 'L') { + cmptparm.bigendian = 1; + } else if (endian2 == 'M' && endian1 == 'L') { + cmptparm.bigendian = 0; + } else { + fprintf(stdout, "[ERROR] Bad pgx header, please check input file\n"); + fclose(f); + return NULL; + } + + if (s == 0) { + /* initialize volume component */ + + cmptparm.x0 = parameters->volume_offset_x0; + cmptparm.y0 = parameters->volume_offset_y0; + cmptparm.z0 = parameters->volume_offset_z0; + cmptparm.w = !cmptparm.x0 ? (w - 1) * parameters->subsampling_dx + 1 : + cmptparm.x0 + (w - 1) * parameters->subsampling_dx + 1; + cmptparm.h = !cmptparm.y0 ? (h - 1) * parameters->subsampling_dy + 1 : + cmptparm.y0 + (h - 1) * parameters->subsampling_dy + 1; + cmptparm.l = !cmptparm.z0 ? (sliceno - 1) * parameters->subsampling_dz + 1 : + cmptparm.z0 + (sliceno - 1) * parameters->subsampling_dz + 1; + + if (sign == '-') { + cmptparm.sgnd = 1; + } else { + cmptparm.sgnd = 0; + } + cmptparm.prec = prec; + cmptparm.bpp = prec; + cmptparm.dcoffset = parameters->dcoffset; + cmptparm.dx = parameters->subsampling_dx; + cmptparm.dy = parameters->subsampling_dy; + cmptparm.dz = parameters->subsampling_dz; + + /* create the volume */ + volume = opj_volume_create(numcomps, &cmptparm, color_space); + if (!volume) { + fclose(f); + return NULL; + } + /* set volume offset and reference grid */ + volume->x0 = cmptparm.x0; + volume->y0 = cmptparm.y0; + volume->z0 = cmptparm.z0; + volume->x1 = cmptparm.w; + volume->y1 = cmptparm.h; + volume->z1 = cmptparm.l; + + /* set volume data :only one component, that is a volume*/ + comp = &volume->comps[0]; + + }/*if sliceno==1*/ + + offset = w * h * s; + + for (i = 0; i < w * h; i++) { + int v; + if (comp->prec <= 8) { + if (!comp->sgnd) { + v = readuchar(f); + } else { + v = (char) readuchar(f); + } + } else if (comp->prec <= 16) { + if (!comp->sgnd) { + v = readushort(f, cmptparm.bigendian); + } else { + v = (short) readushort(f, cmptparm.bigendian); + } + } else { + if (!comp->sgnd) { + v = readuint(f, cmptparm.bigendian); + } else { + v = (int) readuint(f, cmptparm.bigendian); + } + } + if (v > maxvalue) { + maxvalue = v; + } + comp->data[i + offset] = v; + + } + fclose(f); + } /* for s --> sliceno*/ + comp->bpp = int_floorlog2(maxvalue) + 1; + if (sliceno != 1) { + closedir(dirp); + } + /*dump_volume(stdout, volume);*/ + return volume; +} + + +int volumetopgx(opj_volume_t * volume, char *outfile) +{ + int w, wr, wrr, h, hr, hrr, l, lr, lrr; + int i, j, compno, offset, sliceno; + FILE *fdest = NULL; + + for (compno = 0; compno < volume->numcomps; compno++) { + opj_volume_comp_t *comp = &volume->comps[compno]; + char name[256]; + int nbytes = 0; + char *tmp = outfile; + while (*tmp) { + tmp++; + } + while (*tmp != '.') { + tmp--; + } + *tmp = '\0'; + for (sliceno = 0; sliceno < volume->z1 - volume->z0; sliceno++) { + + if (volume->numcomps > 1) { + sprintf(name, "%s%d-%d.pgx", outfile, sliceno + 1, compno); + } else if ((volume->z1 - volume->z0) > 1) { + sprintf(name, "%s%d.pgx", outfile, sliceno + 1); + } else { + sprintf(name, "%s.pgx", outfile); + } + + fdest = fopen(name, "wb"); + if (!fdest) { + fprintf(stdout, "[ERROR] Failed to open %s for writing \n", name); + return 1; + } + + fprintf(stdout, "[INFO] Writing in %s (%s)\n", name, + volume->comps[0].bigendian ? "Bigendian" : "Little-endian"); + + w = int_ceildiv(volume->x1 - volume->x0, volume->comps[compno].dx); + wr = volume->comps[compno].w; + wrr = int_ceildivpow2(volume->comps[compno].w, volume->comps[compno].factor[0]); + + h = int_ceildiv(volume->y1 - volume->y0, volume->comps[compno].dy); + hr = volume->comps[compno].h; + hrr = int_ceildivpow2(volume->comps[compno].h, volume->comps[compno].factor[1]); + + l = int_ceildiv(volume->z1 - volume->z0, volume->comps[compno].dz); + lr = volume->comps[compno].l; + lrr = int_ceildivpow2(volume->comps[compno].l, volume->comps[compno].factor[2]); + + fprintf(fdest, "PG %c%c %c%d %d %d\n", comp->bigendian ? 'M' : 'L', + comp->bigendian ? 'L' : 'M', comp->sgnd ? '-' : '+', comp->prec, wr, hr); + if (comp->prec <= 8) { + nbytes = 1; + } else if (comp->prec <= 16) { + nbytes = 2; + } else { + nbytes = 4; + } + + offset = (sliceno / lrr * l) + (sliceno % lrr); + offset = wrr * hrr * offset; + /*fprintf(stdout,"%d %d %d %d\n",offset,wrr*hrr,wrr,w);*/ + for (i = 0; i < wrr * hrr; i++) { + int v = volume->comps[0].data[(i / wrr * w) + (i % wrr) + offset]; + if (volume->comps[0].bigendian) { + for (j = nbytes - 1; j >= 0; j--) { + char byte = (char)((v >> (j * 8)) & 0xff); + fwrite(&byte, 1, 1, fdest); + } + } else { + for (j = 0; j <= nbytes - 1; j++) { + char byte = (char)((v >> (j * 8)) & 0xff); + fwrite(&byte, 1, 1, fdest); + } + } + } + + fclose(fdest); + }/*for sliceno*/ + }/*for compno*/ + + return 0; +} + +/* -->> -->> -->> -->> + +BIN IMAGE FORMAT + +<<-- <<-- <<-- <<-- */ + +opj_volume_t* bintovolume(char *filename, char *fileimg, + opj_cparameters_t *parameters) +{ + int subsampling_dx = parameters->subsampling_dx; + int subsampling_dy = parameters->subsampling_dy; + int subsampling_dz = parameters->subsampling_dz; + + int i, compno, w, h, l, numcomps = 1; + int prec, max = 0; + + /* char temp[32];*/ + char line[100]; + int bigendian; + + FILE *f = NULL; + FILE *fimg = NULL; + OPJ_COLOR_SPACE color_space; + opj_volume_cmptparm_t cmptparm; /* maximum of 1 component */ + opj_volume_t * volume = NULL; + opj_volume_comp_t *comp = NULL; + + bigendian = 0; + color_space = CLRSPC_GRAY; + + fimg = fopen(fileimg, "r"); + if (!fimg) { + fprintf(stdout, "[ERROR] Failed to open %s for reading !!\n", fileimg); + return 0; + } + + fseek(fimg, 0, SEEK_SET); + while (!feof(fimg)) { + fgets(line, 100, fimg); + /*fprintf(stdout,"%s %d \n",line,feof(fimg));*/ + if (strncmp(line, "Bpp", 3) == 0) { + sscanf(line, "%*s%*[ \t]%d", &prec); + } else if (strncmp(line, "Color", 5) == 0) { + sscanf(line, "%*s%*[ \t]%d", &color_space); + } else if (strncmp(line, "Dim", 3) == 0) { + sscanf(line, "%*s%*[ \t]%d%*[ \t]%d%*[ \t]%d", &w, &h, &l); + } + } + /*fscanf(fimg, "Bpp%[ \t]%d%[ \t\n]",temp,&prec,temp);*/ + /*fscanf(fimg, "Color Map%[ \t]%d%[ \n\t]Dimensions%[ \t]%d%[ \t]%d%[ \t]%d%[ \n\t]",temp,&color_space,temp,temp,&w,temp,&h,temp,&l,temp);*/ + /*fscanf(fimg, "Resolution(mm)%[ \t]%d%[ \t]%d%[ \t]%d%[ \n\t]",temp,&subsampling_dx,temp,&subsampling_dy,temp,&subsampling_dz,temp);*/ + +#ifdef VERBOSE + fprintf(stdout, "[INFO] %d \t %d %d %d \t %3.2f %2.2f %2.2f \t %d \n", + color_space, w, h, l, subsampling_dx, subsampling_dy, subsampling_dz, prec); +#endif + fclose(fimg); + + /* initialize volume components */ + memset(&cmptparm, 0, sizeof(opj_volume_cmptparm_t)); + + cmptparm.prec = prec; + cmptparm.bpp = prec; + cmptparm.sgnd = 0; + cmptparm.bigendian = bigendian; + cmptparm.dcoffset = parameters->dcoffset; + cmptparm.dx = subsampling_dx; + cmptparm.dy = subsampling_dy; + cmptparm.dz = subsampling_dz; + cmptparm.w = w; + cmptparm.h = h; + cmptparm.l = l; + + /* create the volume */ + volume = opj_volume_create(numcomps, &cmptparm, color_space); + if (!volume) { + fprintf(stdout, "[ERROR] Unable to create volume"); + fclose(f); + return NULL; + } + + /* set volume offset and reference grid */ + volume->x0 = parameters->volume_offset_x0; + volume->y0 = parameters->volume_offset_y0; + volume->z0 = parameters->volume_offset_z0; + volume->x1 = parameters->volume_offset_x0 + (w - 1) * subsampling_dx + 1; + volume->y1 = parameters->volume_offset_y0 + (h - 1) * subsampling_dy + 1; + volume->z1 = parameters->volume_offset_z0 + (l - 1) * subsampling_dz + 1; + + /* set volume data */ + f = fopen(filename, "rb"); + if (!f) { + fprintf(stdout, "[ERROR] Failed to open %s for reading !!\n", filename); + return 0; + } + + /* BINARY */ + for (compno = 0; compno < volume->numcomps; compno++) { + int whl = w * h * l; + /* set volume data */ + comp = &volume->comps[compno]; + + /*if (comp->prec <= 8) { + if (!comp->sgnd) { + unsigned char *data = (unsigned char *) malloc(whl * sizeof(unsigned char)); + fread(data, 1, whl, f); + for (i = 0; i < whl; i++) { + comp->data[i] = data[i]; + if (comp->data[i] > max) + max = comp->data[i]; + } + free(data); + } else { + char *data = (char *) malloc(whl); + fread(data, 1, whl, f); + for (i = 0; i < whl; i++) { + comp->data[i] = data[i]; + if (comp->data[i] > max) + max = comp->data[i]; + } + free(data); + } + } else if (comp->prec <= 16) { + if (!comp->sgnd) { + unsigned short *data = (unsigned short *) malloc(whl * sizeof(unsigned short)); + int leido = fread(data, 2, whl, f); + if (!leido) { + free(data); fclose(f); + return NULL; + } + + for (i = 0; i < whl; i++) { + if (bigendian) //(c1 << 8) + c2; + comp->data[i] = data[i]; + else{ //(c2 << 8) + c1; + comp->data[i] = ShortSwap(data[i]); + } + if (comp->data[i] > max) + max = comp->data[i]; + } + free(data); + } else { + short *data = (short *) malloc(whl); + int leido = fread(data, 2, whl, f); + if (!leido) { + free(data); fclose(f); + return NULL; + } + for (i = 0; i < whl; i++) { + if (bigendian){ //(c1 << 8) + c2; + comp->data[i] = data[i]; + }else{ //(c2 << 8) + c1; + comp->data[i] = (short) ShortSwap((unsigned short) data[i]); + } + if (comp->data[i] > max) + max = comp->data[i]; + } + free(data); + } + } else { + if (!comp->sgnd) { + unsigned int *data = (unsigned int *) malloc(whl * sizeof(unsigned int)); + int leido = fread(data, 4, whl, f); + if (!leido) { + free(data); fclose(f); + return NULL; + } for (i = 0; i < whl; i++) { + if (!bigendian) + comp->data[i] = LongSwap(data[i]); + else + comp->data[i] = data[i]; + if (comp->data[i] > max) + max = comp->data[i]; + } + free(data); + } else { + int leido = fread(comp->data, 4, whl, f); + if (!leido) { + fclose(f); + return NULL; + } + for (i = 0; i < whl; i++) { + if (!bigendian) + comp->data[i] = (int) LongSwap((unsigned int) comp->data[i]); + if (comp->data[i] > max) + max = comp->data[i]; + } + } + }*/ + + for (i = 0; i < whl; i++) { + int v; + if (comp->prec <= 8) { + if (!comp->sgnd) { + v = readuchar(f); + } else { + v = (char) readuchar(f); + } + } else if (comp->prec <= 16) { + if (!comp->sgnd) { + v = readushort(f, bigendian); + } else { + v = (short) readushort(f, bigendian); + } + } else { + if (!comp->sgnd) { + v = readuint(f, bigendian); + } else { + v = (int) readuint(f, bigendian); + } + } + if (v > max) { + max = v; + } + comp->data[i] = v; + } + comp->bpp = int_floorlog2(max) + 1; + } + fclose(f); + return volume; +} + +int volumetobin(opj_volume_t * volume, char *outfile) +{ + int w, wr, wrr, h, hr, hrr, l, lr, lrr, max; + int i, j, compno, nbytes; + int offset, sliceno; + FILE *fdest = NULL; + FILE *fimgdest = NULL; + /* char *imgtemp;*/ + char name[256]; + + for (compno = 0; compno < 1; compno++) { /*Only one component*/ + + fdest = fopen(outfile, "wb"); + if (!fdest) { + fprintf(stdout, "[ERROR] Failed to open %s for writing\n", outfile); + return 1; + } + fprintf(stdout, "[INFO] Writing outfile %s (%s) \n", outfile, + volume->comps[0].bigendian ? "Bigendian" : "Little-endian"); + + w = int_ceildiv(volume->x1 - volume->x0, volume->comps[compno].dx); + wr = volume->comps[compno].w; + wrr = int_ceildivpow2(volume->comps[compno].w, volume->comps[compno].factor[0]); + + h = int_ceildiv(volume->y1 - volume->y0, volume->comps[compno].dy); + hr = volume->comps[compno].h; + hrr = int_ceildivpow2(volume->comps[compno].h, volume->comps[compno].factor[1]); + + l = int_ceildiv(volume->z1 - volume->z0, volume->comps[compno].dz); + lr = volume->comps[compno].l; + lrr = int_ceildivpow2(volume->comps[compno].l, volume->comps[compno].factor[2]); + + max = (volume->comps[compno].prec <= 8) ? 255 : (1 << + volume->comps[compno].prec) - 1; + + volume->comps[compno].x0 = int_ceildivpow2(volume->comps[compno].x0 - + int_ceildiv(volume->x0, volume->comps[compno].dx), + volume->comps[compno].factor[0]); + volume->comps[compno].y0 = int_ceildivpow2(volume->comps[compno].y0 - + int_ceildiv(volume->y0, volume->comps[compno].dy), + volume->comps[compno].factor[1]); + volume->comps[compno].z0 = int_ceildivpow2(volume->comps[compno].z0 - + int_ceildiv(volume->z0, volume->comps[compno].dz), + volume->comps[compno].factor[2]); + + if (volume->comps[0].prec <= 8) { + nbytes = 1; + } else if (volume->comps[0].prec <= 16) { + nbytes = 2; + } else { + nbytes = 4; + } + + /*fprintf(stdout,"w %d wr %d wrr %d h %d hr %d hrr %d l %d lr %d lrr %d max %d nbytes %d\n Factor %d %d %d",w,wr,wrr,h,hr,hrr,l,lr,lrr,max,nbytes,volume->comps[compno].factor[0],volume->comps[compno].factor[1],volume->comps[compno].factor[2]);*/ + + for (sliceno = 0; sliceno < lrr; sliceno++) { + offset = (sliceno / lrr * l) + (sliceno % lrr); + offset = wrr * hrr * offset; + for (i = 0; i < wrr * hrr; i++) { + int v = volume->comps[0].data[(i / wrr * w) + (i % wrr) + offset]; + if (volume->comps[0].bigendian) { + for (j = nbytes - 1; j >= 0; j--) { + char byte = (char)((v >> (j * 8)) & 0xff); + fwrite(&byte, 1, 1, fdest); + } + } else { + for (j = 0; j <= nbytes - 1; j++) { + char byte = (char)((v >> (j * 8)) & 0xff); + fwrite(&byte, 1, 1, fdest); + } + } + } + } + + } + + fclose(fdest); + + snprintf(name, sizeof(name), "%s.img", outfile); + fimgdest = fopen(name, "w"); + if (!fimgdest) { + fprintf(stdout, "[ERROR] Failed to open %s for writing\n", name); + return 1; + } + fprintf(fimgdest, + "Bpp\t%d\nColor Map\t2\nDimensions\t%d\t%d\t%d\nResolution(mm)\t%d\t%d\t%d\t\n", + volume->comps[0].prec, wrr, hrr, lrr, volume->comps[0].dx, volume->comps[0].dy, + volume->comps[0].dz); + + fclose(fimgdest); + return 0; +} +/* -->> -->> -->> -->> + +IMG IMAGE FORMAT + +<<-- <<-- <<-- <<-- */ +opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) +{ + int subsampling_dx = parameters->subsampling_dx; + int subsampling_dy = parameters->subsampling_dy; + int subsampling_dz = parameters->subsampling_dz; + + int i, compno, w, h, l, numcomps = 1; + int prec, max = 0, min = 0; + float dx, dy, dz; + char filename[100], tmpdirpath[100], dirpath[100], *tmp; + char line[100], datatype[100]; + int bigendian; + + FILE *f = NULL; + FILE *fimg = NULL; + OPJ_COLOR_SPACE color_space; + opj_volume_cmptparm_t cmptparm; /* maximum of 1 component */ + opj_volume_t * volume = NULL; + opj_volume_comp_t *comp = NULL; + + bigendian = 0; + color_space = CLRSPC_GRAY; + + fimg = fopen(fileimg, "r"); + if (!fimg) { + fprintf(stderr, "[ERROR] Failed to open %s for reading !!\n", fileimg); + return 0; + } + + /*Fetch only the path */ + strcpy(tmpdirpath, fileimg); + if ((tmp = strrchr(tmpdirpath, '/')) != NULL) { + tmp++; + *tmp = '\0'; + strcpy(dirpath, tmpdirpath); + } else { + strcpy(dirpath, "./"); + } + + fseek(fimg, 0, SEEK_SET); + while (!feof(fimg)) { + fgets(line, 100, fimg); + /*fprintf(stdout,"%s %d \n",line,feof(fimg));*/ + if (strncmp(line, "Image", 5) == 0) { + sscanf(line, "%*s%*[ \t]%s", datatype); + } else if (strncmp(line, "File", 4) == 0) { + sscanf(line, "%*s %*s%*[ \t]%s", filename); + strcat(dirpath, filename); + strcpy(filename, dirpath); + } else if (strncmp(line, "Min", 3) == 0) { + sscanf(line, "%*s %*s%*[ \t]%d%*[ \t]%d", &min, &max); + prec = int_floorlog2(max - min + 1); + } else if (strncmp(line, "Bpp", 3) == 0) { + sscanf(line, "%*s%*[ \t]%d", &prec); + } else if (strncmp(line, "Color", 5) == 0) { + sscanf(line, "%*s %*s%*[ \t]%d", &color_space); + } else if (strncmp(line, "Dim", 3) == 0) { + sscanf(line, "%*s%*[ \t]%d%*[ \t]%d%*[ \t]%d", &w, &h, &l); + } else if (strncmp(line, "Res", 3) == 0) { + sscanf(line, "%*s%*[ \t]%f%*[ \t]%f%*[ \t]%f", &dx, &dy, &dz); + } + + } +#ifdef VERBOSE + fprintf(stdout, "[INFO] %s %d \t %d %d %d \t %f %f %f \t %d %d %d \n", filename, + color_space, w, h, l, dx, dy, dz, max, min, prec); +#endif + fclose(fimg); + + /* error control */ + if (!prec || !w || !h || !l) { + fprintf(stderr, + "[ERROR] Unable to read IMG file correctly. Found some null values."); + return NULL; + } + + /* initialize volume components */ + memset(&cmptparm, 0, sizeof(opj_volume_cmptparm_t)); + + cmptparm.prec = prec; + cmptparm.bpp = prec; + cmptparm.sgnd = 0; + cmptparm.bigendian = bigendian; + cmptparm.dcoffset = parameters->dcoffset; + cmptparm.dx = subsampling_dx; + cmptparm.dy = subsampling_dy; + cmptparm.dz = subsampling_dz; + cmptparm.w = w; + cmptparm.h = h; + cmptparm.l = l; + + /* create the volume */ + volume = opj_volume_create(numcomps, &cmptparm, color_space); + if (!volume) { + fprintf(stdout, "[ERROR] Unable to create volume"); + return NULL; + } + + /* set volume offset and reference grid */ + volume->x0 = parameters->volume_offset_x0; + volume->y0 = parameters->volume_offset_y0; + volume->z0 = parameters->volume_offset_z0; + volume->x1 = parameters->volume_offset_x0 + (w - 1) * subsampling_dx + 1; + volume->y1 = parameters->volume_offset_y0 + (h - 1) * subsampling_dy + 1; + volume->z1 = parameters->volume_offset_z0 + (l - 1) * subsampling_dz + 1; + + max = 0; + /* set volume data */ + f = fopen(filename, "rb"); + if (!f) { + fprintf(stderr, "[ERROR] Failed to open %s for reading !!\n", filename); + fclose(f); + return 0; + } + + /* BINARY */ + for (compno = 0; compno < volume->numcomps; compno++) { + int whl = w * h * l; + /* set volume data */ + comp = &volume->comps[compno]; + + /*if (comp->prec <= 8) { + if (!comp->sgnd) { + unsigned char *data = (unsigned char *) malloc(whl * sizeof(unsigned char)); + fread(data, 1, whl, f); + for (i = 0; i < whl; i++) { + comp->data[i] = data[i]; + if (comp->data[i] > max) + max = comp->data[i]; + } + free(data); + } else { + char *data = (char *) malloc(whl); + fread(data, 1, whl, f); + for (i = 0; i < whl; i++) { + comp->data[i] = data[i]; + if (comp->data[i] > max) + max = comp->data[i]; + } + free(data); + } + } else if (comp->prec <= 16) { + if (!comp->sgnd) { + unsigned short *data = (unsigned short *) malloc(whl * sizeof(unsigned short)); + int leido = fread(data, 2, whl, f); + if (!leido) { + free(data); fclose(f); + return NULL; + } + + for (i = 0; i < whl; i++) { + if (bigendian) //(c1 << 8) + c2; + comp->data[i] = data[i]; + else{ //(c2 << 8) + c1; + comp->data[i] = ShortSwap(data[i]); + } + if (comp->data[i] > max) + max = comp->data[i]; + } + free(data); + } else { + short *data = (short *) malloc(whl); + int leido = fread(data, 2, whl, f); + if (!leido) { + free(data); fclose(f); + return NULL; + } + for (i = 0; i < whl; i++) { + if (bigendian){ //(c1 << 8) + c2; + comp->data[i] = data[i]; + }else{ //(c2 << 8) + c1; + comp->data[i] = (short) ShortSwap((unsigned short) data[i]); + } + if (comp->data[i] > max) + max = comp->data[i]; + } + free(data); + } + } else { + if (!comp->sgnd) { + unsigned int *data = (unsigned int *) malloc(whl * sizeof(unsigned int)); + int leido = fread(data, 4, whl, f); + if (!leido) { + free(data); fclose(f); + return NULL; + } for (i = 0; i < whl; i++) { + if (!bigendian) + comp->data[i] = LongSwap(data[i]); + else + comp->data[i] = data[i]; + if (comp->data[i] > max) + max = comp->data[i]; + } + free(data); + } else { + int leido = fread(comp->data, 4, whl, f); + if (!leido) { + fclose(f); + return NULL; + } + for (i = 0; i < whl; i++) { + if (!bigendian) + comp->data[i] = (int) LongSwap((unsigned int) comp->data[i]); + if (comp->data[i] > max) + max = comp->data[i]; + } + } + }*/ + + for (i = 0; i < whl; i++) { + int v; + if (comp->prec <= 8) { + if (!comp->sgnd) { + v = readuchar(f); + } else { + v = (char) readuchar(f); + } + } else if (comp->prec <= 16) { + if (!comp->sgnd) { + v = readushort(f, bigendian); + } else { + v = (short) readushort(f, bigendian); + } + } else { + if (!comp->sgnd) { + v = readuint(f, bigendian); + } else { + v = (int) readuint(f, bigendian); + } + } + if (v > max) { + max = v; + } + comp->data[i] = v; + } + comp->bpp = int_floorlog2(max) + 1; + } + fclose(f); + return volume; +} + diff --git a/src/bin/jp3d/convert.h b/src/bin/jp3d/convert.h new file mode 100644 index 0000000..255717e --- /dev/null +++ b/src/bin/jp3d/convert.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __JP3D_CONVERT_H +#define __JP3D_CONVERT_H + +/** +Load a single volume component encoded in PGX file format +@param filename Name of the PGX file to load +@param parameters *List ?* +@return Returns a greyscale volume if successful, returns NULL otherwise +*/ +opj_volume_t* pgxtovolume(char *filename, opj_cparameters_t *parameters); + +int volumetopgx(opj_volume_t *volume, char *outfile); + +opj_volume_t* bintovolume(char *filename, char *fileimg, + opj_cparameters_t *parameters); + +int volumetobin(opj_volume_t *volume, char *outfile); + +opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters); + +#endif /* __J2K_CONVERT_H */ + diff --git a/src/bin/jp3d/getopt.c b/src/bin/jp3d/getopt.c new file mode 100644 index 0000000..855b9ae --- /dev/null +++ b/src/bin/jp3d/getopt.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* last review : october 29th, 2002 */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int getopt(int nargc, char *const *nargv, const char *ostr) +{ + +# define __progname nargv[0] /* program name */ + + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (-1); + } + } /* option letter okay? */ + + if ((optopt = (int) * place++) == (int) ':' || !(oli = strchr(ostr, optopt))) { + /* if the user didn't specify '-' as an option, assume it means -1. */ + if (optopt == (int) '-') { + return (-1); + } + if (!*place) { + ++optind; + } + if (opterr && *ostr != ':') { + (void) fprintf(stdout, "[ERROR] %s: illegal option -- %c\n", __progname, + optopt); + } + return (BADCH); + } + + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) { + ++optind; + } + } else { /* need an argument */ + if (*place) { /* no white space */ + optarg = place; + } else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') { + return (BADARG); + } + if (opterr) { + (void) fprintf(stdout, "[ERROR] %s: option requires an argument -- %c\n", + __progname, optopt); + } + return (BADCH); + } else { /* white space */ + optarg = nargv[optind]; + } + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} diff --git a/src/bin/jp3d/getopt.h b/src/bin/jp3d/getopt.h new file mode 100644 index 0000000..935171b --- /dev/null +++ b/src/bin/jp3d/getopt.h @@ -0,0 +1,14 @@ +/* last review : october 29th, 2002 */ + +#ifndef _GETOPT_H_ +#define _GETOPT_H_ + +extern int opterr; +extern int optind; +extern int optopt; +extern int optreset; +extern char *optarg; + +extern int getopt(int nargc, char *const *nargv, const char *ostr); + +#endif /* _GETOPT_H_ */ diff --git a/src/bin/jp3d/opj_jp3d_compress.c b/src/bin/jp3d/opj_jp3d_compress.c new file mode 100644 index 0000000..901a14f --- /dev/null +++ b/src/bin/jp3d/opj_jp3d_compress.c @@ -0,0 +1,989 @@ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include + +#include "opj_config.h" +#include "openjp3d.h" +#include "opj_getopt.h" +#include "convert.h" + +#ifdef _WIN32 +#include +#else +#define stricmp strcasecmp +#define strnicmp strncasecmp +#endif /* _WIN32 */ + +/* ----------------------------------------------------------------------- */ + +void encode_help_display() +{ + fprintf(stdout, "List of parameters for the JPEG2000 Part 10 encoder:\n"); + fprintf(stdout, "------------\n"); + fprintf(stdout, "\n"); + fprintf(stdout, "Required Parameters (except with -h):\n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "-i : source file (-i source.bin or source*.pgx) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "-m : source characteristics file (-m imgfile.img) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, "-o : destination file (-o dest.jp3d) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, "Optional Parameters:\n"); + fprintf(stdout, "\n"); + fprintf(stdout, "-h : display the help information \n "); + fprintf(stdout, "\n"); + fprintf(stdout, "-n : number of resolutions (-n 3,3,3) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "-I : use the irreversible transforms: ICT + DWT 9-7 (-I) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, "-C : coding algorithm (-C 2EB) [2EB, 3EB] \n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "-r : different compression ratios for successive layers (-r 20,10,5)\n "); + fprintf(stdout, + " - The rate specified for each quality level is the desired compression factor.\n"); + fprintf(stdout, " - Rate 1 means lossless compression\n"); + fprintf(stdout, + " (options -r and -q cannot be used together)\n "); + fprintf(stdout, "\n"); + fprintf(stdout, + "-q : different psnr for successive layers (-q 30,40,50) \n "); + fprintf(stdout, + " (options -r and -q cannot be used together)\n "); + fprintf(stdout, "\n"); + fprintf(stdout, "-b : size of code block (-b 32,32,32) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, "-c : size of precinct (-c 128,128,128) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, "-t : size of tile (-t 512,512,512) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] \n"); + fprintf(stdout, "\n"); + fprintf(stdout, "-s : subsampling factor (-s 2,2,2) [-s X,Y,Z] \n"); + fprintf(stdout, " - Remark: subsampling bigger than 2 can produce error\n"); + fprintf(stdout, "\n"); + fprintf(stdout, "-SOP : write SOP marker before each packet \n"); + fprintf(stdout, "\n"); + fprintf(stdout, "-EPH : write EPH marker after each header packet \n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "-M : code-block style (-M 0) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n"); + fprintf(stdout, " 8=VSC 16=PTERM 32=SEGSYM 64=3DCTXT] \n"); + fprintf(stdout, + " Indicate multiple modes by adding their values. \n"); + fprintf(stdout, + " ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n"); + fprintf(stdout, "\n"); + fprintf(stdout, "-D : define DC offset (-D 12) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "-x : create an index file *.Idx (-x index_name.Idx) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "-ROI : c=%%d,U=%%d : quantization indices upshifted \n"); + fprintf(stdout, " for component c=%%d [%%d = 0,1,2]\n"); + fprintf(stdout, + " with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI:c=0,U=25) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "-d : offset of the origin of the volume (-d 150,300,100) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "-l : offset of the origin of the tiles (-l 100,75,25) \n"); + fprintf(stdout, "\n"); + fprintf(stdout, "\n"); + fprintf(stdout, "DEFAULT CODING:\n"); + fprintf(stdout, "------------\n"); + fprintf(stdout, "\n"); + fprintf(stdout, " * Lossless\n"); + fprintf(stdout, " * 1 tile\n"); + fprintf(stdout, + " * Size of precinct : 2^15 x 2^15 x 2^15 (means 1 precinct)\n"); + fprintf(stdout, " * Size of code-block : 64 x 64 x 64\n"); + fprintf(stdout, " * Number of resolutions in x, y and z axis: 3\n"); + fprintf(stdout, " * No SOP marker in the codestream\n"); + fprintf(stdout, " * No EPH marker in the codestream\n"); + fprintf(stdout, " * No sub-sampling in x, y or z direction\n"); + fprintf(stdout, " * No mode switch activated\n"); + fprintf(stdout, " * Progression order: LRCP\n"); + fprintf(stdout, " * No index file\n"); + fprintf(stdout, " * No ROI upshifted\n"); + fprintf(stdout, " * No offset of the origin of the volume\n"); + fprintf(stdout, " * No offset of the origin of the tiles\n"); + fprintf(stdout, " * Reversible DWT 5-3 on each 2D slice\n"); + fprintf(stdout, " * Coding algorithm: 2D-EBCOT \n"); + fprintf(stdout, "\n"); + fprintf(stdout, "REMARKS:\n"); + fprintf(stdout, "---------\n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "- The markers written to the main_header are : SOC SIZ COD QCD COM.\n"); + fprintf(stdout, + "- COD and QCD markers will never appear in the tile_header.\n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "- You need enough disk space memory (twice the original) to encode \n"); + fprintf(stdout, + "the volume,i.e. for a 1.5 GB volume you need a minimum of 3GB of disk memory)\n"); + fprintf(stdout, "\n"); + fprintf(stdout, + "- When loading *.pgx files, a relative path to directory is needed for input argument \n"); + fprintf(stdout, + " followed by the common prefix of the slices and a '*' character representing sequential numeration.\n"); + fprintf(stdout, "( -i relativepath/slices*.pgx )\n"); + fprintf(stdout, "\n"); + fprintf(stdout, " - The index file has the structure below:\n"); + fprintf(stdout, "\n"); + fprintf(stdout, "\t Image_height Image_width Image_depth\n"); + fprintf(stdout, "\t Progression order: 0 (LRCP)\n"); + fprintf(stdout, "\t Tiles_size_X Tiles_size_Y Tiles_size_Z\n"); + fprintf(stdout, "\t Components_nb\n"); + fprintf(stdout, "\t Layers_nb\n"); + fprintf(stdout, "\t Decomposition_levels\n"); + fprintf(stdout, + "\t [Precincts_size_X_res_Nr Precincts_size_Y_res_Nr Precincts_size_Z_res_Nr]\n\t ...\n"); + fprintf(stdout, + "\t [Precincts_size_X_res_0 Precincts_size_Y_res_0 Precincts_size_Z_res_0]\n"); + fprintf(stdout, "\t Main_header_end_position\n"); + fprintf(stdout, "\t Codestream_size\n"); + fprintf(stdout, + "\t Tile_0 [start_pos end_header end_pos TotalDisto NumPix MaxMSE]\n"); + fprintf(stdout, "\t ...\n"); + fprintf(stdout, + "\t Tile_Nt [ '' '' '' '' '' '' ]\n"); + fprintf(stdout, + "\t Tpacket_0 [Tile layer res. comp. prec. start_pos end_pos disto]\n"); + fprintf(stdout, "\t ...\n"); + fprintf(stdout, + "\t Tpacket_Np ['' '' '' '' '' '' '' '' ]\n"); + fprintf(stdout, "\t MaxDisto\n"); + fprintf(stdout, "\t TotalDisto\n\n"); + fprintf(stdout, "\n"); + +} + +OPJ_PROG_ORDER give_progression(char progression[4]) +{ + if (strncmp(progression, "LRCP", 4) == 0) { + return LRCP; + } + if (strncmp(progression, "RLCP", 4) == 0) { + return RLCP; + } + if (strncmp(progression, "RPCL", 4) == 0) { + return RPCL; + } + if (strncmp(progression, "PCRL", 4) == 0) { + return PCRL; + } + if (strncmp(progression, "CPRL", 4) == 0) { + return CPRL; + } + + return PROG_UNKNOWN; +} + +OPJ_TRANSFORM give_transform(char transform[4]) +{ + if (strncmp(transform, "2DWT", 4) == 0) { + return TRF_2D_DWT; + } + if (strncmp(transform, "3DWT", 4) == 0) { + return TRF_3D_DWT; + } + return TRF_UNKNOWN; +} + +OPJ_ENTROPY_CODING give_coding(char coding[3]) +{ + + if (strncmp(coding, "2EB", 3) == 0) { + return ENCOD_2EB; + } + if (strncmp(coding, "3EB", 3) == 0) { + return ENCOD_3EB; + } + /*if(strncmp(coding, "2GR", 3) == 0) { + return ENCOD_2GR; + } + if(strncmp(coding, "3GR", 3) == 0) { + return ENCOD_3GR; + }*/ + + return ENCOD_UNKNOWN; +} + +int get_file_format(char *filename) +{ + int i; + static const char *extension[] = {"pgx", "bin", "img", "j3d", "jp3d", "j2k"}; + static const int format[] = { PGX_DFMT, BIN_DFMT, IMG_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT}; + char * ext = strrchr(filename, '.'); + if (ext) { + ext++; + for (i = 0; i < sizeof(format) / sizeof(*format); i++) { + if (strnicmp(ext, extension[i], 3) == 0) { + return format[i]; + } + } + } + + return -1; +} + +/* ------------------------------------------------------------------------------------ */ + +int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) +{ + int i, value; + + /* parse the command line */ + + while (1) { + int c = opj_getopt(argc, argv, + "i:m:o:r:q:f:t:n:c:b:x:p:s:d:hP:S:E:M:D:R:l:T:C:A:I"); + if (c == -1) { + break; + } + switch (c) { + case 'i': { /* input file */ + char *infile = opj_optarg; + parameters->decod_format = get_file_format(infile); + switch (parameters->decod_format) { + case PGX_DFMT: + case BIN_DFMT: + case IMG_DFMT: + break; + default: + fprintf(stdout, + "[ERROR] Unrecognized format for infile : %s [accept only *.pgx or *.bin] !!\n\n", + infile); + return 1; + break; + } + strncpy(parameters->infile, infile, MAX_PATH); + fprintf(stdout, "[INFO] Infile: %s \n", parameters->infile); + + } + break; + + /* ----------------------------------------------------- */ + case 'm': { /* input IMG file */ + char *imgfile = opj_optarg; + int imgformat = get_file_format(imgfile); + switch (imgformat) { + case IMG_DFMT: + break; + default: + fprintf(stdout, + "[ERROR] Unrecognized format for imgfile : %s [accept only *.img] !!\n\n", + imgfile); + return 1; + break; + } + strncpy(parameters->imgfile, imgfile, MAX_PATH); + fprintf(stdout, "[INFO] Imgfile: %s Format: %d\n", parameters->imgfile, + imgformat); + } + break; + + /* ----------------------------------------------------- */ + case 'o': { /* output file */ + char *outfile = opj_optarg; + parameters->cod_format = get_file_format(outfile); + switch (parameters->cod_format) { + case J3D_CFMT: + case J2K_CFMT: + case LSE_CFMT: + break; + default: + fprintf(stdout, + "[ERROR] Unknown output format volume %s [only *.j2k, *.lse3d or *.jp3d]!! \n", + outfile); + return 1; + break; + } + strncpy(parameters->outfile, outfile, MAX_PATH); + fprintf(stdout, "[INFO] Outfile: %s \n", parameters->outfile); + } + break; + + /* ----------------------------------------------------- */ + + case 'r': { /* define compression rates for each layer */ + char *s = opj_optarg; + while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == + 1) { + parameters->tcp_numlayers++; + while (*s && *s != ',') { + s++; + } + if (!*s) { + break; + } + s++; + } + parameters->cp_disto_alloc = 1; + } + break; + + /* ----------------------------------------------------- */ + + case 'q': { /* define distorsion (PSNR) for each layer */ + char *s = opj_optarg; + while (sscanf(s, "%f", ¶meters->tcp_distoratio[parameters->tcp_numlayers]) + == 1) { + parameters->tcp_numlayers++; + while (*s && *s != ',') { + s++; + } + if (!*s) { + break; + } + s++; + } + parameters->cp_fixed_quality = 1; + } + break; + + /* ----------------------------------------------------- */ + + case 'f': { + fprintf(stdout, "/---------------------------------------------------\\\n"); + fprintf(stdout, "| Fixed layer allocation option not implemented !! |\n"); + fprintf(stdout, "\\---------------------------------------------------/\n"); + /*int *row = NULL, *col = NULL; + int numlayers = 0, matrix_width = 0; + + char *s = opj_optarg; + sscanf(s, "%d", &numlayers); + s++; + if (numlayers > 9) + s++; + + parameters->tcp_numlayers = numlayers; + matrix_width = parameters->numresolution[0] + parameters->numresolution[1] + parameters->numresolution[2]; + parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int)); + s = s + 2; + + for (i = 0; i < numlayers; i++) { + row = ¶meters->cp_matrice[i * matrix_width]; + col = row; + parameters->tcp_rates[i] = 1; + sscanf(s, "%d,", &col[0]); + s += 2; + if (col[0] > 9) + s++; + col[1] = 0; + col[2] = 0; + for (j = 1; j < matrix_width; j++) { + col += 3; j+=2; + sscanf(s, "%d,%d,%d", &col[0], &col[1], &col[2]); + s += 6; + if (col[0] > 9) + s++; + if (col[1] > 9) + s++; + if (col[2] > 9) + s++; + } + if (i < numlayers - 1) + s++; + } + parameters->cp_fixed_alloc = 1; */ + } + break; + + /* ----------------------------------------------------- */ + + case 't': { /* tiles */ + if (sscanf(opj_optarg, "%d,%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy, + ¶meters->cp_tdz) != 3) { + fprintf(stdout, + "[ERROR] '-t' 'dimensions of tiles' argument error ! [-t tdx,tdy,tdz]\n"); + return 1; + } + parameters->tile_size_on = true; + } + break; + + /* ----------------------------------------------------- */ + + case 'n': { /* resolution */ + int aux; + aux = sscanf(opj_optarg, "%d,%d,%d", ¶meters->numresolution[0], + ¶meters->numresolution[1], ¶meters->numresolution[2]); + if (aux == 2) { + parameters->numresolution[2] = 1; + } else if (aux == 1) { + parameters->numresolution[1] = parameters->numresolution[0]; + parameters->numresolution[2] = 1; + } else if (aux == 0) { + parameters->numresolution[0] = 1; + parameters->numresolution[1] = 1; + parameters->numresolution[2] = 1; + } + } + break; + + /* ----------------------------------------------------- */ + case 'c': { /* precinct dimension */ + char sep; + int res_spec = 0; + int aux; + char *s = opj_optarg; + do { + sep = 0; + aux = sscanf(s, "[%d,%d,%d]%c", ¶meters->prct_init[0][res_spec], + ¶meters->prct_init[1][res_spec], ¶meters->prct_init[2][res_spec], &sep); + if (sep == ',' && aux != 4) { + fprintf(stdout, + "[ERROR] '-c' 'dimensions of precincts' argument error ! [-c [prcx_res0,prcy_res0,prcz_res0],...,[prcx_resN,prcy_resN,prcz_resN]]\n"); + return 1; + } + parameters->csty |= 0x01; + res_spec++; + s = strpbrk(s, "]") + 2; + } while (sep == ','); + parameters->res_spec = res_spec; /* number of precinct size specifications */ + } + break; + + /* ----------------------------------------------------- */ + + case 'b': { /* code-block dimension */ + int cblockw_init = 0, cblockh_init = 0, cblockl_init = 0; + if (sscanf(opj_optarg, "%d,%d,%d", &cblockw_init, &cblockh_init, + &cblockl_init) != 3) { + fprintf(stdout, + "[ERROR] '-b' 'dimensions of codeblocks' argument error ! [-b cblkx,cblky,cblkz]\n"); + return 1; + } + if (cblockw_init * cblockh_init * cblockl_init > (1 << 18) || + cblockw_init > 1024 || cblockw_init < 4 || cblockh_init > 1024 || + cblockh_init < 4 || cblockl_init > 1024 || cblockl_init < 4) { + fprintf(stdout, + "[ERROR] Size of code_block error (option -b) !!\n\nRestriction :\n * width*height*length<=4096\n * 4<=width,height,length<= 1024\n\n"); + return 1; + } + parameters->cblock_init[0] = cblockw_init; + parameters->cblock_init[1] = cblockh_init; + parameters->cblock_init[2] = cblockl_init; + } + break; + + /* ----------------------------------------------------- */ + + case 'x': { /* creation of index file */ + char *index = opj_optarg; + strncpy(parameters->index, index, MAX_PATH); + parameters->index_on = 1; + } + break; + + /* ----------------------------------------------------- */ + + case 'p': { /* progression order */ + char progression[4]; + + strncpy(progression, opj_optarg, 4); + parameters->prog_order = give_progression(progression); + if (parameters->prog_order == -1) { + fprintf(stdout, + "[ERROR] Unrecognized progression order [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 's': { /* subsampling factor */ + if (sscanf(opj_optarg, "%d,%d,%d", ¶meters->subsampling_dx, + ¶meters->subsampling_dy, ¶meters->subsampling_dz) != 3) { + fprintf(stdout, "[ERROR] '-s' sub-sampling argument error ! [-s dx,dy,dz]\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'd': { /* coordonnate of the reference grid */ + if (sscanf(opj_optarg, "%d,%d,%d", ¶meters->volume_offset_x0, + ¶meters->volume_offset_y0, ¶meters->volume_offset_z0) != 3) { + fprintf(stdout, + "[ERROR] -d 'coordonnate of the reference grid' argument error !! [-d x0,y0,z0]\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'h': { /* display an help description */ + encode_help_display(); + return 1; + } + break; + + /* ----------------------------------------------------- */ + + case 'P': { /* POC */ + int numpocs = 0; /* number of progression order change (POC) default 0 */ + opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */ + + char *s = opj_optarg; + POC = parameters->POC; + + fprintf(stdout, "/----------------------------------\\\n"); + fprintf(stdout, "| POC option not fully tested !! |\n"); + fprintf(stdout, "\\----------------------------------/\n"); + + while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%s", &POC[numpocs].tile, + &POC[numpocs].resno0, &POC[numpocs].compno0, + &POC[numpocs].layno1, &POC[numpocs].resno1, + &POC[numpocs].compno1, POC[numpocs].progorder) == 7) { + POC[numpocs].prg = give_progression(POC[numpocs].progorder); + /* POC[numpocs].tile; */ + numpocs++; + while (*s && *s != '/') { + s++; + } + if (!*s) { + break; + } + s++; + } + parameters->numpocs = numpocs; + } + break; + + /* ------------------------------------------------------ */ + + case 'S': { /* SOP marker */ + parameters->csty |= 0x02; + } + break; + + /* ------------------------------------------------------ */ + + case 'E': { /* EPH marker */ + parameters->csty |= 0x04; + } + break; + + /* ------------------------------------------------------ */ + + case 'M': { /* Codification mode switch */ + fprintf(stdout, "[INFO] Mode switch option not fully tested !!\n"); + value = 0; + if (sscanf(opj_optarg, "%d", &value) == 1) { + for (i = 0; i <= 6; i++) { + int cache = value & (1 << i); + if (cache) { + parameters->mode |= (1 << i); + } + } + } + } + break; + + /* ------------------------------------------------------ */ + + case 'D': { /* DCO */ + if (sscanf(opj_optarg, "%d", ¶meters->dcoffset) != 1) { + fprintf(stdout, "[ERROR] DC offset error !! [-D %d]\n", parameters->dcoffset); + return 1; + } + } + break; + + /* ------------------------------------------------------ */ + + case 'R': { /* ROI */ + if (sscanf(opj_optarg, "OI:c=%d,U=%d", ¶meters->roi_compno, + ¶meters->roi_shift) != 2) { + fprintf(stdout, "[ERROR] ROI error !! [-ROI:c='compno',U='shift']\n"); + return 1; + } + } + break; + + /* ------------------------------------------------------ */ + + case 'l': { /* Tile offset */ + if (sscanf(opj_optarg, "%d,%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0, + ¶meters->cp_tz0) != 3) { + fprintf(stdout, "[ERROR] -l 'tile offset' argument error !! [-l X0,Y0,Z0]"); + return 1; + } + } + break; + + /* ------------------------------------------------------ + + case 'T': // Transformation of original data (2D-DWT/3D-DWT/3D-RLS/2D-DWT+1D-RLS) + { + char transform[4]; + + strncpy(transform, opj_optarg, 4); + parameters->transform_format = give_transform(transform); + if (parameters->transform_format == -1) { + fprintf(stdout, "[ERROR] -T 'Transform domain' argument error !! [-T 2DWT, 3DWT, 3RLS or 3LSE only]"); + return 1; + } + } + break; + + ------------------------------------------------------ */ + + case 'C': { /* Coding of transformed data */ + char coding[3]; + + strncpy(coding, opj_optarg, 3); + parameters->encoding_format = give_coding(coding); + if (parameters->encoding_format == -1) { + fprintf(stdout, + "[ERROR] -C 'Coding algorithm' argument error !! [-C 2EB, 3EB, 2GR, 3GR or GRI only]"); + return 1; + } + } + break; + + /* ------------------------------------------------------ */ + + case 'I': { /* reversible or not */ + parameters->irreversible = 1; + } + break; + + default: + fprintf(stdout, "[ERROR] This option is not valid \"-%c %s\"\n", c, opj_optarg); + return 1; + } + } + + /* check for possible errors */ + + if ((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { + fprintf(stdout, "usage: jp3d_vm_enc -i volume-file -o jp3d-file (+ options)\n"); + return 1; + } + + if ((parameters->decod_format == BIN_DFMT) && (parameters->imgfile[0] == 0)) { + fprintf(stdout, + "usage: jp3d_vm_enc -i bin-volume-file -m img-file -o jp3d-file (+ options)\n"); + return 1; + } + + if ((parameters->decod_format != BIN_DFMT) && + (parameters->decod_format != PGX_DFMT) && + (parameters->decod_format != IMG_DFMT)) { + fprintf(stdout, + "usage: jp3d_vm_enc -i input-volume-file [*.bin,*.pgx,*.img] -o jp3d-file [*.jp3d,*.j2k] (+ options)\n"); + return 1; + } + if ((parameters->cod_format != J3D_CFMT) && + (parameters->cod_format != J2K_CFMT)) { + fprintf(stdout, + "usage: jp3d_vm_enc -i input-volume-file [*.bin,*.pgx,*.img] -o jp3d-file [*.jp3d,*.j2k] (+ options)\n"); + return 1; + } + + if ((parameters->encoding_format == ENCOD_2GR || + parameters->encoding_format == ENCOD_3GR) && + parameters->transform_format != TRF_3D_LSE && + parameters->transform_format != TRF_3D_RLS) { + fprintf(stdout, + "[ERROR] Entropy coding options -C [2GR,3GR] are only compatible with predictive-based transform algorithms: -T [3RLS,3LSE].\n"); + return 1; + } + if (parameters->encoding_format == ENCOD_3EB) { + parameters->mode |= (1 << 6); + } + + if ((parameters->mode >> 6) & 1) { + parameters->encoding_format = ENCOD_3EB; + } + + if ((parameters->numresolution[2] == 0 || (parameters->numresolution[1] == 0) || + (parameters->numresolution[0] == 0))) { + fprintf(stdout, + "[ERROR] -n 'resolution levels' argument error ! Resolutions must be greater than 1 in order to perform DWT.\n"); + return 1; + } + if (parameters->numresolution[1] != parameters->numresolution[0]) { + fprintf(stdout, + "[ERROR] -n 'resolution levels' argument error ! Resolutions in X and Y axis must be the same in this implementation.\n"); + return 1; + } + + if (parameters->numresolution[2] > parameters->numresolution[0]) { + fprintf(stdout, + "[ERROR] -n 'resolution levels' argument error ! Resolutions in Z axis must be lower than in X-Y axis.\n"); + return 1; + } + + if (parameters->dcoffset >= 128 && parameters->dcoffset <= -128) { + fprintf(stdout, + "[ERROR] -D 'DC offset' argument error ! Value must be -128<=DCO<=128.\n"); + return 1; + } + + if (parameters->numresolution[2] != 1) { + parameters->transform_format = TRF_3D_DWT; + /*fprintf(stdout, "[Warning] Resolution level in axial dim > 1 : 3D-DWT will be performed... \n");*/ + } else if (parameters->numresolution[2] == 1) { + parameters->transform_format = TRF_2D_DWT; + /*fprintf(stdout, "[Warning] Resolution level in axial dim == 1 : 2D-DWT will be performed... \n");*/ + } + + if ((parameters->cod_format == J2K_CFMT) && + (parameters->transform_format != TRF_2D_DWT || + parameters->encoding_format != ENCOD_2EB)) { + fprintf(stdout, + "[WARNING] Incompatible options -o *.j2k and defined transform or encoding algorithm. Latter will be ignored\n"); + parameters->transform_format = TRF_2D_DWT; + parameters->encoding_format = ENCOD_2EB; + } + + if ((parameters->cp_disto_alloc || parameters->cp_fixed_alloc || + parameters->cp_fixed_quality) && + (!(parameters->cp_disto_alloc ^ parameters->cp_fixed_quality))) { + fprintf(stdout, "[ERROR] Options -r and -q cannot be used together !!\n"); + return 1; + } /* mod fixed_quality */ + + /* if no rate entered, lossless by default */ + if (parameters->tcp_numlayers == 0) { + parameters->tcp_rates[0] = 0.0; /* MOD antonin : losslessbug */ + parameters->tcp_numlayers++; + parameters->cp_disto_alloc = 1; + } + + if ((parameters->cp_tx0 > parameters->volume_offset_x0) || + (parameters->cp_ty0 > parameters->volume_offset_y0) || + (parameters->cp_tz0 > parameters->volume_offset_z0)) { + fprintf(stdout, + "[ERROR] Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) TZO(%d)<=IMG_Z0(%d)\n", + parameters->cp_tx0, parameters->volume_offset_x0, parameters->cp_ty0, + parameters->volume_offset_y0, + parameters->cp_tz0, parameters->volume_offset_z0); + return 1; + } + + for (i = 0; i < parameters->numpocs; i++) { + if (parameters->POC[i].prg == -1) { + fprintf(stdout, + "[ERROR] Unrecognized progression order in option -P (POC n %d) [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n", + i + 1); + } + } + return 0; +} + +/* -------------------------------------------------------------------------- */ + +/** +sample error callback expecting a FILE* client object +*/ +void error_callback(const char *msg, void *client_data) +{ + FILE *stream = (FILE*)client_data; + fprintf(stream, "[ERROR] %s", msg); +} +/** +sample warning callback expecting a FILE* client object +*/ +void warning_callback(const char *msg, void *client_data) +{ + FILE *stream = (FILE*)client_data; + fprintf(stream, "[WARNING] %s", msg); +} +/** +sample debug callback expecting a FILE* client object +*/ +void info_callback(const char *msg, void *client_data) +{ + FILE *stream = (FILE*)client_data; + fprintf(stream, "[INFO] %s", msg); +} + +/* -------------------------------------------------------------------------- */ + +int main(int argc, char **argv) +{ + bool bSuccess; + bool delete_comment = true; + opj_cparameters_t parameters; /* compression parameters */ + opj_event_mgr_t event_mgr; /* event manager */ + opj_volume_t *volume = NULL; + + /* + configure the event callbacks (not required) + setting of each callback is optional + */ + 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 encoding parameters to default values */ + opj_set_default_encoder_parameters(¶meters); + + /* parse input and get user encoding parameters */ + if (parse_cmdline_encoder(argc, argv, ¶meters) == 1) { + return 0; + } + + if (parameters.cp_comment == NULL) { + parameters.cp_comment = "Created by OpenJPEG version JP3D"; + /* no need to delete parameters.cp_comment on exit */ + delete_comment = false; + } + + /* encode the destination volume */ + /* ---------------------------- */ + if (parameters.cod_format == J3D_CFMT || parameters.cod_format == J2K_CFMT) { + int codestream_length, pixels, bitsin; + opj_cio_t *cio = NULL; + FILE *f = NULL; + opj_cinfo_t* cinfo = NULL; + + /* decode the source volume */ + /* ----------------------- */ + switch (parameters.decod_format) { + case PGX_DFMT: + fprintf(stdout, "[INFO] Loading pgx file(s)\n"); + volume = pgxtovolume(parameters.infile, ¶meters); + if (!volume) { + fprintf(stdout, "[ERROR] Unable to load pgx files\n"); + return 1; + } + break; + + case BIN_DFMT: + fprintf(stdout, "[INFO] Loading bin file\n"); + volume = bintovolume(parameters.infile, parameters.imgfile, ¶meters); + if (!volume) { + fprintf(stdout, "[ERROR] Unable to load bin file\n"); + return 1; + } + break; + + case IMG_DFMT: + fprintf(stdout, "[INFO] Loading img file\n"); + volume = imgtovolume(parameters.infile, ¶meters); + if (!volume) { + fprintf(stderr, "[ERROR] Unable to load img file\n"); + return 1; + } + break; + } + + /* get a JP3D or J2K compressor handle */ + if (parameters.cod_format == J3D_CFMT) { + cinfo = opj_create_compress(CODEC_J3D); + } else if (parameters.cod_format == J2K_CFMT) { + cinfo = opj_create_compress(CODEC_J2K); + } + + /* catch events using our callbacks and give a local context */ + opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stdout); + + /* setup the encoder parameters using the current volume and using user parameters */ + opj_setup_encoder(cinfo, ¶meters, volume); + + /* open a byte stream for writing */ + /* allocate memory for all tiles */ + cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); + + /* encode the volume */ + /*fprintf(stdout, "[INFO] Encode the volume\n");*/ + bSuccess = opj_encode(cinfo, cio, volume, parameters.index); + if (!bSuccess) { + opj_cio_close(cio); + fprintf(stdout, "[ERROR] Failed to encode volume\n"); + return 1; + } + codestream_length = cio_tell(cio); + pixels = (volume->x1 - volume->x0) * (volume->y1 - volume->y0) * + (volume->z1 - volume->z0); + bitsin = pixels * volume->comps[0].prec; + fprintf(stdout, + "[RESULT] Volume: %d x %d x %d (x %d bpv)\n Codestream: %d B, Ratio: %5.3f bpv, (%5.3f : 1) \n", + (volume->x1 - volume->x0), (volume->y1 - volume->y0), (volume->z1 - volume->z0), + volume->comps[0].prec, + codestream_length, ((double)codestream_length * 8.0 / (double)pixels), + ((double)bitsin / (8.0 * (double)codestream_length))); + + /* write the buffer to disk */ + f = fopen(parameters.outfile, "wb"); + if (!f) { + fprintf(stdout, "[ERROR] Failed to open %s for writing\n", parameters.outfile); + return 1; + } + fwrite(cio->buffer, 1, codestream_length, f); + fclose(f); + + /* close and free the byte stream */ + opj_cio_close(cio); + + /* free remaining compression structures */ + opj_destroy_compress(cinfo); + } else { + fprintf(stdout, "[ERROR] Cod_format != JP3d !!! \n"); + return 1; + } + + /* free user parameters structure */ + if (delete_comment) { + if (parameters.cp_comment) { + free(parameters.cp_comment); + } + } + if (parameters.cp_matrice) { + free(parameters.cp_matrice); + } + + /* free volume data */ + opj_volume_destroy(volume); + + return 0; +} diff --git a/src/bin/jp3d/opj_jp3d_decompress.c b/src/bin/jp3d/opj_jp3d_decompress.c new file mode 100644 index 0000000..eb7ebe8 --- /dev/null +++ b/src/bin/jp3d/opj_jp3d_decompress.c @@ -0,0 +1,601 @@ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include + +#include "opj_config.h" +#include "openjp3d.h" +#include "opj_getopt.h" +#include "convert.h" + +#ifdef _WIN32 +#include +#else +#define stricmp strcasecmp +#define strnicmp strncasecmp +#endif /* _WIN32 */ + +/* ----------------------------------------------------------------------- */ +static double calc_PSNR(opj_volume_t *original, opj_volume_t *decoded) +{ + int max, i, k, compno = 0, size; + double sum, total = 0; + int global = 1; + + max = (original->comps[compno].prec <= 8) ? 255 : (1 << + original->comps[compno].prec) - 1; + if (global) { + size = (original->x1 - original->x0) * (original->y1 - original->y0) * + (original->z1 - original->z0); + + for (compno = 0; compno < original->numcomps; compno++) { + for (sum = 0, i = 0; i < size; ++i) { + if ((decoded->comps[compno].data[i] < 0) || + (decoded->comps[compno].data[i] > max)) { + fprintf(stdout, "[WARNING] Data out of range during PSNR computing...\n"); + } else { + sum += (original->comps[compno].data[i] - decoded->comps[compno].data[i]) * + (original->comps[compno].data[i] - decoded->comps[compno].data[i]); + } + } + } + sum /= size; + total = ((sum == 0.0) ? 0.0 : 10 * log10(max * max / sum)); + } else { + size = (original->x1 - original->x0) * (original->y1 - original->y0); + + for (k = 0; k < original->z1 - original->z0; k++) { + int offset = k * size; + for (sum = 0, compno = 0; compno < original->numcomps; compno++) { + for (i = 0; i < size; ++i) { + if ((decoded->comps[compno].data[i + offset] < 0) || + (decoded->comps[compno].data[i + offset] > max)) { + fprintf(stdout, "[WARNING] Data out of range during PSNR computing...\n"); + } else { + sum += (original->comps[compno].data[i + offset] - decoded->comps[compno].data[i + + offset]) * (original->comps[compno].data[i + offset] - + decoded->comps[compno].data[i + offset]); + } + } + } + sum /= size; + total = total + ((sum == 0.0) ? 0.0 : 10 * log10(max * max / sum)); + } + + } + if (total == 0) { /* perfect reconstruction, PSNR should return infinity */ + return -1.0; + } + + return total; + /*return 20 * log10((max - 1) / sqrt(sum));*/ +} + +static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded) +{ + int max, i, compno = 0, size, sizeM; + double sum; + double mux = 0.0, muy = 0.0, sigmax = 0.0, sigmay = 0.0, + sigmaxy = 0.0/*, structx = 0.0, structy = 0.0*/; + double lcomp, ccomp, scomp; + double C1, C2, C3; + + max = (original->comps[compno].prec <= 8) ? 255 : (1 << + original->comps[compno].prec) - 1; + size = (original->x1 - original->x0) * (original->y1 - original->y0) * + (original->z1 - original->z0); + + /*MSSIM*/ + + /* sizeM = size / (original->z1 - original->z0);*/ + + sizeM = size; + for (sum = 0, i = 0; i < sizeM; ++i) { + /* First, the luminance of each signal is compared.*/ + mux += original->comps[compno].data[i]; + muy += decoded->comps[compno].data[i]; + } + mux /= sizeM; + muy /= sizeM; + + /*We use the standard deviation (the square root of variance) as an estimate of the signal contrast.*/ + for (sum = 0, i = 0; i < sizeM; ++i) { + /* First, the luminance of each signal is compared.*/ + sigmax += (original->comps[compno].data[i] - mux) * + (original->comps[compno].data[i] - mux); + sigmay += (decoded->comps[compno].data[i] - muy) * + (decoded->comps[compno].data[i] - muy); + sigmaxy += (original->comps[compno].data[i] - mux) * + (decoded->comps[compno].data[i] - muy); + } + sigmax /= sizeM - 1; + sigmay /= sizeM - 1; + sigmaxy /= sizeM - 1; + + sigmax = sqrt(sigmax); + sigmay = sqrt(sigmay); + sigmaxy = sqrt(sigmaxy); + + /*Third, the signal is normalized (divided) by its own standard deviation, */ + /*so that the two signals being compared have unit standard deviation.*/ + + /*Luminance comparison*/ + C1 = (0.01 * max) * (0.01 * max); + lcomp = ((2 * mux * muy) + C1) / ((mux * mux) + (muy * mux) + C1); + /*Constrast comparison*/ + C2 = (0.03 * max) * (0.03 * max); + ccomp = ((2 * sigmax * sigmay) + C2) / ((sigmax * sigmax) + + (sigmay * sigmay) + C2); + /*Structure comparison*/ + C3 = C2 / 2; + scomp = (sigmaxy + C3) / (sigmax * sigmay + C3); + /*Similarity measure*/ + + sum = lcomp * ccomp * scomp; + return sum; +} + +void decode_help_display() +{ + fprintf(stdout, "HELP\n----\n\n"); + fprintf(stdout, "- the -h option displays this help information on screen\n\n"); + + fprintf(stdout, "List of parameters for the JPEG 2000 encoder:\n"); + fprintf(stdout, "\n"); + fprintf(stdout, " Required arguments \n"); + fprintf(stdout, " ---------------------------- \n"); + fprintf(stdout, " -i ( *.jp3d, *.j3d )\n"); + fprintf(stdout, + " Currently accepts J3D-files. The file type is identified based on its suffix.\n"); + fprintf(stdout, " -o ( *.pgx, *.bin )\n"); + fprintf(stdout, + " Currently accepts PGX-files and BIN-files. Binary data is written to the file (not ascii). \n"); + fprintf(stdout, + " If a PGX filename is given, there will be as many output files as slices; \n"); + fprintf(stdout, + " an indice starting from 0 will then be appended to the output filename,\n"); + fprintf(stdout, " just before the \"pgx\" extension.\n"); + fprintf(stdout, " -m ( *.img ) \n"); + fprintf(stdout, + " Required only for BIN-files. Ascii data of volume characteristics is written. \n"); + fprintf(stdout, "\n"); + fprintf(stdout, " Optional \n"); + fprintf(stdout, " ---------------------------- \n"); + fprintf(stdout, " -h \n "); + fprintf(stdout, " Display the help information\n"); + fprintf(stdout, " -r \n"); + fprintf(stdout, + " Set the number of highest resolution levels to be discarded on each dimension. \n"); + fprintf(stdout, + " The volume resolution is effectively divided by 2 to the power of the\n"); + fprintf(stdout, + " number of discarded levels. The reduce factor is limited by the\n"); + fprintf(stdout, + " smallest total number of decomposition levels among tiles.\n"); + fprintf(stdout, " -l \n"); + fprintf(stdout, + " Set the maximum number of quality layers to decode. If there are\n"); + fprintf(stdout, + " less quality layers than the specified number, all the quality layers\n"); + fprintf(stdout, " are decoded. \n"); + fprintf(stdout, " -O original-file \n"); + fprintf(stdout, + " This option offers the possibility to compute some quality results \n"); + fprintf(stdout, + " for the decompressed volume, like the PSNR value achieved or the global SSIM value. \n"); + fprintf(stdout, + " Needs the original file in order to compare with the new one.\n"); + fprintf(stdout, + " NOTE: Only valid when -r option is 0,0,0 (both original and decompressed volumes have same resolutions) \n"); + fprintf(stdout, + " NOTE: If original file is .BIN file, the volume characteristics file shall be defined with the -m option. \n"); + fprintf(stdout, " (i.e. -O original-BIN-file -m original-IMG-file) \n"); + fprintf(stdout, " -BE \n"); + fprintf(stdout, + " Define that the recovered volume data will be saved with big endian byte order.\n"); + fprintf(stdout, " By default, little endian byte order is used.\n"); + fprintf(stdout, "\n"); +} + +/* -------------------------------------------------------------------------- */ + +int get_file_format(char *filename) +{ + int i; + static const char *extension[] = {"pgx", "bin", "j3d", "jp3d", "j2k", "img"}; + static const int format[] = { PGX_DFMT, BIN_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT, IMG_DFMT}; + char * ext = strrchr(filename, '.'); + if (ext) { + ext++; + for (i = 0; i < sizeof(format) / sizeof(format[0]); i++) { + if (strnicmp(ext, extension[i], 3) == 0) { + return format[i]; + } + } + } + + return -1; +} + +/* -------------------------------------------------------------------------- */ + +int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters) +{ + /* parse the command line */ + + while (1) { + int c = opj_getopt(argc, argv, "i:o:O:r:l:B:m:h"); + if (c == -1) { + break; + } + switch (c) { + case 'i': { /* input file */ + char *infile = opj_optarg; + parameters->decod_format = get_file_format(infile); + switch (parameters->decod_format) { + case J3D_CFMT: + case J2K_CFMT: + break; + default: + fprintf(stdout, "[ERROR] Unknown format for infile %s [only *.j3d]!! \n", + infile); + return 1; + break; + } + strncpy(parameters->infile, infile, MAX_PATH); + fprintf(stdout, "[INFO] Infile: %s \n", parameters->infile); + + } + break; + + case 'm': { /* img file */ + char *imgfile = opj_optarg; + int imgformat = get_file_format(imgfile); + switch (imgformat) { + case IMG_DFMT: + break; + default: + fprintf(stdout, + "[ERROR] Unrecognized format for imgfile : %s [accept only *.img] !!\n\n", + imgfile); + return 1; + break; + } + strncpy(parameters->imgfile, imgfile, MAX_PATH); + fprintf(stdout, "[INFO] Imgfile: %s Format: %d\n", parameters->imgfile, + imgformat); + } + break; + + /* ----------------------------------------------------- */ + + case 'o': { /* output file */ + char *outfile = opj_optarg; + parameters->cod_format = get_file_format(outfile); + switch (parameters->cod_format) { + case PGX_DFMT: + case BIN_DFMT: + break; + default: + fprintf(stdout, + "[ERROR] Unrecognized format for outfile : %s [accept only *.pgx or *.bin] !!\n\n", + outfile); + return 1; + break; + } + strncpy(parameters->outfile, outfile, MAX_PATH); + fprintf(stdout, "[INFO] Outfile: %s \n", parameters->outfile); + + } + break; + + /* ----------------------------------------------------- */ + + case 'O': { /* Original image for PSNR computing */ + char *original = opj_optarg; + parameters->orig_format = get_file_format(original); + switch (parameters->orig_format) { + case PGX_DFMT: + case BIN_DFMT: + break; + default: + fprintf(stdout, + "[ERROR] Unrecognized format for original file : %s [accept only *.pgx or *.bin] !!\n\n", + original); + return 1; + break; + } + strncpy(parameters->original, original, MAX_PATH); + fprintf(stdout, "[INFO] Original file: %s \n", parameters->original); + } + break; + + /* ----------------------------------------------------- */ + + case 'r': { /* reduce option */ + /*sscanf(opj_optarg, "%d, %d, %d", ¶meters->cp_reduce[0], ¶meters->cp_reduce[1], ¶meters->cp_reduce[2]);*/ + int aux; + aux = sscanf(opj_optarg, "%d,%d,%d", ¶meters->cp_reduce[0], + ¶meters->cp_reduce[1], ¶meters->cp_reduce[2]); + if (aux == 2) { + parameters->cp_reduce[2] = 0; + } else if (aux == 1) { + parameters->cp_reduce[1] = parameters->cp_reduce[0]; + parameters->cp_reduce[2] = 0; + } else if (aux == 0) { + parameters->cp_reduce[0] = 0; + parameters->cp_reduce[1] = 0; + parameters->cp_reduce[2] = 0; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'l': { /* layering option */ + sscanf(opj_optarg, "%d", ¶meters->cp_layer); + } + break; + + /* ----------------------------------------------------- */ + + case 'B': { /* BIGENDIAN vs. LITTLEENDIAN */ + parameters->bigendian = 1; + } + break; + + /* ----------------------------------------------------- */ + + case 'L': { /* BIGENDIAN vs. LITTLEENDIAN */ + parameters->decod_format = LSE_CFMT; + } + break; + + /* ----------------------------------------------------- */ + + case 'h': { /* display an help description */ + decode_help_display(); + return 1; + } + break; + + /* ----------------------------------------------------- */ + + default: + fprintf(stdout, "[WARNING] This option is not valid \"-%c %s\"\n", c, + opj_optarg); + break; + } + } + + /* check for possible errors */ + + if ((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { + fprintf(stdout, + "[ERROR] At least one required argument is missing\n Check jp3d_to_volume -help for usage information\n"); + return 1; + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ + +/** +sample error callback expecting a FILE* client object +*/ +void error_callback(const char *msg, void *client_data) +{ + FILE *stream = (FILE*)client_data; + fprintf(stream, "[ERROR] %s", msg); +} +/** +sample warning callback expecting a FILE* client object +*/ +void warning_callback(const char *msg, void *client_data) +{ + FILE *stream = (FILE*)client_data; + fprintf(stream, "[WARNING] %s", msg); +} +/** +sample debug callback expecting no client object +*/ +void info_callback(const char *msg, void *client_data) +{ + fprintf(stdout, "[INFO] %s", msg); +} + +/* -------------------------------------------------------------------------- */ + +int main(int argc, char **argv) +{ + + opj_dparameters_t parameters; /* decompression parameters */ + opj_event_mgr_t event_mgr; /* event manager */ + opj_volume_t *volume = NULL; + + opj_volume_t *original = NULL; + opj_cparameters_t cparameters; /* original parameters */ + + FILE *fsrc = NULL; + unsigned char *src = NULL; + int file_length; + int decodeok; + double psnr, ssim; + + opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ + opj_cio_t *cio = NULL; + + /* 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); + + /* parse input and get user decoding parameters */ + strcpy(parameters.original, "NULL"); + strcpy(parameters.imgfile, "NULL"); + if (parse_cmdline_decoder(argc, argv, ¶meters) == 1) { + return 0; + } + + /* read the input file and put it in memory */ + /* ---------------------------------------- */ + fprintf(stdout, "[INFO] Loading %s file \n", + parameters.decod_format == J3D_CFMT ? ".jp3d" : ".j2k"); + fsrc = fopen(parameters.infile, "rb"); + if (!fsrc) { + fprintf(stdout, "[ERROR] Failed to open %s for reading\n", parameters.infile); + return 1; + } + 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 */ + /* ---------------------- */ + if (parameters.decod_format == J3D_CFMT || + parameters.decod_format == J2K_CFMT) { + /* get a JP3D or J2K decoder handle */ + if (parameters.decod_format == J3D_CFMT) { + dinfo = opj_create_decompress(CODEC_J3D); + } else if (parameters.decod_format == J2K_CFMT) { + dinfo = opj_create_decompress(CODEC_J2K); + } + + /* 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 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 volume structure */ + volume = opj_decode(dinfo, cio); + if (!volume) { + fprintf(stdout, "[ERROR] jp3d_to_volume: failed to decode volume!\n"); + opj_destroy_decompress(dinfo); + opj_cio_close(cio); + return 1; + } + + /* close the byte stream */ + opj_cio_close(cio); + } + + /* free the memory containing the code-stream */ + free(src); + src = NULL; + + /* create output volume */ + /* ------------------- */ + + switch (parameters.cod_format) { + case PGX_DFMT: /* PGX */ + decodeok = volumetopgx(volume, parameters.outfile); + if (decodeok) { + fprintf(stdout, "[ERROR] Unable to write decoded volume into pgx files\n"); + } + break; + + case BIN_DFMT: /* BMP */ + decodeok = volumetobin(volume, parameters.outfile); + if (decodeok) { + fprintf(stdout, "[ERROR] Unable to write decoded volume into pgx files\n"); + } + break; + } + switch (parameters.orig_format) { + case PGX_DFMT: /* PGX */ + if (strcmp("NULL", parameters.original) != 0) { + fprintf(stdout, "Loading original file %s \n", parameters.original); + cparameters.subsampling_dx = 1; + cparameters.subsampling_dy = 1; + cparameters.subsampling_dz = 1; + cparameters.volume_offset_x0 = 0; + cparameters.volume_offset_y0 = 0; + cparameters.volume_offset_z0 = 0; + original = pgxtovolume(parameters.original, &cparameters); + } + break; + + case BIN_DFMT: /* BMP */ + if (strcmp("NULL", parameters.original) != 0 && + strcmp("NULL", parameters.imgfile) != 0) { + fprintf(stdout, "Loading original file %s %s\n", parameters.original, + parameters.imgfile); + cparameters.subsampling_dx = 1; + cparameters.subsampling_dy = 1; + cparameters.subsampling_dz = 1; + cparameters.volume_offset_x0 = 0; + cparameters.volume_offset_y0 = 0; + cparameters.volume_offset_z0 = 0; + original = bintovolume(parameters.original, parameters.imgfile, &cparameters); + } + break; + } + + fprintf(stdout, "[RESULT] Volume: %d x %d x %d (x %d bpv)\n ", + (volume->comps[0].w >> volume->comps[0].factor[0]), + (volume->comps[0].h >> volume->comps[0].factor[1]), + (volume->comps[0].l >> volume->comps[0].factor[2]), + volume->comps[0].prec); + + if (original) { + psnr = calc_PSNR(original, volume); + ssim = calc_SSIM(original, volume); + if (psnr < 0.0) { + fprintf(stdout, " PSNR: Inf , SSMI %f -- Perfect reconstruction!\n", ssim); + } else { + fprintf(stdout, " PSNR: %f , SSIM %f \n", psnr, ssim); + } + } + /* free remaining structures */ + if (dinfo) { + opj_destroy_decompress(dinfo); + } + + /* free volume data structure */ + opj_volume_destroy(volume); + + return 0; +} + diff --git a/src/bin/jp3d/tcltk/LPI_JP3D_VM.tcl b/src/bin/jp3d/tcltk/LPI_JP3D_VM.tcl new file mode 100755 index 0000000..37657b2 --- /dev/null +++ b/src/bin/jp3d/tcltk/LPI_JP3D_VM.tcl @@ -0,0 +1,115 @@ +#!/bin/sh +# The next line is executed by /bin/sh, but not tcl \ +exec wish "$0" ${1+"$@"} +lappend auto_path /usr/share/tcltk/bwidget1.9.2 + +namespace eval jp3dVM { + + variable _progress 0 + variable _afterid "" + variable _status "Compute in progress..." + variable notebook + variable mainframe + variable dataout "Process execution information" + variable status + variable prgtext + variable prgindic + + set pwd [pwd] + cd [file dirname [info script]] + variable VMDIR [pwd] + cd $pwd + + foreach script {encoder.tcl decoder.tcl} { + namespace inscope :: source $VMDIR/$script + } +} + + +proc jp3dVM::create { } { + variable notebook + variable mainframe + variable dataout + + bind all { catch {console show} } + + # Menu description + set descmenu { + "&File" {} {} 0 { + {command "E&xit" {} "Exit BWidget jp3dVM" {} -command exit} + } + "&Options" {} {} 0 { + {command "&Encode" {} "Show encoder" {} + -command {$jp3dVM::notebook raise [$jp3dVM::notebook page 0]} + } + {command "&Decode" {} "Show decoder" {} + -command {$jp3dVM::notebook raise [$jp3dVM::notebook page 1]} + } + } + "&Help" {} {} 0 { + {command "&About authors..." {} "Show info about authors" {} + -command {MessageDlg .msgdlg -parent . -title "About authors" -message " Copyright @ LPI-UVA 2006 " -type ok -icon info}} + } + } + + set mainframe [MainFrame .mainframe \ + -menu $descmenu \ + -textvariable jp3dVM::status \ + -progressvar jp3dVM::prgindic] + + $mainframe addindicator -text "JP3D Verification Model 1.0.0" + + # NoteBook creation + set frame [$mainframe getframe] + set notebook [NoteBook $frame.nb] + + set logo [frame $frame.logo] + #creo imagen logo + image create photo LPIimg -file logoLPI.gif + set logoimg [Label $logo.logoimg -image LPIimg] + + set f0 [VMEncoder::create $notebook] + set f1 [VMDecoder::create $notebook] + + set tfinfo [TitleFrame $frame.codinfo -text "Program Execution"] + set codinfo [$tfinfo getframe] + set sw [ScrolledWindow $codinfo.sw -relief sunken -borderwidth 2 -scrollbar both] + set sf [ScrollableFrame $codinfo.sf ] + $sw setwidget $sf + set subf [$sf getframe] + set labinfo [label $subf.labinfo -textvariable jp3dVM::dataout -justify left] + + pack $labinfo -side left + pack $sw + + $notebook compute_size + $notebook raise [$notebook page 0] + + pack $logoimg -side left -fill x -expand yes + pack $notebook -expand yes + pack $logo $tfinfo -side left -expand yes + pack $mainframe -fill both -expand yes + update idletasks +} + + +proc jp3dVM::main {} { + variable VMDIR + + lappend ::auto_path [file dirname $VMDIR] + namespace inscope :: package require BWidget + + option add *TitleFrame.l.font {helvetica 11 bold italic} + + wm withdraw . + wm title . "JP3D Verification Model @ LPI" + + jp3dVM::create + BWidget::place . 0 0 center + wm deiconify . + raise . + focus -force . +} + +jp3dVM::main +wm geom . [wm geom .] diff --git a/src/bin/jp3d/tcltk/README b/src/bin/jp3d/tcltk/README new file mode 100644 index 0000000..f4e2e35 --- /dev/null +++ b/src/bin/jp3d/tcltk/README @@ -0,0 +1,13 @@ +HOWTO USE THE TCL/TK APP IN 'jp3d/tcltk' +---------------------------------------- +1. Download the 'BWidget-1.9.2' + http://www.sourceforge.net/projects/tcllib/ + +2. Install it e.g. in '/usr/local/BWidget-1.9.2/' +3. Add the lappend command in line 4 + to jp3d/tcltk/LPI_JP3D_VM.tcl: + +#!/bin/sh +# The next line is executed by /bin/sh, but not tcl \ +exec wish "$0" ${1+"$@"} +lappend auto_path /usr/local/BWidget-1.9.2 diff --git a/src/bin/jp3d/tcltk/Thumbs.db b/src/bin/jp3d/tcltk/Thumbs.db new file mode 100755 index 0000000000000000000000000000000000000000..5d6ffdf99eb8ebe582a94fa45d711c3e0bb856ca GIT binary patch literal 18944 zcmeIZ2Urwcw!d2l2nZ5Hk|Y%nB}$gqB9cXvoO4EUj!pOgCAENnB9al1BstTPGf2)E zBtw%MXuAK!_syI+Gw0rOXU>^>?=#Oc8(yk+)$Xd=p*Cy%_Nt!)WDDsfcNT%aNfH1y zfW{C2*Z(KWD8@YUc2lN4YK*4h|&1Ga+YAG`jc zzofvm|ET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!8Ul`sET=U>gb-e; zWKTi#m)WCfhqUx`0_^TTvHk&Z^wCKDAFCbJecs*lvdR|%&55DfOq#FSoP~&ag^O&a z7k?vdS5e%s&_hhHZ9ab5avg`k1?gJ2qj12!B@-@sVe7$6#@3&ehbK&fW4ZNOVEC5u zNp>|uiZ>`pxT zRn`Epn!As3B}U%ecQab^R83xk7AgBTHkV6`%pXxyfu_V3`nF#-e4QO!?1YY^*bVbL z(Ei-DhAYYy&>m#*A^XN0MdQ%UbJES+ZhV%nRn}Svth1D7ULDT18C4OTRpDa6CC^a# z<&L7n^9pSjs?eVr^Ps6xjC_p&2pST8>#=pAI*BYke3xOenU)MF6yZs|786m}^f-eY zunBP2R`t;?|I_r27ylH!gA0u3u>+%euF}T{{fZr Be`5du literal 0 HcmV?d00001 diff --git a/src/bin/jp3d/tcltk/decoder.tcl b/src/bin/jp3d/tcltk/decoder.tcl new file mode 100755 index 0000000..98edcde --- /dev/null +++ b/src/bin/jp3d/tcltk/decoder.tcl @@ -0,0 +1,272 @@ + +namespace eval VMDecoder { + variable var + variable JP3Ddecoder "../bin/jp3d_to_volume.exe" + #variable JP3Ddecoder "jp3d_to_volume.exe" +} + + +proc VMDecoder::create { nb } { + variable var + + set frameD [$nb insert end VMDecoder -text "Decoder"] + set topfD [frame $frameD.topfD] + set medfD [frame $frameD.medfD] + set bottomfD [frame $frameD.bottomfD] + set srcfD [TitleFrame $topfD.srcfD -text "Source"] + set dstfD [TitleFrame $topfD.dstfD -text "Destination"] + set paramfD [TitleFrame $medfD.paramfD -text "Decoding parameters"] + set infofD [TitleFrame $medfD.infofD -text "Distortion measures"] + + set frame1 [$srcfD getframe] + _sourceD $frame1 + set frame2 [$dstfD getframe] + _destinationD $frame2 + set frame3 [$infofD getframe] + _originalD $frame3 + set frame4 [$paramfD getframe] + _paramsD $frame4 + + set butD [Button $bottomfD.butD -text "Decode!" \ + -command "VMDecoder::_decode $frame1 $frame2 $frame3" \ + -helptext "Decoding trigger button"] + set butR [Button $bottomfD.butR -text "Save info" \ + -command "VMDecoder::_save $frame3" \ + -helptext "Save information"] + + pack $srcfD $dstfD -side left -fill both -padx 10 -ipadx 5 -expand yes + pack $topfD -pady 4 -fill x + + pack $paramfD $infofD -side left -fill both -padx 10 -pady 2 -ipadx 5 -expand yes + pack $medfD -pady 4 -fill x + + pack $butD $butR -side left -padx 4 -pady 5 -expand yes + pack $bottomfD -pady 4 -fill x + +return $frameD +} + + +proc fileDialogD {w ent operation} { + + variable file + + if {$operation == "open"} { + #-----Type names---------Extension(s)--- + set types { + {"JP3D Files" {.jp3d} } + {"All files" *} + } + set file [tk_getOpenFile -filetypes $types -parent $w ] + } elseif {$operation == "original"} { + #-----Type names---------Extension(s)--- + set types { + {"BIN Raw Image Files" {.bin} } + {"PGX Raw Image Files" {.pgx} } + {"All files" *} + } + set file [tk_getOpenFile -filetypes $types -parent $w ] + } else { + #-----Type names---------Extension(s)--- + set types { + {"BIN Raw Image Files" {.bin} } + {"PGX Raw Image Files" {.pgx} } + {"All files" *} + } + set file [tk_getSaveFile -filetypes $types -parent $w -initialfile Untitled -defaultextension "*.bin"] + } + if {[string compare $file ""]} { + $ent delete 0 end + $ent insert end $file + $ent xview moveto 1 + } +} + +proc VMDecoder::_sourceD { parent } { + + variable var + + set labsrcD [LabelFrame $parent.labsrcD -text "Select compressed file: " -side top \ + -anchor w -relief flat -borderwidth 0] + set subsrcD [$labsrcD getframe] + set listD [entry $subsrcD.entrysrcD -width 40 -textvariable VMDecoder::var(sourceD)] + + set labbrw [LabelFrame $parent.labbrw -side top -anchor w -relief flat -borderwidth 0] + set subbrw [$labbrw getframe] + set butbrw [button $subbrw.butbrw -image [Bitmap::get open] \ + -relief raised -borderwidth 1 -padx 1 -pady 1 \ + -command "fileDialogD . $subsrcD.entrysrcD open"] + + pack $listD -side top + pack $butbrw -side top + pack $labsrcD $labbrw -side left -fill both -expand yes + + +} + +proc VMDecoder::_destinationD { parent } { + + variable var + + set labdstD [LabelFrame $parent.labdstD -text "Save decompressed volume file(s) as: " -side top \ + -anchor w -relief flat -borderwidth 0] + set subdstD [$labdstD getframe] + set listD [entry $subdstD.entrydstD -width 40 -textvariable VMDecoder::var(destinationD)] + + set labbrw [LabelFrame $parent.labbrw -side top -anchor w -relief flat -borderwidth 0] + set subbrw [$labbrw getframe] + set butbrw [button $subbrw.butbrw -image [Bitmap::get save] \ + -relief raised -borderwidth 1 -padx 1 -pady 1 \ + -command "fileDialogD . $subdstD.entrydstD save"] + + pack $listD -side top + pack $butbrw -side top + pack $labdstD $labbrw -side left -fill both -expand yes +} + +proc VMDecoder::_originalD { parent } { + + variable var + + set laborgD [LabelFrame $parent.laborgD -text "Select original file: " -side top \ + -anchor w -relief flat -borderwidth 0] + set suborgD [$laborgD getframe] + set listorgD [entry $suborgD.entryorgD -width 30 -textvariable VMDecoder::var(originalD)] + + set labbrw2 [LabelFrame $parent.labbrw2 -side top -anchor w -relief flat -borderwidth 0] + set subbrw2 [$labbrw2 getframe] + set butbrw2 [button $subbrw2.butbrw2 -image [Bitmap::get open] \ + -relief raised -borderwidth 1 -padx 1 -pady 1 \ + -command "fileDialogD . $suborgD.entryorgD original"] + + set infoD [Label $parent.infoD -relief sunken -textvariable VMDecoder::var(decodinfo) -justify left] + + pack $listorgD -side left -anchor n + pack $butbrw2 -side left -anchor n + pack $infoD -side bottom -anchor nw -pady 4 -ipadx 150 -ipady 20 -expand yes + pack $laborgD $labbrw2 -side left -fill both + + +} + +proc VMDecoder::_paramsD { parent } { + + variable var + + ########### DECODING ############# + set labcod [LabelFrame $parent.labcod -side top -anchor w -relief sunken -borderwidth 1] + set subcod [$labcod getframe] + + set frameres [frame $subcod.frameres -borderwidth 1] + set labres [LabelEntry $frameres.labres -label "Resolutions to discard: " -labelwidth 20 -labelanchor w \ + -textvariable VMDecoder::var(resdiscard) -editable 1 \ + -helptext "Number of highest resolution levels to be discarded on each dimension" ] + set VMDecoder::var(resdiscard) "0,0,0" + + set framelayer [frame $subcod.framelayer -borderwidth 1] + set lablayer [LabelEntry $framelayer.lablayer -label "Layers to decode: " -labelwidth 20 -labelanchor w \ + -textvariable VMDecoder::var(layer) -editable 1 \ + -helptext "Maximum number of quality layers to decode" ] + set VMDecoder::var(layer) "All" + + set framebe [frame $subcod.framebe -borderwidth 1] + set chkbe [checkbutton $framebe.chkbe -text "Write decoded file with BigEndian byte order" \ + -variable VMDecoder::var(be) -onvalue 1 -offvalue 0 ] + + pack $labres -side left -padx 2 -anchor n + pack $lablayer -side left -padx 2 -anchor n + pack $chkbe -side left -padx 2 -anchor w + pack $frameres $framelayer $framebe -side top -anchor w + + pack $subcod -anchor n + pack $labcod -side left -fill both -padx 4 -expand yes +} + + +proc VMDecoder::_decode { framesrc framedst frameinfo} { + + variable var + + set sourceD [$framesrc.labsrcD.f.entrysrcD get ] + set destinationD [$framedst.labdstD.f.entrydstD get ] + set originD [$frameinfo.laborgD.f.entryorgD get ] + set cond1 [string match *.pgx [string tolower $destinationD]] + set cond2 [string match *\**.pgx [string tolower $destinationD]] + set cond3 [string match *.bin [string tolower $destinationD]] + + #comprobamos datos son correctos + if {($cond1 == 1) && ($cond2 == 0)} { + set pgx "*.pgx" + set pattern [string range $destinationD 0 [expr [string length $destinationD]-5]] + set destinationD $pattern$img + } elseif {$sourceD == ""} { + MessageDlg .msgdlg -parent . -message "Error : Source file is not defined !" -type ok -icon error + } elseif {$destinationD == ""} { + MessageDlg .msgdlg -parent . -message "Error : Destination file is not defined !" -type ok -icon error + } else { + + #creamos datain a partir de los parametros de entrada + #set dirJP3Ddecoder [mk_relativepath $VMDecoder::JP3Ddecoder] + set dirJP3Ddecoder $VMDecoder::JP3Ddecoder + set datain [concat " $dirJP3Ddecoder -i [mk_relativepath $sourceD] "] + set datain [concat " $datain -o [mk_relativepath $destinationD] "] + if {$originD != ""} { + set datain [concat " $datain -O [mk_relativepath $originD] "] + if {$cond3 == 1} { + set img ".img" + set pattern [string range $originD 0 [expr [string length $originD]-5]] + set pattern $pattern$img + if {[file exists $pattern]} { + set datain [concat " $datain -m [mk_relativepath $pattern] "] + } else { + MessageDlg .msgdlg -parent . -message "Error : IMG file associated to original BIN volume file not found in same directory !" -type ok -icon info + } + } + } + if {$VMDecoder::var(resdiscard) != "0,0,0"} { + set datain [concat " $datain -r $VMDecoder::var(resdiscard) "] + } + if {$VMDecoder::var(layer) != "All" && $VMDecoder::var(layer) > 0} { + set datain [concat " $datain -l $VMDecoder::var(layer) "] + } + if {$VMDecoder::var(be) == 1} { + set datain [concat " $datain -BE"] + } + + set VMDecoder::var(progval) 10 + ProgressDlg .progress -parent . -title "Wait..." \ + -type infinite \ + -width 20 \ + -textvariable "Compute in progress..."\ + -variable VMDecoder::progval \ + -stop "Stop" \ + -command {destroy .progress} + + after 200 set VMDecoder::var(progval) 2 + + set fp [open "| $datain " r+] + fconfigure $fp -buffering line + set jp3dVM::dataout [concat "EXECUTED PROGRAM:\n\t$datain"] + while {-1 != [gets $fp tmp]} { + set jp3dVM::dataout [concat "$jp3dVM::dataout\n$tmp"] + } + close $fp + destroy .progress + set cond [string first "ERROR" $jp3dVM::dataout] + set cond2 [string first "PSNR" $jp3dVM::dataout] + set cond3 [string first "RESULT" $jp3dVM::dataout] + if {$cond != -1} { + MessageDlg .msgdlg -parent . -message [string range $jp3dVM::dataout [expr $cond-1] end] -type ok -icon error + } elseif {$cond3 != -1} { + if {$cond2 != -1} { + set VMDecoder::var(decodinfo) [string range $jp3dVM::dataout [expr $cond2-1] end] + } + MessageDlg .msgdlg -parent . -message [string range $jp3dVM::dataout [expr $cond3-1] end] -type ok -icon info + } + } +} + +proc VMDecoder::_save { frameinfo } { + +} + diff --git a/src/bin/jp3d/tcltk/encoder.tcl b/src/bin/jp3d/tcltk/encoder.tcl new file mode 100755 index 0000000..6c4a508 --- /dev/null +++ b/src/bin/jp3d/tcltk/encoder.tcl @@ -0,0 +1,470 @@ + +namespace eval VMEncoder { + variable var + variable JP3Dencoder "../bin/bin/volume_to_jp3d" +} + +proc VMEncoder::create { nb } { + + set frame [$nb insert end VMEncoder -text "Encoder"] + set topf [frame $frame.topf] + set midf [frame $frame.midf] + set bottomf [frame $frame.bottomf] + set srcf [TitleFrame $topf.srcf -text "Source"] + set dstf [TitleFrame $topf.dstf -text "Destination"] + set Tparf [TitleFrame $midf.parfT -text "Transform Parameters"] + set Cparf [TitleFrame $midf.parfC -text "Coding Parameters"] + + set frame1 [$srcf getframe] + VMEncoder::_sourceE $frame1 + + set frame2 [$dstf getframe] + VMEncoder::_destinationE $frame2 + + set frame3 [$Tparf getframe] + VMEncoder::_transformE $frame3 + + set frame4 [$Cparf getframe] + VMEncoder::_codingE $frame4 + + set butE [Button $bottomf.butE -text "Encode!" \ + -command "VMEncoder::_encode $frame1 $frame2" \ + -helptext "Encoding trigger button"] + set butR [Button $bottomf.butR -text "Restore defaults" \ + -command "VMEncoder::_reset $frame1 $frame2 $frame3 $frame4" \ + -helptext "Reset to default values"] + + pack $srcf $dstf -side left -fill y -padx 4 -expand yes + pack $topf -pady 2 -fill x + + pack $Tparf $Cparf -side left -fill both -padx 4 -expand yes + pack $midf -pady 2 -fill x + + pack $butE $butR -side left -padx 40 -pady 5 -fill y -expand yes + pack $bottomf -pady 2 -fill x + + return $frame +} + +proc VMEncoder::_sourceE { parent } { + + variable var + + set labsrc [LabelFrame $parent.labsrc -text "Select volume file to encode: " -side top \ + -anchor w -relief flat -borderwidth 0] + set subsrc [$labsrc getframe] + set list [entry $subsrc.entrysrc -width 30 -textvariable VMDecoder::var(source)] + + set labbrw [LabelFrame $parent.labbrw -side top -anchor w -relief flat -borderwidth 0] + set subbrw [$labbrw getframe] + set butbrw [button $subbrw.butbrw -image [Bitmap::get open] \ + -relief raised -borderwidth 1 -padx 1 -pady 1 \ + -command "fileDialogE . $subsrc.entrysrc open"] + + pack $list -side top + pack $butbrw -side top + pack $labsrc $labbrw -side left -fill both -expand yes +} + +proc VMEncoder::_destinationE { parent } { + + variable var + + set labdst [LabelFrame $parent.labdst -text "Save compressed volume as: " -side top \ + -anchor w -relief flat -borderwidth 0] + set subdst [$labdst getframe] + set list [entry $subdst.entrydst -width 30 -textvariable VMDecoder::var(destination)] + + set labbrw [LabelFrame $parent.labbrw -side top -anchor w -relief flat -borderwidth 0] + set subbrw [$labbrw getframe] + set butbrw [button $subbrw.butbrw -image [Bitmap::get save] \ + -relief raised -borderwidth 1 -padx 1 -pady 1 \ + -command "fileDialogE . $subdst.entrydst save"] + + pack $list -side top + pack $butbrw -side top + pack $labdst $labbrw -side left -fill both -expand yes +} + +proc VMEncoder::_codingE { parent } { + + + ########### CODING ############# + set labcod [LabelFrame $parent.labcod -side top -anchor w -relief sunken -borderwidth 1] + set subcod [$labcod getframe] + + set framerate [frame $subcod.framerate -borderwidth 1] + set labrate [LabelEntry $framerate.labrate -label "Rates: " -labelwidth 9 -labelanchor w \ + -textvariable VMEncoder::var(rate) -editable 1 \ + -helptext "Compression ratios for different layers (R1, R2, R3,...). If R=1, lossless coding" ] + set VMEncoder::var(rate) "1" + + set framecblk [frame $subcod.framecblk -borderwidth 1] + set labcblk [LabelEntry $framecblk.labcblk -label "Codeblock: " -labelwidth 9 -labelanchor w \ + -textvariable VMEncoder::var(cblksize) -editable 1 \ + -helptext "Codeblock size (X, Y, Z)" ] + set VMEncoder::var(cblksize) "64,64,64" + + set frametile [frame $subcod.frametile -borderwidth 1] + set labtile [LabelEntry $frametile.labtile -label "Tile size: " -labelwidth 9 -labelanchor w \ + -textvariable VMEncoder::var(tilesize) -editable 1 \ + -helptext "Tile size (X, Y, Z)" ] + set VMEncoder::var(tilesize) "512,512,512" + + set framesop [frame $subcod.framesop -borderwidth 1] + set chksop [checkbutton $framesop.chksop -text "Write SOP marker" \ + -variable VMEncoder::var(sop) -onvalue 1 -offvalue 0 ] + set frameeph [frame $subcod.frameeph -borderwidth 1] + set chkeph [checkbutton $frameeph.chkeph -text "Write EPH marker" \ + -variable VMEncoder::var(eph) -onvalue 1 -offvalue 0 ] + + set framepoc [frame $subcod.framepoc -borderwidth 1] + set labpoc [label $framepoc.labpoc -text "Progression order: " ] + set progorder [ComboBox $framepoc.progorder \ + -text {Choose a progression order} \ + -width 10 \ + -textvariable VMEncoder::var(progorder) \ + -values {"LRCP" "RLCP" "RPCL" "PCRL" "CPRL"} \ + -helptext "Progression order"] + set VMEncoder::var(progorder) "LRCP" + + pack $labrate -side left -padx 2 -anchor n + pack $labcblk -side left -padx 2 -anchor n + pack $labpoc $progorder -side left -padx 2 -anchor w + #pack $labtile -side left -padx 2 -anchor n + pack $chksop -side left -padx 2 -anchor w + pack $chkeph -side left -padx 2 -anchor w + ########### ENTROPY CODING ############# + set labent [LabelFrame $parent.labent -text "Entropy Coding" -side top -anchor w -relief sunken -borderwidth 1] + set subent [$labent getframe] + foreach entval {2EB 3EB} entropy {2D_EBCOT 3D_EBCOT} { + set rad [radiobutton $subent.$entval \ + -text $entropy \ + -variable VMEncoder::var(encoding) \ + -command "disableGR $entval $labcblk $progorder $labrate $chksop $chkeph" \ + -value $entval ] + pack $rad -anchor w + } + $subent.2EB select + + pack $subent -padx 2 -anchor n + + pack $framerate $framecblk $framepoc $framesop $frameeph -side top -anchor w + pack $subcod -anchor n + + pack $labent $labcod -side left -fill both -padx 4 -expand yes + + +} + +proc VMEncoder::_transformE { parent } { + + variable var + + ########### TRANSFORM ############# + set labtrf [LabelFrame $parent.labtrf -text "Transform" -side top -anchor w -relief sunken -borderwidth 1] + set subtrf [$labtrf getframe] + set labres [LabelFrame $parent.labres -side top -anchor w -relief sunken -borderwidth 1] + set subres [$labres getframe] + + ########### ATK ############# + set frameatk [frame $subres.frameatk -borderwidth 1] + set labatk [label $frameatk.labatk -text "Wavelet kernel: " -anchor w] + set atk [ComboBox $frameatk.atk \ + -textvariable VMEncoder::var(atk) \ + -width 20 \ + -text {Choose a wavelet kernel} \ + -editable false \ + -values {"R5.3" "I9.7"} ] + set VMEncoder::var(atk) "R5.3" + pack $labatk $atk -side left -anchor w + ########### RESOLUTIONS ############# + set frameres1 [frame $subres.frameres1 -borderwidth 1] + set labresolution [label $frameres1.labresol -text "Resolutions: " -anchor w ] + set frameres2 [frame $subres.frameres2 -borderwidth 1] + set labresX [label $frameres2.labresX -text " X" -anchor w ] + set labresY [label $frameres2.labresY -text " Y" -anchor w ] + set labresZ [label $frameres2.labresZ -text " Z" -anchor w ] + + + set resX [SpinBox $frameres2.spinresX \ + -range {1 6 1} -textvariable VMEncoder::var(resX) \ + -helptext "Number of resolutions in X" \ + -width 3 \ + -editable false ] + set resY [SpinBox $frameres2.spinresY \ + -range {1 6 1} -textvariable VMEncoder::var(resY) \ + -helptext "Number of resolutions in Y" \ + -width 3 \ + -editable false ] + set resZ [SpinBox $frameres2.spinresZ \ + -range {1 6 1} -textvariable VMEncoder::var(resZ) \ + -helptext "Number of resolutions in Z" \ + -width 3 \ + -editable false \ + -state disabled ] + set VMEncoder::var(resX) 3 + set VMEncoder::var(resY) 3 + set VMEncoder::var(resZ) 3 + + ########### TRF ############# + foreach trfval {2DWT 3DWT} trf {2D-DWT 3D-DWT} { + set rad [radiobutton $subtrf.$trfval -text $trf \ + -variable VMEncoder::var(transform) \ + -command "disable3RLS $trfval $atk $resX $resY $resZ"\ + -value $trfval ] + pack $rad -anchor w + } + $subtrf.2DWT select + + pack $subtrf -side left -padx 2 -pady 4 + + pack $labresolution -padx 2 -side left -anchor w + pack $labresX $resX -padx 2 -side left -anchor w + pack $labresY $resY -padx 2 -side left -anchor w + pack $labresZ $resZ -padx 2 -side left -anchor w + + pack $frameres1 -side top -fill x + pack $frameres2 $frameatk -side top -padx 2 -pady 4 -anchor n + + pack $subres -side left -padx 2 -pady 4 + pack $labtrf $labres -side left -fill both -padx 4 -expand yes +} + + +proc VMEncoder::_encode { framesrc framedst } { + + variable var + + set source [$framesrc.labsrc.f.entrysrc get ] + set destination [$framedst.labdst.f.entrydst get ] + set cond1 [string match *.pgx [string tolower $source]] + set cond2 [string match *-*.pgx [string tolower $source]] + set cond3 [string match *.bin [string tolower $source]] + + set img ".img" + set pattern [string range $source 0 [expr [string length $source]-5]] + set pattern $pattern$img + set exist [file exists $pattern] + + #comprobamos datos son correctos + if {($cond1 == 1) && ($cond2 == 0)} { + MessageDlg .msgdlg -parent . -message "Info : Really want to encode an slice instead of a volume?.\n For a group of .pgx slices, name must contain a - denoting a sequential index!" -type ok -icon info + } + + if {$source == ""} { + MessageDlg .msgdlg -parent . -message "Error : Source file is not defined !" -type ok -icon error + } elseif {$destination == ""} { + MessageDlg .msgdlg -parent . -message "Error : Destination file is not defined !" -type ok -icon error + } elseif { ($VMEncoder::var(transform) != "3RLS") && ($VMEncoder::var(atk) == "Choose a wavelet transformation kernel") } { + MessageDlg .msgdlg -parent . -title "Info" -message "Please choose a wavelet transformation kernel"\ + -type ok -icon warning + } elseif {($exist == 0) && ($cond1 == 0) && ($cond3 == 1)} { + MessageDlg .msgdlg -parent . -message "Error : IMG file associated to BIN volume file not found in same directory !" -type ok -icon info + } else { + + #creamos datain a partir de los parametros de entrada +# set dirJP3Dencoder [mk_relativepath $VMEncoder::JP3Dencoder] + set dirJP3Dencoder $VMEncoder::JP3Dencoder + set datain [concat " $dirJP3Dencoder -i [mk_relativepath $source] "] + if {$cond3 == 1} { + set datain [concat " $datain -m [mk_relativepath $pattern] "] + } + set datain [concat " $datain -o [mk_relativepath $destination] "] + if {$VMEncoder::var(encoding) != "2EB"} { + set datain [concat " $datain -C $VMEncoder::var(encoding) "] + } + if {$VMEncoder::var(transform) == "2DWT"} { + set datain [concat " $datain -n $VMEncoder::var(resX),$VMEncoder::var(resY) "] + } elseif {$VMEncoder::var(transform) == "3DWT"} { + set datain [concat " $datain -n $VMEncoder::var(resX),$VMEncoder::var(resY),$VMEncoder::var(resZ) "] + } + + set datain [concat " $datain -r $VMEncoder::var(rate) "] + + if {$VMEncoder::var(atk) == "I9.7"} { + set datain [concat " $datain -I "] + } + if {$VMEncoder::var(sop) == 1} { + set datain [concat " $datain -SOP "] + } + if {$VMEncoder::var(eph) == 1} { + set datain [concat " $datain -EPH "] + } + if {$VMEncoder::var(progorder) != "LRCP"} { + set datain [concat " $datain -p $VMEncoder::var(progorder) "] + } + if {$VMEncoder::var(cblksize) != "64,64,64"} { + set datain [concat " $datain -b $VMEncoder::var(cblksize) "] + } + + + #Making this work would be great !!! + set VMEncoder::var(progval) 10 + ProgressDlg .progress -parent . -title "Wait..." \ + -type infinite \ + -width 20 \ + -textvariable "Compute in progress..."\ + -variable VMEncoder::progval \ + -stop "Stop" \ + -command {destroy .progress} + after 200 set VMEncoder::var(progval) 2 + set fp [open "| $datain " r+] + fconfigure $fp -buffering line + set jp3dVM::dataout [concat "EXECUTED PROGRAM:\n\t$datain"] + while {-1 != [gets $fp tmp]} { + set jp3dVM::dataout [concat "$jp3dVM::dataout\n$tmp"] + } + destroy .progress + set cond [string first "ERROR" $jp3dVM::dataout] + set cond2 [string first "RESULT" $jp3dVM::dataout] + if {$cond != -1} { + MessageDlg .msgdlg -parent . -message [string range $jp3dVM::dataout [expr $cond-1] end] -type ok -icon error + } elseif {$cond2 != -1} { + MessageDlg .msgdlg -parent . -message [string range $jp3dVM::dataout [expr $cond2+7] end] -type ok -icon info + close $fp + } else { + #Must do something with this !!! [pid $fp] + close $fp + } + } +} + +proc VMEncoder::_reset { framesrc framedst frametrf framecod} { + + variable var + + #Restore defaults values + set VMEncoder::var(transform) 2DWT + set VMEncoder::var(encoding) 2EB + set VMEncoder::var(atk) "R5.3" + set VMEncoder::var(progorder) "LRCP" + set atk $frametrf.labres.f.frameatk.atk + set resX $frametrf.labres.f.frameres2.spinresX + set resY $frametrf.labres.f.frameres2.spinresY + set resZ $frametrf.labres.f.frameres2.spinresZ + disable3RLS 2DWT $atk $resX $resY $resZ + set labcblk $framecod.labcod.f.framecblk.labcblk + set progorder $framecod.labcod.f.framepoc.progorder + set labrate $framecod.labcod.f.framerate.labrate + set chksop $framecod.labcod.f.framesop.chksop + set chkeph $framecod.labcod.f.frameeph.chkeph + disableGR 3EB $labcblk $progorder $labrate $chksop $chkeph + + $framesrc.labsrc.f.entrysrc delete 0 end + $framedst.labdst.f.entrydst delete 0 end +} + +proc fileDialogE {w ent operation} { + + variable file + variable i j + + if {$operation == "open"} { + set types { + {"Source Image Files" {.pgx .bin} } + {"All files" *} + } + set file [tk_getOpenFile -filetypes $types -parent $w] + if {[string compare $file ""]} { + $ent delete 0 end + $ent insert end $file + $ent xview moveto 1 + } + } else { + set types { + {"JP3D Files" {.jp3d} } + {"JPEG2000 Files" {.j2k} } + {"All files" *} + } + set file [tk_getSaveFile -filetypes $types -parent $w \ + -initialfile Untitled -defaultextension .jp3d] + if {[string compare $file ""]} { + $ent delete 0 end + $ent insert end $file + $ent xview moveto 1 + } + } +} + +proc mk_relativepath {abspath} { + + set mydir [split [string trimleft [pwd] {/}] {/}] + set abspathcomps [split [string trimleft $abspath {/}] {/}] + + set i 0 + while {$i<[llength $mydir]} { + if {![string compare [lindex $abspathcomps $i] [lindex $mydir $i]]} { + incr i + } else { + break + } + } + set h [expr [llength $mydir]-$i] + set j [expr [llength $abspathcomps]-$i] + + if {!$h} { + set relpath "./" + } else { + set relpath "" + while { $h > 0 } { + set relpath "../$relpath" + incr h -1 + } + } + + set h [llength $abspathcomps] + while { $h > $i } { + set relpath [concat $relpath[lindex $abspathcomps [expr [llength $abspathcomps]-$j]]/] + incr h -1 + incr j -1 + } + return [string trim $relpath {/}] +} + +proc disable3RLS {flag atk resX resY resZ} { + + if {$flag == "3RLS"} { + $atk configure -state disabled + $resX configure -state disabled + $resY configure -state disabled + $resZ configure -state disabled + } elseif {$flag == "2DWT"} { + $atk configure -state normal + $resX configure -state normal + $resY configure -state normal + $resZ configure -state disabled + } elseif {$flag == "3DWT"} { + $atk configure -state normal + $resX configure -state normal + $resY configure -state normal + $resZ configure -state normal + } +} + +proc disableGR {flag labcblk progorder labrate chksop chkeph} { + + if {$flag == "2EB"} { + $labcblk configure -state normal + $progorder configure -state normal + $labrate configure -state normal + $chksop configure -state normal + $chkeph configure -state normal + set VMEncoder::var(cblksize) "64,64,64" + set VMEncoder::var(tilesize) "512,512,512" + } elseif {$flag == "3EB"} { + $labcblk configure -state normal + $progorder configure -state normal + $labrate configure -state normal + $chksop configure -state normal + $chkeph configure -state normal + set VMEncoder::var(cblksize) "64,64,64" + set VMEncoder::var(tilesize) "512,512,512" + } else { + $labcblk configure -state disabled + $progorder configure -state disabled + $labrate configure -state disabled + $chksop configure -state disabled + $chkeph configure -state disabled + } +} diff --git a/src/bin/jp3d/tcltk/logoLPI.gif b/src/bin/jp3d/tcltk/logoLPI.gif new file mode 100755 index 0000000000000000000000000000000000000000..df79515057f4163e12943482993fc337eafe2002 GIT binary patch literal 5212 zcmWmD`6CpK1IO{%d*|4hao>!il5>kFDMN~MO$VvuS<$UpdY;I zQc2?o>99IHU3wN3(NpUvQt^GhpFiO9)9W2Hd)DMBQOAIVz##DdaX1_x%F4>x+S3)8GBuV=F`v(LB%$PAFFfefD%$c)h%?b(%3JwmQJ$rUYNXVQy zbLP&SJ8#~+`Sa&5Sg?SisD%p`E?Tr`@#4ixmMjSk4GjwmTe@^fZTt4^3WZ|FjvYI9?%cI& z*Y4fB_w3oTckkYP`}WZ^osf`_n3$N9l%!ND_wV1IoSdAJl9HO5df>o;w6wJJ^z@93 zjDrUcW@ct)Wo4;Us_g9SLx&C>K79Ddkt0Ws9zAyK*zx1Xb8>P{oH%jvkiUA}zz z%9SfuuU`G@ufNo4b#ZZVNl8g*X=zzm*|lreu3x`?-O#26%`eC z?%b)Yth{^oF3Yl2RaMp1)ipIWwY9bP?%k`atE;cCZ)j+^fB$}CW8;Gd4<0^z_~_B2 z$B!R3H8p88n&#%_Cr_R{efsp-vuDqrKW}Mi`TOs`U%Ytn^5x4{uU@@={rb(DH?6I$ zZ{NQC=bwMHT5VffTYGzZM@PrIckkZ6fB)gbhtAHoH1z%Z_u=8;A3uKl{Q2|OuU{i0 zBcr3EF8?p!|1ALG5nvRw3|2E$Nn!)1hz9kUniSkVBsaJ?|6aPO$A*foEd}*igy=Ev z?<*GNah;D7UMD|#b#2p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sxUn_gG7r&=sT{QMfjh4Pg zQ?^@lv2nc&`ia~#D#N;2>|ea7*%pdnMEN?bc8BCTY!aK7F-Xi?!%NzY7<5ZCk|r(trU5UgVQz85M-m)WNiJ%z>mm4&*!$_4vZFetDuomxrSSXW@z9t=H93bO#_f@ z`7K_RU?q;`G0i*ajXea^tpzIxypD$Ns=@7L@DUO@KpQ@lLS3Y|{MDW1cb-SIKId=% HVCw$>l!K-J literal 0 HcmV?d00001 diff --git a/src/bin/jp3d/windirent.h b/src/bin/jp3d/windirent.h new file mode 100644 index 0000000..4b1d9ff --- /dev/null +++ b/src/bin/jp3d/windirent.h @@ -0,0 +1,679 @@ +/* + * uce-dirent.h - operating system independent dirent implementation + * + * Copyright (C) 1998-2002 Toni Ronkko + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * ``Software''), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * + * May 28 1998, Toni Ronkko + * + * $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $ + * + * $Log: uce-dirent.h,v $ + * Revision 1.7 2002/05/13 10:48:35 tr + * embedded some source code directly to the header so that no source + * modules need to be included in the MS Visual C project using the + * interface, removed all the dependencies to other headers of the `uce' + * library so that the header can be made public + * + * Revision 1.6 2002/04/12 16:22:04 tr + * Unified Compiling Environment (UCE) replaced `std' library + * + * Revision 1.5 2001/07/20 16:33:40 tr + * moved to `std' library and re-named defines accordingly + * + * Revision 1.4 2001/07/10 16:47:18 tronkko + * revised comments + * + * Revision 1.3 2001/01/11 13:16:43 tr + * using ``uce-machine.h'' for finding out defines such as `FREEBSD' + * + * Revision 1.2 2000/10/08 16:00:41 tr + * copy of FreeBSD man page + * + * Revision 1.1 2000/07/10 05:53:16 tr + * Initial revision + * + * Revision 1.2 1998/07/19 18:29:14 tr + * Added error reporting capabilities and some asserts. + * + * Revision 1.1 1998/07/04 16:27:51 tr + * Initial revision + * + * + * MSVC 1.0 scans automatic dependencies incorrectly when your project + * contains this very header. The problem is that MSVC cannot handle + * include directives inside #if..#endif block those are never entered. + * Since this header ought to compile in many different operating systems, + * there had to be several conditional blocks that are compiled only in + * operating systems for what they were designed for. MSVC 1.0 cannot + * handle inclusion of sys/dir.h in a part that is compiled only in Apollo + * operating system. To fix the problem you need to insert DIR.H into + * SYSINCL.DAT located in MSVC\BIN directory and restart visual C++. + * Consult manuals for more informaton about the problem. + * + * Since many UNIX systems have dirent.h we assume to have one also. + * However, if your UNIX system does not have dirent.h you can download one + * for example at: http://ftp.uni-mannheim.de/ftp/GNU/dirent/dirent.tar.gz. + * You can also see if you have one of dirent.h, direct.h, dir.h, ndir.h, + * sys/dir.h and sys/ndir.h somewhere. Try defining HAVE_DIRENT_H, + * HAVE_DIRECT_H, HAVE_DIR_H, HAVE_NDIR_H, HAVE_SYS_DIR_H and + * HAVE_SYS_NDIR_H according to the files found. + */ +#ifndef DIRENT_H +#define DIRENT_H +#define DIRENT_H_INCLUDED + +/* find out platform */ +#if defined(MSDOS) /* MS-DOS */ +#elif defined(__MSDOS__) /* Turbo C/Borland */ +# define MSDOS +#elif defined(__DOS__) /* Watcom */ +# define MSDOS +#endif + +#if defined(WIN32) /* MS-Windows */ +#elif defined(__NT__) /* Watcom */ +# define WIN32 +#elif defined(_WIN32) /* Microsoft */ +# define WIN32 +#elif defined(__WIN32__) /* Borland */ +# define WIN32 +#endif + +/* + * See what kind of dirent interface we have unless autoconf has already + * determinated that. + */ +#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H) +# if defined(_MSC_VER) /* Microsoft C/C++ */ +/* no dirent.h */ +# elif defined(__MINGW32__) /* MinGW */ +/* no dirent.h */ +# elif defined(__BORLANDC__) /* Borland C/C++ */ +# define HAVE_DIRENT_H +# define VOID_CLOSEDIR +# elif defined(__TURBOC__) /* Borland Turbo C */ +/* no dirent.h */ +# elif defined(__WATCOMC__) /* Watcom C/C++ */ +# define HAVE_DIRECT_H +# elif defined(__apollo) /* Apollo */ +# define HAVE_SYS_DIR_H +# elif defined(__hpux) /* HP-UX */ +# define HAVE_DIRENT_H +# elif defined(__alpha) || defined(__alpha__) /* Alpha OSF1 */ +# error "not implemented" +# elif defined(__sgi) /* Silicon Graphics */ +# define HAVE_DIRENT_H +# elif defined(sun) || defined(_sun) /* Sun Solaris */ +# define HAVE_DIRENT_H +# elif defined(__FreeBSD__) /* FreeBSD */ +# define HAVE_DIRENT_H +# elif defined(__linux__) /* Linux */ +# define HAVE_DIRENT_H +# elif defined(__GNUC__) /* GNU C/C++ */ +# define HAVE_DIRENT_H +# else +# error "not implemented" +# endif +#endif + +/* include proper interface headers */ +#if defined(HAVE_DIRENT_H) +# include +# ifdef FREEBSD +# define NAMLEN(dp) ((int)((dp)->d_namlen)) +# else +# define NAMLEN(dp) ((int)(strlen((dp)->d_name))) +# endif + +#elif defined(HAVE_NDIR_H) +# include +# define NAMLEN(dp) ((int)((dp)->d_namlen)) + +#elif defined(HAVE_SYS_NDIR_H) +# include +# define NAMLEN(dp) ((int)((dp)->d_namlen)) + +#elif defined(HAVE_DIRECT_H) +# include +# define NAMLEN(dp) ((int)((dp)->d_namlen)) + +#elif defined(HAVE_DIR_H) +# include +# define NAMLEN(dp) ((int)((dp)->d_namlen)) + +#elif defined(HAVE_SYS_DIR_H) +# include +# include +# ifndef dirent +# define dirent direct +# endif +# define NAMLEN(dp) ((int)((dp)->d_namlen)) + +#elif defined(MSDOS) || defined(WIN32) + +/* figure out type of underlaying directory interface to be used */ +# if defined(WIN32) +# define DIRENT_WIN32_INTERFACE +# elif defined(MSDOS) +# define DIRENT_MSDOS_INTERFACE +# else +# error "missing native dirent interface" +# endif + +/*** WIN32 specifics ***/ +# if defined(DIRENT_WIN32_INTERFACE) +# include +# if !defined(DIRENT_MAXNAMLEN) +# define DIRENT_MAXNAMLEN (MAX_PATH) +# endif + + +/*** MS-DOS specifics ***/ +# elif defined(DIRENT_MSDOS_INTERFACE) +# include + +/* Borland defines file length macros in dir.h */ +# if defined(__BORLANDC__) +# include +# if !defined(DIRENT_MAXNAMLEN) +# define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT)) +# endif +# if !defined(_find_t) +# define _find_t find_t +# endif + +/* Turbo C defines ffblk structure in dir.h */ +# elif defined(__TURBOC__) +# include +# if !defined(DIRENT_MAXNAMLEN) +# define DIRENT_MAXNAMLEN ((MAXFILE)+(MAXEXT)) +# endif +# define DIRENT_USE_FFBLK + +/* MSVC */ +# elif defined(_MSC_VER) +# if !defined(DIRENT_MAXNAMLEN) +# define DIRENT_MAXNAMLEN (12) +# endif + +/* Watcom */ +# elif defined(__WATCOMC__) +# if !defined(DIRENT_MAXNAMLEN) +# if defined(__OS2__) || defined(__NT__) +# define DIRENT_MAXNAMLEN (255) +# else +# define DIRENT_MAXNAMLEN (12) +# endif +# endif + +# endif +# endif + +/*** generic MS-DOS and MS-Windows stuff ***/ +# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN) +# define NAME_MAX DIRENT_MAXNAMLEN +# endif +# if NAME_MAX < DIRENT_MAXNAMLEN +# error "assertion failed: NAME_MAX >= DIRENT_MAXNAMLEN" +# endif + + +/* + * Substitute for real dirent structure. Note that `d_name' field is a + * true character array although we have it copied in the implementation + * dependent data. We could save some memory if we had declared `d_name' + * as a pointer referring the name within implementation dependent data. + * We have not done that since some code may rely on sizeof(d_name) to be + * something other than four. Besides, directory entries are typically so + * small that it takes virtually no time to copy them from place to place. + */ +typedef struct dirent { + char d_name[NAME_MAX + 1]; + + /*** Operating system specific part ***/ +# if defined(DIRENT_WIN32_INTERFACE) /*WIN32*/ + WIN32_FIND_DATA data; +# elif defined(DIRENT_MSDOS_INTERFACE) /*MSDOS*/ +# if defined(DIRENT_USE_FFBLK) + struct ffblk data; +# else + struct _find_t data; +# endif +# endif +} dirent; + +/* DIR substitute structure containing directory name. The name is + * essential for the operation of ``rewinndir'' function. */ +typedef struct DIR { + char *dirname; /* directory being scanned */ + dirent current; /* current entry */ + int dirent_filled; /* is current un-processed? */ + + /*** Operating system specific part ***/ +# if defined(DIRENT_WIN32_INTERFACE) + HANDLE search_handle; +# elif defined(DIRENT_MSDOS_INTERFACE) +# endif +} DIR; + +# ifdef __cplusplus +extern "C" { +# endif + +/* supply prototypes for dirent functions */ +static DIR *opendir(const char *dirname); +static struct dirent *readdir(DIR *dirp); +static int closedir(DIR *dirp); +static void rewinddir(DIR *dirp); + +/* + * Implement dirent interface as static functions so that the user does not + * need to change his project in any way to use dirent function. With this + * it is sufficient to include this very header from source modules using + * dirent functions and the functions will be pulled in automatically. + */ +#include +#include +#include +#include +#include + +/* use ffblk instead of _find_t if requested */ +#if defined(DIRENT_USE_FFBLK) +# define _A_ARCH (FA_ARCH) +# define _A_HIDDEN (FA_HIDDEN) +# define _A_NORMAL (0) +# define _A_RDONLY (FA_RDONLY) +# define _A_SUBDIR (FA_DIREC) +# define _A_SYSTEM (FA_SYSTEM) +# define _A_VOLID (FA_LABEL) +# define _dos_findnext(dest) findnext(dest) +# define _dos_findfirst(name,flags,dest) findfirst(name,dest,flags) +#endif + +static int _initdir(DIR *p); +static const char *_getdirname(const struct dirent *dp); +static void _setdirname(struct DIR *dirp); + +/* + * + * open directory stream for reading + * DIR *opendir (const char *dirname); + * + * Open named directory stream for read and return pointer to the + * internal working area that is used for retrieving individual directory + * entries. The internal working area has no fields of your interest. + * + * Returns a pointer to the internal working area or NULL in case the + * directory stream could not be opened. Global `errno' variable will set + * in case of error as follows: + * + * + * [EACESS |Permission denied. + * [EMFILE |Too many open files used by the process. + * [ENFILE |Too many open files in system. + * [ENOENT |Directory does not exist. + * [ENOMEM |Insufficient memory. + * [ENOTDIR |dirname does not refer to directory. This value is not + * reliable on MS-DOS and MS-Windows platforms. Many + * implementations return ENOENT even when the name refers to a + * file.] + *
+ *
+ */ +static DIR *opendir(const char *dirname) +{ + DIR *dirp; + assert(dirname != NULL); + + dirp = (DIR*)malloc(sizeof(struct DIR)); + if (dirp != NULL) { + char *p; + + /* allocate room for directory name */ + dirp->dirname = (char*) malloc(strlen(dirname) + 1 + strlen("\\*.*")); + if (dirp->dirname == NULL) { + /* failed to duplicate directory name. errno set by malloc() */ + free(dirp); + return NULL; + } + /* Copy directory name while appending directory separator and "*.*". + * Directory separator is not appended if the name already ends with + * drive or directory separator. Directory separator is assumed to be + * '/' or '\' and drive separator is assumed to be ':'. */ + strcpy(dirp->dirname, dirname); + p = strchr(dirp->dirname, '\0'); + if (dirp->dirname < p && + *(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') { + strcpy(p++, "\\"); + } +# ifdef DIRENT_WIN32_INTERFACE + strcpy(p, "*"); /*scan files with and without extension in win32*/ +# else + strcpy(p, "*.*"); /*scan files with and without extension in DOS*/ +# endif + + /* open stream */ + if (_initdir(dirp) == 0) { + /* initialization failed */ + free(dirp->dirname); + free(dirp); + return NULL; + } + } + return dirp; +} + + +/* + * + * read a directory entry + * struct dirent *readdir (DIR *dirp); + * + * Read individual directory entry and return pointer to a structure + * containing the name of the entry. Individual directory entries returned + * include normal files, sub-directories, pseudo-directories "." and ".." + * and also volume labels, hidden files and system files in MS-DOS and + * MS-Windows. You might want to use stat(2) function to determinate which + * one are you dealing with. Many dirent implementations already contain + * equivalent information in dirent structure but you cannot depend on + * this. + * + * The dirent structure contains several system dependent fields that + * generally have no interest to you. The only interesting one is char + * d_name[] that is also portable across different systems. The d_name + * field contains the name of the directory entry without leading path. + * While d_name is portable across different systems the actual storage + * capacity of d_name varies from system to system and there is no portable + * way to find out it at compile time as different systems define the + * capacity of d_name with different macros and some systems do not define + * capacity at all (besides actual declaration of the field). If you really + * need to find out storage capacity of d_name then you might want to try + * NAME_MAX macro. The NAME_MAX is defined in POSIX standard although + * there are many MS-DOS and MS-Windows implementations those do not define + * it. There are also systems that declare d_name as "char d_name[1]" and + * then allocate suitable amount of memory at run-time. Thanks to Alain + * Decamps (Alain.Decamps@advalvas.be) for pointing it out to me. + * + * This all leads to the fact that it is difficult to allocate space + * for the directory names when the very same program is being compiled on + * number of operating systems. Therefore I suggest that you always + * allocate space for directory names dynamically. + * + * + * Returns a pointer to a structure containing name of the directory entry + * in `d_name' field or NULL if there was an error. In case of an error the + * global `errno' variable will set as follows: + * + * + * [EBADF |dir parameter refers to an invalid directory stream. This value + * is not set reliably on all implementations.] + *
+ *
+ */ +static struct dirent * +readdir(DIR *dirp) +{ + assert(dirp != NULL); + if (dirp == NULL) { + errno = EBADF; + return NULL; + } + +#if defined(DIRENT_WIN32_INTERFACE) + if (dirp->search_handle == INVALID_HANDLE_VALUE) { + /* directory stream was opened/rewound incorrectly or it ended normally */ + errno = EBADF; + return NULL; + } +#endif + + if (dirp->dirent_filled != 0) { + /* + * Directory entry has already been retrieved and there is no need to + * retrieve a new one. Directory entry will be retrieved in advance + * when the user calls readdir function for the first time. This is so + * because real dirent has separate functions for opening and reading + * the stream whereas Win32 and DOS dirents open the stream + * automatically when we retrieve the first file. Therefore, we have to + * save the first file when opening the stream and later we have to + * return the saved entry when the user tries to read the first entry. + */ + dirp->dirent_filled = 0; + } else { + /* fill in entry and return that */ +#if defined(DIRENT_WIN32_INTERFACE) + if (FindNextFile(dirp->search_handle, &dirp->current.data) == FALSE) { + /* Last file has been processed or an error occurred */ + FindClose(dirp->search_handle); + dirp->search_handle = INVALID_HANDLE_VALUE; + errno = ENOENT; + return NULL; + } + +# elif defined(DIRENT_MSDOS_INTERFACE) + if (_dos_findnext(&dirp->current.data) != 0) { + /* _dos_findnext and findnext will set errno to ENOENT when no + * more entries could be retrieved. */ + return NULL; + } +# endif + + _setdirname(dirp); + assert(dirp->dirent_filled == 0); + } + return &dirp->current; +} + + +/* + * + * close directory stream. + * int closedir (DIR *dirp); + * + * Close directory stream opened by the `opendir' function. Close of + * directory stream invalidates the DIR structure as well as previously read + * dirent entry. + * + * The function typically returns 0 on success and -1 on failure but + * the function may be declared to return void on same systems. At least + * Borland C/C++ and some UNIX implementations use void as a return type. + * The dirent wrapper tries to define VOID_CLOSEDIR whenever closedir is + * known to return nothing. The very same definition is made by the GNU + * autoconf if you happen to use it. + * + * The global `errno' variable will set to EBADF in case of error. + * + */ +static int +closedir(DIR *dirp) +{ + int retcode = 0; + + /* make sure that dirp points to legal structure */ + assert(dirp != NULL); + if (dirp == NULL) { + errno = EBADF; + return -1; + } + + /* free directory name and search handles */ + if (dirp->dirname != NULL) { + free(dirp->dirname); + } + +#if defined(DIRENT_WIN32_INTERFACE) + if (dirp->search_handle != INVALID_HANDLE_VALUE) { + if (FindClose(dirp->search_handle) == FALSE) { + /* Unknown error */ + retcode = -1; + errno = EBADF; + } + } +#endif + + /* clear dirp structure to make sure that it cannot be used anymore*/ + memset(dirp, 0, sizeof(*dirp)); +# if defined(DIRENT_WIN32_INTERFACE) + dirp->search_handle = INVALID_HANDLE_VALUE; +# endif + + free(dirp); + return retcode; +} + + +/* + * + * rewind directory stream to the beginning + * void rewinddir (DIR *dirp); + * + * Rewind directory stream to the beginning so that the next call of + * readdir() returns the very first directory entry again. However, note + * that next call of readdir() may not return the same directory entry as it + * did in first time. The directory stream may have been affected by newly + * created files. + * + * Almost every dirent implementation ensure that rewinddir will update + * the directory stream to reflect any changes made to the directory entries + * since the previous ``opendir'' or ``rewinddir'' call. Keep an eye on + * this if your program depends on the feature. I know at least one dirent + * implementation where you are required to close and re-open the stream to + * see the changes. + * + * Returns nothing. If something went wrong while rewinding, you will + * notice it later when you try to retrieve the first directory entry. + */ +static void +rewinddir(DIR *dirp) +{ + /* make sure that dirp is legal */ + assert(dirp != NULL); + if (dirp == NULL) { + errno = EBADF; + return; + } + assert(dirp->dirname != NULL); + + /* close previous stream */ +#if defined(DIRENT_WIN32_INTERFACE) + if (dirp->search_handle != INVALID_HANDLE_VALUE) { + if (FindClose(dirp->search_handle) == FALSE) { + /* Unknown error */ + errno = EBADF; + } + } +#endif + + /* re-open previous stream */ + if (_initdir(dirp) == 0) { + /* initialization failed but we cannot deal with error. User will notice + * error later when she tries to retrieve first directory enty. */ + /*EMPTY*/; + } +} + + +/* + * Open native directory stream object and retrieve first file. + * Be sure to close previous stream before opening new one. + */ +static int +_initdir(DIR *dirp) +{ + assert(dirp != NULL); + assert(dirp->dirname != NULL); + dirp->dirent_filled = 0; + +# if defined(DIRENT_WIN32_INTERFACE) + /* Open stream and retrieve first file */ + dirp->search_handle = FindFirstFile(dirp->dirname, &dirp->current.data); + if (dirp->search_handle == INVALID_HANDLE_VALUE) { + /* something went wrong but we don't know what. GetLastError() could + * give us more information about the error, but then we should map + * the error code into errno. */ + errno = ENOENT; + return 0; + } + +# elif defined(DIRENT_MSDOS_INTERFACE) + if (_dos_findfirst(dirp->dirname, + _A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN, + &dirp->current.data) != 0) { + /* _dos_findfirst and findfirst will set errno to ENOENT when no + * more entries could be retrieved. */ + return 0; + } +# endif + + /* initialize DIR and it's first entry */ + _setdirname(dirp); + dirp->dirent_filled = 1; + return 1; +} + + +/* + * Return implementation dependent name of the current directory entry. + */ +static const char * +_getdirname(const struct dirent *dp) +{ +#if defined(DIRENT_WIN32_INTERFACE) + return dp->data.cFileName; + +#elif defined(DIRENT_USE_FFBLK) + return dp->data.ff_name; + +#else + return dp->data.name; +#endif +} + + +/* + * Copy name of implementation dependent directory entry to the d_name field. + */ +static void +_setdirname(struct DIR *dirp) +{ + /* make sure that d_name is long enough */ + assert(strlen(_getdirname(&dirp->current)) <= NAME_MAX); + + strncpy(dirp->current.d_name, + _getdirname(&dirp->current), + NAME_MAX); + dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/ +} + +# ifdef __cplusplus +} +# endif +# define NAMLEN(dp) ((int)(strlen((dp)->d_name))) + +#else +# error "missing dirent interface" +#endif + + +#endif /*DIRENT_H*/ diff --git a/src/bin/jpip/CMakeLists.txt b/src/bin/jpip/CMakeLists.txt new file mode 100644 index 0000000..301d885 --- /dev/null +++ b/src/bin/jpip/CMakeLists.txt @@ -0,0 +1,161 @@ +# Headers file are located here: +include_directories( + ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h + ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2 + ${OPENJPEG_SOURCE_DIR}/src/bin/common # opj_getopt.h + ${OPENJPEG_SOURCE_DIR}/src/bin/jp2 # convert.h + ${OPENJPEG_SOURCE_DIR}/src/lib/openjpip + ${FCGI_INCLUDE_DIRS} +) + +# Tool to embed metadata into JP2 file +add_executable(opj_jpip_addxml opj_jpip_addxml.c) +# Install exe +install(TARGETS opj_jpip_addxml + EXPORT OpenJPEGTargets + DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications + ) + +if(BUILD_JPIP_SERVER) + set(OPJ_SERVER_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/opj_server.c + ) + + # Build executable + add_executable(opj_server ${OPJ_SERVER_SRCS}) + target_link_libraries(opj_server ${FCGI_LIBRARIES} openjpip_server) + set_property( + TARGET opj_server + APPEND PROPERTY + COMPILE_DEFINITIONS SERVER QUIT_SIGNAL="quitJPIP" + ) + + # On unix you need to link to the math library: + if(UNIX) + target_link_libraries(opj_server m) + endif() + + # Install exe + install(TARGETS opj_server + EXPORT OpenJPEGTargets + DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications + ) +endif() + +set(EXES + opj_dec_server + opj_jpip_transcode + opj_jpip_test + ) +foreach(exe ${EXES}) +add_executable(${exe} ${exe}.c) + target_link_libraries(${exe} openjpip) + install(TARGETS ${exe} + EXPORT OpenJPEGTargets + DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications + ) +endforeach() + +# Build the two java clients: +find_package(Java 1.5 COMPONENTS Development) # javac, jar + +# User can override this: +if(NOT DEFINED JAVA_SOURCE_VERSION) + set(JAVA_SOURCE_VERSION 1.5) +endif() +if(NOT DEFINED JAVA_TARGET_VERSION) + set(JAVA_TARGET_VERSION 1.5) +endif() + +# Only build the java viewer if dev is found: +if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE) + set(jflags $ENV{JFLAGS}) + # search for package org.apache.xerces.parsers + find_file(APACHE_XERCES_JAR + NAMES xerces-j2.jar xercesImpl.jar + PATHS /usr/share/java/ + NO_DEFAULT_PATH + ) + mark_as_advanced(APACHE_XERCES_JAR) + + # Decide to build the simple viewer or the xerces one: + if(EXISTS ${APACHE_XERCES_JAR}) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer_xerces/dist/manifest.txt.in + ${CMAKE_CURRENT_BINARY_DIR}/opj_viewer_xerces/dist/manifest.txt + @ONLY + ) + # build dep list: + file(GLOB java2_srcs "opj_viewer_xerces/src/*.java") + + # Need some common files: + list(APPEND java2_srcs + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/src/ImageManager.java + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/src/ImgdecClient.java + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/src/JPIPHttpClient.java + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/src/MML.java + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/src/PnmImage.java + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/src/RegimViewer.java + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/src/ResizeListener.java + ) + + # make sure target javac dir exists: + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/classes2) + # Build java + add_custom_command( + OUTPUT ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar + COMMAND ${Java_JAVAC_EXECUTABLE} ${jflags} + -source ${JAVA_SOURCE_VERSION} -target ${JAVA_TARGET_VERSION} + -classpath ${APACHE_XERCES_JAR} + ${java2_srcs} -d ${CMAKE_CURRENT_BINARY_DIR}/classes2 + COMMAND ${Java_JAR_EXECUTABLE} cfm ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar + ${CMAKE_CURRENT_BINARY_DIR}/opj_viewer_xerces/dist/manifest.txt + -C ${CMAKE_CURRENT_BINARY_DIR}/classes2 . + DEPENDS ${java2_srcs} + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer_xerces/dist/manifest.txt.in + COMMENT "javac *.java; jar cvf -> opj_viewer_xerces.jar" + ) + + # name the target + add_custom_target(OPJViewerXercesJar ALL + DEPENDS ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar + COMMENT "building opj_jpip_viewer.jar (xerces)" + ) + + install(FILES ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar + DESTINATION ${OPENJPEG_INSTALL_SHARE_DIR} COMPONENT JavaModule + ) + else() + # opj_viewer (simple, no xerces) + # build dep list: + file(GLOB java1_srcs "opj_viewer/src/*.java") + + # make sure target javac dir exists: + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/classes1) + # Build java + add_custom_command( + OUTPUT ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar + COMMAND ${Java_JAVAC_EXECUTABLE} ${jflags} + -source ${JAVA_SOURCE_VERSION} -target ${JAVA_TARGET_VERSION} + ${java1_srcs} -d ${CMAKE_CURRENT_BINARY_DIR}/classes1 + COMMAND ${Java_JAR_EXECUTABLE} cfm ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/dist/manifest.txt -C + ${CMAKE_CURRENT_BINARY_DIR}/classes1 . + DEPENDS ${java1_srcs} + ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/dist/manifest.txt + COMMENT "javac *.java; jar cvf -> opj_jpip_viewer.jar" + ) + + # name the target + add_custom_target(OPJViewerJar ALL + DEPENDS ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar + COMMENT "building opj_jpip_viewer.jar (no xerces found)" + ) + + install(FILES ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar + DESTINATION ${OPENJPEG_INSTALL_SHARE_DIR} COMPONENT JavaModule + ) + endif() +else() + message(WARNING "No java compiler found. Wont be able to build java viewer") +endif() diff --git a/src/bin/jpip/README b/src/bin/jpip/README new file mode 100644 index 0000000..5bcb01f --- /dev/null +++ b/src/bin/jpip/README @@ -0,0 +1,149 @@ +======================================================================== + OpenJPIP software 2.1 ReadMe + +OpenJPEG: +http://www.openjpeg.org + +Written by: +Kaori Hagihara +UCL/SST/ICTM/ELEN +February 18 2011 +======================================================================== + +Contents: +1. Introduction +2. License +3. System requirements +4. Implementing instructions +5. JP2 encoding instructions + + +---------- +1. Introduction +---------- + +OpenJPIP software is an implementation of JPEG 2000 Part9: Interactivity tools, APIs and protocols (JPIP). +( For more info about JPIP, check the website: http://www.jpeg.org/jpeg2000/j2kpart9.html) +The current implementation uses some results from the 2KAN project (http://www.2kan.org). + +Version 2.1 covers: + - JPT-stream (Tile) and JPP-stream (Precinct) media types + - Session, channels, cache model managements + - JPIP over HTTP, HTTP requests and TCP return + - Indexing JPEG 2000 files + - Embedding XML formatted metadata + - Region Of Interest (ROI) requests + - Access to JP2 files with their URL + +---------- +2. License +---------- + +This software is released under the BSD license, anybody can use or modify the library, even for commercial applications. +The only restriction is to retain the copyright in the sources or the binaries documentation. +Neither the author, nor the university accept any responsibility for any kind of error or data loss which may occur during usage. + +---------- +3. System requirements +---------- + + - FastCGI development kit (C libraries) at server (http://www.fastcgi.com) + - libcURL library + - Java application launcher at client + + - Xerces2 java XML parser on the client for accessing embedded image metadata (http://xerces.apache.org/xerces2-j) + +We tested this software with a virtual server running on the same Linux machine as the clients. + +---------- +4. Building instructions +---------- + +A Makefile is available in the same directory as this README file. Simply type 'make' and it will build all the required C-executables. +Concerning the java-based opj_viewer, simply type 'ant' in the corresponding directory (requires 'ant' utility of course) + +The documentation can be build this way (requires doxygen utility): + cd doc + doxygen Doxyfile + +---------- +5. Usage +---------- + +Preliminary notes : + * HTML documentation is available at http://www.openjpeg.org/jpip/doc/html + * Example image is available at http://www.openjpeg.org/jpip/data/copenhague1.zip (20 Mb !) + +Webserver: + You need a webserver running with the fastcgi module enabled and correctly configured. + For Apache, add the following line to your /etc/apache2/mods-available/fastcgi.conf configuration file: + + FastCGIExternalServer /var/www/myFCGI -host localhost:3000 + + where /var/www is your DocumentRoot. + Please refer to 'http://www.openjpeg.org/jpip/doc/ApacheFastCGITutorial.pdf' for more details. + +Server: + 1. Store JP2 files in the same directory as opj_server + + 2. Launch opj_server from the server terminal: + % spawn-fcgi -f ./opj_server -p 3000 -n + + For shutting down JPIP server: + %GET http://hostname/myFCGI?quitJPIP + Notice, http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting) + Requst message "quitJPIP" can be changed in Makfile, modify -DQUIT_SIGNAL=\"quitJPIP\" + +Client: + 1. Launch image decoding server, and keep it alive as long as image viewers are open + % ./opj_dec_server [portnumber (50000 by default)] + + You might prefer to implement this program from another directory since cache files are saved in the working directory. + % mkdir cache + % cd cache + % ../opj_dec_server + + 2. Open image viewers (as many as needed) + % java -jar opj_viewer.jar http://hostname/myFCGI path/filename.jp2 [hostname] [portnumber] [stateless/session] [jptstream/jppstream] [tcp/udp] + ( The arguments + - http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting) + - path/filename.jp2 is the server local path or URL of a JP2 file + - host name of opj_dec_server, localhost by default + - portnumber of opj_dec_server, 50000 by default + - request type stateless for no caching, session (default) for caching + - return media type, JPT-stream tile based stream, or JPP-stream (default) precinct based stream + - auxiliary return protocol, tcp or udp (udp is not implemented yet), if not given, return data is filled in http chunk + Image viewer GUI instructions: + Scale up request: Enlarge the window + ROI request: Select a region by mouse click and drag, then click inside the red frame of the selected region + + % java -jar opj_viewer_xerces.jar http://hostname/myFCGI JP2_filename.jp2 + Annotate image with ROI information in XML metadata: Click button "Region Of Interest" + Open a new window presenting an aligned image with a locally stored image: Click button "Image Registration" (Under Construction) + + 3. Quit the image decoding server through the telnet, be sure all image viewers are closed + % telnet localhost 50000 + quit + +---------- +5. JP2 encoding instructions +---------- + +An example to encode a TIF image "copenhague1.tif" at resolution 4780x4050, 8bit/pixel, grayscale. + % ./image_to_j2k -i copenhague1.tif -o copenhague1.jp2 -p RPCL -c [64,64] -t 640,480 -jpip -TP R + + options + -jpip : embed index table 'cidx' box into the output JP2 file (obligation for JPIP) + -TP R : partition a tile into tile parts of different resolution levels (obligation for JPT-stream) + +