Skip to content

Commit

Permalink
Move tables, test logic to core now compression is moved
Browse files Browse the repository at this point in the history
Signed-off-by: Kimball Thurston <[email protected]>
  • Loading branch information
kdt3rd committed May 6, 2024
1 parent 0921b3c commit 0c734d3
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 14,705 deletions.
4 changes: 1 addition & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ cc_library(
"src/lib/IlmThread/IlmThreadConfig.h",
"src/lib/OpenEXR/OpenEXRConfig.h",
"src/lib/OpenEXR/OpenEXRConfigInternal.h",
"src/lib/OpenEXR/dwaLookups.h",
"src/lib/OpenEXRCore/attributes.c",
"src/lib/OpenEXRCore/backward_compatibility.h",
"src/lib/OpenEXRCore/base.c",
Expand Down Expand Up @@ -199,6 +198,7 @@ cc_library(
"src/lib/OpenEXRCore/internal_dwa_encoder.h",
"src/lib/OpenEXRCore/internal_dwa_helpers.h",
"src/lib/OpenEXRCore/internal_dwa_simd.h",
"src/lib/OpenEXRCore/dwaLookups.h",
"src/lib/OpenEXRCore/internal_file.h",
"src/lib/OpenEXRCore/internal_float_vector.h",
"src/lib/OpenEXRCore/internal_huf.c",
Expand Down Expand Up @@ -375,8 +375,6 @@ cc_library(
"src/lib/OpenEXR/ImfWav.cpp",
"src/lib/OpenEXR/ImfZip.cpp",
"src/lib/OpenEXR/ImfZipCompressor.cpp",
"src/lib/OpenEXR/b44ExpLogTable.h",
"src/lib/OpenEXR/dwaLookups.h",
],
hdrs = [
"src/lib/Iex/IexConfig.h",
Expand Down
2 changes: 0 additions & 2 deletions src/lib/OpenEXR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ openexr_define_library(OpenEXR
ImfTiledMisc.h
ImfZip.h
ImfZipCompressor.h
b44ExpLogTable.h
dwaLookups.h
ImfAcesFile.cpp
ImfAttribute.cpp
ImfB44Compressor.cpp
Expand Down
3 changes: 3 additions & 0 deletions src/lib/OpenEXR/b44ExpLogTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
//
// The tables are used by class B44Compressor.
//
// NB: the pre-computed table itself has moved to the core library,
// and made internal to the C library
//
//---------------------------------------------------------------------------

#include <half.h>
Expand Down
14,579 changes: 0 additions & 14,579 deletions src/lib/OpenEXR/b44ExpLogTable.h

This file was deleted.

3 changes: 3 additions & 0 deletions src/lib/OpenEXR/dwaLookups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// A program to generate various acceleration lookup tables
// for Imf::DwaCompressor
//
// NB: the pre-computed table itself has moved to the core library,
// being C-only
//

#include <cstddef>
#include <math.h>
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions src/lib/OpenEXRCore/internal_dwa_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#ifndef IMF_INTERNAL_DWA_HELPERS_H_HAS_BEEN_INCLUDED
#define IMF_INTERNAL_DWA_HELPERS_H_HAS_BEEN_INCLUDED

/* TODO: move to here when ready */
#include "../OpenEXR/dwaLookups.h"
#include "dwaLookups.h"

/**************************************/

Expand Down
3 changes: 3 additions & 0 deletions src/test/OpenEXRCoreTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_executable(OpenEXRCoreTest
buffer.cpp
buffer.h
compression.cpp
compressionTables.cpp
compression.h
deep.cpp
deep.h
Expand Down Expand Up @@ -104,6 +105,8 @@ define_openexrcore_tests(
testWriteDeep

testHUF
testDWATable
testB44Table
testNoCompression
testRLECompression
testZIPCompression
Expand Down
3 changes: 3 additions & 0 deletions src/test/OpenEXRCoreTest/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

void testHUF (const std::string& tempdir);

void testDWATable (const std::string& tempdir);
void testB44Table (const std::string& tempdir);

void testNoCompression (const std::string& tempdir);
void testRLECompression (const std::string& tempdir);
void testZIPCompression (const std::string& tempdir);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
//
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) Contributors to the OpenEXR Project.
//
// Copyright Contributors to the OpenEXR Project.

#include <assert.h>
#include <cstddef>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
// Windows specific addition to prevent the indirect import of the redefined min/max macros
#if defined _WIN32 || defined _WIN64
# ifdef NOMINMAX
# undef NOMINMAX
# endif
# define NOMINMAX
#endif

#include "compression.h"

#include "test_value.h"

#include <openexr.h>
#include <half.h>

#include <OpenEXRConfig.h>
#include <OpenEXRConfigInternal.h>
Expand All @@ -22,26 +28,31 @@
#endif

#include "ImfNamespace.h"
#include "dwaLookups.h"
#include <IlmThread.h>
#include <IlmThreadSemaphore.h>
#include <ImfIO.h>
#include <ImfXdr.h>
#include <half.h>
#include "IlmThread.h"
#include "IlmThreadSemaphore.h"
#include "ImfIO.h"
#include "ImfXdr.h"

//
// This test uses the code that generates the dwaLookups.h header to
// validate that the values in the tables are correct.
//
#include <cstddef>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace OPENEXR_IMF_NAMESPACE;
using namespace OPENEXR_IMF_NAMESPACE;
#if defined(OPENEXR_ENABLE_API_VISIBILITY)
#include "../../lib/OpenEXRCore/internal_b44_table.c"
#else
extern const uint16_t* exrcore_expTable;
extern const uint16_t* exrcore_logTable;
#endif

OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
namespace internal_test_ns {

#include "dwaLookups.h"
#include "../../lib/OpenEXRCore/dwaLookups.h"

OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
} // namespace internal_test_ns

using namespace OPENEXR_IMF_NAMESPACE;

namespace
{
Expand Down Expand Up @@ -221,14 +232,14 @@ class LutHeaderWorker
//
// Generate a no-op LUT, to cut down in conditional branches
//
void
static void
testNoop ()
{
printf ("test dwaCompressorNoOp[] \n");

for (unsigned int i = 0; i < 65536; ++i)
{
assert (i == OPENEXR_IMF_INTERNAL_NAMESPACE::dwaCompressorNoOp[i]);
EXRCORE_TEST (i == internal_test_ns::dwaCompressorNoOp[i]);
}
}

Expand Down Expand Up @@ -258,7 +269,7 @@ testNoop ()
// outputs XDR half values.
//

void
static void
testToLinear ()
{
unsigned short toLinear[65536];
Expand Down Expand Up @@ -304,12 +315,12 @@ testToLinear ()

printf ("test dwaCompressorToLinear[]\n");
for (int i = 0; i < 65536; ++i)
assert (
EXRCORE_TEST (
toLinear[i] ==
OPENEXR_IMF_INTERNAL_NAMESPACE::dwaCompressorToLinear[i]);
internal_test_ns::dwaCompressorToLinear[i]);
}

void
static void
testToNonlinear ()
{
unsigned short toNonlinear[65536];
Expand Down Expand Up @@ -358,16 +369,16 @@ testToNonlinear ()

printf ("test dwaCompressorToNonlinear[]\n");
for (int i = 0; i < 65536; ++i)
assert (
EXRCORE_TEST (
toNonlinear[i] ==
OPENEXR_IMF_INTERNAL_NAMESPACE::dwaCompressorToNonlinear[i]);
internal_test_ns::dwaCompressorToNonlinear[i]);
}

//
// Attempt to get available CPUs in a somewhat portable way.
//

int
static int
cpuCount ()
{
if (!ILMTHREAD_NAMESPACE::supportsThreads ()) return 1;
Expand Down Expand Up @@ -414,7 +425,7 @@ cpuCount ()
// can exit fairly quickly.
//

void
static void
testLutHeader ()
{
std::vector<LutHeaderWorker*> workers;
Expand Down Expand Up @@ -464,8 +475,8 @@ testLutHeader ()
{
for (size_t value = 0; value < workers[i]->numValues (); ++value)
{
assert (
OPENEXR_IMF_INTERNAL_NAMESPACE::closestDataOffset[offsetIdx] ==
EXRCORE_TEST (
internal_test_ns::closestDataOffset[offsetIdx] ==
workers[i]->offset ()[value] + offsetPrev);
offsetIdx++;
}
Expand All @@ -480,8 +491,8 @@ testLutHeader ()
for (size_t element = 0; element < workers[i]->numElements ();
++element)
{
assert (
OPENEXR_IMF_INTERNAL_NAMESPACE::closestData[elementIdx] ==
EXRCORE_TEST (
internal_test_ns::closestData[elementIdx] ==
workers[i]->elements ()[element]);
elementIdx++;
}
Expand All @@ -493,11 +504,49 @@ testLutHeader ()
}
}

////////////////////////////////////////

void
testDwaLookups (const std::string&)
testDWATable (const std::string&)
{
testNoop ();
testToLinear ();
testToNonlinear ();
testLutHeader ();
}

////////////////////////////////////////

void
testB44Table (const std::string&)
{
const int iMax = (1 << 16);

for (int i = 0; i < iMax; i++)
{
half h;
h.setBits (i);

if (!h.isFinite ())
h = 0;
else if (h >= 8 * log (HALF_MAX))
h = HALF_MAX;
else
h = exp (h / 8);

EXRCORE_TEST (exrcore_expTable[i] == h.bits ());
}

for (int i = 0; i < iMax; i++)
{
half h;
h.setBits (i);

if (!h.isFinite () || h < 0)
h = 0;
else
h = 8 * log (h);

EXRCORE_TEST (exrcore_logTable[i] == h.bits ());
}
}
2 changes: 2 additions & 0 deletions src/test/OpenEXRCoreTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ main (int argc, char* argv[])
TEST (testWriteDeep, "core_write");

TEST (testHUF, "core_compression");
TEST (testDWATable, "core_compression");
TEST (testB44Table, "core_compression");
TEST (testNoCompression, "core_compression");
TEST (testRLECompression, "core_compression");
TEST (testZIPCompression, "core_compression");
Expand Down
5 changes: 0 additions & 5 deletions src/test/OpenEXRTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ add_executable(OpenEXRTest
random.h
testAttributes.cpp
testAttributes.h
testB44ExpLogTable.cpp
testB44ExpLogTable.h
testBackwardCompatibility.cpp
testBackwardCompatibility.h
testBadTypeAttributes.cpp
Expand Down Expand Up @@ -51,8 +49,6 @@ add_executable(OpenEXRTest
testDeepScanLineMultipleRead.h
testDeepTiledBasic.cpp
testDeepTiledBasic.h
testDwaLookups.cpp
testDwaLookups.h
testExistingStreams.cpp
testExistingStreams.h
testFutureProofing.cpp
Expand Down Expand Up @@ -151,7 +147,6 @@ endfunction()

define_openexr_tests(
testAttributes
testB44ExpLogTable
testBackwardCompatibility
testBadTypeAttributes
testChannels
Expand Down
4 changes: 0 additions & 4 deletions src/test/OpenEXRTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "OpenEXRConfigInternal.h"

#include "testAttributes.h"
#include "testB44ExpLogTable.h"
#include "testBackwardCompatibility.h"
#include "testBadTypeAttributes.h"
#include "testChannels.h"
Expand All @@ -29,7 +28,6 @@
#include "testDeepScanLineHuge.h"
#include "testDeepScanLineMultipleRead.h"
#include "testDeepTiledBasic.h"
#include "testDwaLookups.h"
#include "testExistingStreams.h"
#include "testFutureProofing.h"
#include "testHeader.h"
Expand Down Expand Up @@ -229,8 +227,6 @@ main (int argc, char* argv[])
TEST (testBackwardCompatibility, "core");
TEST (testFutureProofing, "core");
TEST (testRle, "core");
TEST (testB44ExpLogTable, "core");
TEST (testDwaLookups, "core");
TEST (testIDManifest, "core");
TEST (testCpuId, "core");
TEST (testHeader, "basic");
Expand Down
Loading

0 comments on commit 0c734d3

Please sign in to comment.