From 490bc569ed0fb0a27dfd726150b5220bc7125800 Mon Sep 17 00:00:00 2001 From: Katarzyna Miernikiewicz Date: Tue, 1 Sep 2020 11:06:12 +0000 Subject: [PATCH] changed copying files to patching --- oss-internship-2020/openjpeg/.gitignore | 2 - .../openjpeg/examples/CMakeLists.txt | 38 ++++++++----------- .../openjpeg/examples/convert.patch | 6 +-- .../openjpeg/examples/convert_h.patch | 6 +-- .../openjpeg/examples/decompress_example.cc | 2 +- 5 files changed, 22 insertions(+), 32 deletions(-) diff --git a/oss-internship-2020/openjpeg/.gitignore b/oss-internship-2020/openjpeg/.gitignore index cccbfce..567609b 100644 --- a/oss-internship-2020/openjpeg/.gitignore +++ b/oss-internship-2020/openjpeg/.gitignore @@ -1,3 +1 @@ build/ -examples/convert_lib.cc -examples/convert_lib.h diff --git a/oss-internship-2020/openjpeg/examples/CMakeLists.txt b/oss-internship-2020/openjpeg/examples/CMakeLists.txt index 77b4290..ca11b74 100644 --- a/oss-internship-2020/openjpeg/examples/CMakeLists.txt +++ b/oss-internship-2020/openjpeg/examples/CMakeLists.txt @@ -12,26 +12,25 @@ # See the License for the specific language governing permissions and # limitations under the License. -add_custom_target(patching_reverse_before - COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch -R --no-backup-if-mismatch -r /dev/null convert.c < ${PROJECT_SOURCE_DIR}/examples/convert.patch > /dev/null || (exit 0) - COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch -R --no-backup-if-mismatch -r /dev/null convert.h < ${PROJECT_SOURCE_DIR}/examples/convert_h.patch > /dev/null || (exit 0) - ) +# we need to use modified versions of some of the library tools + +file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/gen_files") +file(COPY "${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/convert.c" DESTINATION "${PROJECT_BINARY_DIR}/gen_files/") +file(COPY "${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/convert.h" DESTINATION "${PROJECT_BINARY_DIR}/gen_files/") +file(COPY "${PROJECT_SOURCE_DIR}/examples/convert.patch" DESTINATION "${PROJECT_BINARY_DIR}/gen_files/") +file(COPY "${PROJECT_SOURCE_DIR}/examples/convert_h.patch" DESTINATION "${PROJECT_BINARY_DIR}/gen_files/") add_custom_command( - DEPENDS opj_decompress opj_compress opj_dump - OUTPUT ${PROJECT_SOURCE_DIR}/examples/convert_lib.cc ${PROJECT_SOURCE_DIR}/examples/convert_lib.h - COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch convert.c < ${PROJECT_SOURCE_DIR}/examples/convert.patch > /dev/null && cp convert.c ${PROJECT_SOURCE_DIR}/examples/convert_lib.cc - COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch convert.h < ${PROJECT_SOURCE_DIR}/examples/convert_h.patch > /dev/null && cp convert.h ${PROJECT_SOURCE_DIR}/examples/convert_lib.h - ) - -add_library(convert_helper STATIC - ${PROJECT_SOURCE_DIR}/examples/convert_lib.cc - ${PROJECT_SOURCE_DIR}/examples/convert_lib.h + OUTPUT ${PROJECT_BINARY_DIR}/gen_files/convert.cc ${PROJECT_BINARY_DIR}/gen_files/convert.h + COMMAND cd ${PROJECT_BINARY_DIR}/gen_files && patch < ${PROJECT_SOURCE_DIR}/examples/convert.patch > /dev/null + COMMAND cd ${PROJECT_BINARY_DIR}/gen_files && patch < ${PROJECT_SOURCE_DIR}/examples/convert_h.patch > /dev/null + COMMAND mv ${PROJECT_BINARY_DIR}/gen_files/convert.c ${PROJECT_BINARY_DIR}/gen_files/convert.cc ) -add_dependencies(opj_decompress patching_reverse_before) -add_dependencies(opj_compress patching_reverse_before) -add_dependencies(opj_dump patching_reverse_before) +add_library(convert_helper STATIC + ${PROJECT_BINARY_DIR}/gen_files/convert.cc + ${PROJECT_BINARY_DIR}/gen_files/convert.h +) add_executable(decompress_sandboxed decompress_example.cc @@ -47,10 +46,3 @@ target_link_libraries(convert_helper PRIVATE openjp2_sapi sapi::sapi ) - -add_custom_target(patching_reverse ALL - COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch -R convert.c < ${PROJECT_SOURCE_DIR}/examples/convert.patch > /dev/null - COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch -R convert.h < ${PROJECT_SOURCE_DIR}/examples/convert_h.patch > /dev/null - ) - -add_dependencies(patching_reverse decompress_sandboxed) diff --git a/oss-internship-2020/openjpeg/examples/convert.patch b/oss-internship-2020/openjpeg/examples/convert.patch index 416c6b7..15bc1a3 100644 --- a/oss-internship-2020/openjpeg/examples/convert.patch +++ b/oss-internship-2020/openjpeg/examples/convert.patch @@ -1,5 +1,5 @@ --- convert.c 2020-08-27 15:46:32.911584344 +0000 -+++ ../../../../examples/convert_helper.cc 2020-08-27 15:10:52.695231032 +0000 ++++ convert_helper.cc 2020-08-27 15:10:52.695231032 +0000 @@ -35,2605 +35,311 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. @@ -62,7 +62,7 @@ - } - component->prec = precision; -} -+// copies of a few library tools ++// patched versions of a few library tools -/* Component precision scaling */ -static void scale_component_up(opj_image_comp_t* component, @@ -181,7 +181,7 @@ -{ - OPJ_SIZE_T i; - const OPJ_INT32* pSrc0 = pSrc[0]; -+#include "convert_lib.h" ++#include "convert.h" - for (i = 0; i < length; i++) { - pDst[i] = pSrc0[i] + adjust; diff --git a/oss-internship-2020/openjpeg/examples/convert_h.patch b/oss-internship-2020/openjpeg/examples/convert_h.patch index efeafc6..53f729c 100644 --- a/oss-internship-2020/openjpeg/examples/convert_h.patch +++ b/oss-internship-2020/openjpeg/examples/convert_h.patch @@ -1,5 +1,5 @@ --- convert.h 2020-08-27 15:46:45.028628305 +0000 -+++ ../../../../examples/convert_helper.h 2020-08-27 14:26:02.155455250 +0000 ++++ convert_helper.h 2020-08-27 14:26:02.155455250 +0000 @@ -1,126 +1,8 @@ -/* - * The copyright in this software is being made available under the 2-clauses @@ -39,8 +39,8 @@ - */ -#ifndef __J2K_CONVERT_H -#define __J2K_CONVERT_H -+// imagetopnm and the two functions it calls internaly are copied from the -+// library's tools; from openjpeg/src/bin/jp2/convert.c ++// imagetopnm and the two functions it calls internaly are patched ++// versions of the library's tools; from openjpeg/src/bin/jp2/convert.c -/**@name RAW component encoding parameters */ -/*@{*/ diff --git a/oss-internship-2020/openjpeg/examples/decompress_example.cc b/oss-internship-2020/openjpeg/examples/decompress_example.cc index 9b3db0e..68bddf8 100644 --- a/oss-internship-2020/openjpeg/examples/decompress_example.cc +++ b/oss-internship-2020/openjpeg/examples/decompress_example.cc @@ -21,7 +21,7 @@ #include #include -#include "convert_lib.h" +#include "gen_files/convert.h" #include "openjp2_sapi.sapi.h" class Openjp2SapiSandbox : public Openjp2Sandbox {