1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.media.codecs.ultrahdr; 18 19 import static com.google.media.codecs.ultrahdr.UltraHDRCommon.UHDR_IMG_FMT_12bppYCbCr420; 20 import static com.google.media.codecs.ultrahdr.UltraHDRCommon.UHDR_IMG_FMT_24bppYCbCrP010; 21 import static com.google.media.codecs.ultrahdr.UltraHDRCommon.UHDR_IMG_FMT_32bppRGBA1010102; 22 import static com.google.media.codecs.ultrahdr.UltraHDRCommon.UHDR_IMG_FMT_32bppRGBA8888; 23 import static com.google.media.codecs.ultrahdr.UltraHDRCommon.UHDR_IMG_FMT_64bppRGBAHalfFloat; 24 25 import java.io.IOException; 26 27 /** 28 * Ultra HDR encoding utility class. 29 */ 30 public class UltraHDREncoder implements AutoCloseable { 31 32 // Fields describing the compression technology used to encode the content 33 /** 34 * Compress {Hdr, Sdr rendition} to an {Sdr rendition + Gain Map} using jpeg 35 */ 36 public static final int UHDR_CODEC_JPG = 0; 37 38 /** 39 * Compress {Hdr, Sdr rendition} to an {Sdr rendition + Gain Map} using heif 40 */ 41 public static final int UHDR_CODEC_HEIF = 1; 42 43 /** 44 * Compress {Hdr, Sdr rendition} to an {Sdr rendition + Gain Map} using avif 45 */ 46 public static final int UHDR_CODEC_AVIF = 2; 47 48 // Fields describing the encoder tuning configurations 49 /** 50 * Tune encoder settings for best performance 51 */ 52 public static final int UHDR_USAGE_REALTIME = 0; 53 54 /** 55 * Tune encoder settings for best quality 56 */ 57 public static final int UHDR_USAGE_BEST_QUALITY = 1; 58 59 // APIs 60 61 /** 62 * Create and Initialize an ultrahdr encoder instance 63 * 64 * @throws IOException If the codec cannot be created then exception is thrown 65 */ UltraHDREncoder()66 public UltraHDREncoder() throws IOException { 67 handle = 0; 68 init(); 69 } 70 71 /** 72 * Release current ultrahdr encoder instance 73 * 74 * @throws Exception During release, if errors are seen, then exception is thrown 75 */ 76 @Override close()77 public void close() throws Exception { 78 destroy(); 79 } 80 81 /** 82 * Add raw image info to encoder context. This interface is used for adding 32 bits-per-pixel 83 * packed formats. The function goes through all the arguments and checks for their sanity. 84 * If no anomalies are seen then the image info is added to internal list. Repeated calls to 85 * this function will replace the old entry with the current. 86 * 87 * @param rgbBuff rgb buffer handle 88 * @param width image width 89 * @param height image height 90 * @param rgbStride rgb buffer stride 91 * @param colorGamut color gamut of input image 92 * @param colorTransfer color transfer of input image 93 * @param colorRange color range of input image 94 * @param colorFormat color format of input image 95 * @param intent {@link UltraHDRCommon#UHDR_HDR_IMG} for hdr intent, 96 * {@link UltraHDRCommon#UHDR_SDR_IMG} for sdr intent 97 * @throws IOException If parameters are not valid or current encoder instance is not valid 98 * or current encoder instance is not suitable for configuration 99 * exception is thrown 100 */ setRawImage(int[] rgbBuff, int width, int height, int rgbStride, int colorGamut, int colorTransfer, int colorRange, int colorFormat, int intent)101 public void setRawImage(int[] rgbBuff, int width, int height, int rgbStride, int colorGamut, 102 int colorTransfer, int colorRange, int colorFormat, int intent) throws IOException { 103 if (rgbBuff == null) { 104 throw new IOException("received null for image data handle"); 105 } 106 if (width <= 0 || height <= 0) { 107 throw new IOException("received bad width and/or height, width or height is <= 0"); 108 } 109 if (rgbStride <= 0) { 110 throw new IOException("received bad stride, stride is <= 0"); 111 } 112 if (colorFormat != UHDR_IMG_FMT_32bppRGBA8888 113 && colorFormat != UHDR_IMG_FMT_32bppRGBA1010102) { 114 throw new IOException("received unsupported color format. supported color formats are" 115 + "{UHDR_IMG_FMT_32bppRGBA8888, UHDR_IMG_FMT_32bppRGBA1010102}"); 116 } 117 setRawImageNative(rgbBuff, width, height, rgbStride, colorGamut, colorTransfer, colorRange, 118 colorFormat, intent); 119 } 120 121 /** 122 * Add raw image info to encoder context. This interface is used for adding 64 bits-per-pixel 123 * packed formats. The function goes through all the arguments and checks for their sanity. 124 * If no anomalies are seen then the image info is added to internal list. Repeated calls to 125 * this function will replace the old entry with the current. 126 * 127 * @param rgbBuff rgb buffer handle 128 * @param width image width 129 * @param height image height 130 * @param rgbStride rgb buffer stride 131 * @param colorGamut color gamut of input image 132 * @param colorTransfer color transfer of input image 133 * @param colorRange color range of input image 134 * @param colorFormat color format of input image 135 * @param intent {@link UltraHDRCommon#UHDR_HDR_IMG} for hdr intent 136 * @throws IOException If parameters are not valid or current encoder instance is not valid 137 * or current encoder instance is not suitable for configuration 138 * exception is thrown 139 */ setRawImage(long[] rgbBuff, int width, int height, int rgbStride, int colorGamut, int colorTransfer, int colorRange, int colorFormat, int intent)140 public void setRawImage(long[] rgbBuff, int width, int height, int rgbStride, int colorGamut, 141 int colorTransfer, int colorRange, int colorFormat, int intent) throws IOException { 142 if (rgbBuff == null) { 143 throw new IOException("received null for image data handle"); 144 } 145 if (width <= 0 || height <= 0) { 146 throw new IOException("received bad width and/or height, width or height is <= 0"); 147 } 148 if (rgbStride <= 0) { 149 throw new IOException("received bad stride, stride is <= 0"); 150 } 151 if (colorFormat != UHDR_IMG_FMT_64bppRGBAHalfFloat) { 152 throw new IOException("received unsupported color format. supported color formats are" 153 + "{UHDR_IMG_FMT_64bppRGBAHalfFloat}"); 154 } 155 setRawImageNative(rgbBuff, width, height, rgbStride, colorGamut, colorTransfer, colorRange, 156 colorFormat, intent); 157 } 158 159 /** 160 * Add raw image info to encoder context. This interface is used for adding 16 bits-per-sample 161 * pixel formats. The function goes through all the arguments and checks for their sanity. If 162 * no anomalies are seen then the image info is added to internal list. Repeated calls to 163 * this function will replace the old entry with the current. 164 * 165 * @param yBuff luma buffer handle 166 * @param uvBuff Chroma buffer handle 167 * @param width image width 168 * @param height image height 169 * @param yStride luma buffer stride 170 * @param uvStride Chroma buffer stride 171 * @param colorGamut color gamut of input image 172 * @param colorTransfer color transfer of input image 173 * @param colorRange color range of input image 174 * @param colorFormat color format of input image 175 * @param intent {@link UltraHDRCommon#UHDR_HDR_IMG} for hdr intent 176 * @throws IOException If parameters are not valid or current encoder instance is not valid 177 * or current encoder instance is not suitable for configuration 178 * exception is thrown 179 */ setRawImage(short[] yBuff, short[] uvBuff, int width, int height, int yStride, int uvStride, int colorGamut, int colorTransfer, int colorRange, int colorFormat, int intent)180 public void setRawImage(short[] yBuff, short[] uvBuff, int width, int height, 181 int yStride, int uvStride, int colorGamut, int colorTransfer, 182 int colorRange, int colorFormat, int intent) throws IOException { 183 if (yBuff == null || uvBuff == null) { 184 throw new IOException("received null for image data handle"); 185 } 186 if (width <= 0 || height <= 0) { 187 throw new IOException("received bad width and/or height, width or height is <= 0"); 188 } 189 if (yStride <= 0 || uvStride <= 0) { 190 throw new IOException("received bad stride, stride is <= 0"); 191 } 192 if (colorFormat != UHDR_IMG_FMT_24bppYCbCrP010) { 193 throw new IOException("received unsupported color format. supported color formats are" 194 + "{UHDR_IMG_FMT_24bppYCbCrP010}"); 195 } 196 setRawImageNative(yBuff, uvBuff, width, height, yStride, uvStride, colorGamut, 197 colorTransfer, colorRange, colorFormat, intent); 198 } 199 200 /** 201 * Add raw image info to encoder context. This interface is used for adding 8 bits-per-sample 202 * pixel formats. The function goes through all the arguments and checks for their sanity. If 203 * no anomalies are seen then the image info is added to internal list. Repeated calls to 204 * this function will replace the old entry with the current. 205 * 206 * @param yBuff luma buffer handle 207 * @param uBuff Cb buffer handle 208 * @param vBuff Cr buffer handle 209 * @param width image width 210 * @param height image height 211 * @param yStride luma buffer stride 212 * @param uStride Cb buffer stride 213 * @param vStride Cr buffer stride 214 * @param colorGamut color gamut of input image 215 * @param colorTransfer color transfer of input image 216 * @param colorRange color range of input image 217 * @param colorFormat color format of input image 218 * @param intent {@link UltraHDRCommon#UHDR_SDR_IMG} for sdr intent 219 * @throws IOException If parameters are not valid or current encoder instance is not valid 220 * or current encoder instance is not suitable for configuration 221 * exception is thrown 222 */ setRawImage(byte[] yBuff, byte[] uBuff, byte[] vBuff, int width, int height, int yStride, int uStride, int vStride, int colorGamut, int colorTransfer, int colorRange, int colorFormat, int intent)223 public void setRawImage(byte[] yBuff, byte[] uBuff, byte[] vBuff, int width, int height, 224 int yStride, int uStride, int vStride, int colorGamut, int colorTransfer, 225 int colorRange, int colorFormat, int intent) throws IOException { 226 if (yBuff == null || uBuff == null || vBuff == null) { 227 throw new IOException("received null for image data handle"); 228 } 229 if (width <= 0 || height <= 0) { 230 throw new IOException("received bad width and/or height, width or height is <= 0"); 231 } 232 if (yStride <= 0 || uStride <= 0 || vStride <= 0) { 233 throw new IOException("received bad stride, stride is <= 0"); 234 } 235 if (colorFormat != UHDR_IMG_FMT_12bppYCbCr420) { 236 throw new IOException("received unsupported color format. supported color formats are" 237 + "{UHDR_IMG_FMT_12bppYCbCr420}"); 238 } 239 setRawImageNative(yBuff, uBuff, vBuff, width, height, yStride, uStride, vStride, colorGamut, 240 colorTransfer, colorRange, colorFormat, intent); 241 } 242 243 /** 244 * Add compressed image info to encoder context. The function goes through all the arguments 245 * and checks for their sanity. If no anomalies are seen then the image info is added to 246 * internal list. Repeated calls to this function will replace the old entry with the current. 247 * <p> 248 * If both {@link UltraHDREncoder#setRawImage} and this function are called during a session 249 * for the same intent, it is assumed that raw image descriptor and compressed image 250 * descriptor are relatable via compress <-> decompress process. 251 * 252 * @param data byteArray containing compressed image data 253 * @param size compressed image size 254 * @param colorGamut color standard of the image. Certain image formats are capable of 255 * storing color standard information in the bitstream, for instance heif. 256 * Some formats are not capable of storing the same. This field can be used 257 * as an additional source to convey this information. If unknown, this can 258 * be set to {@link UltraHDRCommon#UHDR_CG_UNSPECIFIED}. 259 * @param colorTransfer color transfer of the image. Just like colorGamut parameter, this 260 * field can be used as an additional source to convey image transfer 261 * characteristics. If unknown, this can be set to 262 * {@link UltraHDRCommon#UHDR_CT_UNSPECIFIED}. 263 * @param range color range. Just like colorGamut parameter, this field can be used 264 * as an additional source to convey color range characteristics. If 265 * unknown, this can be set to {@link UltraHDRCommon#UHDR_CR_UNSPECIFIED}. 266 * @param intent {@link UltraHDRCommon#UHDR_HDR_IMG} for hdr intent, 267 * {@link UltraHDRCommon#UHDR_SDR_IMG} for sdr intent, 268 * {@link UltraHDRCommon#UHDR_BASE_IMG} for base image intent 269 * @throws IOException If parameters are not valid or current encoder instance is not valid 270 * or current encoder instance is not suitable for configuration 271 * exception is thrown 272 */ setCompressedImage(byte[] data, int size, int colorGamut, int colorTransfer, int range, int intent)273 public void setCompressedImage(byte[] data, int size, int colorGamut, int colorTransfer, 274 int range, int intent) throws IOException { 275 if (data == null) { 276 throw new IOException("received null for image data handle"); 277 } 278 if (size <= 0) { 279 throw new IOException("received invalid compressed image size, size is <= 0"); 280 } 281 setCompressedImageNative(data, size, colorGamut, colorTransfer, range, intent); 282 } 283 284 /** 285 * Add gain map image descriptor and gainmap metadata info that was used to generate the 286 * aforth gainmap image to encoder context. The function internally goes through all the 287 * arguments and checks for their sanity. If no anomalies are seen then the image is added to 288 * internal list. Repeated calls to this function will replace the old entry with the current. 289 * <p> 290 * NOTE: There are apis that allow configuration of gainmap info separately. For instance 291 * {@link UltraHDREncoder#setGainMapGamma(float)}, 292 * {@link UltraHDREncoder#setGainMapScaleFactor(int)}, ... They have no effect on the 293 * information that is configured via this api. The information configured here is treated as 294 * immutable and used as-is in encoding scenario where gainmap computations are intended to 295 * be by-passed. 296 * 297 * @param data byteArray containing compressed image data 298 * @param size compressed image size 299 * @param maxContentBoost value to control how much brighter an image can get, when shown on 300 * an HDR display, relative to the SDR rendition. This is constant for 301 * a given image. Value MUST be in linear scale. 302 * @param minContentBoost value to control how much darker an image can get, when shown on 303 * an HDR display, relative to the SDR rendition. This is constant for 304 * a given image. Value MUST be in linear scale. 305 * @param gainmapGamma Encoding gamma of gainmap image. 306 * @param offsetSdr The offset to apply to the SDR pixel values during gainmap 307 * generation and application. 308 * @param offsetHdr The offset to apply to the HDR pixel values during gainmap 309 * generation and application. 310 * @param hdrCapacityMin Minimum display boost value for which the map is applied completely. 311 * Value MUST be in linear scale. 312 * @param hdrCapacityMax Maximum display boost value for which the map is applied completely. 313 * Value MUST be in linear scale. 314 * @throws IOException If parameters are not valid or current encoder instance is not valid 315 * or current encoder instance is not suitable for configuration 316 * exception is thrown 317 */ setGainMapImageInfo(byte[] data, int size, float maxContentBoost, float minContentBoost, float gainmapGamma, float offsetSdr, float offsetHdr, float hdrCapacityMin, float hdrCapacityMax)318 public void setGainMapImageInfo(byte[] data, int size, float maxContentBoost, 319 float minContentBoost, float gainmapGamma, float offsetSdr, float offsetHdr, 320 float hdrCapacityMin, float hdrCapacityMax) throws IOException { 321 if (data == null) { 322 throw new IOException("received null for image data handle"); 323 } 324 if (size <= 0) { 325 throw new IOException("received invalid compressed image size, size is <= 0"); 326 } 327 setGainMapImageInfoNative(data, size, maxContentBoost, minContentBoost, gainmapGamma, 328 offsetSdr, offsetHdr, hdrCapacityMin, hdrCapacityMax); 329 } 330 331 /** 332 * Set Exif data that needs to be inserted in the output compressed stream. This function 333 * does not generate or validate exif data on its own. It merely copies the supplied 334 * information into the bitstream. 335 * 336 * @param data exif data 337 * @param size exif size 338 * @throws IOException If parameters are not valid or current encoder instance is not valid 339 * or current encoder instance is not suitable for configuration 340 * exception is thrown 341 */ setExifData(byte[] data, int size)342 public void setExifData(byte[] data, int size) throws IOException { 343 if (data == null) { 344 throw new IOException("received null for exif data handle"); 345 } 346 if (size <= 0) { 347 throw new IOException("received invalid compressed image size, size is <= 0"); 348 } 349 setExifDataNative(data, size); 350 } 351 352 /** 353 * Set quality factor for compressing base image and/or gainmap image. Default configured 354 * quality factor of base image and gainmap image are 95 and 95 respectively. 355 * 356 * @param qualityFactor Any integer in range [0 - 100] 357 * @param intent {@link UltraHDRCommon#UHDR_BASE_IMG} or 358 * {@link UltraHDRCommon#UHDR_GAIN_MAP_IMG} 359 * @throws IOException If parameters are not valid or current encoder instance is not valid 360 * or current encoder instance is not suitable for configuration 361 * exception is thrown 362 */ setQualityFactor(int qualityFactor, int intent)363 public void setQualityFactor(int qualityFactor, int intent) throws IOException { 364 setQualityFactorNative(qualityFactor, intent); 365 } 366 367 /** 368 * Enable/Disable multi-channel gainmap. By default, multi-channel gainmap is enabled. 369 * 370 * @param enable if true, multi-channel gainmap is enabled, else, single-channel gainmap is 371 * enabled 372 * @throws IOException If parameters are not valid or current encoder instance is not valid 373 * or current encoder instance is not suitable for configuration 374 * exception is thrown 375 */ setMultiChannelGainMapEncoding(boolean enable)376 public void setMultiChannelGainMapEncoding(boolean enable) throws IOException { 377 setMultiChannelGainMapEncodingNative(enable); 378 } 379 380 /** 381 * Set gain map scaling factor. The encoding process allows signalling a downscaled gainmap 382 * image instead of full resolution. This setting controls the factor by which the renditions 383 * are downscaled. For instance, gain_map_scale_factor = 2 implies gainmap_image_width = 384 * primary_image_width / 2 and gainmap image height = primary_image_height / 2. 385 * Default gain map scaling factor is 1. 386 * <p> 387 * NOTE: This has no effect on base image rendition. Base image is signalled in full resolution 388 * always. 389 * 390 * @param scaleFactor gain map scale factor. Any integer in range (0, 128] 391 * @throws IOException If parameters are not valid or current encoder instance is not valid 392 * or current encoder instance is not suitable for configuration 393 * exception is thrown 394 */ setGainMapScaleFactor(int scaleFactor)395 public void setGainMapScaleFactor(int scaleFactor) throws IOException { 396 setGainMapScaleFactorNative(scaleFactor); 397 } 398 399 /** 400 * Set encoding gamma of gainmap image. For multi-channel gainmap image, set gamma is used 401 * for gamma correction of all planes separately. Default gamma value is 1.0. 402 * 403 * @param gamma gamma of gainmap image. Any positive real number 404 * @throws IOException If parameters are not valid or current encoder instance is not valid 405 * or current encoder instance is not suitable for configuration 406 * exception is thrown 407 */ setGainMapGamma(float gamma)408 public void setGainMapGamma(float gamma) throws IOException { 409 setGainMapGammaNative(gamma); 410 } 411 412 /** 413 * Set encoding preset. Tunes the encoder configurations for performance or quality. Default 414 * configuration is {@link UltraHDREncoder#UHDR_USAGE_BEST_QUALITY}. 415 * 416 * @param preset encoding preset. {@link UltraHDREncoder#UHDR_USAGE_REALTIME} for best 417 * performance {@link UltraHDREncoder#UHDR_USAGE_BEST_QUALITY} for best quality 418 * @throws IOException If parameters are not valid or current encoder instance is not valid 419 * or current encoder instance is not suitable for configuration 420 * exception is thrown 421 */ setEncPreset(int preset)422 public void setEncPreset(int preset) throws IOException { 423 setEncPresetNative(preset); 424 } 425 426 /** 427 * Set output image compression format. Selects the compression format for encoding base 428 * image and gainmap image. Default configuration is {@link UltraHDREncoder#UHDR_CODEC_JPG}. 429 * 430 * @param mediaType output image compression format. Supported values are 431 * {@link UltraHDREncoder#UHDR_CODEC_JPG} 432 * @throws IOException If parameters are not valid or current encoder instance is not valid 433 * or current encoder instance is not suitable for configuration 434 * exception is thrown 435 */ setOutputFormat(int mediaType)436 public void setOutputFormat(int mediaType) throws IOException { 437 setOutputFormatNative(mediaType); 438 } 439 440 /** 441 * Set min max content boost. This configuration is treated as a recommendation by the 442 * library. It is entirely possible for the library to use a different set of values. Value 443 * MUST be in linear scale. 444 * 445 * @param minContentBoost min content boost. Any positive real number 446 * @param maxContentBoost max content boost. Any positive real numer >= minContentBoost 447 * @throws IOException If parameters are not valid or current encoder instance 448 * is not valid or current encoder instance is not suitable 449 * for configuration exception is thrown 450 */ setMinMaxContentBoost(float minContentBoost, float maxContentBoost)451 public void setMinMaxContentBoost(float minContentBoost, float maxContentBoost) 452 throws IOException { 453 setMinMaxContentBoostNative(minContentBoost, maxContentBoost); 454 } 455 456 /** 457 * Set target display peak brightness in nits. This is used for configuring 458 * {@link UltraHDRDecoder.GainMapMetadata#hdrCapacityMax}. This value determines the weight 459 * by which the gain map coefficients are scaled during decode. If this is not configured, 460 * then default peak luminance of HDR intent's color transfer under test is used. For 461 * {@link UltraHDRCommon#UHDR_CT_HLG} input, this corresponds to 1000 nits and for 462 * {@link UltraHDRCommon#UHDR_CT_LINEAR} and {@link UltraHDRCommon#UHDR_CT_PQ} inputs, this 463 * corresponds to 10000 nits. 464 * 465 * @param nits target display peak brightness in nits. Any positive real number in range 466 * [203, 10000] 467 * @throws IOException If parameters are not valid or current encoder instance 468 * is not valid or current encoder instance is not suitable 469 * for configuration exception is thrown 470 */ setTargetDisplayPeakBrightness(float nits)471 public void setTargetDisplayPeakBrightness(float nits) throws IOException { 472 setTargetDisplayPeakBrightnessNative(nits); 473 } 474 475 /** 476 * Encode process call. 477 * <p> 478 * After initializing the encoder context, call to this function will submit data for 479 * encoding. If the call is successful, the encoded output is stored internally and is 480 * accessible via {@link UltraHDREncoder#getOutput()}. 481 * 482 * @throws IOException If any errors are encountered during the encoding process, exception is 483 * thrown 484 */ encode()485 public void encode() throws IOException { 486 encodeNative(); 487 } 488 489 /** 490 * Get encoded ultra hdr stream 491 * 492 * @return byte array contains encoded output data 493 * @throws IOException If {@link UltraHDREncoder#encode()} is not called or encoding process 494 * is not successful, exception is thrown 495 */ getOutput()496 public byte[] getOutput() throws IOException { 497 return getOutputNative(); 498 } 499 500 /** 501 * Reset encoder instance. Clears all previous settings and resets to default state and ready 502 * for re-initialization and usage. 503 * 504 * @throws IOException If the current encoder instance is not valid exception is thrown. 505 */ reset()506 public void reset() throws IOException { 507 resetNative(); 508 } 509 init()510 private native void init() throws IOException; 511 destroy()512 private native void destroy() throws IOException; 513 setRawImageNative(int[] rgbBuff, int width, int height, int rgbStride, int colorGamut, int colorTransfer, int colorRange, int colorFormat, int intent)514 private native void setRawImageNative(int[] rgbBuff, int width, int height, int rgbStride, 515 int colorGamut, int colorTransfer, int colorRange, int colorFormat, int intent) 516 throws IOException; 517 setRawImageNative(long[] rgbBuff, int width, int height, int rgbStride, int colorGamut, int colorTransfer, int colorRange, int colorFormat, int intent)518 private native void setRawImageNative(long[] rgbBuff, int width, int height, int rgbStride, 519 int colorGamut, int colorTransfer, int colorRange, int colorFormat, int intent) 520 throws IOException; 521 setRawImageNative(short[] yBuff, short[] uvBuff, int width, int height, int yStride, int uvStride, int colorGamut, int colorTransfer, int colorRange, int colorFormat, int intent)522 private native void setRawImageNative(short[] yBuff, short[] uvBuff, int width, int height, 523 int yStride, int uvStride, int colorGamut, int colorTransfer, int colorRange, 524 int colorFormat, int intent) throws IOException; 525 setRawImageNative(byte[] yBuff, byte[] uBuff, byte[] vBuff, int width, int height, int yStride, int uStride, int vStride, int colorGamut, int colorTransfer, int colorRange, int colorFormat, int intent)526 private native void setRawImageNative(byte[] yBuff, byte[] uBuff, byte[] vBuff, int width, 527 int height, int yStride, int uStride, int vStride, int colorGamut, int colorTransfer, 528 int colorRange, int colorFormat, int intent) throws IOException; 529 setCompressedImageNative(byte[] data, int size, int colorGamut, int colorTransfer, int range, int intent)530 private native void setCompressedImageNative(byte[] data, int size, int colorGamut, 531 int colorTransfer, int range, int intent) throws IOException; 532 setGainMapImageInfoNative(byte[] data, int size, float maxContentBoost, float minContentBoost, float gainmapGamma, float offsetSdr, float offsetHdr, float hdrCapacityMin, float hdrCapacityMax)533 private native void setGainMapImageInfoNative(byte[] data, int size, float maxContentBoost, 534 float minContentBoost, float gainmapGamma, float offsetSdr, float offsetHdr, 535 float hdrCapacityMin, float hdrCapacityMax) throws IOException; 536 setExifDataNative(byte[] data, int size)537 private native void setExifDataNative(byte[] data, int size) throws IOException; 538 setQualityFactorNative(int qualityFactor, int intent)539 private native void setQualityFactorNative(int qualityFactor, int intent) throws IOException; 540 setMultiChannelGainMapEncodingNative(boolean enable)541 private native void setMultiChannelGainMapEncodingNative(boolean enable) throws IOException; 542 setGainMapScaleFactorNative(int scaleFactor)543 private native void setGainMapScaleFactorNative(int scaleFactor) throws IOException; 544 setGainMapGammaNative(float gamma)545 private native void setGainMapGammaNative(float gamma) throws IOException; 546 setEncPresetNative(int preset)547 private native void setEncPresetNative(int preset) throws IOException; 548 setOutputFormatNative(int mediaType)549 private native void setOutputFormatNative(int mediaType) throws IOException; 550 setMinMaxContentBoostNative(float minContentBoost, float maxContentBoost)551 private native void setMinMaxContentBoostNative(float minContentBoost, 552 float maxContentBoost) throws IOException; 553 setTargetDisplayPeakBrightnessNative(float nits)554 private native void setTargetDisplayPeakBrightnessNative(float nits) throws IOException; 555 encodeNative()556 private native void encodeNative() throws IOException; 557 getOutputNative()558 private native byte[] getOutputNative() throws IOException; 559 resetNative()560 private native void resetNative() throws IOException; 561 562 /** 563 * Encoder handle. Filled by {@link UltraHDREncoder#init()} 564 */ 565 private long handle; 566 567 static { 568 System.loadLibrary("uhdrjni"); 569 } 570 } 571