diff options
author | Picca Frédéric-Emmanuel <picca@debian.org> | 2018-03-04 10:20:27 +0100 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@debian.org> | 2018-03-04 10:20:27 +0100 |
commit | 270d5ddc31c26b62379e3caa9044dd75ccc71847 (patch) | |
tree | 55c5bfc851dfce7172d335cd2405b214323e3caf /silx/resources | |
parent | e19c96eff0c310c06c4f268c8b80cb33bd08996f (diff) |
New upstream version 0.7.0+dfsg
Diffstat (limited to 'silx/resources')
-rw-r--r-- | silx/resources/__init__.py | 45 | ||||
-rw-r--r-- | silx/resources/gui/icons/colormap-histogram.png | bin | 0 -> 641 bytes | |||
-rw-r--r-- | silx/resources/gui/icons/colormap-histogram.svg | 37 | ||||
-rw-r--r-- | silx/resources/gui/icons/colormap-none.png | bin | 0 -> 232 bytes | |||
-rw-r--r-- | silx/resources/gui/icons/colormap-none.svg | 33 | ||||
-rw-r--r-- | silx/resources/gui/icons/colormap-range.png | bin | 0 -> 284 bytes | |||
-rw-r--r-- | silx/resources/gui/icons/colormap-range.svg | 37 | ||||
-rw-r--r-- | silx/resources/gui/icons/math-phase.png | bin | 515 -> 1868 bytes | |||
-rw-r--r-- | silx/resources/gui/icons/math-phase.svg | 4 | ||||
-rw-r--r-- | silx/resources/gui/icons/math-square-amplitude.png | bin | 0 -> 592 bytes | |||
-rw-r--r-- | silx/resources/gui/icons/math-square-amplitude.svg | 3 | ||||
-rw-r--r-- | silx/resources/opencl/codec/byte_offset.cl | 235 | ||||
-rw-r--r-- | silx/resources/opencl/image/cast.cl | 181 | ||||
-rw-r--r-- | silx/resources/opencl/image/histogram.cl | 178 | ||||
-rw-r--r-- | silx/resources/opencl/image/map.cl | 85 | ||||
-rw-r--r-- | silx/resources/opencl/image/max_min.cl | 207 |
16 files changed, 1012 insertions, 33 deletions
diff --git a/silx/resources/__init__.py b/silx/resources/__init__.py index 250aed1..a45457a 100644 --- a/silx/resources/__init__.py +++ b/silx/resources/__init__.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2016-2017 European Synchrotron Radiation Facility +# Copyright (c) 2016-2018 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -56,7 +56,7 @@ of this modules to ensure access across different distribution schemes: __authors__ = ["V.A. Sole", "Thomas Vincent", "J. Kieffer"] __license__ = "MIT" -__date__ = "06/09/2017" +__date__ = "15/02/2018" import os @@ -162,7 +162,7 @@ def list_dir(resource): :param str resource: Name of the resource directory to list :return: list of name contained in the directory - :rtype: list + :rtype: List """ resource_directory, resource_name = _get_package_and_resource(resource) @@ -194,6 +194,16 @@ def is_dir(resource): return os.path.isdir(path) +def exists(resource): + """True is the resource exists. + + :param str resource: Name of the resource + :rtype: bool + """ + path = resource_filename(resource) + return os.path.exists(path) + + def _get_package_and_resource(resource, default_directory=None): """ Return the resource directory class and a cleaned resource name without @@ -301,7 +311,6 @@ class ExternalResources(object): """ self.project = project self._initialized = False - self._tempdir = None self.sem = threading.Semaphore() self.env_key = env_key or (self.project.upper() + "_DATA") self.url_base = url_base @@ -309,14 +318,6 @@ class ExternalResources(object): self.timeout = timeout self.data_home = None - def _initialize_tmpdir(self): - """Initialize the temporary directory""" - if not self._tempdir: - with self.sem: - if not self._tempdir: - self._tempdir = tempfile.mkdtemp("_" + getpass.getuser(), - self.project + "_") - def _initialize_data(self): """Initialize for downloading test data""" if not self._initialized: @@ -335,26 +336,8 @@ class ExternalResources(object): self.all_data = set(json.load(f)) self._initialized = True - @property - def tempdir(self): - if not self._tempdir: - self._initialize_tmpdir() - return self._tempdir - def clean_up(self): - """Removes the temporary directory (and all its content !)""" - with self.sem: - if not self._tempdir: - return - if not os.path.isdir(self._tempdir): - return - for root, dirs, files in os.walk(self._tempdir, topdown=False): - for name in files: - os.remove(os.path.join(root, name)) - for name in dirs: - os.rmdir(os.path.join(root, name)) - os.rmdir(self._tempdir) - self._tempdir = None + pass def getfile(self, filename): """Downloads the requested file from web-server available diff --git a/silx/resources/gui/icons/colormap-histogram.png b/silx/resources/gui/icons/colormap-histogram.png Binary files differnew file mode 100644 index 0000000..a199adb --- /dev/null +++ b/silx/resources/gui/icons/colormap-histogram.png diff --git a/silx/resources/gui/icons/colormap-histogram.svg b/silx/resources/gui/icons/colormap-histogram.svg new file mode 100644 index 0000000..951dee6 --- /dev/null +++ b/silx/resources/gui/icons/colormap-histogram.svg @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="100%" + height="100%" + viewBox="0 0 32 32" + id="svg2"> + <metadata + id="metadata10"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs8" /> + <path + d="m 28.857399,28.857399 -26.0259991,0 C 12.191411,28.847797 6.2161112,2.8599459 15.844399,2.8313999 c 9.628288,-0.028546 3.521475,26.0156951 13.013,26.0259991 z" + id="rect4" + style="fill:#f7941e;fill-opacity:0.81568998;stroke:none" /> + <path + d="m 28.857399,2.8314 0,26.025999 m -26.0259991,0 0,-26.025999" + id="rect4-3" + style="fill:none;stroke:#000000;stroke-width:1.39999998;stroke-miterlimit:2" /> +</svg> diff --git a/silx/resources/gui/icons/colormap-none.png b/silx/resources/gui/icons/colormap-none.png Binary files differnew file mode 100644 index 0000000..5441fa5 --- /dev/null +++ b/silx/resources/gui/icons/colormap-none.png diff --git a/silx/resources/gui/icons/colormap-none.svg b/silx/resources/gui/icons/colormap-none.svg new file mode 100644 index 0000000..127238a --- /dev/null +++ b/silx/resources/gui/icons/colormap-none.svg @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="100%" + height="100%" + viewBox="0 0 32 32" + id="svg2"> + <metadata + id="metadata10"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs8" /> + <path + d="m 28.857399,2.8314 0,26.025999 m -26.0259991,0 0,-26.025999" + id="rect4-3" + style="fill:none;stroke:#000000;stroke-width:1.39999998;stroke-miterlimit:2" /> +</svg> diff --git a/silx/resources/gui/icons/colormap-range.png b/silx/resources/gui/icons/colormap-range.png Binary files differnew file mode 100644 index 0000000..6225375 --- /dev/null +++ b/silx/resources/gui/icons/colormap-range.png diff --git a/silx/resources/gui/icons/colormap-range.svg b/silx/resources/gui/icons/colormap-range.svg new file mode 100644 index 0000000..087af92 --- /dev/null +++ b/silx/resources/gui/icons/colormap-range.svg @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="100%" + height="100%" + viewBox="0 0 32 32" + id="svg2"> + <metadata + id="metadata10"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs8" /> + <path + d="m 28.857399,2.8313999 0,26.0259991 -26.0259991,0 0,-26.0259991 z" + id="rect4" + style="fill:#f7941e;fill-opacity:0.81568998;stroke:none" /> + <path + d="m 28.857399,2.8314 0,26.025999 m -26.0259991,0 0,-26.025999" + id="rect4-3" + style="fill:none;stroke:#000000;stroke-width:1.39999998;stroke-miterlimit:2" /> +</svg> diff --git a/silx/resources/gui/icons/math-phase.png b/silx/resources/gui/icons/math-phase.png Binary files differindex ee5800f..da3867a 100644 --- a/silx/resources/gui/icons/math-phase.png +++ b/silx/resources/gui/icons/math-phase.png diff --git a/silx/resources/gui/icons/math-phase.svg b/silx/resources/gui/icons/math-phase.svg index 3bd1671..44a7160 100644 --- a/silx/resources/gui/icons/math-phase.svg +++ b/silx/resources/gui/icons/math-phase.svg @@ -1,3 +1,3 @@ <?xml version="1.0" encoding="UTF-8"?> -<svg version="1.1" viewBox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><metadata><rdf:RDF><cc:Work rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/><dc:title/></cc:Work></rdf:RDF></metadata><g><path d="m17.834 8.7344c-0.50782 1.14e-5 -0.76173 0.56642-0.76172 1.6992v8.0391c0.74218 2e-6 1.4844-0.40625 2.2266-1.2188 0.66405-0.72656 0.99608-1.9609 0.99609-3.7031-1.2e-5 -1.625-0.33595-2.875-1.0078-3.75-0.54688-0.71093-1.0313-1.0664-1.4531-1.0664m0-1.8398c1.0937 1.33e-5 2.1367 0.51564 3.1289 1.5469 1.0703 1.1016 1.6055 2.8047 1.6055 5.1094-1.4e-5 2.1172-0.53517 3.8047-1.6055 5.0625-1.0078 1.1875-2.3047 1.7812-3.8906 1.7812v4.7109h-2.1445v-4.6992c-1.5547 0-2.8555-0.59766-3.9023-1.793-1.0625-1.2187-1.5938-2.9023-1.5938-5.0508-1.3e-6 -2.2344 0.53125-3.9219 1.5938-5.0625 0.79687-0.85155 1.8437-1.3867 3.1406-1.6055v1.9102c-0.51563 0.1797-1 0.57423-1.4531 1.1836-0.67188 0.89845-1.0078 2.0899-1.0078 3.5742-3e-6 1.5781 0.33593 2.8164 1.0078 3.7148 0.60156 0.80469 1.3398 1.207 2.2148 1.207v-8.0508c-6e-6 -2.3594 0.96874-3.539 2.9062-3.5391"/></g><text x="0.49070829" y="48.29847" fill="#f7941e" font-family="Accanthis ADF Std" font-size="40px" letter-spacing="0px" word-spacing="0px" style="line-height:125%" xml:space="preserve"><tspan x="0.49070829" y="48.29847" fill="#f7941e" font-family="Sans" font-size="24px"/></text> -</svg> +<svg version="1.1" viewBox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><radialGradient id="d" cx="-16.701" cy="15.943" r="7.9219" gradientTransform="matrix(1,0,0,1.1509,0,-2.4056)" gradientUnits="userSpaceOnUse"><stop offset="0"/><stop stop-color="#c0c0c0" offset="1"/></radialGradient><radialGradient id="c" cx="-16.701" cy="15.943" r="7.9219" gradientTransform="matrix(1,0,0,1.1509,0,-2.4056)" gradientUnits="userSpaceOnUse" xlink:href="#d"/></defs><g transform="matrix(.062683 0 0 -.062683 15.338 21.436)"><path d="m17.834 8.7344c-0.50782 1.14e-5 -0.76173 0.56642-0.76172 1.6992v8.0391c0.74218 2e-6 1.4844-0.40625 2.2266-1.2188 0.66405-0.72656 0.99608-1.9609 0.99609-3.7031-1.2e-5 -1.625-0.33595-2.875-1.0078-3.75-0.54688-0.71093-1.0313-1.0664-1.4531-1.0664m0-1.8398c1.0937 1.33e-5 2.1367 0.51564 3.1289 1.5469 1.0703 1.1016 1.6055 2.8047 1.6055 5.1094-1.4e-5 2.1172-0.53517 3.8047-1.6055 5.0625-1.0078 1.1875-2.3047 1.7812-3.8906 1.7812v4.7109h-2.1445v-4.6992c-1.5547 0-2.8555-0.59766-3.9023-1.793-1.0625-1.2187-1.5938-2.9023-1.5938-5.0508-1.3e-6 -2.2344 0.53125-3.9219 1.5938-5.0625 0.79687-0.85155 1.8437-1.3867 3.1406-1.6055v1.9102c-0.51563 0.1797-1 0.57423-1.4531 1.1836-0.67188 0.89845-1.0078 2.0899-1.0078 3.5742-3e-6 1.5781 0.33593 2.8164 1.0078 3.7148 0.60156 0.80469 1.3398 1.207 2.2148 1.207v-8.0508c-6e-6 -2.3594 0.96874-3.539 2.9062-3.5391"/><g fill="url(#c)"><path d="m-14.111 6.8256c1.1797 1.32e-5 2.3164 0.50001 3.4102 1.5 1.2812 1.1641 1.9219 2.8945 1.9219 5.1914-1.74e-5 3.8672-1.9453 6.0508-5.8359 6.5508v4.9922h-4.1719v-4.9922c-3.8906-0.5-5.8359-2.6836-5.8359-6.5508-1e-6 -2.1562 0.64062-3.8437 1.9219-5.0625 1.0547-1.0078 2.2383-1.5117 3.5508-1.5117v2.6836c-0.17969 0.015635-0.43751 0.35548-0.77344 1.0195-0.32813 0.65626-0.49219 1.4727-0.49219 2.4492-5e-6 1.8672 0.54296 3.1914 1.6289 3.9727v-4.5938c-8e-6 -3.7656 1.5586-5.6484 4.6758-5.6484m0.12891 3.1172c-0.42189 0.046885-0.63282 0.89063-0.63281 2.5313v4.5938c1.0469-0.75781 1.5898-2.082 1.6289-3.9727 0.02342-1.0469-0.06251-1.8398-0.25781-2.3789-0.19532-0.54686-0.44142-0.80468-0.73828-0.77344" fill="url(#c)"/></g><path id="a" d="m210.56 70.719-200 16 200 16z" opacity=".99"/><use width="32" height="32" fill="#ff0000" stroke="#ff0000" xlink:href="#a"/><use transform="matrix(.98769 .15643 -.15643 .98769 13.696 -.58469)" width="32" height="32" fill="#ff2600" stroke="#ff2600" xlink:href="#a"/><use transform="matrix(.95106 .30902 -.30902 .95106 27.315 .98033)" width="32" height="32" fill="#ff4d00" stroke="#ff4d00" xlink:href="#a"/><use transform="matrix(.89101 .45399 -.45399 .89101 40.521 4.6565)" width="32" height="32" fill="#ff7300" stroke="#ff7300" xlink:href="#a"/><use transform="matrix(.80902 .58779 -.58779 .80902 52.989 10.353)" width="32" height="32" fill="#ff9900" stroke="#ff9900" xlink:href="#a"/><use transform="matrix(.70711 .70711 -.70711 .70711 64.413 17.931)" width="32" height="32" fill="#ffbf00" stroke="#ffbf00" xlink:href="#a"/><use transform="matrix(.58779 .80902 -.80902 .58779 74.511 27.202)" width="32" height="32" fill="#ffe600" stroke="#ffe600" xlink:href="#a"/><use transform="matrix(.45399 .89101 -.89101 .45399 83.034 37.938)" width="32" height="32" fill="#f2ff00" stroke="#f2ff00" xlink:href="#a"/><use transform="matrix(.30902 .95106 -.95106 .30902 89.773 49.876)" width="32" height="32" fill="#ccff00" stroke="#ccff00" xlink:href="#a"/><use transform="matrix(.15643 .98769 -.98769 .15643 94.561 62.72)" width="32" height="32" fill="#a6ff00" stroke="#a6ff00" xlink:href="#a"/><use transform="matrix(0,1,-1,0,97.281,76.156)" width="32" height="32" fill="#80ff00" stroke="#80ff00" xlink:href="#a"/><use transform="matrix(-.15643 .98769 -.98769 -.15643 97.866 89.852)" width="32" height="32" fill="#59ff00" stroke="#59ff00" xlink:href="#a"/><use transform="matrix(-.30902 .95106 -.95106 -.30902 96.301 103.47)" width="32" height="32" fill="#33ff00" stroke="#33ff00" xlink:href="#a"/><use transform="matrix(-.45399 .89101 -.89101 -.45399 92.625 116.68)" width="32" height="32" fill="#0dff00" stroke="#0dff00" xlink:href="#a"/><use transform="matrix(-.58779 .80902 -.80902 -.58779 86.928 129.15)" width="32" height="32" fill="#00ff19" stroke="#00ff19" xlink:href="#a"/><use transform="matrix(-.70711 .70711 -.70711 -.70711 79.351 140.57)" width="32" height="32" fill="#00ff40" stroke="#00ff40" xlink:href="#a"/><use transform="matrix(-.80902 .58779 -.58779 -.80902 70.08 150.67)" width="32" height="32" fill="#00ff66" stroke="#00ff66" xlink:href="#a"/><use transform="matrix(-.89101 .45399 -.45399 -.89101 59.343 159.19)" width="32" height="32" fill="#00ff8c" stroke="#00ff8c" xlink:href="#a"/><use transform="matrix(-.95106 .30902 -.30902 -.95106 47.406 165.93)" width="32" height="32" fill="#00ffb2" stroke="#00ffb2" xlink:href="#a"/><use transform="matrix(-.98769 .15643 -.15643 -.98769 34.561 170.72)" width="32" height="32" fill="#00ffd9" stroke="#00ffd9" xlink:href="#a"/><use transform="matrix(-1,0,0,-1,21.125,173.44)" width="32" height="32" fill="#00ffff" stroke="#00ffff" xlink:href="#a"/><use transform="matrix(-.98769 -.15643 .15643 -.98769 7.4292 174.02)" width="32" height="32" fill="#00d9ff" stroke="#00d9ff" xlink:href="#a"/><use transform="matrix(-.95106 -.30902 .30902 -.95106 -6.1895 172.46)" width="32" height="32" fill="#00b2ff" stroke="#00b2ff" xlink:href="#a"/><use transform="matrix(-.89101 -.45399 .45399 -.89101 -19.396 168.78)" width="32" height="32" fill="#008cff" stroke="#008cff" xlink:href="#a"/><use transform="matrix(-.80902 -.58779 .58779 -.80902 -31.864 163.08)" width="32" height="32" fill="#0066ff" stroke="#0066ff" xlink:href="#a"/><use transform="matrix(-.70711 -.70711 .70711 -.70711 -43.288 155.51)" width="32" height="32" fill="#0040ff" stroke="#0040ff" xlink:href="#a"/><use transform="matrix(-.58779 -.80902 .80902 -.58779 -53.386 146.24)" width="32" height="32" fill="#001aff" stroke="#001aff" xlink:href="#a"/><use transform="matrix(-.45399 -.89101 .89101 -.45399 -61.909 135.5)" width="32" height="32" fill="#0d00ff" stroke="#0d00ff" xlink:href="#a"/><use transform="matrix(-.30902 -.95106 .95106 -.30902 -68.648 123.56)" width="32" height="32" fill="#3300ff" stroke="#3300ff" xlink:href="#a"/><use transform="matrix(-.15643 -.98769 .98769 -.15643 -73.436 110.72)" width="32" height="32" fill="#5900ff" stroke="#5900ff" xlink:href="#a"/><use transform="matrix(0,-1,1,0,-76.156,97.281)" width="32" height="32" fill="#8000ff" stroke="#8000ff" xlink:href="#a"/><use transform="matrix(.15643 -.98769 .98769 .15643 -76.741 83.585)" width="32" height="32" fill="#a600ff" stroke="#a600ff" xlink:href="#a"/><use transform="matrix(.30902 -.95106 .95106 .30902 -75.176 69.967)" width="32" height="32" fill="#cc00ff" stroke="#cc00ff" xlink:href="#a"/><use transform="matrix(.45399 -.89101 .89101 .45399 -71.5 56.761)" width="32" height="32" fill="#f200ff" stroke="#f200ff" xlink:href="#a"/><use transform="matrix(.58779 -.80902 .80902 .58779 -65.803 44.292)" width="32" height="32" fill="#ff00e5" stroke="#ff00e5" xlink:href="#a"/><use transform="matrix(.70711 -.70711 .70711 .70711 -58.226 32.868)" width="32" height="32" fill="#ff00bf" stroke="#ff00bf" xlink:href="#a"/><use transform="matrix(.80902 -.58779 .58779 .80902 -48.955 22.77)" width="32" height="32" fill="#ff0099" stroke="#ff0099" xlink:href="#a"/><use transform="matrix(.89101 -.45399 .45399 .89101 -38.218 14.247)" width="32" height="32" fill="#ff0073" stroke="#ff0073" xlink:href="#a"/><use transform="matrix(.95106 -.30902 .30902 .95106 -26.281 7.5083)" width="32" height="32" fill="#ff004d" stroke="#ff004d" xlink:href="#a"/><use transform="matrix(.98769 -.15643 .15643 .98769 -13.436 2.72)" width="32" height="32" fill="#ff0026" stroke="#ff0026" xlink:href="#a"/></g><text x="0.49070829" y="48.29847" fill="#f7941e" font-family="Accanthis ADF Std" font-size="40px" letter-spacing="0px" word-spacing="0px" style="line-height:125%" xml:space="preserve"><tspan x="0.49070829" y="48.29847" fill="#f7941e" font-family="Sans" font-size="24px"/></text> +<g transform="translate(8.7329 -5.8799)"><g transform="translate(-17.638 -.085622)" fill="#fff" stroke="#fff" stroke-width="1.5"><path d="m26.739 14.7c-0.50782 1.1e-5 -0.76173 0.56642-0.76172 1.6992v8.0391c0.74218 2e-6 1.4844-0.40625 2.2266-1.2188 0.66405-0.72656 0.99608-1.9609 0.99609-3.7031-1.2e-5 -1.625-0.33595-2.875-1.0078-3.75-0.54689-0.71093-1.0313-1.0664-1.4531-1.0664m0-1.8398c1.0937 1.3e-5 2.1367 0.51564 3.1289 1.5469 1.0703 1.1016 1.6055 2.8047 1.6055 5.1094-1.4e-5 2.1172-0.53517 3.8047-1.6055 5.0625-1.0078 1.1875-2.3047 1.7812-3.8906 1.7812v4.7109h-2.1445v-4.6992c-1.5547-1e-6 -2.8555-0.59766-3.9023-1.793-1.0625-1.2187-1.5938-2.9023-1.5938-5.0508-1e-6 -2.2344 0.53125-3.9219 1.5938-5.0625 0.79687-0.85155 1.8437-1.3867 3.1406-1.6055v1.9102c-0.51563 0.1797-1 0.57423-1.4531 1.1836-0.67188 0.89845-1.0078 2.0899-1.0078 3.5742-4e-6 1.5781 0.33593 2.8164 1.0078 3.7148 0.60156 0.80469 1.3398 1.207 2.2148 1.207v-8.0508c-7e-6 -2.3594 0.96874-3.539 2.9062-3.5391" fill="#fff" stroke="#fff" stroke-width="1.5"/></g><g transform="translate(-17.638 -.085622)"><path d="m26.739 14.7c-0.50782 1.1e-5 -0.76173 0.56642-0.76172 1.6992v8.0391c0.74218 2e-6 1.4844-0.40625 2.2266-1.2188 0.66405-0.72656 0.99608-1.9609 0.99609-3.7031-1.2e-5 -1.625-0.33595-2.875-1.0078-3.75-0.54689-0.71093-1.0313-1.0664-1.4531-1.0664m0-1.8398c1.0937 1.3e-5 2.1367 0.51564 3.1289 1.5469 1.0703 1.1016 1.6055 2.8047 1.6055 5.1094-1.4e-5 2.1172-0.53517 3.8047-1.6055 5.0625-1.0078 1.1875-2.3047 1.7812-3.8906 1.7812v4.7109h-2.1445v-4.6992c-1.5547-1e-6 -2.8555-0.59766-3.9023-1.793-1.0625-1.2187-1.5938-2.9023-1.5938-5.0508-1e-6 -2.2344 0.53125-3.9219 1.5938-5.0625 0.79687-0.85155 1.8437-1.3867 3.1406-1.6055v1.9102c-0.51563 0.1797-1 0.57423-1.4531 1.1836-0.67188 0.89845-1.0078 2.0899-1.0078 3.5742-4e-6 1.5781 0.33593 2.8164 1.0078 3.7148 0.60156 0.80469 1.3398 1.207 2.2148 1.207v-8.0508c-7e-6 -2.3594 0.96874-3.539 2.9062-3.5391"/></g></g></svg> diff --git a/silx/resources/gui/icons/math-square-amplitude.png b/silx/resources/gui/icons/math-square-amplitude.png Binary files differnew file mode 100644 index 0000000..2da16f2 --- /dev/null +++ b/silx/resources/gui/icons/math-square-amplitude.png diff --git a/silx/resources/gui/icons/math-square-amplitude.svg b/silx/resources/gui/icons/math-square-amplitude.svg new file mode 100644 index 0000000..7c18730 --- /dev/null +++ b/silx/resources/gui/icons/math-square-amplitude.svg @@ -0,0 +1,3 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg version="1.1" viewBox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><text x="0.49070829" y="48.29847" fill="#f7941e" font-family="Accanthis ADF Std" font-size="40px" letter-spacing="0px" word-spacing="0px" style="line-height:125%" xml:space="preserve"><tspan x="0.49070829" y="48.29847" fill="#f7941e" font-family="Sans" font-size="24px"/></text> +<g transform="translate(-1.0132 -.23022)"><g transform="translate(-.91624 -.18292)"><g transform="matrix(.82803 0 0 .82803 1.0566 4.3647)"><path d="m16 9.584-3.2109 8.707h6.4336l-3.2227-8.707m-1.3359-2.332h2.6836l6.668 17.496h-2.4609l-1.5938-4.4883h-7.8867l-1.5938 4.4883h-2.4961l6.6797-17.496"/></g><path d="m22.052 24.967v-14.708" fill="none" stroke="#000" stroke-width=".82803px"/><path d="m6.5581 24.967v-14.708" fill="none" stroke="#000" stroke-width=".82803px"/><g transform="translate(2)"><path d="m25.148 12.277h2.5664v1.1055h-4.2383v-1.1055l2.1289-1.8789c0.1901-0.17187 0.33073-0.33984 0.42188-0.50391 0.09114-0.16406 0.13672-0.33463 0.13672-0.51172-4e-6 -0.27343-0.09245-0.49349-0.27734-0.66016-0.1823-0.16666-0.42578-0.25-0.73047-0.25-0.23438 4.9e-6 -0.49089 0.050786-0.76953 0.15234-0.27865 0.098963-0.57682 0.2474-0.89453 0.44531v-1.2812c0.33854-0.11197 0.67318-0.19661 1.0039-0.25391 0.33073-0.05989 0.65494-0.089838 0.97266-0.089844 0.69791 5.9e-6 1.2396 0.15365 1.625 0.46094 0.38802 0.3073 0.58203 0.73568 0.58203 1.2852-5e-6 0.31771-0.08204 0.61459-0.24609 0.89063-0.16407 0.27344-0.50912 0.64063-1.0352 1.1016l-1.2461 1.0938"/></g></g></g></svg> diff --git a/silx/resources/opencl/codec/byte_offset.cl b/silx/resources/opencl/codec/byte_offset.cl new file mode 100644 index 0000000..56a24c4 --- /dev/null +++ b/silx/resources/opencl/codec/byte_offset.cl @@ -0,0 +1,235 @@ +/* + * Project: SILX: A data analysis tool-kit + * + * Copyright (C) 2017 European Synchrotron Radiation Facility + * Grenoble, France + * + * Principal authors: J. Kieffer (kieffer@esrf.fr) + * + * 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 THE AUTHORS OR COPYRIGHT + * HOLDERS 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. + */ + +/* To decompress CBF byte-offset compressed in parallel on GPU one needs to: + * - Set all values in mask and exception counter to zero. + * - Mark regions with exceptions and set values without exception. + * This generates the values (zeros for exceptions), the exception mask, + * counts the number of exception region and provides a start position for + * each exception. + * - Treat exceptions. For this, one thread in a workgoup treats a complete + * masked region in a serial fashion. All regions are treated in parallel. + * Values written at this stage are marked in the mask with -1. + * - Double scan: inclusive cum sum for values, exclusive cum sum to generate + * indices in output array. Values with mask = 1 are considered as 0. + * - Compact and copy output by removing duplicated values in exceptions. + */ + +kernel void mark_exceptions(global char* raw, + int size, + int full_size, + global int* mask, + global int* values, + global int* cnt, + global int* exc) +{ + int gid; + gid = get_global_id(0); + if (gid<size) + { + int value, position; + value = raw[gid]; + if (value == -128) + { + int maxi; + values[gid] = 0; + position = atomic_inc(cnt); + exc[position] = gid; + maxi = size - 1; + mask[gid] = 1; + mask[min(maxi, gid+1)] = 1; + mask[min(maxi, gid+2)] = 1; + + if (((int) raw[min(gid+1, maxi)] == 0) && + ((int) raw[min(gid+2, maxi)] == -128)) + { + mask[min(maxi, gid+3)] = 1; + mask[min(maxi, gid+4)] = 1; + mask[min(maxi, gid+5)] = 1; + mask[min(maxi, gid+6)] = 1; + } + } + else + { // treat simple data + + values[gid] = value; + } + } + else if (gid<full_size) + { + mask[gid]=1; + values[gid] = 0; + } +} + +//run with WG=1, as may as exceptions +kernel void treat_exceptions(global char* raw, //raw compressed stream + int size, //size of the raw compressed stream + global int* mask, //tells if the value is masked + global int* exc, //array storing the position of the start of exception zones + global int* values)// stores decompressed values. +{ + int gid = get_global_id(0); + int inp_pos = exc[gid]; + if ((inp_pos<=0) || ((int)mask[inp_pos - 1] == 0)) + { + int value, is_masked, next_value, inc; + is_masked = (mask[inp_pos] != 0); + while ((is_masked) && (inp_pos<size)) + { + value = (int) raw[inp_pos]; + if (value == -128) + { // this correspond to 16 bits exception + uchar low_byte = raw[inp_pos+1]; + char high_byte = raw[inp_pos+2] ; + next_value = high_byte<<8 | low_byte; + if (next_value == -32768) + { // this correspond to 32 bits exception + uchar low_byte1 = raw[inp_pos+3], + low_byte2 = raw[inp_pos+4], + low_byte3 = raw[inp_pos+5]; + char high_byte4 = raw[inp_pos+6] ; + value = high_byte4<<24 | low_byte3<<16 | low_byte2<<8 | low_byte1; + inc = 7; + } + else + { + value = next_value; + inc = 3; + } + } + else + { + inc = 1; + } + values[inp_pos] = value; + mask[inp_pos] = -1; // mark the processed data as valid in the mask + inp_pos += inc; + is_masked = (mask[inp_pos] != 0); + } + } +} + +// copy the values of the elements to definitive position +kernel void copy_result_int(global int* values, + global int* indexes, + int in_size, + int out_size, + global int* output + ) +{ + int gid = get_global_id(0); + if (gid < in_size) + { + int current = max(indexes[gid], 0), + next = (gid >= (in_size - 1)) ? in_size + 1 : indexes[gid + 1]; + //we keep always the last element + if ((current <= out_size) && (current < next)) + { + output[current] = values[gid]; + } + } +} + +// copy the values of the elements to definitive position +kernel void copy_result_float(global int* values, + global int* indexes, + int in_size, + int out_size, + global float* output + ) +{ + int gid = get_global_id(0); + if (gid<in_size) + { + int current = max(indexes[gid], 0), + next = (gid >= (in_size - 1)) ? in_size + 1 : indexes[gid + 1]; + if ((current < out_size) && (current < next)) + { + output[current] = (float) values[gid]; + } + } +} + + +// combined memset for all arrays used for Byte Offset decompression +kernel void byte_offset_memset(global char* raw, + global int* mask, + global int* index, + global int* result, + int full_size, + int actual_size + ) +{ + int gid = get_global_id(0); + if (gid < full_size) + { + raw[gid] = 0; + index[gid] = 0; + result[gid] = 0; + if (gid<actual_size) + { + mask[gid] = 0; + } + else + { + mask[gid] = 1; + } + + } +} + + +//Simple memset kernel for char arrays +kernel void fill_char_mem(global char* ary, + int size, + char pattern, + int start_at) +{ + int gid = get_global_id(0); + if ((gid >= start_at) && (gid < size)) + { + ary[gid] = pattern; + } +} + +//Simple memset kernel for int arrays +kernel void fill_int_mem(global int* ary, + int size, + int pattern, + int start_at) +{ + int gid = get_global_id(0); + if ((gid >= start_at) && (gid < size)) + { + ary[gid] = pattern; + } +} + diff --git a/silx/resources/opencl/image/cast.cl b/silx/resources/opencl/image/cast.cl new file mode 100644 index 0000000..9e23a82 --- /dev/null +++ b/silx/resources/opencl/image/cast.cl @@ -0,0 +1,181 @@ +/* + * Project: SILX: Alogorithms for image processing + * + * Copyright (C) 2013-2017 European Synchrotron Radiation Facility + * Grenoble, France + * + * Principal authors: J. Kieffer (kieffer@esrf.fr) + * + * 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 THE AUTHORS OR COPYRIGHT + * HOLDERS 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. + */ + +#ifndef NB_COLOR + #define NB_COLOR 1 +#endif + + +/** + * \brief Cast values of an array of uint8 into a float output array. + * + * :param array_input: Pointer to global memory with the input data as unsigned8 array + * :param array_float: Pointer to global memory with the output data as float array + * :param width: Width of the image + * :param height: Height of the image + */ +kernel void u8_to_float( global unsigned char *array_input, + global float *array_float, + const int width, + const int height) +{ + //Global memory guard for padding + if ((get_global_id(0) < width) && (get_global_id(1)<height)) + { + int i = NB_COLOR * (get_global_id(0) + width * get_global_id(1)); + for (int c=0; c<NB_COLOR; c++) + { + array_float[i + c] = (float) array_input[i + c]; + } //end loop over colors + } //end test in image +} //end kernel + +/** + * \brief Cast values of an array of uint8 into a float output array. + * + * :param array_input: Pointer to global memory with the input data as signed8 array + * :param array_float: Pointer to global memory with the output data as float array + * :param width: Width of the image + * :param height: Height of the image + */ +kernel void s8_to_float( global char *array_input, + global float *array_float, + const int width, + const int height) +{ + //Global memory guard for padding + if ((get_global_id(0) < width) && (get_global_id(1)<height)) + { + int i = NB_COLOR * (get_global_id(0) + width * get_global_id(1)); + for (int c=0; c<NB_COLOR; c++) + { + array_float[i + c] = (float) array_input[i + c]; + } //end loop over colors + } //end test in image +} //end kernel + + +/** + * \brief cast values of an array of uint16 into a float output array. + * + * :param array_input: Pointer to global memory with the input data as unsigned16 array + * :param array_float: Pointer to global memory with the output data as float array + * :param width: Width of the image + * :param height: Height of the image + */ +kernel void u16_to_float(global unsigned short *array_input, + global float *array_float, + const int width, + const int height) +{ + //Global memory guard for padding + if ((get_global_id(0) < width) && (get_global_id(1)<height)) + { + int i = NB_COLOR * (get_global_id(0) + width * get_global_id(1)); + for (int c=0; c<NB_COLOR; c++) + { + array_float[i + c] = (float) array_input[i + c]; + } //end loop over colors + } //end test in image +} //end kernel + +/** + * \brief cast values of an array of int16 into a float output array. + * + * :param array_input: Pointer to global memory with the input data as signed16 array + * :param array_float: Pointer to global memory with the output data as float array + * :param width: Width of the image + * :param height: Height of the image + */ +kernel void s16_to_float(global short *array_input, + global float *array_float, + const int width, + const int height) +{ + //Global memory guard for padding + if ((get_global_id(0) < width) && (get_global_id(1)<height)) + { + int i = NB_COLOR * (get_global_id(0) + width * get_global_id(1)); + for (int c=0; c<NB_COLOR; c++) + { + array_float[i + c] = (float) array_input[i + c]; + } //end loop over colors + } //end test in image +}//end kernel + +/** + * \brief cast values of an array of uint32 into a float output array. + * + * :param array_input: Pointer to global memory with the input data as unsigned32 array + * :param array_float: Pointer to global memory with the output data as float array + * :param width: Width of the image + * :param height: Height of the image + */ +kernel void u32_to_float(global unsigned int *array_input, + global float *array_float, + const int width, + const int height) +{ + //Global memory guard for padding + if ((get_global_id(0) < width) && (get_global_id(1)<height)) + { + int i = NB_COLOR * (get_global_id(0) + width * get_global_id(1)); + for (int c=0; c<NB_COLOR; c++) + { + array_float[i + c] = (float) array_input[i + c]; + } //end loop over colors + } //end test in image +}//end kernel + + +/** + * \brief convert values of an array of int32 into a float output array. + * + * :param array_input: Pointer to global memory with the data in int + * :param array_float: Pointer to global memory with the data in float + * :param width: Width of the image + * :param height: Height of the image + */ +kernel void s32_to_float(global int *array_input, + global float *array_float, + const int width, + const int height) +{ + //Global memory guard for padding + if ((get_global_id(0) < width) && (get_global_id(1)<height)) + { + int i = NB_COLOR * (get_global_id(0) + width * get_global_id(1)); + for (int c=0; c<NB_COLOR; c++) + { + array_float[i + c] = (float) array_input[i + c]; + } //end loop over colors + } //end test in image +}//end kernel + diff --git a/silx/resources/opencl/image/histogram.cl b/silx/resources/opencl/image/histogram.cl new file mode 100644 index 0000000..7fb1485 --- /dev/null +++ b/silx/resources/opencl/image/histogram.cl @@ -0,0 +1,178 @@ +//CL// + +/* + * Project: SILX: Alogorithms for image processing + * + * Copyright (C) 2013-2018 European Synchrotron Radiation Facility + * Grenoble, France + * + * Principal authors: J. Kieffer (kieffer@esrf.fr) + * + * 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 THE AUTHORS OR COPYRIGHT + * HOLDERS 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. + */ + +/* Single kernel histogram for float array. + * + * Can perform histograming in log-scale (using the arcsinh) + +Parameters: + - data: buffer with the image content in float (input) + - data_size: input + - mini: Lower bound of the first bin + - maxi: upper bouns of the last bin + - map_operation: Type of pre-processor to use. if if set to !=0, use log scale + - hist: resulting histogram (ouptut) + - hist_size: number of bins + - tmp_hist: temporary storage of size hist_size*num_groups + - processed: temporary storage of size 1 initialially set to 0 + - local_hist: local storage of size hist_size + + +Grid information: + * use the largest WG size. If it is larger than the number of bins (hist_size), + take the power of 2 immediately above + *Schedule as many WG as the device has compute engines. No need to schuedule more, + it is just a waist of memory + * The histogram should fit in shared (local) memory and tmp_hist can be large! + +Assumes: + hist and local_hist have size hist_size + edges has size hist_size+2 + tmp_hist has size hist_size*num_groups + processed is of size one and initially set to 0 + +*/ + + +static float preprocess(float value, int code) +{ + //This function can be modified to have more scales + if (code!=0) + { + return asinh(value); + } + else + { + return value; + } +} + +kernel void histogram(global float *data, + int data_size, + float mini, + float maxi, + int map_operation, + global int *hist, + global float *edges, + int hist_size, + global int *tmp_hist, + global int *processed, + local int *local_hist) +{ + // each thread + int lid = get_local_id(0); + int ws = get_local_size(0); + int nb_engine = get_num_groups(0); + int engine_id = get_group_id(0); + + // memset the local_hist array + for (int i=0; i<hist_size; i+=ws) + { + int j = i + lid; + if (j<hist_size) + { + local_hist[j] = 0; + } + } + barrier(CLK_LOCAL_MEM_FENCE); + + // Process the local data and accumulate in shared memory + int bloc_size = (int) ceil((float)data_size/(float)nb_engine); + int start = bloc_size * engine_id; + int stop = min(start + bloc_size, data_size); + float vmini = preprocess(mini, map_operation); + float vscale = (float)hist_size/(preprocess(maxi, map_operation) -vmini); + for (int i = start; i<stop; i+=ws) + { + int address = i + lid; + if (address < stop) + { + float value = data[address]; + if ((!isnan(value)) && (value>=mini) && (value<=maxi)) + { + float vvalue = (preprocess(value, map_operation)-vmini)*vscale; + int idx = clamp((int) vvalue, 0, hist_size - 1); + atomic_inc(&local_hist[idx]); + } + } + } + barrier(CLK_LOCAL_MEM_FENCE); + + //Now copy result into the right place and reset the first value of the shared array + for (int i=0; i<hist_size; i+=ws) + { + int j = i + lid; + if (j<hist_size) + { + tmp_hist[hist_size * engine_id + j] = local_hist[j]; + } + } + barrier(CLK_LOCAL_MEM_FENCE); + + local_hist[0] = 0; + + barrier(CLK_LOCAL_MEM_FENCE); + + //Increment the system wide shared variable processed and share the result with the workgroup + if (lid == 0) + { + local_hist[0] = atomic_inc(processed); + } + barrier(CLK_LOCAL_MEM_FENCE); + + // If we are the engine last to work, perform the concatenation of all results + + if ((local_hist[0] + 1) == nb_engine) + { + for (int i=0; i<hist_size; i+=ws) + { + int j = i + lid; + int lsum = 0; + if (j<hist_size) + { + for (int k=0; k<nb_engine; k++) + { + lsum += tmp_hist[hist_size * k + j]; + } + hist[j] = lsum; + edges[j] = vmini + j/vscale; + } + } + // Finally reset the counter + if (lid == 0) + { + processed[0] = 0; + edges[hist_size] = vmini + hist_size/vscale;; + } + + } +} diff --git a/silx/resources/opencl/image/map.cl b/silx/resources/opencl/image/map.cl new file mode 100644 index 0000000..804a5a1 --- /dev/null +++ b/silx/resources/opencl/image/map.cl @@ -0,0 +1,85 @@ +/* + * Project: SILX: Data analysis library + * kernel for maximum and minimum calculation + * + * + * Copyright (C) 2013-2017 European Synchrotron Radiation Facility + * Grenoble, France + * + * Principal authors: J. Kieffer (kieffer@esrf.fr) + * + * 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 THE AUTHORS OR COPYRIGHT + * HOLDERS 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. + * + * + */ + +#ifndef NB_COLOR + #define NB_COLOR 1 +#endif + + +/** + * \brief Linear scale of signal in an image (maybe multi-color) + * + * :param image: contains the input image + * :param output: contains the output image after scaling + * :param max_min_input: 2-floats containing the maximum and the minimum value of image + * :param minimum: float scalar with the minimum of the output + * :param maximum: float scalar with the maximum of the output + * :param width: integer, number of columns the matrices + * :param height: integer, number of lines of the matrices + * + * + */ + + +kernel void normalize_image(global float* image, + global float* output, + int width, + int height, + global float* max_min_input, + float minimum, + float maximum + ) +{ + //Global memory guard for padding + if((get_global_id(0) < width) && (get_global_id(1)<height)) + { + int idx = NB_COLOR* (get_global_id(0) + width * get_global_id(1)); + float mini_in, maxi_in, scale; + maxi_in = max_min_input[0]; + mini_in = max_min_input[1]; + if (maxi_in == mini_in) + { + scale = NAN; + } + else + { + scale = (maximum - minimum) / (maxi_in - mini_in); + } + + for (int c=0; c<NB_COLOR; c++) + { + output[idx+c] = fma(scale, image[idx+c]-mini_in, minimum); + } // end color loop + }//end if in IMAGE +}//end kernel diff --git a/silx/resources/opencl/image/max_min.cl b/silx/resources/opencl/image/max_min.cl new file mode 100644 index 0000000..246cd48 --- /dev/null +++ b/silx/resources/opencl/image/max_min.cl @@ -0,0 +1,207 @@ +/* + * Project: SILX: Data analysis library + * kernel for maximum and minimum calculation + * + * + * Copyright (C) 2013-2017 European Synchrotron Radiation Facility + * Grenoble, France + * + * Principal authors: J. Kieffer (kieffer@esrf.fr) + * + * 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 THE AUTHORS OR COPYRIGHT + * HOLDERS 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. + * + * + */ + +#ifndef NB_COLOR + #define NB_COLOR 1 +#endif + + + +#define REDUCE(a, b) ((float2) (fmax(a.x, b.x), fmin(a.y, b.y))) + +static float2 read_and_map(int idx, + global float* data) +{ + idx *= NB_COLOR; + float tmp = data[idx]; + float2 res = (float2) (tmp, tmp); + if (NB_COLOR > 1) + { + for (int c=1; c<NB_COLOR; c++) + { + tmp = data[idx + c]; + res = (float2) (fmax(res.x, tmp), fmin(res.y, tmp)); + } + } + return res; +} + + +/** + * \brief max_min_global_stage1: Look for the maximum an the minimum of an array. stage1 + * + * optimal workgroup size: 2^n greater than sqrt(size), limited to 512 + * optimal total item size: (workgroup size)^2 + * if size >total item size: adjust seq_count. + * + * :param data: Float pointer to global memory storing the vector of data. + * :param out: Float2 pointer to global memory storing the temporary results (workgroup size) + * :param seq_count: how many blocksize each thread should read + * :param size: size of the problem (number of element in the image + * :param l_data Shared memory: 2 float per thread in workgroup + * +**/ + + +kernel void max_min_reduction_stage1( global const float *data, + global float2 *out, + int size, + local float2 *l_data)// local storage 2 float per thread +{ + int group_size = get_local_size(0); + int lid = get_local_id(0); + float2 acc; + int big_block = group_size * get_num_groups(0); + int i = lid + group_size * get_group_id(0); + + if (lid<size) + acc = read_and_map(lid, data); + else + acc = read_and_map(0, data); + + // Linear pre-reduction stage 0 + + while (i<size){ + acc = REDUCE(acc, read_and_map(i, data)); + i += big_block; + } + + // parallel reduction stage 1 + + l_data[lid] = acc; + barrier(CLK_LOCAL_MEM_FENCE); + for (int block=group_size/2; block>1; block/=2) + { + if ((lid < block) && ((lid + block)<group_size)){ + l_data[lid] = REDUCE(l_data[lid], l_data[lid + block]); + } + barrier(CLK_LOCAL_MEM_FENCE); + } + if (lid == 0) + { + if (group_size > 1) + { + acc = REDUCE(l_data[0], l_data[1]); + } + else + { + acc = l_data[0]; + } + out[get_group_id(0)] = acc; + } +} + + +/** + * \brief global_max_min: Look for the maximum an the minimum of an array. + * + * + * + * :param data2: Float2 pointer to global memory storing the vector of pre-reduced data (workgroup size). + * :param maximum: Float pointer to global memory storing the maximum value + * :param minumum: Float pointer to global memory storing the minimum value + * :param l_data Shared memory: 2 float per thread in workgroup + * +**/ + +kernel void max_min_reduction_stage2( + global const float2 *data2, + global float2 *maxmin, + local float2 *l_data)// local storage 2 float per thread +{ + int lid = get_local_id(0); + int group_size = get_local_size(0); + float2 acc = (float2)(-1.0f, -1.0f); + if (lid<=group_size) + { + l_data[lid] = data2[lid]; + } + else + { + l_data[lid] = acc; + } + + // parallel reduction stage 2 + + + barrier(CLK_LOCAL_MEM_FENCE); + for (int block=group_size/2; block>1; block/=2) + { + if ((lid < block) && ((lid + block)<group_size)) + { + l_data[lid] = REDUCE(l_data[lid], l_data[lid + block]); + } + barrier(CLK_LOCAL_MEM_FENCE); + + } + + if (lid == 0 ) + { + if ( group_size > 1) + { + acc = REDUCE(l_data[0], l_data[1]); + } + else + { + acc = l_data[0]; + } + maxmin[0] = acc; + } +} + +/*This is the serial version of the min_max kernel. + * + * It has to be launched with WG=1 and only 1 WG has to be launched ! + * + * :param data: Float pointer to global memory storing the vector of data. + * :param size: size of the + * :param maximum: Float pointer to global memory storing the maximum value + * :param minumum: Float pointer to global memory storing the minimum value + * + * + */ +kernel void max_min_serial( + global const float *data, + unsigned int size, + global float2 *maxmin + ) +{ + float2 acc = read_and_map(0, data); + for (int i=1; i<size; i++) + { + acc = REDUCE(acc, read_and_map(i, data)); + } + + maxmin[0] = acc; +} |