(self)
| 6931 | @needs_make('make') |
| 6932 | @is_slow_test |
| 6933 | def test_openjpeg(self): |
| 6934 | if self.get_setting('WASMFS'): |
| 6935 | self.set_setting('FORCE_FILESYSTEM') |
| 6936 | |
| 6937 | def line_splitter(data): |
| 6938 | out = '' |
| 6939 | counter = 0 |
| 6940 | |
| 6941 | for ch in data: |
| 6942 | out += ch |
| 6943 | if ch == ' ' and counter > 60: |
| 6944 | out += '\n' |
| 6945 | counter = 0 |
| 6946 | else: |
| 6947 | counter += 1 |
| 6948 | |
| 6949 | return out |
| 6950 | |
| 6951 | original_j2k = test_file('openjpeg/syntensity_lobby_s.j2k') |
| 6952 | image_bytes = list(bytearray(read_binary(original_j2k))) |
| 6953 | create_file('pre.js', """ |
| 6954 | Module.preRun = () => FS.createDataFile('/', 'image.j2k', %s, true, false, false); |
| 6955 | Module.postRun = () => { |
| 6956 | out('Data: ' + JSON.stringify(Array.from(FS.readFile('image.raw')))); |
| 6957 | }; |
| 6958 | """ % line_splitter(str(image_bytes))) |
| 6959 | |
| 6960 | # ensure libpng is built so that openjpeg's configure step can detect it. |
| 6961 | # If we don't do this then we don't know what the state of the cache will be |
| 6962 | # and this test would different non-deterministic results based on, for example, |
| 6963 | # what other tests had previously run. |
| 6964 | builder_cmd = [EMBUILDER, 'build', 'libpng'] |
| 6965 | if self.is_wasm64(): |
| 6966 | builder_cmd.append('--wasm64') |
| 6967 | self.cflags.append('-Wno-pointer-to-int-cast') |
| 6968 | self.run_process(builder_cmd) |
| 6969 | lib = self.get_library('third_party/openjpeg', |
| 6970 | ['codec/CMakeFiles/j2k_to_image.dir/index.c.o', |
| 6971 | 'codec/CMakeFiles/j2k_to_image.dir/convert.c.o', |
| 6972 | 'codec/CMakeFiles/j2k_to_image.dir/__/common/color.c.o', |
| 6973 | 'codec/CMakeFiles/j2k_to_image.dir/__/common/getopt.c.o', |
| 6974 | 'bin/libopenjpeg.a'], |
| 6975 | configure=['cmake', '.', '-DBUILD_SHARED_LIBS=OFF'], |
| 6976 | # configure_args=['--enable-tiff=no', '--enable-jp3d=no', '--enable-png=no'], |
| 6977 | make_args=[]) # no -j 2, since parallel builds can fail |
| 6978 | |
| 6979 | # We use doubles in JS, so we get slightly different values than native code. So we |
| 6980 | # check our output by comparing the average pixel difference |
| 6981 | def image_compare(output): |
| 6982 | # Get the image generated by JS, from the JSON.stringify'd array |
| 6983 | m = re.search(r'\[[\d, -]*\]', output) |
| 6984 | |
| 6985 | self.assertIsNotNone(m, 'Failed to find proper image output in: ' + output) |
| 6986 | # Evaluate the output as a python array |
| 6987 | js_data = eval(m.group(0)) |
| 6988 | |
| 6989 | js_data = [x if x >= 0 else 256 + x for x in js_data] # Our output may be signed, so unsign it |
| 6990 | # Get the correct output |
nothing calls this directly
no test coverage detected