Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avif-alpha is working as expected #2180

Open
indolia111 opened this issue May 29, 2024 · 1 comment
Open

Avif-alpha is working as expected #2180

indolia111 opened this issue May 29, 2024 · 1 comment

Comments

@indolia111
Copy link

Here is the image which is correctly working in AVIF while in AVIF-alpha showing outlines on icons.
image after avif-alpha:
image
image with avif:
image

here is the code that i am using :

`IgcBufBase::Ptr IsrvImageRects::CreateAvifImage(IrsRasConst ras, int /* format */, int ippEncoding, int quality, bool doAlpha, size_t * length)
{
IrsRas avifRas = CreateRasForAvif(ras, doAlpha);
int depth = 8;
int height = avifRas.rect().ht();
int width = avifRas.rect().wd();
avifPixelFormat format = AVIF_PIXEL_FORMAT_YUV420;

IrsTAccessConst<IgcDtBit8> pixels(avifRas);

avifRGBImage rgb;
avifImage * image = avifImageCreate(width, height, depth, format);
avifRGBImageSetDefaults(&rgb, image);
image->colorPrimaries = AVIF_COLOR_PRIMARIES_BT709;
image->transferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_SRGB;
image->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT601;
rgb.pixels=(uint8_t*)  pixels.ptr();
rgb.rowBytes=avifRas.numComps() * avifRas.rect().wd();

if (avifRas.numComps() == 4) {
    rgb.format = AVIF_RGB_FORMAT_RGBA;
} else {
    rgb.format = AVIF_RGB_FORMAT_RGB;
}

if (avifImageRGBToYUV(image, &rgb) != AVIF_RESULT_OK) {
    avifImageDestroy(image);
    throw new IgcEx_Unsupported("AVIF format - Problem in RGB(A) to YUV conversion", IGC_WHERE);
}

avifRWData encodedData = AVIF_DATA_EMPTY;
avifEncoder * encoder = NULL;
encoder = avifEncoderCreate();
encoder->codecChoice=AVIF_CODEC_CHOICE_AUTO;
encoder->maxThreads = 2;
encoder->speed = 8;
encoder->quality = quality;

if ( avifEncoderWrite(encoder, image, &encodedData) != AVIF_RESULT_OK) {
    avifEncoderDestroy(encoder);
    avifImageDestroy(image);
    throw new IgcEx_Unsupported("AVIF format - Encoding Failed", IGC_WHERE);
}

avifEncoderDestroy(encoder);
avifImageDestroy(image);

IgcBufSpec spec(encodedData.size);
IgcBufBase::Ptr buf = IgcBufBase::Create(spec);
memcpy(buf->buf(), encodedData.data,encodedData.size);

*length = encodedData.size;
avifRWDataFree(&encodedData);
return buf;

}`

@wantehchang
Copy link
Collaborator

Hi indolia111,

Your code looks correct to me. I am afraid that we will need the input RGBA image (perhaps as a PNG file) to debug this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants