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

Add HTJ2K Compressor #1883

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing bugs
  • Loading branch information
palemieux committed Oct 11, 2024
commit d6a673e33f8f799a55845cb4d4c29f312a326c25
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ cc_library(
"src/lib/OpenEXRCore/internal_float_vector.h",
"src/lib/OpenEXRCore/internal_ht.cpp",
"src/lib/OpenEXRCore/internal_htk.cpp",
"src/lib/OpenEXRCore/internal_ht_common.cpp",
"src/lib/OpenEXRCore/internal_huf.c",
"src/lib/OpenEXRCore/internal_huf.h",
"src/lib/OpenEXRCore/internal_memory.h",
Expand Down
1 change: 1 addition & 0 deletions src/lib/OpenEXRCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ openexr_define_library(OpenEXRCore
internal_piz.c
internal_ht.cpp
internal_htk.cpp
internal_ht_common.cpp
internal_dwa.c
internal_huf.c

Expand Down
67 changes: 6 additions & 61 deletions src/lib/OpenEXRCore/internal_ht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,7 @@
#include <ojph_codestream.h>

#include "openexr_compression.h"

int
make_channel_map (
int channel_count, exr_coding_channel_info_t* channels, int cs_to_file_ch[])
{
int r_index = -1;
int g_index = -1;
int b_index = -1;

for (size_t i = 0; i < channel_count; i++)
{
assert (channels[i].data_type == EXR_PIXEL_HALF);
assert (channels[i].x_samples == 1);
assert (channels[i].y_samples == 1);

char c_name = channels[i].channel_name[0];

if (c_name == 'R') { r_index = i; }
else if (c_name == 'G') { g_index = i; }
else if (c_name == 'B') { b_index = i; }
}

int isRGB;

if (r_index >= 0 && g_index >= 0 && b_index >= 0)
{
isRGB = 1;

cs_to_file_ch[0] = r_index;
cs_to_file_ch[1] = g_index;
cs_to_file_ch[2] = b_index;

int cs_i = 3;
for (size_t i = 0; i < channel_count; i++)
{
if (i != r_index && i != g_index && i != b_index)
{
cs_to_file_ch[cs_i++] = i;
}
}
}
else
{
isRGB = 0;

for (size_t i = 0; i < channel_count; i++)
{
cs_to_file_ch[i] = i;
}
}

return isRGB;
}
#include "internal_ht_common.h"

extern "C" exr_result_t
internal_exr_undo_ht (
Expand All @@ -84,9 +32,8 @@ internal_exr_undo_ht (
{
exr_result_t rv = EXR_ERR_SUCCESS;

assert (decode->channel_count <= 6);
int cs_to_file_ch[6];
int isRGB = make_channel_map (
std::vector<int> cs_to_file_ch (decode->channel_count);
bool isRGB = make_channel_map (
decode->channel_count, decode->channels, cs_to_file_ch);

ojph::mem_infile infile;
Expand Down Expand Up @@ -141,15 +88,13 @@ internal_exr_undo_ht (
return rv;
}

extern "C"
exr_result_t
extern "C" exr_result_t
internal_exr_apply_ht (exr_encode_pipeline_t* encode)
{
exr_result_t rv = EXR_ERR_SUCCESS;

assert (encode->channel_count <= 6);
int cs_to_file_ch[6];
int isRGB = make_channel_map (
std::vector<int> cs_to_file_ch(encode->channel_count);
bool isRGB = make_channel_map (
encode->channel_count, encode->channels, cs_to_file_ch);

int height = encode->channels[0].height;
Expand Down
73 changes: 73 additions & 0 deletions src/lib/OpenEXRCore/internal_ht_common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
** SPDX-License-Identifier: BSD-3-Clause
** Copyright Contributors to the OpenEXR Project.
*/

#include "internal_ht_common.h"

#include "internal_compress.h"
#include "internal_decompress.h"

#include "internal_coding.h"
#include "internal_structs.h"

#include <vector>
#include <string>

#include "openexr_compression.h"
#include <cassert>

bool
make_channel_map (
int channel_count, exr_coding_channel_info_t* channels, std::vector<int>& cs_to_file_ch)
{
int r_index = -1;
int g_index = -1;
int b_index = -1;

cs_to_file_ch.resize(channel_count);

for (size_t i = 0; i < channel_count; i++)
{
assert (channels[i].data_type == EXR_PIXEL_HALF);
assert (channels[i].x_samples == 1);
assert (channels[i].y_samples == 1);

std::string c_name(channels[i].channel_name);

if (c_name == "R") { r_index = i; }
else if (c_name == "G") { g_index = i; }
else if (c_name == "B") { b_index = i; }
}

bool isRGB;

if (r_index >= 0 && g_index >= 0 && b_index >= 0)
{
isRGB = true;

cs_to_file_ch[0] = r_index;
cs_to_file_ch[1] = g_index;
cs_to_file_ch[2] = b_index;

int cs_i = 3;
for (size_t i = 0; i < channel_count; i++)
{
if (i != r_index && i != g_index && i != b_index)
{
cs_to_file_ch[cs_i++] = i;
}
}
}
else
{
isRGB = false;

for (size_t i = 0; i < channel_count; i++)
{
cs_to_file_ch[i] = i;
}
}

return isRGB;
}
24 changes: 24 additions & 0 deletions src/lib/OpenEXRCore/internal_ht_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
** SPDX-License-Identifier: BSD-3-Clause
** Copyright Contributors to the OpenEXR Project.
*/

#ifndef OPENEXR_PRIVATE_HT_COMMON_H
#define OPENEXR_PRIVATE_HT_COMMON_H

#include "internal_compress.h"
#include "internal_decompress.h"

#include "internal_coding.h"
#include "internal_structs.h"

#include <vector>
#include <string>

#include "openexr_compression.h"

bool
make_channel_map (
int channel_count, exr_coding_channel_info_t* channels, std::vector<int>& cs_to_file_ch);

#endif /* OPENEXR_PRIVATE_HT_COMMON_H */
55 changes: 2 additions & 53 deletions src/lib/OpenEXRCore/internal_htk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "internal_coding.h"
#include "internal_structs.h"

#include "internal_ht_common.h"

#include <limits.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -68,60 +70,7 @@ class error_message_handler : public kdu_core::kdu_message {

static error_message_handler error_handler;

bool
make_channel_map (
int channel_count, exr_coding_channel_info_t* channels, std::vector<int>& cs_to_file_ch)
{
int r_index = -1;
int g_index = -1;
int b_index = -1;

cs_to_file_ch.resize(channel_count);

for (size_t i = 0; i < channel_count; i++)
{
assert (channels[i].data_type == EXR_PIXEL_HALF);
assert (channels[i].x_samples == 1);
assert (channels[i].y_samples == 1);

std::string c_name(channels[i].channel_name);

if (c_name == "R") { r_index = i; }
else if (c_name == "G") { g_index = i; }
else if (c_name == "B") { b_index = i; }
}

bool isRGB;

if (r_index >= 0 && g_index >= 0 && b_index >= 0)
{
isRGB = true;

cs_to_file_ch[0] = r_index;
cs_to_file_ch[1] = g_index;
cs_to_file_ch[2] = b_index;

int cs_i = 3;
for (size_t i = 0; i < channel_count; i++)
{
if (i != r_index && i != g_index && i != b_index)
{
cs_to_file_ch[cs_i++] = i;
}
}
}
else
{
isRGB = false;

for (size_t i = 0; i < channel_count; i++)
{
cs_to_file_ch[i] = i;
}
}

return isRGB;
}

extern "C" exr_result_t
internal_exr_undo_htk (
Expand Down
4 changes: 2 additions & 2 deletions src/test/OpenEXRTest/testCompressionApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ testCompressionApi (const string& tempDir)
cout << "Testing compression API functions." << endl;

// update this if you add a new compressor.
string codecList = "none/rle/zips/zip/piz/pxr24/b44/b44a/dwaa/dwab";
string codecList = "none/rle/zips/zip/piz/pxr24/b44/b44a/dwaa/dwab/ht/ht256/htk/htk256";

int numMethods = static_cast<int> (NUM_COMPRESSION_METHODS);
// update this if you add a new compressor.
assert (numMethods == 10);
assert (numMethods == 14);

for (int i = 0; i < numMethods; i++)
{
Expand Down