Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: Add build recipe for PNG #4423

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
38 changes: 38 additions & 0 deletions THIRD-PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,44 @@ DEALINGS IN THE SOFTWARE.

-------------------------------------------------------------------------

PNG Reference Library License version 2
SPDX-License-Identifier: libpng-2.0

* libpng https://github.com/pnggroup/libpng
Copyright (c) 1995-2024 The PNG Reference Library Authors.
Copyright (c) 1995-2024 The PNG Reference Library Authors.
Copyright (c) 2018-2024 Cosmin Truta.
Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson.
Copyright (c) 1996-1997 Andreas Dilger.
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.

The software is supplied "as is", without warranty of any kind,
express or implied, including, without limitation, the warranties
of merchantability, fitness for a particular purpose, title, and
non-infringement. In no event shall the Copyright owners, or
anyone distributing the software, be liable for any damages or
other liability, whether in contract, tort or otherwise, arising
from, out of, or in connection with the software, or the use or
other dealings in the software, even if advised of the possibility
of such damage.

Permission is hereby granted to use, copy, modify, and distribute
this software, or portions hereof, for any purpose, without fee,
subject to the following restrictions:

1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you
use this software in a product, an acknowledgment in the product
documentation would be appreciated, but is not required.

2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.

3. This Copyright notice may not be removed or altered from any
source or altered source distribution.

-------------------------------------------------------------------------

Zlib license
SPDX-License-Identifier: Zlib

Expand Down
50 changes: 50 additions & 0 deletions src/cmake/build_PNG.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

######################################################################
# PNG by hand!
######################################################################

set_cache (PNG_BUILD_VERSION 1.6.44 "PNG version for local builds")
set (PNG_GIT_REPOSITORY "https://github.com/glennrp/libpng")
set (PNG_GIT_TAG "v${PNG_BUILD_VERSION}")

set_cache (PNG_BUILD_SHARED_LIBS ${LOCAL_BUILD_SHARED_LIBS_DEFAULT}
DOC "Should execute a local PNG build, if necessary, build shared libraries" ADVANCED)

string (MAKE_C_IDENTIFIER ${PNG_BUILD_VERSION} PNG_VERSION_IDENT)

build_dependency_with_cmake(PNG
VERSION ${PNG_BUILD_VERSION}
GIT_REPOSITORY ${PNG_GIT_REPOSITORY}
GIT_TAG ${PNG_GIT_TAG}
CMAKE_ARGS
-D PNG_SHARED=${PNG_BUILD_SHARED_LIBS}
-D PNG_EXECUTABLES=OFF
-D PNG_TESTS=OFF
-D PNG_FRAMEWORK=OFF
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
-D CMAKE_INSTALL_LIBDIR=lib
)

# Set some things up that we'll need for a subsequent find_package to work
set (PNG_ROOT ${PNG_LOCAL_INSTALL_DIR})
set (PNG_DIR ${PNG_LOCAL_INSTALL_DIR})

# Signal to caller that we need to find again at the installed location
set (PNG_REFIND TRUE)
set (PNG_REFIND_VERSION ${PNG_BUILD_VERSION})

# If building PNG >= 1.6.44, refind with PNG's CMake Config
if (${PNG_BUILD_VERSION} VERSION_GREATER_EQUAL 1.6.44)
message (STATUS "PNG ${PNG_BUILD_VERSION} >= 1.6.44, refinding with CMake Config")
set(_refind_config REQUIRED CONFIG)
endif ()
set(PNG_REFIND_ARGS ${_refind_config}
HINTS ${PNG_LOCAL_INSTALL_DIR}/lib/libpng
)

if (PNG_BUILD_SHARED_LIBS)
install_local_dependency_libs (PNG PNG)
endif ()
38 changes: 38 additions & 0 deletions src/cmake/build_ZLIB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

######################################################################
# ZLIB by hand!
######################################################################

set_cache (ZLIB_BUILD_VERSION 1.3.1 "ZLIB version for local builds")
set (ZLIB_GIT_REPOSITORY "https://github.com/madler/zlib")
set (ZLIB_GIT_TAG "v${ZLIB_BUILD_VERSION}")

set_cache (ZLIB_BUILD_SHARED_LIBS ${LOCAL_BUILD_SHARED_LIBS_DEFAULT}
DOC "Should execute a local ZLIB build, if necessary, build shared libraries" ADVANCED)

string (MAKE_C_IDENTIFIER ${ZLIB_BUILD_VERSION} ZLIB_VERSION_IDENT)

build_dependency_with_cmake(ZLIB
VERSION ${ZLIB_BUILD_VERSION}
GIT_REPOSITORY ${ZLIB_GIT_REPOSITORY}
GIT_TAG ${ZLIB_GIT_TAG}
CMAKE_ARGS
-D BUILD_SHARED_LIBS=${ZLIB_BUILD_SHARED_LIBS}
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
-D CMAKE_INSTALL_LIBDIR=lib
)

# Set some things up that we'll need for a subsequent find_package to work
set (ZLIB_ROOT ${ZLIB_LOCAL_INSTALL_DIR})

# Signal to caller that we need to find again at the installed location
set (ZLIB_REFIND TRUE)
set (ZLIB_VERSION ${ZLIB_BUILD_VERSION})
set (ZLIB_REFIND_VERSION ${ZLIB_BUILD_VERSION})

if (ZLIB_BUILD_SHARED_LIBS)
install_local_dependency_libs (ZLIB ZLIB)
endif ()
64 changes: 32 additions & 32 deletions testsuite/oiiotool-demosaic/ref/out.txt
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
Computing diff of "testimage_float.exr" vs "result_float_RGGB-linear.exr"
Computing diff of "testimage.exr" vs "result_float_RGGB-linear.exr"
PASS
Computing diff of "testimage_float.exr" vs "result_float_GRBG-linear.exr"
Computing diff of "testimage.exr" vs "result_float_GRBG-linear.exr"
PASS
Computing diff of "testimage_float.exr" vs "result_float_GBRG-linear.exr"
Computing diff of "testimage.exr" vs "result_float_GBRG-linear.exr"
PASS
Computing diff of "testimage_float.exr" vs "result_float_BGGR-linear.exr"
Computing diff of "testimage.exr" vs "result_float_BGGR-linear.exr"
PASS
Computing diff of "testimage_float.exr" vs "result_float_RGGB-MHC.exr"
Computing diff of "testimage.exr" vs "result_float_RGGB-MHC.exr"
PASS
Computing diff of "testimage_float.exr" vs "result_float_GRBG-MHC.exr"
Computing diff of "testimage.exr" vs "result_float_GRBG-MHC.exr"
PASS
Computing diff of "testimage_float.exr" vs "result_float_GBRG-MHC.exr"
Computing diff of "testimage.exr" vs "result_float_GBRG-MHC.exr"
PASS
Computing diff of "testimage_float.exr" vs "result_float_BGGR-MHC.exr"
Computing diff of "testimage.exr" vs "result_float_BGGR-MHC.exr"
PASS
Computing diff of "testimage_half.exr" vs "result_half_RGGB-linear.exr"
Computing diff of "testimage.exr" vs "result_half_RGGB-linear.exr"
PASS
Computing diff of "testimage_half.exr" vs "result_half_GRBG-linear.exr"
Computing diff of "testimage.exr" vs "result_half_GRBG-linear.exr"
PASS
Computing diff of "testimage_half.exr" vs "result_half_GBRG-linear.exr"
Computing diff of "testimage.exr" vs "result_half_GBRG-linear.exr"
PASS
Computing diff of "testimage_half.exr" vs "result_half_BGGR-linear.exr"
Computing diff of "testimage.exr" vs "result_half_BGGR-linear.exr"
PASS
Computing diff of "testimage_half.exr" vs "result_half_RGGB-MHC.exr"
Computing diff of "testimage.exr" vs "result_half_RGGB-MHC.exr"
PASS
Computing diff of "testimage_half.exr" vs "result_half_GRBG-MHC.exr"
Computing diff of "testimage.exr" vs "result_half_GRBG-MHC.exr"
PASS
Computing diff of "testimage_half.exr" vs "result_half_GBRG-MHC.exr"
Computing diff of "testimage.exr" vs "result_half_GBRG-MHC.exr"
PASS
Computing diff of "testimage_half.exr" vs "result_half_BGGR-MHC.exr"
Computing diff of "testimage.exr" vs "result_half_BGGR-MHC.exr"
PASS
Computing diff of "testimage_uint16.tiff" vs "result_uint16_RGGB-linear.tiff"
Computing diff of "testimage.exr" vs "result_uint16_RGGB-linear.tiff"
PASS
Computing diff of "testimage_uint16.tiff" vs "result_uint16_GRBG-linear.tiff"
Computing diff of "testimage.exr" vs "result_uint16_GRBG-linear.tiff"
PASS
Computing diff of "testimage_uint16.tiff" vs "result_uint16_GBRG-linear.tiff"
Computing diff of "testimage.exr" vs "result_uint16_GBRG-linear.tiff"
PASS
Computing diff of "testimage_uint16.tiff" vs "result_uint16_BGGR-linear.tiff"
Computing diff of "testimage.exr" vs "result_uint16_BGGR-linear.tiff"
PASS
Computing diff of "testimage_uint16.tiff" vs "result_uint16_RGGB-MHC.tiff"
Computing diff of "testimage.exr" vs "result_uint16_RGGB-MHC.tiff"
PASS
Computing diff of "testimage_uint16.tiff" vs "result_uint16_GRBG-MHC.tiff"
Computing diff of "testimage.exr" vs "result_uint16_GRBG-MHC.tiff"
PASS
Computing diff of "testimage_uint16.tiff" vs "result_uint16_GBRG-MHC.tiff"
Computing diff of "testimage.exr" vs "result_uint16_GBRG-MHC.tiff"
PASS
Computing diff of "testimage_uint16.tiff" vs "result_uint16_BGGR-MHC.tiff"
Computing diff of "testimage.exr" vs "result_uint16_BGGR-MHC.tiff"
PASS
Computing diff of "testimage_uint8.tiff" vs "result_uint8_RGGB-linear.tiff"
Computing diff of "testimage.exr" vs "result_uint8_RGGB-linear.tiff"
PASS
Computing diff of "testimage_uint8.tiff" vs "result_uint8_GRBG-linear.tiff"
Computing diff of "testimage.exr" vs "result_uint8_GRBG-linear.tiff"
PASS
Computing diff of "testimage_uint8.tiff" vs "result_uint8_GBRG-linear.tiff"
Computing diff of "testimage.exr" vs "result_uint8_GBRG-linear.tiff"
PASS
Computing diff of "testimage_uint8.tiff" vs "result_uint8_BGGR-linear.tiff"
Computing diff of "testimage.exr" vs "result_uint8_BGGR-linear.tiff"
PASS
Computing diff of "testimage_uint8.tiff" vs "result_uint8_RGGB-MHC.tiff"
Computing diff of "testimage.exr" vs "result_uint8_RGGB-MHC.tiff"
PASS
Computing diff of "testimage_uint8.tiff" vs "result_uint8_GRBG-MHC.tiff"
Computing diff of "testimage.exr" vs "result_uint8_GRBG-MHC.tiff"
PASS
Computing diff of "testimage_uint8.tiff" vs "result_uint8_GBRG-MHC.tiff"
Computing diff of "testimage.exr" vs "result_uint8_GBRG-MHC.tiff"
PASS
Computing diff of "testimage_uint8.tiff" vs "result_uint8_BGGR-MHC.tiff"
Computing diff of "testimage.exr" vs "result_uint8_BGGR-MHC.tiff"
PASS
29 changes: 14 additions & 15 deletions testsuite/oiiotool-demosaic/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
"BGGR": make_pattern_BGGR
}

# Create a test image with color gradients
make_testimage = f"--pattern fill:topleft=0,0,1:topright=0,1,0:bottomleft=1,0,1:bottomright=1,1,0 {width}x{height} 3 "


types = [
{
"type" : "float",
Expand All @@ -51,29 +47,32 @@
]


# Create a test image with color gradient
make_testimage = f"--pattern fill:topleft=0,0,1:topright=0,1,0:bottomleft=1,0,1:bottomright=1,1,0 {width}x{height} 3 "
command += oiiotool (make_testimage + f" -o:type=float testimage.exr")

# For each Bayer pattern (RGGB, RGRB, GBRG, BGGR), create an image with that
# pure pattern ({pattern}.exr), then multiply it by the test image and take
# the channel sum to get a Bayer mosaic image ({pattern}-bayer.exr).
# This is somewhat expensive, so we do it only once (for float) and then will
# convert it to the appropriate type upon input.
for pattern, maker in layouts.items():
command += oiiotool (f"{maker} -o:type=float pattern_{pattern}.exr testimage.exr -mul -chsum -o:type=float bayer_{pattern}.exr")


for dict in types:

type = dict["type"]
ext = dict["ext"]
threshold = dict["threshold"]

command += oiiotool (make_testimage + f" -o:type={type} testimage_{type}.{ext}")

# For each Bayer pattern (RGGB, RGRB, GBRG, BGGR), create an image with that
# pure pattern ({pattern}.exr), then multiply it by the test image and take
# the channel sum to get a Bayer mosaic image ({pattern}-bayer.exr).
for pattern, maker in layouts.items():
command += oiiotool (f"{maker} -o:type={type} pattern_{type}_{pattern}.{ext} testimage_{type}.{ext} -mul -chsum -o:type={type} bayer_{type}_{pattern}.{ext}")

test = f" --fail {threshold} --hardfail {threshold} --warn {threshold} --diff "


# For each algorithm, try demosaicing each pattern test image and compare to
# the original test image.
for algo in ['linear', 'MHC']:
for pattern, maker in layouts.items():
command += oiiotool (f"-i:type={type} testimage_{type}.{ext} -i:type={type} bayer_{type}_{pattern}.{ext} --demosaic:algorithm={algo}:layout={pattern} -o:type={type} result_{type}_{pattern}-{algo}.{ext} ")
command += oiiotool (f"-i:type={type} testimage.exr -i:type={type} bayer_{pattern}.exr --demosaic:algorithm={algo}:layout={pattern} -o:type={type} result_{type}_{pattern}-{algo}.{ext} ")

crop = 2

Expand All @@ -82,4 +81,4 @@
else:
cut_cmd = ""

command += oiiotool (f"testimage_{type}.{ext} " + cut_cmd + f"result_{type}_{pattern}-{algo}.{ext} " + cut_cmd + test)
command += oiiotool (f"testimage.exr " + cut_cmd + f"result_{type}_{pattern}-{algo}.{ext} " + cut_cmd + test)
Loading