Skip to content

Commit

Permalink
Add libultrahdr java wrapper
Browse files Browse the repository at this point in the history
This changes introduces jni wrapper and java front end classes for uhdr
api.

Co-authored-by: Ram Mohan M <[email protected]>

Change-Id: Icfd82938269cfceff2527847aa14cc0cc7493b7d
  • Loading branch information
ram-mohan committed Aug 26, 2024
1 parent bddf8da commit a87007b
Show file tree
Hide file tree
Showing 7 changed files with 2,108 additions and 2 deletions.
42 changes: 40 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ endif()
###########################################################
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
set(JAVA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/java)
set(TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
set(BENCHMARK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/benchmark)
set(FUZZERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fuzzer)
Expand Down Expand Up @@ -94,9 +95,10 @@ option_if_not_defined(UHDR_BUILD_BENCHMARK "Build benchmark " FALSE)
option_if_not_defined(UHDR_BUILD_FUZZERS "Build fuzzers " FALSE)
option_if_not_defined(UHDR_BUILD_DEPS "Build deps and not use pre-installed packages " FALSE)
option_if_not_defined(UHDR_ENABLE_LOGS "Build with verbose logging " FALSE)
option_if_not_defined(UHDR_ENABLE_INSTALL "Add install and uninstall targets for libuhdr package" TRUE)
option_if_not_defined(UHDR_ENABLE_INSTALL "Add install and uninstall targets for libuhdr package " TRUE)
option_if_not_defined(UHDR_ENABLE_INTRINSICS "Build with intrinsics " TRUE)
option_if_not_defined(UHDR_ENABLE_GLES "Build with gpu acceleration " TRUE)
option_if_not_defined(UHDR_BUILD_JAVA "Build jni wrapper and java util classes " FALSE)

# pre-requisites
if(UHDR_BUILD_TESTS AND EMSCRIPTEN)
Expand Down Expand Up @@ -382,6 +384,23 @@ if(NOT JPEG_FOUND)
endif()
endif()

if(UHDR_BUILD_JAVA)
# build jni and java util classes
find_package(Java REQUIRED)
if(${CMAKE_SYSTEM_NAME} MATCHES "Android")
find_package(JNI QUIET)
if(NOT JAVA_INCLUDE_PATH)
message(FATAL_ERROR "Could NOT find JNI Component")
else()
message(STATUS "Found JNI Component")
endif()
set(UHDR_JNI_INCLUDE_PATH ${JAVA_INCLUDE_PATH})
else()
find_package(JNI REQUIRED)
set(UHDR_JNI_INCLUDE_PATH ${JNI_INCLUDE_DIRS})
endif()
endif()

if(UHDR_BUILD_TESTS)
# gtest and gmock
set(GTEST_TARGET_NAME googletest)
Expand Down Expand Up @@ -457,6 +476,10 @@ if(UHDR_ENABLE_GLES)
file(GLOB UHDR_CORE_GLES_SRCS_LIST "${SOURCE_DIR}/src/gpu/*.cpp")
list(APPEND UHDR_CORE_SRCS_LIST ${UHDR_CORE_GLES_SRCS_LIST})
endif()
if(UHDR_BUILD_JAVA)
file(GLOB UHDR_JNI_SRCS_LIST "${JAVA_DIR}/jni/*.cpp")
file(GLOB UHDR_JAVA_SRCS_LIST "${JAVA_DIR}/com/google/media/codecs/ultrahdr/*.java")
endif()
file(GLOB UHDR_TEST_SRCS_LIST "${TESTS_DIR}/*.cpp")
file(GLOB UHDR_BM_SRCS_LIST "${BENCHMARK_DIR}/*.cpp")
file(GLOB IMAGE_IO_SRCS_LIST "${THIRD_PARTY_DIR}/image_io/src/**/*.cc")
Expand Down Expand Up @@ -617,9 +640,24 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Android")
target_link_libraries(${UHDR_TARGET_NAME} PRIVATE ${log-lib})
endif()
target_link_libraries(${UHDR_TARGET_NAME} PRIVATE ${JPEG_LIBRARIES})
set_target_properties(${UHDR_TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} PUBLIC_HEADER ultrahdr_api.h)
set_target_properties(${UHDR_TARGET_NAME}
PROPERTIES VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER ultrahdr_api.h)
combine_static_libs(${UHDR_CORE_LIB_NAME} ${UHDR_TARGET_NAME})

if(UHDR_BUILD_JAVA)
include(UseJava)

set(UHDR_JNI_TARGET_NAME uhdrjni)
add_library(${UHDR_JNI_TARGET_NAME} SHARED ${UHDR_JNI_SRCS_LIST})
add_dependencies(${UHDR_JNI_TARGET_NAME} ${UHDR_TARGET_NAME})
target_include_directories(${UHDR_JNI_TARGET_NAME} PRIVATE ${UHDR_JNI_INCLUDE_PATH} ${EXPORT_INCLUDE_DIR})
target_link_libraries(${UHDR_JNI_TARGET_NAME} PRIVATE ${UHDR_TARGET_NAME})

add_jar(uhdr-java SOURCES ${UHDR_JAVA_SRCS_LIST})
endif()

if(UHDR_ENABLE_INSTALL)
if(NOT(MSVC OR XCODE))
include(GNUInstallDirs)
Expand Down
201 changes: 201 additions & 0 deletions java/com/google/media/codecs/ultrahdr/UltraHDRCommon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.media.codecs.ultrahdr;

/**
* Ultra HDR common utility class (cannot be instantiated)
*/
public class UltraHDRCommon {
// Fields describing the color format of raw input
/**
* Unspecified color format
*/
public static final int UHDR_IMG_FMT_UNSPECIFIED = -1;

/**
* P010 is 10-bit-per component 4:2:0 YCbCr semiplanar format.
* <p>
* This format uses 24 allocated bits per pixel with 15 bits of
* data per pixel. Chroma planes are subsampled by 2 both
* horizontally and vertically. Each chroma and luma component
* has 16 allocated bits in little-endian configuration with 10
* MSB of actual data.
*
* <pre>
* byte byte
* <--------- i --------> | <------ i + 1 ------>
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | UNUSED | Y/Cb/Cr |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* 0 5 6 7 0 7
* bit
* </pre>
*/
public static final int UHDR_IMG_FMT_24bppYCbCrP010 = 0;

/**
* Flexible 12 bits per pixel, subsampled YUV color format with 8-bit chroma and luma
* components.
* <p>
* Chroma planes are subsampled by 2 both horizontally and vertically.
*/
public static final int UHDR_IMG_FMT_12bppYCbCr420 = 1;

/**
* 8 bits per pixel Y color format.
* <p>
* Each byte contains a single pixel.
*/
public static final int UHDR_IMG_FMT_8bppYCbCr400 = 2;

/**
* 32 bits per pixel RGBA color format, with 8-bit red, green, blue, and alpha components.
* <p>
* Using 32-bit little-endian representation, colors stored as Red 7:0, Green 15:8,
* Blue 23:16, and Alpha 31:24.
* <pre>
* byte byte byte byte
* <------ i -----> | <---- i+1 ----> | <---- i+2 ----> | <---- i+3 ----->
* +-----------------+-----------------+-----------------+-----------------+
* | RED | GREEN | BLUE | ALPHA |
* +-----------------+-----------------+-----------------+-----------------+
* </pre>
*/
public static final int UHDR_IMG_FMT_32bppRGBA8888 = 3;

/**
* 64 bits per pixel RGBA color format, with 16-bit signed
* floating point red, green, blue, and alpha components.
* <p>
*
* <pre>
* byte byte byte byte
* <-- i -->|<- i+1 ->|<- i+2 ->|<- i+3 ->|<- i+4 ->|<- i+5 ->|<- i+6 ->|<- i+7 ->
* +---------+---------+-------------------+---------+---------+---------+---------+
* | RED | GREEN | BLUE | ALPHA |
* +---------+---------+-------------------+---------+---------+---------+---------+
* 0 7 0 7 0 7 0 7 0 7 0 7 0 7 0 7
* </pre>
*/
public static final int UHDR_IMG_FMT_64bppRGBAHalfFloat = 4;

/**
* 32 bits per pixel RGBA color format, with 10-bit red, green,
* blue, and 2-bit alpha components.
* <p>
* Using 32-bit little-endian representation, colors stored as
* Red 9:0, Green 19:10, Blue 29:20, and Alpha 31:30.
* <pre>
* byte byte byte byte
* <------ i -----> | <---- i+1 ----> | <---- i+2 ----> | <---- i+3 ----->
* +-----------------+---+-------------+-------+---------+-----------+-----+
* | RED | GREEN | BLUE |ALPHA|
* +-----------------+---+-------------+-------+---------+-----------+-----+
* 0 7 0 1 2 7 0 3 4 7 0 5 6 7
* </pre>
*/
public static final int UHDR_IMG_FMT_32bppRGBA1010102 = 5;

// Fields describing the color primaries of the content
/**
* Unspecified color gamut
*/
public static final int UHDR_CG_UNSPECIFIED = -1;

/**
* BT.709 color chromaticity coordinates with KR = 0.2126, KB = 0.0722
*/
public static final int UHDR_CG_BT709 = 0;

/**
* Display P3 color chromaticity coordinates with KR = 0.22897, KB = 0.07929
*/
public static final int UHDR_CG_DISPlAY_P3 = 1;

/**
* BT.2020 color chromaticity coordinates with KR = 0.2627, KB = 0.0593
*/
public static final int UHDR_CG_BT2100 = 2;

// Fields describing the opto-electronic transfer function of the content
/**
* Unspecified color transfer
*/
public static final int UHDR_CT_UNSPECIFIED = -1;

/**
* Linear transfer characteristic curve
*/
public static final int UHDR_CT_LINEAR = 0;

/**
* hybrid-log-gamma transfer function
*/
public static final int UHDR_CT_HLG = 1;

/**
* PQ transfer function
*/
public static final int UHDR_CT_PQ = 2;

/**
* sRGB transfer function
*/
public static final int UHDR_CT_SRGB = 3;

// Fields describing the data range of the content
/**
* Unspecified color range
*/
public static final int UHDR_CR_UNSPECIFIED = -1;

/**
* Limited range. Y component values range from [16 - 235] * pow(2, (bpc - 8)) and Cb, Cr
* component values range from [16 - 240] * pow(2, (bpc - 8)). Here, bpc is bits per channel
*/
public static final int UHDR_CR_LIMITED_RANGE = 0;

/**
* Full range. Y component values range from [0 - 255] * pow(2, (bpc - 8)) and Cb, Cr
* component values range from [0 - 255] * pow(2, (bpc - 8)). Here, bpc is bits per channel
*/
public static final int UHDR_CR_FULL_RANGE = 1;

// Fields describing the technology associated with the content
/**
* Hdr rendition of an image
*/
public static final int UHDR_HDR_IMG = 0;

/**
* Sdr rendition of an image
*/
public static final int UHDR_SDR_IMG = 1;

/**
* Base rendition of an ultrahdr image
*/
public static final int UHDR_BASE_IMG = 2;

/**
* GainMap rendition of an ultrahdr image
*/
public static final int UHDR_GAIN_MAP_IMG = 3;

private UltraHDRCommon() {
}
}
Loading

0 comments on commit a87007b

Please sign in to comment.