Skip to content

Commit 078d50d

Browse files
committedAug 18, 2020
Initial commit
0 parents  commit 078d50d

13 files changed

+1318
-0
lines changed
 

‎README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CubeMapToOctMap
2+
Fast tool to convert OpenExr Cube Maps to Octahedron Maps
3+
4+
Build with Bazel:
5+
bazel build //src:cubemap_to_octmap

‎WORKSPACE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
workspace(name = "cubemap_to_octmap")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
6+
name = "gtest",
7+
url = "https://github.com/google/googletest/archive/release-1.8.0.zip",
8+
strip_prefix = "googletest-release-1.8.0",
9+
sha256 = "f3ed3b58511efd272eb074a3a6d6fb79d7c2e6a0e374323d1e6bcbcc1ef141bf",
10+
build_file = "@//third_party:gtest.BUILD",
11+
)
12+
13+
http_archive(
14+
name = "openexr",
15+
build_file = "@//third_party:openexr.BUILD",
16+
strip_prefix = "openexr-2.2.0",
17+
urls = ["https://github.com/openexr/openexr/archive/v2.2.0.zip"],
18+
)
19+
20+
http_archive(
21+
name = "zlib",
22+
build_file = "@//third_party:zlib.BUILD",
23+
strip_prefix = "zlib-1.2.11",
24+
sha256 = "f5cc4ab910db99b2bdbba39ebbdc225ffc2aa04b4057bc2817f1b94b6978cfc3",
25+
urls = ["https://github.com/madler/zlib/archive/v1.2.11.zip"],
26+
)

‎src/BUILD

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright(c) 2020 Matthias Bühlmann, Mabulous GmbH. http://www.mabulous.com
2+
3+
config_setting(
4+
name = "windows",
5+
values = {
6+
"crosstool_top": "//crosstools/windows",
7+
},
8+
)
9+
10+
cc_library(
11+
name = "openexr_deps",
12+
deps = [
13+
"@openexr//:ilm_imf",
14+
"@openexr//:imath",
15+
],
16+
)
17+
18+
cc_binary(
19+
name = "cubemap_to_octmap",
20+
srcs = [
21+
"main.cc",
22+
"stringutils.cc"
23+
],
24+
includes = [
25+
"cubemaputil.h",
26+
"octmaputil.h",
27+
"stringutils.h",
28+
"filter.h"
29+
],
30+
copts = select({
31+
":windows": ["/std:c++17"],
32+
"//conditions:default": ["-std:c++17"],
33+
}),
34+
deps = [":openexr_deps"],
35+
visibility = ["//visibility:public"],
36+
)

‎src/cubemaputil.h

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* Copyright(c) 2020 Matthias Bühlmann, Mabulous GmbH. http://www.mabulous.com
3+
*/
4+
5+
#ifndef CUBEMAP_UTIL_H
6+
#define CUBEMAP_UTIL_H
7+
8+
#include <cmath>
9+
10+
#include "IlmBase/Imath/ImathVec.h"
11+
12+
// considers cubemaps to be in the following order:
13+
// [right][left][top][bottom][back][front]
14+
// This is how renderers like V-Ray or Keyshot output cubemaps.
15+
16+
// for coordinates, a right handed coordinate syste is considered with:
17+
// Right: +X
18+
// Top: +Y
19+
// Forward: -Z
20+
21+
// uv coordinates are considered to start in the bottom left corner.
22+
23+
#define MIRROR_FACES 1
24+
// if this is defined, each face of the cubemap is teated as horizontally mirrored (except for top and bottom, which are vertically mirrored),
25+
// which again is how V-Ray and Keyshot output their cubemaps.
26+
27+
Imath::V2f sampleCube(
28+
const Imath::V3f& v,
29+
int* faceIndex)
30+
{
31+
Imath::V3f vAbs = Imath::V3f(std::abs(v.x), std::abs(v.y), std::abs(v.z));
32+
float ma;
33+
Imath::V2f uv;
34+
if (vAbs.z >= vAbs.x && vAbs.z >= vAbs.y)
35+
{ // +Z -Z
36+
*faceIndex = v.z < 0 ? 5 : 4;
37+
ma = 0.5f / vAbs.z;
38+
uv = Imath::V2f(v.z < 0 ? v.x : -v.x, v.y);
39+
#ifdef MIRROR_FACES
40+
uv.x = -uv.x;
41+
#endif
42+
}
43+
else if (vAbs.y >= vAbs.x)
44+
{
45+
*faceIndex = v.y < 0 ? 3 : 2;
46+
ma = 0.5f / vAbs.y;
47+
uv = Imath::V2f(v.x, v.y < 0 ? -v.z : v.z);
48+
#ifdef MIRROR_FACES
49+
uv.y = -uv.y;
50+
#endif
51+
}
52+
else
53+
{
54+
*faceIndex = v.x < 0 ? 1 : 0;
55+
ma = 0.5f / vAbs.x;
56+
uv = Imath::V2f(v.x < 0 ? -v.z : v.z, v.y);
57+
#ifdef MIRROR_FACES
58+
uv.x = -uv.x;
59+
#endif
60+
}
61+
return (uv * ma) + Imath::V2f(0.5f,0.5f);
62+
}
63+
64+
/** Assumes that v is a unit vector. The result is a cubemap vector on the [0, 1] square. */
65+
Imath::V2f cubeEncode(const Imath::V3f& v, int* face_out) {
66+
Imath::V2f uv = sampleCube(v, face_out);
67+
uv.x = std::clamp(uv.x, 0.0f, 1.0f);
68+
uv.y = std::clamp(uv.y, 0.0f, 1.0f);
69+
return uv;
70+
}
71+
72+
/** Returns a unit vector. Argument o is an cubemap vector packed via cubeEncode,
73+
on the [0, +1] square*/
74+
Imath::V3f cubeDecode(const Imath::V2f& o) {
75+
float tmp;
76+
float u = std::modf(o.x, &tmp);
77+
if (u < 0)
78+
u = 1.0f + u;
79+
float v = std::modf(o.y, &tmp);
80+
if (v < 0)
81+
v = 1.0f + u;
82+
83+
Imath::V3f res;
84+
85+
v = v * 2.0f - 1.0f;
86+
u *= 6.0f;
87+
if (u < 1.0f) { // Right, +X
88+
u = (u-0.5) * 2.0f;
89+
#ifdef MIRROR_FACES
90+
u = -u;
91+
#endif
92+
res.x = 1.0f;
93+
res.y = v;
94+
res.z = u;
95+
}
96+
else if (u < 2.0f) { // Left, -X
97+
u = (u-1.5f) * 2.0f;
98+
#ifdef MIRROR_FACES
99+
u = -u;
100+
#endif
101+
res.x = -1.0f;
102+
res.y = v;
103+
res.z = -u;
104+
}
105+
else if (u < 3.0f) { // Top, +Y
106+
u = (u-2.5f) * 2.0f;
107+
#ifdef MIRROR_FACES
108+
v = -v;
109+
#endif
110+
res.x = u;
111+
res.y = 1.0f;
112+
res.z = v;
113+
}
114+
else if (u < 4.0f) { // Bottom, -Y
115+
u = (u-3.5f) * 2.0f;
116+
#ifdef MIRROR_FACES
117+
v = -v;
118+
#endif
119+
res.x = u;
120+
res.y = -1.0f;
121+
res.z = -v;
122+
}
123+
else if (u < 5.0f) { // Back, +Z
124+
u = (u-4.5f) * 2.0f;
125+
#ifdef MIRROR_FACES
126+
u = -u;
127+
#endif
128+
res.x = -u;
129+
res.y = v;
130+
res.z = 1.0f;
131+
}
132+
else { // Front, -Z
133+
u = (u-5.5f) * 2.0f;
134+
#ifdef MIRROR_FACES
135+
u = -u;
136+
#endif
137+
res.x = u;
138+
res.y = v;
139+
res.z = -1.0f;
140+
}
141+
return res.normalized();
142+
}
143+
144+
#endif // CUBEMAP_UTIL_H

‎src/filter.h

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright(c) 2020 Matthias Bühlmann, Mabulous GmbH. http://www.mabulous.com
3+
*/
4+
5+
#ifndef IMAGE_FILTER_H
6+
#define IMAGE_FILTER_H
7+
8+
#include "IlmBase/Imath/ImathVec.h"
9+
10+
class Filter {
11+
public:
12+
// Evaluate the filter for the given position relative to it's center.
13+
virtual float Eval(const Imath::V2f& position) const = 0;
14+
15+
// Return the radius of the filter. This is a bounding circle around the
16+
// support of the filter.
17+
virtual float GetRadius() const = 0;
18+
};
19+
20+
class MitchellFilter : public Filter {
21+
public:
22+
// Constructs a Mitchell filter with the given parameters B and C.
23+
// B = 0, C = 1 is the cubic B-spline.
24+
// B = 0, is the family of cardinal splines.
25+
// B = 0, C = 0.5 is the Catmull-Rom spline.
26+
// The authors of the original paper suggest B + 2C = 1 as good parameters.
27+
// In particular B = C = 1/3.
28+
MitchellFilter(float b, float c) : b_(b), c_(c) {}
29+
30+
// Default constructor, B = C = 1/3.
31+
MitchellFilter() : b_(1.0f / 3.0f), c_(1.0f / 3.0f) {}
32+
33+
float Eval(const Imath::V2f& position) const override {
34+
const float d = position.length();
35+
const float d2 = d * d;
36+
const float d3 = d2 * d;
37+
if (d < 1.0f) {
38+
return ((12.0f - 9.0f * b_ - 6.0f * c_) * d3 +
39+
(-18.0f + 12.0f * b_ + 6.0f * c_) * d2 +
40+
(6.0f - 2.0f * b_)) /
41+
6.0f;
42+
} else if ((d >= 1.0f) && (d < 2.0f)) {
43+
return ((-b_ - 6.0f * c_) * d3 +
44+
(6.0f * b_ + 30.0f * c_) * d2 +
45+
(-12.0f * b_ - 48.0f * c_) * d +
46+
(8.0f * b_ + 24.0f * c_)) /
47+
6.0f;
48+
} else {
49+
return 0.0f;
50+
}
51+
}
52+
53+
float GetRadius() const override { return 2.0f; }
54+
55+
private:
56+
// The two constants B and C defining the filter's shape.
57+
const float b_;
58+
const float c_;
59+
};
60+
61+
class GaussianFilter : public Filter {
62+
public:
63+
// Constructs a gaussian filter with the given standard deviation sigma and
64+
// radius. The gaussian is truncated at distance radius and shifted such
65+
// that f(radius) = 0. As a rule of thumb, radius = 3 * sigma is a reasonable
66+
// choice for the cut-off.
67+
GaussianFilter(float sigma, float radius)
68+
: radius_(radius),
69+
a_(1.0f / (std::sqrt(2 * M_PI) * sigma)),
70+
b_(-1.0f / (2.0f * sigma * sigma)),
71+
c_(-a_ * std::exp(radius * radius * b_)) {}
72+
73+
// Default constructor with radius = 2.0, sigma = 2.0/3
74+
GaussianFilter() : GaussianFilter(2.0f/3, 2.0f) {}
75+
76+
77+
float Eval(const Imath::V2f& position) const override {
78+
const float d2 = position.length2();;
79+
if (d2 >= radius_ * radius_) {
80+
return 0.0f;
81+
}
82+
return a_ * std::exp(d2 * b_) + c_;
83+
}
84+
85+
float GetRadius() const override { return radius_; }
86+
87+
private:
88+
const float radius_;
89+
const float a_;
90+
const float b_;
91+
const float c_;
92+
};
93+
94+
95+
#endif // IMAGE_FILTER_H

‎src/main.cc

+444
Large diffs are not rendered by default.

‎src/octmaputil.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright(c) 2020 Matthias Bühlmann, Mabulous GmbH. http://www.mabulous.com
3+
*/
4+
5+
#ifndef OCTMAP_UTIL_H
6+
#define OCTMAP_UTIL_H
7+
8+
#include <cmath>
9+
10+
#include "IlmBase/Imath/ImathVec.h"
11+
12+
float signNotZero(float k) {
13+
return (k >= 0.0f) ? 1.0f : -1.0f;
14+
}
15+
16+
Imath::V2f signNotZero(const Imath::V2f& v) {
17+
return Imath::V2f(signNotZero(v.x), signNotZero(v.y));
18+
}
19+
20+
21+
// X+ maps to result.x+
22+
// Y+ maps to result.y+
23+
// Z+ maps to the center
24+
// Z- maps to the corners
25+
26+
/** Assumes that v is a unit vector. The result is an octahedral vector on the [-1, +1] square. */
27+
Imath::V2f octEncode(const Imath::V3f& v) {
28+
float l1norm = std::abs(v.x) + abs(v.y) + abs(v.z);
29+
float invL1norm = 1.0f / l1norm;
30+
Imath::V2f result(v.x * invL1norm, v.y * invL1norm);
31+
if (v.z < 0.0f) {
32+
result = (Imath::V2f(1.0f,1.0f) - Imath::V2f(std::abs(result.y), std::abs(result.x))) *
33+
signNotZero(Imath::V2f(result.x, result.y));
34+
}
35+
return result;
36+
}
37+
38+
/** Returns a unit vector. Argument o is an octahedral vector packed via octEncode,
39+
on the [-1, +1] square*/
40+
Imath::V3f octDecode(const Imath::V2f& o) {
41+
Imath::V3f v(o.x, o.y, 1.0f - std::abs(o.x) - std::abs(o.y));
42+
if (v.z < 0.0f) {
43+
v.x = (1.0f - std::abs(o.y)) * signNotZero(o.x);
44+
v.y = (1.0f - std::abs(o.x)) * signNotZero(o.y);
45+
}
46+
v.normalize();
47+
return v;
48+
}
49+
50+
#endif // OCTMAP_UTIL_H

‎src/stringutils.cc

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright(c) 2020 Matthias Bühlmann, Mabulous GmbH. http://www.mabulous.com
3+
*/
4+
5+
#include "stringutils.h"
6+
7+
#include <algorithm>
8+
#include <cctype>
9+
10+
// Removes leading and trailing whitespace from string.
11+
std::string trim(const std::string& s) {
12+
std::string tmp = s.substr(0, s.find_last_not_of(" ") + 1);
13+
tmp = tmp.substr(tmp.find_first_not_of(" "));
14+
return tmp;
15+
}
16+
17+
// Splits string at delimiter into array.
18+
std::vector<std::string> split(const std::string& str, const std::string& delimiter) {
19+
std::string s = str;
20+
size_t delimiterPos = s.find(delimiter);
21+
if (delimiterPos == std::string::npos) {
22+
s = trim(s);
23+
return std::vector<std::string>(1, s);
24+
}
25+
std::string left = s.substr(0, delimiterPos);
26+
left = trim(left);
27+
std::string right = s.substr(delimiterPos + 1, std::string::npos);
28+
right = trim(right);
29+
std::vector<std::string> res(1, left);
30+
std::vector<std::string> rightElements = split(right, delimiter);
31+
res.insert(res.end(), rightElements.begin(), rightElements.end());
32+
return res;
33+
}
34+
35+
// Converts string to lower case.
36+
std::string toLower(const std::string& s) {
37+
std::string lower = s;
38+
std::transform(lower.begin(), lower.end(), lower.begin(),
39+
[](unsigned char c) { return std::tolower(c); });
40+
return lower;
41+
}

‎src/stringutils.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright(c) 2020 Matthias Bühlmann, Mabulous GmbH. http://www.mabulous.com
3+
*/
4+
5+
#ifndef STRING_UTILS_H
6+
#define STRING_UTILS_H
7+
8+
#include <string>
9+
#include <vector>
10+
11+
// Removes leading and trailing whitespace from string.
12+
std::string trim(const std::string& s);
13+
14+
// Splits string at delimiter into array.
15+
std::vector<std::string> split(const std::string& str, const std::string& delimiter);
16+
17+
// Converts string to lower case.
18+
std::string toLower(const std::string& s);
19+
20+
#endif // STRING_UTILS_H

‎third_party/BUILD

Whitespace-only changes.

‎third_party/gtest.BUILD

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cc_library(
2+
name = "main",
3+
srcs = glob(
4+
include = ["googletest/src/*.h",
5+
"googletest/include/gtest/internal/**/*.h",
6+
"googletest/src/*.cc"],
7+
exclude = ["googletest/src/gtest-all.cc"]
8+
),
9+
hdrs = glob(["googletest/include/gtest/*.h"]),
10+
includes = ["googletest/",
11+
"googletest/include"],
12+
linkopts = ["-pthread"],
13+
visibility = ["//visibility:public"],
14+
)

‎third_party/openexr.BUILD

+367
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,367 @@
1+
# Copyright 2017 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS-IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Description:
16+
# Bazel build file for the ILM OpenEXR libraries.
17+
18+
package(
19+
default_visibility = ["//visibility:public"],
20+
features = [
21+
"-layering_check",
22+
"-parse_headers",
23+
],
24+
)
25+
26+
licenses(["notice"]) # BSD
27+
28+
exports_files(["LICENSE"])
29+
30+
config_setting(
31+
name = "linux_x86_64",
32+
values = {"cpu": "k8"},
33+
visibility = ["//visibility:public"],
34+
)
35+
36+
config_setting(
37+
name = "windows_x86_64",
38+
values = {"cpu": "x64_windows"},
39+
visibility = ["//visibility:public"],
40+
)
41+
42+
DEFINES = [
43+
"DISABLE_GOOGLE_GLOBAL_USING_DECLARATIONS",
44+
] + select({
45+
":linux_x86_64": [
46+
"OS_LINUX=OS_LINUX",
47+
"ARCH_K8",
48+
],
49+
":windows_x86_64": [
50+
"NOGDI", # Don't pollute with GDI macros in windows.h.
51+
"NOMINMAX", # Don't define min/max macros in windows.h.
52+
"OS_WINDOWS=OS_WINDOWS",
53+
"PRAGMA_SUPPORTED",
54+
"WIN32",
55+
"WINVER=0x0600",
56+
"_CRT_SECURE_NO_DEPRECATE",
57+
"_WIN32",
58+
"_WIN32_WINNT=0x0600",
59+
"_WINDOWS",
60+
61+
# Defaults for other headers (along with OS_WINDOWS).
62+
"COMPILER_MSVC",
63+
64+
# Use math constants (M_PI, etc.) from the math library
65+
"_USE_MATH_DEFINES",
66+
67+
# Allows 'Foo&&' (e.g., move constructors).
68+
"COMPILER_HAS_RVALUEREF",
69+
70+
# Doublespeak for "don't bloat namespace with incompatible winsock
71+
# versions that I didn't include".
72+
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms737629.aspx
73+
"WIN32_LEAN_AND_MEAN=1",
74+
75+
"PLATFORM_WINDOWS",
76+
],
77+
})
78+
79+
# Options for everything below
80+
all_options = [
81+
"-D_THREAD_SAFE",
82+
] + select({
83+
":windows_x86_64": ["/EHsc"],
84+
":linux_x86_64": [
85+
"-fexceptions",
86+
"-fno-common",
87+
"-Wno-unused-variable",
88+
"-Wno-unused-result",
89+
"-Wno-string-conversion",
90+
"-Wno-switch",
91+
"-Wno-tautological-compare",
92+
"-Wno-deprecated-register",
93+
# IlmImf/ImfHuf.cpp:111 wants to put a 21520 byte object on the stack.
94+
"$(STACK_FRAME_UNLIMITED)",
95+
],
96+
})
97+
98+
# Generates the config headers. Note we don't use the autoconf, but the
99+
# libraries still require a header.
100+
genrule(
101+
name = "configure_ilmbase",
102+
outs = ["IlmBase/config/IlmBaseConfig.h"],
103+
cmd = "touch $@",
104+
)
105+
106+
# Wraps the config header auto generation, then injects the desired defines and
107+
# include folder configuration.
108+
cc_library(
109+
name = "ilmbase_config",
110+
hdrs = [":configure_ilmbase"],
111+
defines = DEFINES,
112+
includes = ["IlmBase/config/"],
113+
)
114+
115+
################################################################################
116+
# Build the half library and its support components
117+
# ILM's libhalf is considered the reference implementation.
118+
half_path = "IlmBase/Half/"
119+
120+
cc_binary(
121+
name = "toFloat",
122+
srcs = [half_path + "toFloat.cpp"],
123+
copts = all_options,
124+
defines = DEFINES,
125+
)
126+
127+
cc_binary(
128+
name = "eLut",
129+
srcs = [half_path + "eLut.cpp"],
130+
copts = all_options,
131+
defines = DEFINES,
132+
)
133+
134+
genrule(
135+
name = "toFloatAutoGen",
136+
outs = [half_path + "toFloat.h"],
137+
# Runs the tool from its built location, and captures to the single output
138+
# of this rule.
139+
cmd = "$(location :toFloat) > $@",
140+
tools = [":toFloat"],
141+
)
142+
143+
genrule(
144+
name = "eLutAutoGen",
145+
outs = [half_path + "eLut.h"],
146+
# Runs the tool from its built location, and captures to the single output
147+
# of this rule.
148+
cmd = "$(location :eLut) > $@",
149+
tools = [":eLut"],
150+
)
151+
152+
cc_library(
153+
name = "half",
154+
srcs = glob([half_path + "half.cpp"]),
155+
copts = all_options,
156+
defines = DEFINES,
157+
includes = [half_path],
158+
textual_hdrs = glob([
159+
half_path + "half.h",
160+
half_path + "halfExport.h",
161+
half_path + "halfFunction.h",
162+
half_path + "halfLimits.h",
163+
]) + [
164+
":toFloatAutoGen",
165+
":eLutAutoGen",
166+
],
167+
deps = [":ilmbase_config"],
168+
)
169+
170+
################################################################################
171+
# Build the Iex library
172+
iex_path = "IlmBase/Iex/"
173+
174+
cc_library(
175+
name = "iex",
176+
srcs = glob([iex_path + "*.cpp"]),
177+
hdrs = glob([iex_path + "*.h"]),
178+
copts = all_options,
179+
defines = DEFINES,
180+
includes = [iex_path],
181+
deps = [":ilmbase_config"],
182+
)
183+
184+
################################################################################
185+
# Build the IexMath library
186+
iex_math_path = "IlmBase/IexMath/"
187+
188+
cc_library(
189+
name = "iex_math",
190+
srcs = glob([iex_math_path + "*.cpp"]),
191+
hdrs = glob([iex_math_path + "*.h"]),
192+
copts = all_options,
193+
includes = [iex_math_path],
194+
deps = [
195+
":half",
196+
":iex",
197+
],
198+
)
199+
200+
################################################################################
201+
# Build the IlmThread library and its tests components
202+
ilm_thread_path = "IlmBase/IlmThread/"
203+
204+
ilm_thread_win_srcs_pattern = ilm_thread_path + "*Win32.cpp"
205+
206+
ilm_thread_win_hdrs_pattern = ilm_thread_path + "*Win32.h"
207+
208+
cc_library(
209+
name = "ilm_thread",
210+
srcs = glob(
211+
[ilm_thread_path + "*.cpp"],
212+
exclude = [ilm_thread_win_srcs_pattern],
213+
) + select({
214+
":windows_x86_64": glob([ilm_thread_win_srcs_pattern]),
215+
":linux_x86_64": [],
216+
}),
217+
hdrs = glob(
218+
[ilm_thread_path + "*.h"],
219+
exclude = [ilm_thread_win_hdrs_pattern],
220+
) + select({
221+
":windows_x86_64": glob([ilm_thread_win_hdrs_pattern]),
222+
":linux_x86_64": [],
223+
}),
224+
copts = all_options,
225+
defines = DEFINES,
226+
includes = [
227+
ilm_thread_path,
228+
],
229+
deps = [
230+
":iex",
231+
":ilmbase_config",
232+
],
233+
)
234+
235+
################################################################################
236+
# Build the Imath library
237+
imath_path = "IlmBase/Imath/"
238+
239+
cc_library(
240+
name = "imath",
241+
srcs = glob([imath_path + "*.cpp"]),
242+
hdrs = glob([imath_path + "*.h"]),
243+
copts = all_options,
244+
defines = DEFINES,
245+
includes = [
246+
imath_path,
247+
],
248+
deps = [
249+
":half",
250+
":iex",
251+
":iex_math",
252+
":ilmbase_config",
253+
],
254+
)
255+
256+
################################################################################
257+
# Build the IlmImf library
258+
ilm_imf_path = "OpenEXR/IlmImf/"
259+
260+
ilm_imf_util_path = "OpenEXR/IlmImfUtil/"
261+
262+
# Generates the config headers. Note we don't use the autoconf, but the
263+
# libraries still require a header.
264+
genrule(
265+
name = "configure_openexr",
266+
outs = ["OpenEXR/config/OpenEXRConfig.h"],
267+
cmd = "touch $@",
268+
)
269+
270+
# Wraps the config auto generation with the include folder configuration.
271+
cc_library(
272+
name = "openexr_config",
273+
hdrs = [":configure_openexr"],
274+
defines = DEFINES,
275+
includes = ["OpenEXR/config/"],
276+
)
277+
278+
cc_binary(
279+
name = "dwaLookups",
280+
srcs = [
281+
ilm_imf_path + "dwaLookups.cpp",
282+
] +
283+
# Note we include various headers via glob since we don't have cc_library
284+
# targets for some of the sub-libraries of OpenEXR.
285+
glob([
286+
ilm_imf_util_path + "**/*.h",
287+
ilm_imf_path + "*.h",
288+
]),
289+
copts = all_options,
290+
defines = DEFINES,
291+
includes = [
292+
imath_path,
293+
iex_math_path,
294+
ilm_imf_path,
295+
ilm_imf_util_path,
296+
],
297+
deps = [
298+
":half",
299+
":iex",
300+
":ilm_thread",
301+
":imath",
302+
":openexr_config",
303+
],
304+
)
305+
306+
cc_binary(
307+
name = "b44ExpLogTable",
308+
srcs = [
309+
ilm_imf_path + "b44ExpLogTable.cpp",
310+
] + glob(["**/*.h"]),
311+
copts = all_options,
312+
defines = DEFINES,
313+
includes = [
314+
half_path,
315+
imath_path,
316+
iex_math_path,
317+
iex_path,
318+
ilm_imf_path,
319+
ilm_imf_util_path,
320+
ilm_thread_path,
321+
],
322+
deps = [
323+
":half",
324+
":iex",
325+
":ilm_thread",
326+
":openexr_config",
327+
],
328+
)
329+
330+
genrule(
331+
name = "dwaLookupsAutoGen",
332+
outs = [ilm_imf_path + "dwaLookups.h"],
333+
# Runs the tool from its built location, and captures to the single output
334+
# of this rule.
335+
cmd = "$(location :dwaLookups) > $@",
336+
tools = [":dwaLookups"],
337+
)
338+
339+
genrule(
340+
name = "b44ExpLogTableAutoGen",
341+
outs = [ilm_imf_path + "b44ExpLogTable.h"],
342+
# Runs the tool from its built location, and captures to the single output
343+
# of this rule.
344+
cmd = "$(location :b44ExpLogTable) > $@",
345+
tools = [":b44ExpLogTable"],
346+
)
347+
348+
cc_library(
349+
name = "ilm_imf",
350+
srcs = glob([ilm_imf_path + "Imf*.cpp"]) + [
351+
":dwaLookupsAutoGen",
352+
":b44ExpLogTableAutoGen",
353+
],
354+
hdrs = glob([ilm_imf_path + "Imf*.h"]),
355+
copts = all_options,
356+
defines = DEFINES,
357+
includes = [ilm_imf_path],
358+
deps = [
359+
":half",
360+
":iex",
361+
":iex_math",
362+
":ilm_thread",
363+
":imath",
364+
":openexr_config",
365+
"@zlib//:zlib"
366+
],
367+
)

‎third_party/zlib.BUILD

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright 2017 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS-IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Description:
16+
# Bazel build file for ZLib.
17+
18+
package(
19+
default_visibility = ["//visibility:public"],
20+
features = [
21+
"-layering_check",
22+
"-parse_headers",
23+
],
24+
)
25+
26+
genrule(
27+
name = "copy_zconf",
28+
srcs = ["zconf.h.in"],
29+
outs = ["zconf.h"],
30+
cmd_bat = "copy /b /Y $< $@",
31+
cmd = "cp $< $@",
32+
visibility = ["//visibility:private"],
33+
)
34+
35+
cc_library(
36+
name = "zconf",
37+
hdrs = [":copy_zconf"],
38+
visibility = ["//visibility:private"],
39+
)
40+
41+
cc_library(
42+
name = "zlib",
43+
srcs = [
44+
"adler32.c",
45+
"compress.c",
46+
"crc32.c",
47+
"deflate.c",
48+
"gzclose.c",
49+
"gzlib.c",
50+
"gzread.c",
51+
"gzwrite.c",
52+
"infback.c",
53+
"inffast.c",
54+
"inflate.c",
55+
"inftrees.c",
56+
"trees.c",
57+
"uncompr.c",
58+
"zutil.c",
59+
],
60+
includes = ["zconf.h"],
61+
hdrs = [
62+
"crc32.h",
63+
"deflate.h",
64+
"gzguts.h",
65+
"inffast.h",
66+
"inffixed.h",
67+
"inflate.h",
68+
"inftrees.h",
69+
"trees.h",
70+
"zlib.h",
71+
"zutil.h",
72+
"zconf.h"
73+
],
74+
deps = [":zconf"],
75+
visibility = ["//visibility:public"],
76+
)

0 commit comments

Comments
 (0)
Please sign in to comment.