Skip to content

Comments

Replace RGBImagePtr by RGBImageCleanup#3048

Open
vrabaud wants to merge 1 commit intoAOMediaCodec:mainfrom
vrabaud:main
Open

Replace RGBImagePtr by RGBImageCleanup#3048
vrabaud wants to merge 1 commit intoAOMediaCodec:mainfrom
vrabaud:main

Conversation

@vrabaud
Copy link
Contributor

@vrabaud vrabaud commented Feb 19, 2026

No description provided.

@vrabaud vrabaud requested a review from wantehchang February 19, 2026 13:28
@vrabaud vrabaud force-pushed the main branch 4 times, most recently from 831c5e3 to 2e74fb1 Compare February 19, 2026 14:28
@vrabaud vrabaud changed the title Fix RGBImagePtr Replace RGBImagePtr by RGBImageCleanup Feb 19, 2026
Copy link
Collaborator

@wantehchang wantehchang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks. I suggest some changes.

// To use when RGBImage actually owns the pixels. RGBImage can also be used as a view, in which case it does not own the pixels.
using RGBImagePtr = std::unique_ptr<avifRGBImage, UniquePtrDeleter>;

// Automatically cleans the ressources of the avifRGBImage if it owns it.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "if it owns it" is a conditional, but the destructor calls avifRGBImageFreePixels() unconditionally. I think the comment should instead say that this class assumes the avifRGBImage owns its pixels buffer.

testutil::CreateImage(/*width=*/12, /*height=*/34, /*depth=*/8,
AVIF_PIXEL_FORMAT_YUV420, AVIF_PLANES_ALL);

std::unique_ptr<avifRGBImage> rgb(new avifRGBImage());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to a plain avifRGBImage local variable allocated on the stack. That is how avifRGBImage is intended to be used. avifRGBImage is really a struct that collects the parameters for the RGB-to-YUV and YUV-to-RGB conversion functions.

We should also create a local variable rather than a temporary object for RGBImageCleanup. The local variable cleanup is created as soon as the avifRGBImage variable is properly initialized:

  avifRGBImage rgb;
  avifRGBImageSetDefaults(&rgb, image.get());
  RGBImageCleanup cleanup(&rgb);
  ASSERT_EQ(avifRGBImageAllocatePixels(&rgb), AVIF_RESULT_OK);

// testutil::WriteImage(decoded.get(), "/tmp/avifbasictest.png");
}

TEST(BasicTest, SharedPtr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "SharedPtr" doesn't seem to match what the test does...

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

Successfully merging this pull request may close these issues.

2 participants