From abe6aa98ebad0c0d1bdfd4edf42c42ace3a2c2dd Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sun, 12 Mar 2023 17:09:12 -0400 Subject: [PATCH] +libavif (#470) * +libavif Closes #210 * wip --- .../aomedia.googlesource.com/aom/package.yml | 13 ++-- .../github.com/AOMediaCodec/libavif/example.c | 58 ++++++++++++++++++ .../AOMediaCodec/libavif/fixture.png | Bin 0 -> 82 bytes .../AOMediaCodec/libavif/package.yml | 43 +++++++++++++ 4 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 projects/github.com/AOMediaCodec/libavif/example.c create mode 100644 projects/github.com/AOMediaCodec/libavif/fixture.png create mode 100644 projects/github.com/AOMediaCodec/libavif/package.yml diff --git a/projects/aomedia.googlesource.com/aom/package.yml b/projects/aomedia.googlesource.com/aom/package.yml index 89fbdc75..a8d350a2 100644 --- a/projects/aomedia.googlesource.com/aom/package.yml +++ b/projects/aomedia.googlesource.com/aom/package.yml @@ -18,15 +18,16 @@ build: make make install env: - CC: clang ARGS: - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_INSTALL_PREFIX="{{prefix}}" - -test: - script: | - aomenc --help - aomdec --help + linux: + CFLAGS: -fPIC + CXXFLAGS: -fPIC + LDFLAGS: -pie +test: | + aomenc --help + aomdec --help provides: - bin/aomenc diff --git a/projects/github.com/AOMediaCodec/libavif/example.c b/projects/github.com/AOMediaCodec/libavif/example.c new file mode 100644 index 00000000..402ba2c3 --- /dev/null +++ b/projects/github.com/AOMediaCodec/libavif/example.c @@ -0,0 +1,58 @@ +#include "avif/avif.h" +#include +#include +#include + +int main(int argc, char * argv[]) +{ + if (argc != 2) { + fprintf(stderr, "avif_example_decode_file [filename.avif]\n"); + return 1; + } + const char * inputFilename = argv[1]; + + int returnCode = 1; + avifRGBImage rgb; + memset(&rgb, 0, sizeof(rgb)); + + avifDecoder * decoder = avifDecoderCreate(); + + avifResult result = avifDecoderSetIOFile(decoder, inputFilename); + if (result != AVIF_RESULT_OK) { + fprintf(stderr, "Cannot open file for read: %s\n", inputFilename); + goto cleanup; + } + + result = avifDecoderParse(decoder); + if (result != AVIF_RESULT_OK) { + fprintf(stderr, "Failed to decode image: %s\n", avifResultToString(result)); + goto cleanup; + } + + printf("Parsed AVIF: %ux%u (%ubpc)\n", decoder->image->width, decoder->image->height, decoder->image->depth); + + while (avifDecoderNextImage(decoder) == AVIF_RESULT_OK) { + avifRGBImageSetDefaults(&rgb, decoder->image); + + avifRGBImageAllocatePixels(&rgb); + + if (avifImageYUVToRGB(decoder->image, &rgb) != AVIF_RESULT_OK) { + fprintf(stderr, "Conversion from YUV failed: %s\n", inputFilename); + goto cleanup; + } + + if (rgb.depth > 8) { + uint16_t * firstPixel = (uint16_t *)rgb.pixels; + printf(" * First pixel: RGBA(%u,%u,%u,%u)\n", firstPixel[0], firstPixel[1], firstPixel[2], firstPixel[3]); + } else { + uint8_t * firstPixel = rgb.pixels; + printf(" * First pixel: RGBA(%u,%u,%u,%u)\n", firstPixel[0], firstPixel[1], firstPixel[2], firstPixel[3]); + } + } + + returnCode = 0; +cleanup: + avifRGBImageFreePixels(&rgb); + avifDecoderDestroy(decoder); + return returnCode; +} diff --git a/projects/github.com/AOMediaCodec/libavif/fixture.png b/projects/github.com/AOMediaCodec/libavif/fixture.png new file mode 100644 index 0000000000000000000000000000000000000000..18d7a15a9b6204ab5ba01cc1855ae91624fcb1a4 GIT binary patch literal 82 zcmeAS@N?(olHy`uVBq!ia0vp^93afd3?%;@)Hwm9m;-!5Tp1YtcU4>p2XeVQT^vI= cWRo3$N(2}fXF7A91d1|vy85}Sb4q9e0Bvv(uK)l5 literal 0 HcmV?d00001 diff --git a/projects/github.com/AOMediaCodec/libavif/package.yml b/projects/github.com/AOMediaCodec/libavif/package.yml new file mode 100644 index 00000000..11480310 --- /dev/null +++ b/projects/github.com/AOMediaCodec/libavif/package.yml @@ -0,0 +1,43 @@ +distributable: + url: https://github.com/AOMediaCodec/libavif/archive/refs/tags/v{{version}}.tar.gz + strip-components: 1 + +versions: + github: AOMediaCodec/libavif + +dependencies: + aomedia.googlesource.com/aom: ^3 + libpng.org: ^1 + libjpeg-turbo.org: ^2 + +build: + dependencies: + tea.xyz/gx/cc: c99 + tea.xyz/gx/make: '*' + cmake.org: ^3 + working-directory: build + script: | + cmake .. $ARGS + make --jobs {{ hw.concurrency }} install + env: + ARGS: + - -DCMAKE_INSTALL_PREFIX={{prefix}} + - -DCMAKE_BUILD_TYPE=Release + - -DAVIF_CODEC_AOM=ON + - -DAVIF_BUILD_APPS=ON + - -DAVIF_BUILD_EXAMPLES=OFF + - -DAVIF_BUILD_TESTS=OFF + +provides: + - bin/avifenc + - bin/avifdec + +test: | + avifenc fixture.png test.avif + test -f test.avif + + avifdec test.avif test.jpg + test -f test.jpg + + cc example.c -lavif + ./a.out test.avif