Skip to content

Commit

Permalink
Squashed 'externals/coda-oss/' changes from 43cd38f..026c665
Browse files Browse the repository at this point in the history
026c665 Merge pull request ngageoint#255 from mdaus/updateWscripts
b88a2ce Update wscripts to work properly
059e0fc Merge pull request ngageoint#254 from mdaus/ignoreJ2k
374e701 Add new driver to gitignore
bca6b3c Merge pull request ngageoint#253 from mdaus/addJ2k
7fb4541 Add J2K driver from NITRO
9063b5f Merge pull request ngageoint#252 from mdaus/ceilingDivide
29ebc51 Remove unneeded headers
928998b Remove commented code
629deda Move ceilingDivide to .cpp; apply elsewhere
4a953b8 Add ceilingDivide function; update Python

git-subtree-dir: externals/coda-oss
git-subtree-split: 026c6652d9866f5d29cae085df9f1f6864774ca3
  • Loading branch information
JonathanMeans committed May 4, 2018
1 parent 6e8ceb5 commit 0d512c1
Show file tree
Hide file tree
Showing 21 changed files with 627 additions and 165 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ target/

modules/drivers/fftw/fftw-2.1.5/
modules/drivers/jpeg/jpeg-9/
modules/drivers/j2k/openjpeg/openjpeg-2.3.0_mod/
modules/drivers/pcre/pcre2-10.22/
modules/drivers/uuid/e2fsprogs-1.40-uuid/
modules/drivers/xml/xerces/xerces-c-3.1.1/
Expand Down
15 changes: 15 additions & 0 deletions build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,21 @@ def writeConfig(conf, callback, guardTag, infile=None, outfile=None, path=None,

conf.setenv('')


def getDriverIncludes(bld, driver):
driverIncludeDirs = [x.split('=') for x in bld.env['header_builddir']
if x.startswith(driver)]
if not driverIncludeDirs:
bld.fatal('Could not find include dir for driver {}'.format(driver))
if len(driverIncludeDirs) != 1:
bld.fatal('Multiple options for include dir for driver {}'.format(
driver))

driverIncludeDir = driverIncludeDirs[0][1]
driverIncludePathname = os.path.join(bld.bldnode.abspath(),
driverIncludeDir)
return os.path.abspath(os.path.dirname(driverIncludePathname))

def configure(self):

if self.env['DETECTED_BUILD_PY']:
Expand Down
10 changes: 10 additions & 0 deletions modules/c++/math/include/math/Round.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ template<typename T> inline T round(T value, size_t fractionalDigits)
return (value > 0.0 ? std::floor(value * power10 + 0.5) / power10
: std::ceil(value * power10 - 0.5) / power10);
}

/*!
* Equivalent to ceil((float)numerator / denominator)
*
* \param numerator Number to divide
* \param denominator Non-zero number to divide by
* \return Result of division, rounded up
* \throw if denominator is 0
*/
size_t ceilingDivide(size_t numerator, size_t denominator);
}

#endif
37 changes: 37 additions & 0 deletions modules/c++/math/source/Round.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* =========================================================================
* This file is part of math-c++
* =========================================================================
*
* (C) Copyright 2004 - 2018, MDA Information Systems LLC
*
* math-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/

#include <except/Exception.h>
#include <math/Round.h>
#include <sys/Conf.h>

namespace math
{
size_t ceilingDivide(size_t numerator, size_t denominator)
{
if (denominator == 0)
{
throw except::Exception(Ctxt("Attempted division by 0"));
}
return (numerator / denominator) + (numerator % denominator != 0);
}
}
20 changes: 20 additions & 0 deletions modules/c++/math/unittests/test_round.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,32 @@ TEST_CASE(testRoundDigits)
double actual8 = math::round(v8, 2);
TEST_ASSERT_ALMOST_EQ(actual8, expected8);
}

TEST_CASE(testCeilingDivide)
{
size_t n0 = 0;
size_t d0 = 1;
TEST_ASSERT_EQ(math::ceilingDivide(n0, d0), 0);

size_t n1 = 4;
size_t d1 = 2;
TEST_ASSERT_EQ(math::ceilingDivide(n1, d1), 2);

size_t n2 = 5;
size_t d2 = 2;
TEST_ASSERT_EQ(math::ceilingDivide(n2, d2), 3);

size_t n3 = 1;
size_t d3 = 0;
TEST_THROWS(math::ceilingDivide(n3, d3));
}
}

int main()
{
TEST_CHECK(testFix);
TEST_CHECK(testRound);
TEST_CHECK(testRoundDigits);
TEST_CHECK(testCeilingDivide);
return 0;
}
7 changes: 3 additions & 4 deletions modules/c++/mt/source/ThreadPlanner.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <algorithm>

#include <math/Round.h>
#include <mt/ThreadPlanner.h>

namespace mt
Expand All @@ -13,8 +14,7 @@ ThreadPlanner::ThreadPlanner(size_t numElements, size_t numThreads) :
// If there are leftovers, add one more to the elements per thread value
// What this will amount to meaning is that early threads will end up with
// one more piece of work than later threads.
mNumElementsPerThread =
(mNumElements / mNumThreads) + (mNumElements % mNumThreads != 0);
mNumElementsPerThread = math::ceilingDivide(mNumElements, mNumThreads);
}

bool ThreadPlanner::getThreadInfo(size_t threadNum,
Expand Down Expand Up @@ -44,8 +44,7 @@ size_t ThreadPlanner::getNumThreadsThatWillBeUsed() const
else
{
const size_t numThreads =
(mNumElements / mNumElementsPerThread) +
(mNumElements % mNumElementsPerThread != 0);
math::ceilingDivide(mNumElements, mNumElementsPerThread);

return numThreads;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/mt/wscript
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NAME = 'mt'
MAINTAINER = 'jmrandol@users.sourceforge.net'
VERSION = '1.1'
MODULE_DEPS = 'sys except mem types'
MODULE_DEPS = 'sys except math mem types'

options = configure = distclean = lambda p: None

Expand Down
7 changes: 3 additions & 4 deletions modules/c++/serialize/wscript
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os.path import join, dirname, abspath
from build import getDriverIncludes

NAME = 'serialize'
MAINTAINER = 'micah.bojrab@mdaus.com'
Expand All @@ -8,14 +8,13 @@ USELIB = 'BOOST_SERIALIZATION'

options = configure = distclean = lambda p: None


def build(bld):

# there is no target associated with the boost_config (only its install).
# we add the target directory here manually.
globs = globals()
b = [x.split('=') for x in bld.env['header_builddir'] if x.startswith('boost')][0]
boostInclude = dirname(abspath(join(bld.bldnode.abspath(), b[1])))
boostInclude = bld.root.find_dir(boostInclude).path_from(bld.path)
boostInclude = getDriverIncludes(bld, 'boost')
globs['includes'] = ['include', boostInclude]
globs['export_includes'] = ['include', boostInclude]
bld.module(**globs)
16 changes: 7 additions & 9 deletions modules/drivers/boost/wscript
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os, sys
import sys
from os.path import join
from waflib import Options
from waflib.TaskGen import feature, before, task_gen
from build import writeConfig, getConfigFilename
from build import writeConfig, getConfigFilename, getDriverIncludes

build = distclean = lambda x: None

Expand Down Expand Up @@ -36,7 +35,7 @@ def configure(conf):
linkType = 's' if staticLink else ''
libType = 'gd' if debug else ''
boostVer = Options.options.boost_version
libName = ['libboost_serialization', msvcVer[1], 'mt',
libName = ['libboost_serialization', msvcVer[1], 'mt',
linkType + libType, boostVer]
libName = '-'.join(filter(lambda x: x is not '', libName))
incPath = boostHome
Expand All @@ -49,7 +48,7 @@ def configure(conf):

# link the serialization library
libSer = conf.check(lib=libName,
uselib_store='BOOST_SERIALIZATION',
uselib_store='BOOST_SERIALIZATION',
header_name='boost/archive/tmpdir.hpp',
function_name='boost::archive::tmpdir',
libpath=libPath, includes=incPath,
Expand All @@ -66,11 +65,10 @@ def configure(conf):
conf.define('HAVE_BOOST', 1 if conf.env['HAVE_BOOST'] else 0)
writeConfig(conf, boost_callback, boost_guard)

def build (bld) :

def build(bld):
# install the boost_config.h file
b = [x.split('=') for x in bld.env['header_builddir'] if x.startswith(boost_guard)][0]
targetPath = bld.root.find_dir(join(bld.bldnode.abspath(), b[1])).path_from(bld.path)
bld(name='boost_config', features='install_tgt',
files=[getConfigFilename(boost_guard)],
dir=bld.path.make_node(targetPath),
dir=bld.path.make_node(getDriverIncludes(bld, boost_guard)),
install_path=join(bld.env['install_includedir'], boost_guard))
Binary file added modules/drivers/j2k/jasper/jasper-1.900.1-mod.tar
Binary file not shown.
138 changes: 138 additions & 0 deletions modules/drivers/j2k/jasper/wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import os, sys
from os.path import join, exists
from waflib import Options
from waflib.TaskGen import feature, before, task_gen
from build import untarFile

SOURCE = 'jasper-1.900.1-mod'

options = lambda x : None

def configure(conf):

j2kLayer = Options.options.j2k_layer

if j2kLayer == 'jasper' :
# NOTE: JasPer will compile in 64-bit mode, but it internally uses
# 32-bit integers for some offsets. To prevent confusion/badness,
# just don't allow it for a 64-bit build.
if conf.env['IS64BIT'] :
conf.msg('JPEG2000 library', 'jasper not available on 64-bit architectures', color='YELLOW')
return

# callback function to check for all #defines used by the jasper module
def jas_callback(conf):
# check functionality
conf.check_cc(header_name="sys/types.h", define_name='HAVE_SYS_TYPES_H')
conf.check_cc(type_name='uchar', header_name='sys/types.h', mandatory=False)
conf.check_cc(type_name='ushort', header_name='sys/types.h', mandatory=False)
conf.check_cc(type_name='longlong', header_name='sys/types.h', mandatory=False)
conf.check_cc(type_name='ulonglong', header_name='sys/types.h', mandatory=False)

conf.define('PACKAGE', 'jasper')
conf.define('PACKAGE_NAME', 'jasper')
conf.define('JAS_VERSION', '1.900.1')
conf.define('PACKAGE_STRING', 'jasper 1.900.1')
conf.define('PACKAGE_VERSION', '1.900.1')
conf.define('PACKAGE_TARNAME', 'jasper')
conf.define('VERSION', '1.900.1')

# check for the source tarball
# TODO: I believe this file has some local mods and is not exactly
# the vanilla tarball - need to confirm
if not exists(join(conf.path.abspath(), SOURCE + '.tar')):
conf.fatal('Missing JasPer tarfile')

# setup env
conf.env['MAKE_JASPER'] = True
conf.env['MAKE_J2K'] = True
conf.env['HAVE_J2K'] = True
conf.msg('Building local lib', j2kLayer)
untarFile(path=conf.path, fname=SOURCE + '.tar')

jasperNode = bld.path.make_node(join(SOURCE, 'include', 'jasper'))
writeConfig(conf, jas_callback, 'jas', infile=None, outfile='jas_config.h',
path=jasperNode, feature='makeHeader')

def build(bld):
env = bld.get_env()

# check it again just in case
if 'MAKE_JASPER' in env :
jasperDefs = []
if Options.platform.startswith('win'):
jasperDefs.append('JAS_WIN_MSVC_BUILD')

includes = 'bmp include jp2 jpc jpg mif pgx pnm ras'.split()
sources = (
'bmp/bmp_cod.c',
'bmp/bmp_dec.c',
'bmp/bmp_enc.c',
'base/jas_cm.c',
'base/jas_debug.c',
'base/jas_getopt.c',
'base/jas_icc.c',
'base/jas_iccdata.c',
'base/jas_image.c',
'base/jas_init.c',
'base/jas_malloc.c',
'base/jas_seq.c',
'base/jas_stream.c',
'base/jas_string.c',
'base/jas_tmr.c',
'base/jas_tvp.c',
'base/jas_version.c',
'jp2/jp2_cod.c',
'jp2/jp2_dec.c',
'jp2/jp2_enc.c',
'jpc/jpc_bs.c',
'jpc/jpc_cs.c',
'jpc/jpc_dec.c',
'jpc/jpc_enc.c',
'jpc/jpc_math.c',
'jpc/jpc_mct.c',
'jpc/jpc_mqcod.c',
'jpc/jpc_mqdec.c',
'jpc/jpc_mqenc.c',
'jpc/jpc_qmfb.c',
'jpc/jpc_t1cod.c',
'jpc/jpc_t1dec.c',
'jpc/jpc_t1enc.c',
'jpc/jpc_t2cod.c',
'jpc/jpc_t2dec.c',
'jpc/jpc_t2enc.c',
'jpc/jpc_tagtree.c',
'jpc/jpc_tsfb.c',
'jpc/jpc_util.c',
'jpg/jpg_dummy.c',
'jpg/jpg_val.c',
'mif/mif_cod.c',
'pgx/pgx_cod.c',
'pgx/pgx_dec.c',
'pgx/pgx_enc.c',
'pnm/pnm_cod.c',
'pnm/pnm_dec.c',
'pnm/pnm_enc.c',
'ras/ras_cod.c',
'ras/ras_dec.c',
'ras/ras_enc.c',
)

jasper = bld(features='c cstlib add_targets', includes=includes,
source=sources,
target='jasper',
name='J2K',
export_includes='include',
defines=env['DEFINES'] + jasperDefs,
targets_to_add='config_h',
env=env.derive(),
path=bld.path.make_node(SOURCE))

# install lib
if env['install_libs']:
jasper.install_path = env['install_libdir']

# TODO: install headers

def distclean(context):
pass
31 changes: 31 additions & 0 deletions modules/drivers/j2k/openjpeg/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
The openjpeg-2.3.0_mod.tar file is a slight modification of a release of
OpenJPEG 2.3.0. These changes allow for compressing a single tile within an
image, in order to use multiple threads for compression.

diff -wr openjpeg-2.3.0_mod openjpeg-2.3.0
diff -wr openjpeg-2.3.0_mod/src/lib/openjp2/j2k.c openjpeg-2.3.0/src/lib/openjp2/j2k.c
11352c11352,11353
< p_j2k->m_current_tile_number = p_tile_index;
---
> opj_event_msg(p_manager, EVT_ERROR, "The given tile index does not
> match.");
> return OPJ_FALSE;
11534a11536,11537
> ++p_j2k->m_current_tile_number;
>
diff -wr openjpeg-2.3.0_mod/src/lib/openjp2/openjpeg.c openjpeg-2.3.0/src/lib/openjp2/openjpeg.c
791,798d790
< OPJ_BOOL OPJ_CALLCONV opj_flush(opj_codec_t *p_codec, opj_stream_t *p_stream)
< {
< opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec;
< opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream;
<
< return opj_stream_flush(l_stream, &l_codec->m_event_mgr);
< }
<
diff -wr openjpeg-2.3.0_mod/src/lib/openjp2/openjpeg.h openjpeg-2.3.0/src/lib/openjp2/openjpeg.h
1121,1122d1120
< OPJ_API OPJ_BOOL OPJ_CALLCONV opj_flush(opj_codec_t *p_codec, opj_stream_t
*p_stream);
<

Binary file not shown.
Loading

0 comments on commit 0d512c1

Please sign in to comment.