@needs_make('make')
@is_slow_test
def test_openjpeg(self):
    if ('-fsanitize=address' in self.emcc_args):
        self.set_setting('INITIAL_MEMORY', ((128 * 1024) * 1024))

    def line_splitter(data):
        out = ''
        counter = 0
        for ch in data:
            out += ch
            if ((ch == ' ') and (counter > 60)):
                out += '\n'
                counter = 0
            else:
                counter += 1
        return out
    self.emcc_args = [x for x in self.emcc_args if (x != '-g')]
    original_j2k = path_from_root('tests', 'openjpeg', 'syntensity_lobby_s.j2k')
    image_bytes = list(bytearray(open(original_j2k, 'rb').read()))
    create_test_file('pre.js', ("\n      Module.preRun = function() { FS.createDataFile('/', 'image.j2k', %s, true, false, false); };\n      Module.postRun = function() {\n        out('Data: ' + JSON.stringify(MEMFS.getFileDataAsRegularArray(FS.analyzePath('image.raw').object)));\n      };\n      " % line_splitter(str(image_bytes))))
    shutil.copy(path_from_root('tests', 'third_party', 'openjpeg', 'opj_config.h'), self.get_dir())
    lib = self.get_library(os.path.join('third_party', 'openjpeg'), [os.path.sep.join('codec/CMakeFiles/j2k_to_image.dir/index.c.o'.split('/')), os.path.sep.join('codec/CMakeFiles/j2k_to_image.dir/convert.c.o'.split('/')), os.path.sep.join('codec/CMakeFiles/j2k_to_image.dir/__/common/color.c.o'.split('/')), os.path.join('bin', 'libopenjpeg.a')], configure=['cmake', '.'], make_args=[])

    def image_compare(output, err):
        m = re.search('\\[[\\d, -]*\\]', output)
        self.assertIsNotNone(m, ('Failed to find proper image output in: ' + output))
        js_data = eval(m.group(0))
        js_data = [(x if (x >= 0) else (256 + x)) for x in js_data]
        true_data = bytearray(open(path_from_root('tests', 'openjpeg', 'syntensity_lobby_s.raw'), 'rb').read())
        assert (len(js_data) == len(true_data))
        num = len(js_data)
        diff_total = js_total = true_total = 0
        for i in range(num):
            js_total += js_data[i]
            true_total += true_data[i]
            diff_total += abs((js_data[i] - true_data[i]))
        js_mean = (js_total / float(num))
        true_mean = (true_total / float(num))
        diff_mean = (diff_total / float(num))
        image_mean = 83.265
        assert (abs((js_mean - image_mean)) < 0.01), [js_mean, image_mean]
        assert (abs((true_mean - image_mean)) < 0.01), [true_mean, image_mean]
        assert (diff_mean < 0.01), diff_mean
        return output
    self.emcc_args += ['--minify', '0']
    self.emcc_args += ['--pre-js', 'pre.js']

    def do_test():
        self.do_run(open(path_from_root('tests', 'third_party', 'openjpeg', 'codec', 'j2k_to_image.c')).read(), 'Successfully generated', '-i image.j2k -o image.raw'.split(' '), libraries=lib, includes=[path_from_root('tests', 'third_party', 'openjpeg', 'libopenjpeg'), path_from_root('tests', 'third_party', 'openjpeg', 'codec'), path_from_root('tests', 'third_party', 'openjpeg', 'common'), os.path.join(self.get_build_dir(), 'openjpeg')], force_c=True, assert_returncode=0, output_nicerizer=image_compare)
    do_test()
    if (self.get_setting('ALLOW_MEMORY_GROWTH') == 1):
        print('no memory growth', file=sys.stderr)
        self.set_setting('ALLOW_MEMORY_GROWTH', 0)
        do_test()
@needs_make('make')
@is_slow_test
def test_openjpeg(self):
    if ('-fsanitize=address' in self.emcc_args):
        self.set_setting('INITIAL_MEMORY', ((128 * 1024) * 1024))

    def line_splitter(data):
        out = 
        counter = 0
        for ch in data:
            out += ch
            if ((ch == ' ') and (counter > 60)):
                out += '\n'
                counter = 0
            else:
                counter += 1
        return out
    self.emcc_args = [x for x in self.emcc_args if (x != '-g')]
    original_j2k = path_from_root('tests', 'openjpeg', 'syntensity_lobby_s.j2k')
    image_bytes = list(bytearray(open(original_j2k, 'rb').read()))
    create_test_file('pre.js', ("\n      Module.preRun = function() { FS.createDataFile('/', 'image.j2k', %s, true, false, false); };\n      Module.postRun = function() {\n        out('Data: ' + JSON.stringify(MEMFS.getFileDataAsRegularArray(FS.analyzePath('image.raw').object)));\n      };\n      " % line_splitter(str(image_bytes))))
    shutil.copy(path_from_root('tests', 'third_party', 'openjpeg', 'opj_config.h'), self.get_dir())
    lib = self.get_library(os.path.join('third_party', 'openjpeg'), [os.path.sep.join('codec/CMakeFiles/j2k_to_image.dir/index.c.o'.split('/')), os.path.sep.join('codec/CMakeFiles/j2k_to_image.dir/convert.c.o'.split('/')), os.path.sep.join('codec/CMakeFiles/j2k_to_image.dir/__/common/color.c.o'.split('/')), os.path.join('bin', 'libopenjpeg.a')], configure=['cmake', '.'], make_args=[])

    def image_compare(output, err):
        m = re.search('\\[[\\d, -]*\\]', output)
        self.assertIsNotNone(m, ('Failed to find proper image output in: ' + output))
        js_data = eval(m.group(0))
        js_data = [(x if (x >= 0) else (256 + x)) for x in js_data]
        true_data = bytearray(open(path_from_root('tests', 'openjpeg', 'syntensity_lobby_s.raw'), 'rb').read())
        assert (len(js_data) == len(true_data))
        num = len(js_data)
        diff_total = js_total = true_total = 0
        for i in range(num):
            js_total += js_data[i]
            true_total += true_data[i]
            diff_total += abs((js_data[i] - true_data[i]))
        js_mean = (js_total / float(num))
        true_mean = (true_total / float(num))
        diff_mean = (diff_total / float(num))
        image_mean = 83.265
        assert (abs((js_mean - image_mean)) < 0.01), [js_mean, image_mean]
        assert (abs((true_mean - image_mean)) < 0.01), [true_mean, image_mean]
        assert (diff_mean < 0.01), diff_mean
        return output
    self.emcc_args += ['--minify', '0']
    self.emcc_args += ['--pre-js', 'pre.js']

    def do_test():
        self.do_run(open(path_from_root('tests', 'third_party', 'openjpeg', 'codec', 'j2k_to_image.c')).read(), 'Successfully generated', '-i image.j2k -o image.raw'.split(' '), libraries=lib, includes=[path_from_root('tests', 'third_party', 'openjpeg', 'libopenjpeg'), path_from_root('tests', 'third_party', 'openjpeg', 'codec'), path_from_root('tests', 'third_party', 'openjpeg', 'common'), os.path.join(self.get_build_dir(), 'openjpeg')], force_c=True, assert_returncode=0, output_nicerizer=image_compare)
    do_test()
    if (self.get_setting('ALLOW_MEMORY_GROWTH') == 1):
        print('no memory growth', file=sys.stderr)
        self.set_setting('ALLOW_MEMORY_GROWTH', 0)
        do_test()