Skip to content

Commit

Permalink
Add support for creating gain maps for image with different primaries. (
Browse files Browse the repository at this point in the history
  • Loading branch information
maryla-uc authored Dec 13, 2023
1 parent b7e9237 commit e0778af
Show file tree
Hide file tree
Showing 13 changed files with 388 additions and 116 deletions.
1 change: 1 addition & 0 deletions apps/avifgainmaputil/swapbase_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ avifResult ChangeBase(const avifImage& image, int depth,

avifDiagnostics diag;
result = avifImageApplyGainMap(&image, image.gainMap, headroom,
swapped->colorPrimaries,
swapped->transferCharacteristics, &swapped_rgb,
(compute_clli ? &clli : nullptr), &diag);
if (result != AVIF_RESULT_OK) {
Expand Down
8 changes: 4 additions & 4 deletions apps/avifgainmaputil/tonemap_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ avifResult TonemapCommand::Run() {
avifRGBImage tone_mapped_rgb;
avifRGBImageSetDefaults(&tone_mapped_rgb, tone_mapped.get());
avifDiagnostics diag;
result =
avifImageApplyGainMap(decoder->image, image->gainMap, arg_headroom_,
cicp.transfer_characteristics, &tone_mapped_rgb,
clli_set ? nullptr : &clli_box, &diag);
result = avifImageApplyGainMap(
decoder->image, image->gainMap, arg_headroom_, cicp.color_primaries,
cicp.transfer_characteristics, &tone_mapped_rgb,
clli_set ? nullptr : &clli_box, &diag);
if (result != AVIF_RESULT_OK) {
std::cout << "Failed to tone map image: " << avifResultToString(result)
<< " (" << diag.error << ")\n";
Expand Down
9 changes: 6 additions & 3 deletions include/avif/avif.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ typedef struct avifGainMapMetadata
// True if tone mapping should be performed in the color space of the
// base image. If false, the color space of the alternate image should
// be used.
// TODO(maryla): implement.
avifBool useBaseColorSpace;
} avifGainMapMetadata;

Expand Down Expand Up @@ -1551,15 +1550,18 @@ AVIF_NODISCARD AVIF_API avifBool avifPeekCompatibleFileType(const avifROData * i
AVIF_API avifResult avifImageApplyGainMap(const avifImage * baseImage,
const avifGainMap * gainMap,
float hdrHeadroom,
avifColorPrimaries outputColorPrimaries,
avifTransferCharacteristics outputTransferCharacteristics,
avifRGBImage * toneMappedImage,
avifContentLightLevelInformationBox * clli,
avifDiagnostics * diag);
// Same as above but takes an avifRGBImage as input instead of avifImage.
AVIF_API avifResult avifRGBImageApplyGainMap(const avifRGBImage * baseImage,
avifTransferCharacteristics transferCharacteristics,
avifColorPrimaries baseColorPrimaries,
avifTransferCharacteristics baseTransferCharacteristics,
const avifGainMap * gainMap,
float hdrHeadroom,
avifColorPrimaries outputColorPrimaries,
avifTransferCharacteristics outputTransferCharacteristics,
avifRGBImage * toneMappedImage,
avifContentLightLevelInformationBox * clli,
Expand All @@ -1572,10 +1574,11 @@ AVIF_API avifResult avifRGBImageApplyGainMap(const avifRGBImage * baseImage,
// height, depth and yuvFormat fields set to the desired output values for the
// gain map. All of these fields may differ from the source images.
AVIF_API avifResult avifRGBImageComputeGainMap(const avifRGBImage * baseRgbImage,
avifColorPrimaries baseColorPrimaries,
avifTransferCharacteristics baseTransferCharacteristics,
const avifRGBImage * altRgbImage,
avifColorPrimaries altColorPrimaries,
avifTransferCharacteristics altTransferCharacteristics,
avifColorPrimaries colorPrimaries,
avifGainMap * gainMap,
avifDiagnostics * diag);
// Convenience function. Same as above but takes avifImage images as input
Expand Down
1 change: 1 addition & 0 deletions src/avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ avifGainMap * avifGainMapCreate()
gainMap->altTransferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_UNSPECIFIED;
gainMap->altMatrixCoefficients = AVIF_MATRIX_COEFFICIENTS_UNSPECIFIED;
gainMap->altYUVRange = AVIF_RANGE_FULL;
gainMap->metadata.useBaseColorSpace = AVIF_TRUE;
return gainMap;
}

Expand Down
Loading

0 comments on commit e0778af

Please sign in to comment.