Skip to content

Commit

Permalink
Experimental reduced HEIF header
Browse files Browse the repository at this point in the history
Add AVIF_ENABLE_EXPERIMENTAL_AVIR flag.
Add avifHeaderFormat headerFormat member to avifEncoder.
Remove a few hundred bytes of container boilerplate for simple images.
This prototype uses a small box that expands in meaning to a full meta
box with all defined items and properties.

Warning: This feature is experimental and forbidden by the current
AVIF specification.
  • Loading branch information
y-guyon authored Sep 1, 2023
1 parent 262e11d commit 73510a1
Show file tree
Hide file tree
Showing 11 changed files with 955 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-unix-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ jobs:
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_LOCAL_GTEST=ON
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_AVIR=ON
- name: Build libavif (ninja)
working-directory: ./build
run: ninja
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ jobs:
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_LOCAL_GTEST=ON
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_AVIR=ON
- name: Build libavif (ninja)
working-directory: ./build
run: ninja
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
in the future. Files created now might not decode in a future version.
This feature is off by default and must be enabled with the
AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP compilation flag.
* Add the headerFormat member of new type avifHeaderFormat to avifEncoder.
* Add experimental API for reading and writing "avir"-branded AVIF files
behind the compilation flag AVIF_ENABLE_EXPERIMENTAL_AVIR.

### Changed
* Update svt.cmd/svt.sh: v1.7.0
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ option(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R "Enable experimental YCgCo-R matrix code
option(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP
"Enable experimental gain map code (for HDR images that look good both on HDR and SDR displays)" OFF
)
option(AVIF_ENABLE_EXPERIMENTAL_AVIR "Enable experimental reduced header" OFF)

option(AVIF_CODEC_AOM "Use the AOM codec for encoding/decoding (see AVIF_CODEC_AOM_DECODE/AVIF_CODEC_AOM_ENCODE)" OFF)
option(AVIF_CODEC_DAV1D "Use the dav1d codec for decoding" OFF)
Expand Down Expand Up @@ -269,6 +270,10 @@ if(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP)
add_compile_definitions(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP)
endif()

if(AVIF_ENABLE_EXPERIMENTAL_AVIR)
add_compile_definitions(AVIF_ENABLE_EXPERIMENTAL_AVIR)
endif()

set(AVIF_SRCS
src/alpha.c
src/avif.c
Expand Down
10 changes: 10 additions & 0 deletions apps/avifenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ static void syntaxLong(void)
printf(" -j,--jobs J : Number of jobs (worker threads, default: 1. Use \"all\" to use all available cores)\n");
printf(" --no-overwrite : Never overwrite existing output file\n");
printf(" -o,--output FILENAME : Instead of using the last filename given as output, use this filename\n");
#if defined(AVIF_ENABLE_EXPERIMENTAL_AVIR)
printf(" --avir : Use reduced header if possible\n");
#endif
printf(" -l,--lossless : Set all defaults to encode losslessly, and emit warnings when settings/input don't allow for it\n");
printf(" -d,--depth D : Output depth [8,10,12]. (JPEG/PNG only; For y4m or stdin, depth is retained)\n");
printf(" -y,--yuv FORMAT : Output format [default=auto, 444, 422, 420, 400]. Ignored for y4m or stdin (y4m format is retained)\n");
Expand Down Expand Up @@ -669,6 +672,7 @@ typedef struct
avifBool autoTiling;
avifBool progressive;
int speed;
avifHeaderFormat headerFormat;

int paspCount;
uint32_t paspValues[8]; // only the first two are used
Expand Down Expand Up @@ -888,6 +892,7 @@ static avifBool avifEncodeImagesFixedQuality(const avifSettings * settings,
encoder->autoTiling = settings->autoTiling;
encoder->codecChoice = settings->codecChoice;
encoder->speed = settings->speed;
encoder->headerFormat = settings->headerFormat;
encoder->timescale = settings->outputTiming.timescale;
encoder->keyframeInterval = settings->keyframeInterval;
encoder->repetitionCount = settings->repetitionCount;
Expand Down Expand Up @@ -1107,6 +1112,7 @@ int main(int argc, char * argv[])
settings.autoTiling = AVIF_FALSE;
settings.progressive = AVIF_FALSE;
settings.speed = 6;
settings.headerFormat = AVIF_HEADER_FULL;
settings.repetitionCount = AVIF_REPETITION_COUNT_INFINITE;
settings.keyframeInterval = 0;
settings.ignoreExif = AVIF_FALSE;
Expand Down Expand Up @@ -1177,6 +1183,10 @@ int main(int argc, char * argv[])
} else if (!strcmp(arg, "-o") || !strcmp(arg, "--output")) {
NEXTARG();
outputFilename = arg;
#if defined(AVIF_ENABLE_EXPERIMENTAL_AVIR)
} else if (!strcmp(arg, "--avir")) {
settings.headerFormat = AVIF_HEADER_REDUCED;
#endif // AVIF_ENABLE_EXPERIMENTAL_AVIR
} else if (!strcmp(arg, "-d") || !strcmp(arg, "--depth")) {
NEXTARG();
input.requestedDepth = atoi(arg);
Expand Down
18 changes: 18 additions & 0 deletions include/avif/avif.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ typedef enum avifResult

AVIF_API const char * avifResultToString(avifResult result);

// ---------------------------------------------------------------------------
// avifHeaderFormat

typedef enum avifHeaderFormat
{
// AVIF file with an "avif" brand, a MetaBox and all its required boxes for maximum compatibility.
AVIF_HEADER_FULL,
#if defined(AVIF_ENABLE_EXPERIMENTAL_AVIR)
// AVIF file with an "avir" brand and a CondensedImageBox to reduce the encoded file size.
// This is based on the m64572 "Condensed image item" MPEG proposal for HEIF.
// WARNING: Experimental feature. Produces files that are incompatible with older decoders.
AVIF_HEADER_REDUCED,
#endif
} avifHeaderFormat;

// ---------------------------------------------------------------------------
// avifROData/avifRWData: Generic raw memory storage

Expand Down Expand Up @@ -1297,6 +1312,9 @@ typedef struct avifEncoder

// Version 1.0.0 ends here. Add any new members after this line.

// Defaults to AVIF_HEADER_FULL
avifHeaderFormat headerFormat;

#if defined(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP)
int qualityGainMap; // changeable encoder setting
#endif
Expand Down
13 changes: 13 additions & 0 deletions include/avif/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ typedef enum avifItemCategory
#endif
} avifItemCategory;

// ---------------------------------------------------------------------------

#if defined(AVIF_ENABLE_EXPERIMENTAL_AVIR)
// AVIF color_type field meaning in CondensedImageBox
typedef enum avifConiColorType
{
AVIF_CONI_COLOR_TYPE_SRGB = 0,
AVIF_CONI_COLOR_TYPE_NCLX_5BIT = 1,
AVIF_CONI_COLOR_TYPE_NCLX_8BIT = 2,
AVIF_CONI_COLOR_TYPE_ICC = 3
} avifConiColorType;
#endif // AVIF_ENABLE_EXPERIMENTAL_AVIR

// ---------------------------------------------------------------------------
// Grid AVIF images

Expand Down
Loading

0 comments on commit 73510a1

Please sign in to comment.