Skip to content

Commit

Permalink
Use AVIF_CHECKERR() in avifImageCreate() (AOMediaCodec#1944)
Browse files Browse the repository at this point in the history
Use AVIF_CHECK() in avifGetRGBColorSpaceInfo()
  • Loading branch information
y-guyon authored Jan 17, 2024
1 parent 21c1c2c commit 1c3de07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
13 changes: 3 additions & 10 deletions src/avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,11 @@ void avifImageSetDefaults(avifImage * image)
avifImage * avifImageCreate(uint32_t width, uint32_t height, uint32_t depth, avifPixelFormat yuvFormat)
{
// width and height are checked when actually used, for example by avifImageAllocatePlanes().
if (depth > 16) {
// avifImage only supports up to 16 bits per sample. See avifImageUsesU16().
return NULL;
}
if ((yuvFormat < AVIF_PIXEL_FORMAT_NONE) || (yuvFormat > AVIF_PIXEL_FORMAT_YUV400)) {
return NULL;
}
AVIF_CHECKERR(depth <= 16, NULL); // avifImage only supports up to 16 bits per sample. See avifImageUsesU16().
AVIF_CHECKERR(yuvFormat >= AVIF_PIXEL_FORMAT_NONE && yuvFormat < AVIF_PIXEL_FORMAT_COUNT, NULL);

avifImage * image = (avifImage *)avifAlloc(sizeof(avifImage));
if (!image) {
return NULL;
}
AVIF_CHECKERR(image, NULL);
avifImageSetDefaults(image);
image->width = width;
image->height = height;
Expand Down
16 changes: 6 additions & 10 deletions src/reformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ struct YUVBlock

avifBool avifGetRGBColorSpaceInfo(const avifRGBImage * rgb, avifRGBColorSpaceInfo * info)
{
if ((rgb->depth != 8) && (rgb->depth != 10) && (rgb->depth != 12) && (rgb->depth != 16)) {
return AVIF_FALSE;
}
if (rgb->isFloat && rgb->depth != 16) {
return AVIF_FALSE;
}
if (rgb->format == AVIF_RGB_FORMAT_RGB_565 && rgb->depth != 8) {
return AVIF_FALSE;
AVIF_CHECK(rgb->depth == 8 || rgb->depth == 10 || rgb->depth == 12 || rgb->depth == 16);
if (rgb->isFloat) {
AVIF_CHECK(rgb->depth == 16);
}
if (rgb->format < AVIF_RGB_FORMAT_RGB || rgb->format >= AVIF_RGB_FORMAT_COUNT) {
return AVIF_FALSE;
if (rgb->format == AVIF_RGB_FORMAT_RGB_565) {
AVIF_CHECK(rgb->depth == 8);
}
AVIF_CHECK(rgb->format >= AVIF_RGB_FORMAT_RGB && rgb->format < AVIF_RGB_FORMAT_COUNT);

info->channelBytes = (rgb->depth > 8) ? 2 : 1;
info->pixelBytes = avifRGBImagePixelSize(rgb);
Expand Down

0 comments on commit 1c3de07

Please sign in to comment.