Skip to content

Commit

Permalink
AVIF: Minor refactoring in enc.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanpingle committed Oct 30, 2023
1 parent fd53823 commit aad51d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions codecs/avif/enc/avif_enc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
#include <emscripten/val.h>
#include "avif/avif.h"

#include <string>

#define RETURN_NULL_IF_NOT_EQUALS(val1, val2) \
if (val1 != val2) \
return val::null();
do { \
if (val1 != val2) \
return val::null(); \
} while (false)
#define RETURN_NULL_IF_EQUALS(val1, val2) \
if (val1 == val2) \
return val::null();
do { \
if (val1 == val2) \
return val::null(); \
} while (false)

using namespace emscripten;

Expand Down Expand Up @@ -74,7 +80,7 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
format == AVIF_PIXEL_FORMAT_YUV444;

avifImage* image = avifImageCreate(width, height, depth, format);
RETURN_NULL_IF_EQUALS(image, NULL);
RETURN_NULL_IF_EQUALS(image, nullptr);

if (lossless) {
image->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_IDENTITY;
Expand All @@ -92,13 +98,10 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
srcRGB.chromaDownsampling = AVIF_CHROMA_DOWNSAMPLING_SHARP_YUV;
}
status = avifImageRGBToYUV(image, &srcRGB);
if (status == AVIF_RESULT_NOT_IMPLEMENTED) {
printf("libsharpyuv not implemented methinks\n");
}
RETURN_NULL_IF_NOT_EQUALS(status, AVIF_RESULT_OK);

avifEncoder* encoder = avifEncoderCreate();
RETURN_NULL_IF_EQUALS(encoder, NULL);
RETURN_NULL_IF_EQUALS(encoder, nullptr);

if (lossless) {
encoder->quality = AVIF_QUALITY_LOSSLESS;
Expand All @@ -123,7 +126,7 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
}

if (options.chromaDeltaQ) {
status = avifEncoderSetCodecSpecificOption(encoder, "enable-chroma-deltaq", "1");
status = avifEncoderSetCodecSpecificOption(encoder, "color:enable-chroma-deltaq", "1");
RETURN_NULL_IF_NOT_EQUALS(status, AVIF_RESULT_OK);
}

Expand Down
Binary file modified codecs/avif/enc/avif_enc.wasm
Binary file not shown.
Binary file modified codecs/avif/enc/avif_enc_mt.wasm
Binary file not shown.

0 comments on commit aad51d3

Please sign in to comment.