Bug 1726830 - Update mp4parse-rust to c6ba5af. r=kinetik

Update mp4parse_capi API to receive pixi data from parser

There are some necessary changes in nsAVIFDecoder.cpp to accommodate the mp4parse_capi changes. Aside from the addition of `BitsPerChannelToBitDepth`, to facilitate a bit of logging, there should be no functional changes. This is a prerequisite to [[ https://bugzilla.mozilla.org/show_bug.cgi?id=1696045 | bug 1696045 ]], which will add telemetry around the `pixi` box.

Differential Revision: https://phabricator.services.mozilla.com/D123273
This commit is contained in:
Jon Bauman 2021-08-20 23:57:06 +00:00
Родитель 14a11072e2
Коммит 1f9b94dc30
9 изменённых файлов: 115 добавлений и 47 удалений

Просмотреть файл

@ -20,7 +20,7 @@ tag = "v0.4.30"
[source."https://github.com/mozilla/mp4parse-rust"]
git = "https://github.com/mozilla/mp4parse-rust"
replace-with = "vendored-sources"
rev = "62aa5d4e46289351ebfa2712668077ba8aa81064"
rev = "c6ba5afd856c158d9cfc1a447165fcfaaf2b797c"
[source."https://github.com/mozilla/l10nregistry-rs"]
git = "https://github.com/mozilla/l10nregistry-rs"

4
Cargo.lock сгенерированный
Просмотреть файл

@ -3264,7 +3264,7 @@ dependencies = [
[[package]]
name = "mp4parse"
version = "0.11.5"
source = "git+https://github.com/mozilla/mp4parse-rust?rev=62aa5d4e46289351ebfa2712668077ba8aa81064#62aa5d4e46289351ebfa2712668077ba8aa81064"
source = "git+https://github.com/mozilla/mp4parse-rust?rev=c6ba5afd856c158d9cfc1a447165fcfaaf2b797c#c6ba5afd856c158d9cfc1a447165fcfaaf2b797c"
dependencies = [
"bitreader",
"byteorder",
@ -3282,7 +3282,7 @@ version = "0.1.0"
[[package]]
name = "mp4parse_capi"
version = "0.11.5"
source = "git+https://github.com/mozilla/mp4parse-rust?rev=62aa5d4e46289351ebfa2712668077ba8aa81064#62aa5d4e46289351ebfa2712668077ba8aa81064"
source = "git+https://github.com/mozilla/mp4parse-rust?rev=c6ba5afd856c158d9cfc1a447165fcfaaf2b797c#c6ba5afd856c158d9cfc1a447165fcfaaf2b797c"
dependencies = [
"byteorder",
"fallible_collections",

Просмотреть файл

@ -57,6 +57,24 @@ static MaybeIntSize GetImageSize(const Mp4parseAvifImage& image) {
return Nothing();
}
// Translate the number of bits per channel into a single ColorDepth.
// Return Nothing if the number of bits per channel is not uniform.
static Maybe<uint8_t> BitsPerChannelToBitDepth(
const Mp4parseByteData& bits_per_channel) {
if (bits_per_channel.length == 0) {
return Nothing();
}
for (uintptr_t i = 1; i < bits_per_channel.length; ++i) {
if (bits_per_channel.data[i] != bits_per_channel.data[0]) {
// log mismatch
return Nothing();
}
}
return Some(bits_per_channel.data[0]);
}
// Translate the MIAF/HEIF-based orientation transforms (imir, irot) into
// ImageLib's representation. Note that the interpretation of imir was reversed
// Between HEIF (ISO 23008-12:2017) and ISO/IEC 23008-12:2017/DAmd 2. This is
@ -177,8 +195,8 @@ class AVIFParser {
MOZ_LOG(sAVIFLog, LogLevel::Debug,
("[this=%p] mp4parse_avif_get_image -> %d; primary_item length: "
"%zu, alpha_item length: %zu",
this, status, mAvifImage->primary_item.length,
mAvifImage->alpha_item.length));
this, status, mAvifImage->primary_image.coded_data.length,
mAvifImage->alpha_image.coded_data.length));
if (status != MP4PARSE_STATUS_OK) {
mAvifImage.reset();
return nullptr;
@ -453,22 +471,24 @@ class Dav1dDecoder final : AVIFDecoderInterface {
MOZ_LOG(sAVIFLog, LogLevel::Verbose, ("[this=%p] Beginning Decode", this));
if (!parsedImg.primary_item.data || !parsedImg.primary_item.length) {
if (!parsedImg.primary_image.coded_data.data ||
!parsedImg.primary_image.coded_data.length) {
return AsVariant(NonDecoderResult::NoPrimaryItem);
}
mPicture.emplace();
Dav1dResult r =
GetPicture(parsedImg.primary_item, mPicture.ptr(), aIsMetadataDecode);
Dav1dResult r = GetPicture(parsedImg.primary_image.coded_data,
mPicture.ptr(), aIsMetadataDecode);
if (r != 0) {
mPicture.reset();
return AsVariant(r);
}
if (parsedImg.alpha_item.data && parsedImg.alpha_item.length) {
if (parsedImg.alpha_image.coded_data.data &&
parsedImg.alpha_image.coded_data.length) {
mAlphaPlane.emplace();
Dav1dResult r = GetPicture(parsedImg.alpha_item, mAlphaPlane.ptr(),
aIsMetadataDecode);
Dav1dResult r = GetPicture(parsedImg.alpha_image.coded_data,
mAlphaPlane.ptr(), aIsMetadataDecode);
if (r != 0) {
mAlphaPlane.reset();
return AsVariant(r);
@ -606,13 +626,14 @@ class AOMDecoder final : AVIFDecoderInterface {
MOZ_ASSERT(mContext.isSome());
MOZ_ASSERT(mDecodedData.isNothing());
if (!parsedImg.primary_item.data || !parsedImg.primary_item.length) {
if (!parsedImg.primary_image.coded_data.data ||
!parsedImg.primary_image.coded_data.length) {
return AsVariant(NonDecoderResult::NoPrimaryItem);
}
aom_image_t* aomImg = nullptr;
DecodeResult r =
GetImage(parsedImg.primary_item, &aomImg, aIsMetadataDecode);
DecodeResult r = GetImage(parsedImg.primary_image.coded_data, &aomImg,
aIsMetadataDecode);
if (!IsDecodeSuccess(r)) {
return r;
}
@ -628,10 +649,11 @@ class AOMDecoder final : AVIFDecoderInterface {
}
mOwnedImage.reset(clonedImg);
if (parsedImg.alpha_item.data && parsedImg.alpha_item.length) {
if (parsedImg.alpha_image.coded_data.data &&
parsedImg.alpha_image.coded_data.length) {
aom_image_t* alphaImg = nullptr;
DecodeResult r =
GetImage(parsedImg.alpha_item, &alphaImg, aIsMetadataDecode);
DecodeResult r = GetImage(parsedImg.alpha_image.coded_data, &alphaImg,
aIsMetadataDecode);
if (!IsDecodeSuccess(r)) {
return r;
}
@ -1132,7 +1154,7 @@ nsAVIFDecoder::DecodeResult nsAVIFDecoder::Decode(
}
const Mp4parseAvifImage& parsedImg = *parsedImagePtr;
if (parsedImg.alpha_item.data) {
if (parsedImg.alpha_image.coded_data.data) {
PostHasTransparency();
}
@ -1140,11 +1162,16 @@ nsAVIFDecoder::DecodeResult nsAVIFDecoder::Decode(
? GetImageOrientation(parsedImg)
: Orientation{};
MaybeIntSize parsedImageSize = GetImageSize(parsedImg);
Maybe<uint8_t> primaryBitDepth =
BitsPerChannelToBitDepth(parsedImg.primary_image.bits_per_channel);
Maybe<uint8_t> alphaBitDepth =
BitsPerChannelToBitDepth(parsedImg.alpha_image.bits_per_channel);
if (parsedImageSize.isSome()) {
MOZ_LOG(sAVIFLog, LogLevel::Debug,
("[this=%p] Parser returned image size %d x %d", this,
parsedImageSize->width, parsedImageSize->height));
("[this=%p] Parser returned image size %d x %d (%d/%d bit)", this,
parsedImageSize->width, parsedImageSize->height,
primaryBitDepth.valueOr(0), alphaBitDepth.valueOr(0)));
PostSize(parsedImageSize->width, parsedImageSize->height, orientation);
if (IsMetadataDecode()) {
MOZ_LOG(

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"3969c05e1a5ba7f937776863571b7af940d8a2915ba5a7853c5760a2d71b14b1","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"86cb40854b93f988e3a63ce6fe39d2ce95367f8ca301a5ba50676ff98a0ad791","benches/avif_benchmark.rs":"cd99c0dde025ab40d2cd860f53dc697a1587a48c164c3e5c8adfd40add29d772","src/boxes.rs":"7f2236372a84991def6652d5fb3966411632418617c65c4e96ba544f94816c4d","src/lib.rs":"ccf889f955c275ae2179cff4ab7b43ba9f974571ce669a11bcac77f8b4812243","src/macros.rs":"76c840f9299797527fe71aa5b378ffb01312767372b45cc62deddb19775400ae","src/tests.rs":"87a391c2383f601439bf1ebebb3b24d998252e2574dde75c7c578fae9bfc27bb","src/unstable.rs":"c2cef9a3b2b08a4da66fa0305fce7a117bd99c9b8d57b0a044e1d99dbda6faf5","tests/1x1-black-alpha-50pct-premultiplied.avif":"31a8c235bf2cf601a593a7bc33f7f2779f2d5b2e0cd145897b931fce94b0c0b8","tests/amr_nb_1f.3gp":"d1423e3414ad06b69f8b58d5c916ec353ba2d0402d99dec9f1c88acc33b6a127","tests/amr_wb_1f.3gp":"be635b24097e8757b0c04d70ab28e00417ca113e86108b6c269b79b64b89bcd5","tests/av1C-missing-essential.avif":"a1501254c4071847b2269fe40b81409c389ff14e91cf7c0005a47e6ea97a6803","tests/bad-ipma-flags.avif":"ecde7997b97db1910b9dcc7ca8e3c8957da0e83681ea9008c66dc9f12b78ad19","tests/bad-ipma-version.avif":"7f9a1a0b4ebbf8d800d22eaae5ff78970cc6b811317db6c1467c6883952b7c9b","tests/bbb_sunflower_QCIF_30fps_h263_noaudio_1f.3gp":"03e5b1264d0a188d77b9e676ba3ce23a801b17aaa11c0343dfd851d6ea4e3a40","tests/clap-basic-1_3x3-to-1x1.avif":"83af9c8196fa93b2475163585a23d0eb5a8f8015d0db8da7a5d6de61adfb1876","tests/clusterfuzz-testcase-minimized-mp4-6093954524250112":"af7044a470732d4e7e34ac7ab5ff038c58b66f09702cbcd774931d7766bbfd35","tests/corrupt/bug-1655846.avif":"e0a5a06225800fadf05f5352503a4cec11af73eef705c43b4acab5f4a99dea50","tests/corrupt/bug-1661347.avif":"31c26561e1d9eafb60f7c5968b82a0859d203d73f17f26b29276256acee12966","tests/corrupt/hdlr-not-first.avif":"2c29308af077209b9c984921b7e36f8fb7ca7cf379cf8eba4c7a91f65bc7a304","tests/corrupt/hdlr-not-pict.avif":"9fe37619606645a95725300a9e34fada9190d1e0b3919881db84353941ca9291","tests/corrupt/imir-before-clap.avif":"22d6b5dacf0ef0be59053beba7564b08037fed859ada2885e3476e0ff0d19c95","tests/corrupt/ipma-duplicate-item_id.avif":"ca8c5275b0b8b79c1068489a52d0a5c8f0b4453463971e72b694189f11c10745","tests/corrupt/ipma-duplicate-version-and-flags.avif":"cf8e15ec4b210235f3d68332a1adeb64e35c41b8d8e1e7586ae38b6d9cd8926c","tests/corrupt/ipma-invalid-property-index.avif":"2480e773fa716d22883032d05fd4cf2c6b00fba8796cf4ff286a5d1ba26adff6","tests/corrupt/no-alpha-av1C.avif":"ad3d34d6331db7d9bea0c5f37efb88923520e33e08e7c636a5df435a4575eae7","tests/corrupt/no-av1C.avif":"eeb4fc50930c91465999f787c4a2a3b12de20556da0857be72da5a1a9eaa3f01","tests/corrupt/no-hdlr.avif":"91a1eb70c7b6adf2104e471d7deeeb98084a591d64ce09ba106c27edfbc3a409","tests/corrupt/no-ispe.avif":"4b6edfd8c9b40c25dc40305a6057e32b5e65f40da4a9d810c58dbff53254113f","tests/corrupt/no-pixi-for-alpha.avif":"f8adc3573c79ee25bf6d4dd2693c61661469b28f86a5c7b1d9e41b0e8d2d53bb","tests/corrupt/no-pixi.avif":"4b1776def440dc8b913c170e4479772ee6bbb299b8679f7c564704bd03c9597e","tests/imir-missing-essential.avif":"b1226e4b1358528befbd3f1126b5caf0c5051b4354777b87e71f6001f3829f87","tests/irot-missing-essential.avif":"b7da1fc1d1b45bb1b7ca3494476e052f711d794a6d010df6870872ed8b9da10e","tests/multiple-extents.avif":"b5549ac68793e155a726d754e565cea0da03fa17833d3545f45c79e13f4c9360","tests/no-mif1.avif":"1442aa6ffaeb9512724287768bfd1850d3aa29a651ef05abb33e5dec2b3ee5c2","tests/overflow.rs":"16b591d8def1a155b3b997622f6ea255536870d99c3d8f97c51755b77a50de3c","tests/public.rs":"2d8e32c56c0233bf983311de1fb13314543157deda79625bf65a727d01d4fa8b","tests/valid-alpha.avif":"9d417a35b9b62ad3ff66ffbc55f16552aacf821a092aa5ef4adff7e746bd4c2f","tests/valid.avif":"f0b33e09bf01232e0877df325f47986c0bee7764f2a81c9c908ae109e7dc63c4"},"package":null}
{"files":{"Cargo.toml":"3969c05e1a5ba7f937776863571b7af940d8a2915ba5a7853c5760a2d71b14b1","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"86cb40854b93f988e3a63ce6fe39d2ce95367f8ca301a5ba50676ff98a0ad791","benches/avif_benchmark.rs":"cd99c0dde025ab40d2cd860f53dc697a1587a48c164c3e5c8adfd40add29d772","src/boxes.rs":"7f2236372a84991def6652d5fb3966411632418617c65c4e96ba544f94816c4d","src/lib.rs":"baf7c0adcde6ab658553331453555234a3f236402b1454384fd9a25ba29687f9","src/macros.rs":"76c840f9299797527fe71aa5b378ffb01312767372b45cc62deddb19775400ae","src/tests.rs":"87a391c2383f601439bf1ebebb3b24d998252e2574dde75c7c578fae9bfc27bb","src/unstable.rs":"c2cef9a3b2b08a4da66fa0305fce7a117bd99c9b8d57b0a044e1d99dbda6faf5","tests/1x1-black-alpha-50pct-premultiplied.avif":"31a8c235bf2cf601a593a7bc33f7f2779f2d5b2e0cd145897b931fce94b0c0b8","tests/amr_nb_1f.3gp":"d1423e3414ad06b69f8b58d5c916ec353ba2d0402d99dec9f1c88acc33b6a127","tests/amr_wb_1f.3gp":"be635b24097e8757b0c04d70ab28e00417ca113e86108b6c269b79b64b89bcd5","tests/av1C-missing-essential.avif":"a1501254c4071847b2269fe40b81409c389ff14e91cf7c0005a47e6ea97a6803","tests/bad-ipma-flags.avif":"ecde7997b97db1910b9dcc7ca8e3c8957da0e83681ea9008c66dc9f12b78ad19","tests/bad-ipma-version.avif":"7f9a1a0b4ebbf8d800d22eaae5ff78970cc6b811317db6c1467c6883952b7c9b","tests/bbb_sunflower_QCIF_30fps_h263_noaudio_1f.3gp":"03e5b1264d0a188d77b9e676ba3ce23a801b17aaa11c0343dfd851d6ea4e3a40","tests/clap-basic-1_3x3-to-1x1.avif":"83af9c8196fa93b2475163585a23d0eb5a8f8015d0db8da7a5d6de61adfb1876","tests/clusterfuzz-testcase-minimized-mp4-6093954524250112":"af7044a470732d4e7e34ac7ab5ff038c58b66f09702cbcd774931d7766bbfd35","tests/corrupt/bug-1655846.avif":"e0a5a06225800fadf05f5352503a4cec11af73eef705c43b4acab5f4a99dea50","tests/corrupt/bug-1661347.avif":"31c26561e1d9eafb60f7c5968b82a0859d203d73f17f26b29276256acee12966","tests/corrupt/hdlr-not-first.avif":"2c29308af077209b9c984921b7e36f8fb7ca7cf379cf8eba4c7a91f65bc7a304","tests/corrupt/hdlr-not-pict.avif":"9fe37619606645a95725300a9e34fada9190d1e0b3919881db84353941ca9291","tests/corrupt/imir-before-clap.avif":"22d6b5dacf0ef0be59053beba7564b08037fed859ada2885e3476e0ff0d19c95","tests/corrupt/ipma-duplicate-item_id.avif":"ca8c5275b0b8b79c1068489a52d0a5c8f0b4453463971e72b694189f11c10745","tests/corrupt/ipma-duplicate-version-and-flags.avif":"cf8e15ec4b210235f3d68332a1adeb64e35c41b8d8e1e7586ae38b6d9cd8926c","tests/corrupt/ipma-invalid-property-index.avif":"2480e773fa716d22883032d05fd4cf2c6b00fba8796cf4ff286a5d1ba26adff6","tests/corrupt/no-alpha-av1C.avif":"ad3d34d6331db7d9bea0c5f37efb88923520e33e08e7c636a5df435a4575eae7","tests/corrupt/no-av1C.avif":"eeb4fc50930c91465999f787c4a2a3b12de20556da0857be72da5a1a9eaa3f01","tests/corrupt/no-hdlr.avif":"91a1eb70c7b6adf2104e471d7deeeb98084a591d64ce09ba106c27edfbc3a409","tests/corrupt/no-ispe.avif":"4b6edfd8c9b40c25dc40305a6057e32b5e65f40da4a9d810c58dbff53254113f","tests/corrupt/no-pixi-for-alpha.avif":"f8adc3573c79ee25bf6d4dd2693c61661469b28f86a5c7b1d9e41b0e8d2d53bb","tests/corrupt/no-pixi.avif":"4b1776def440dc8b913c170e4479772ee6bbb299b8679f7c564704bd03c9597e","tests/imir-missing-essential.avif":"b1226e4b1358528befbd3f1126b5caf0c5051b4354777b87e71f6001f3829f87","tests/irot-missing-essential.avif":"b7da1fc1d1b45bb1b7ca3494476e052f711d794a6d010df6870872ed8b9da10e","tests/multiple-extents.avif":"b5549ac68793e155a726d754e565cea0da03fa17833d3545f45c79e13f4c9360","tests/no-mif1.avif":"1442aa6ffaeb9512724287768bfd1850d3aa29a651ef05abb33e5dec2b3ee5c2","tests/overflow.rs":"16b591d8def1a155b3b997622f6ea255536870d99c3d8f97c51755b77a50de3c","tests/public.rs":"27ff33f839c2b856720ba7cd7ba2c7bfcd88b9e4601d8b80faa8308ac9494621","tests/valid-alpha.avif":"9d417a35b9b62ad3ff66ffbc55f16552aacf821a092aa5ef4adff7e746bd4c2f","tests/valid.avif":"f0b33e09bf01232e0877df325f47986c0bee7764f2a81c9c908ae109e7dc63c4"},"package":null}

46
third_party/rust/mp4parse/src/lib.rs поставляемый
Просмотреть файл

@ -932,14 +932,35 @@ pub struct AvifContext {
}
impl AvifContext {
pub fn primary_item(&self) -> &[u8] {
pub fn primary_item_coded_data(&self) -> &[u8] {
self.item_as_slice(&self.primary_item)
}
pub fn alpha_item(&self) -> Option<&[u8]> {
pub fn primary_item_bits_per_channel(&self) -> Result<&[u8]> {
self.image_bits_per_channel(self.primary_item.id)
}
pub fn alpha_item_coded_data(&self) -> &[u8] {
self.alpha_item
.as_ref()
.map(|item| self.item_as_slice(item))
.map_or(&[], |item| self.item_as_slice(item))
}
pub fn alpha_item_bits_per_channel(&self) -> Result<&[u8]> {
self.alpha_item
.as_ref()
.map_or(Ok(&[]), |item| self.image_bits_per_channel(item.id))
}
fn image_bits_per_channel(&self, item_id: ItemId) -> Result<&[u8]> {
match self
.item_properties
.get(item_id, BoxType::PixelInformationBox)?
{
Some(ItemProperty::Channels(pixi)) => Ok(pixi.bits_per_channel.as_slice()),
Some(other_property) => panic!("property key mismatch: {:?}", other_property),
None => Ok(&[]),
}
}
pub fn spatial_extents_ptr(&self) -> Result<*const ImageSpatialExtentsProperty> {
@ -2258,7 +2279,7 @@ fn read_iprp<T: Read>(
pub enum ItemProperty {
AuxiliaryType(AuxiliaryTypeProperty),
AV1Config(AV1ConfigBox),
Channels(TryVec<u8>),
Channels(PixelInformation),
Colour(ColourInformation),
ImageSpatialExtents(ImageSpatialExtentsProperty),
Mirroring(ImageMirror),
@ -2716,24 +2737,29 @@ fn read_ispe<T: Read>(src: &mut BMFFBox<T>) -> Result<ImageSpatialExtentsPropert
})
}
#[derive(Debug)]
pub struct PixelInformation {
bits_per_channel: TryVec<u8>,
}
/// Parse pixel information
/// See HEIF (ISO 23008-12:2017) § 6.5.6
fn read_pixi<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<u8>> {
fn read_pixi<T: Read>(src: &mut BMFFBox<T>) -> Result<PixelInformation> {
let version = read_fullbox_version_no_flags(src)?;
if version != 0 {
return Err(Error::Unsupported("pixi version"));
}
let num_channels = src.read_u8()?.into();
let mut channels = TryVec::with_capacity(num_channels)?;
let num_channels_read = src.try_read_to_end(&mut channels)?;
let num_channels = src.read_u8()?;
let mut bits_per_channel = TryVec::with_capacity(num_channels.to_usize())?;
let num_channels_read = src.try_read_to_end(&mut bits_per_channel)?;
if num_channels_read != num_channels {
if u8::try_from(num_channels_read)? != num_channels {
return Err(Error::InvalidData("invalid num_channels"));
}
check_parser_state!(src.content);
Ok(channels)
Ok(PixelInformation { bits_per_channel })
}
/// Despite [Rec. ITU-T H.273] (12/2016) defining the CICP fields as having a

8
third_party/rust/mp4parse/tests/public.rs поставляемый
Просмотреть файл

@ -758,7 +758,7 @@ fn public_avif_primary_item() {
let input = &mut File::open(IMAGE_AVIF).expect("Unknown file");
let context = mp4::read_avif(input, ParseStrictness::Normal).expect("read_avif failed");
assert_eq!(
context.primary_item(),
context.primary_item_coded_data(),
[
0x12, 0x00, 0x0A, 0x07, 0x38, 0x00, 0x06, 0x90, 0x20, 0x20, 0x69, 0x32, 0x0C, 0x16,
0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x79, 0x4C, 0xD2, 0x02
@ -770,7 +770,7 @@ fn public_avif_primary_item() {
fn public_avif_primary_item_split_extents() {
let input = &mut File::open(IMAGE_AVIF_EXTENTS).expect("Unknown file");
let context = mp4::read_avif(input, ParseStrictness::Normal).expect("read_avif failed");
assert_eq!(context.primary_item().len(), 52);
assert_eq!(context.primary_item_coded_data().len(), 52);
}
#[test]
@ -783,7 +783,7 @@ fn public_avif_alpha_item() {
fn public_avif_alpha_non_premultiplied() {
let input = &mut File::open(IMAGE_AVIF_ALPHA).expect("Unknown file");
let context = mp4::read_avif(input, ParseStrictness::Normal).expect("read_avif failed");
assert!(context.alpha_item().is_some());
assert!(!context.alpha_item_coded_data().is_empty());
assert!(!context.premultiplied_alpha);
}
@ -791,7 +791,7 @@ fn public_avif_alpha_non_premultiplied() {
fn public_avif_alpha_premultiplied() {
let input = &mut File::open(IMAGE_AVIF_ALPHA_PREMULTIPLIED).expect("Unknown file");
let context = mp4::read_avif(input, ParseStrictness::Normal).expect("read_avif failed");
assert!(context.alpha_item().is_some());
assert!(!context.alpha_item_coded_data().is_empty());
assert!(context.premultiplied_alpha);
assert_avif_valid(input);
}

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"fa0e2b46e9547dba9134da4001b2cd803fac58f9252394aa62653fe99bd220fa","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"f776ed4bbb7b58a5684402a9c5c28dfe1fa02b6b184139b2c2c49384cc1e3723","cbindgen.toml":"f82065edc5be3d2e43db65ac67490194701b3800ce3d42976fc7ad351928a296","examples/dump.rs":"268093925d28d1636e106d93a2f2917fb1d7ddaf04ecd70880e1551fb578de1a","src/lib.rs":"7097c7e9a9f2852472897b19d1c14268aa6190b78609ae90a0c69a65de5538b8","tests/test_chunk_out_of_range.rs":"b5da583218d98027ed973a29c67434a91a1306f2d2fb39ec4d640d4824c308ce","tests/test_encryption.rs":"b918f0f10e7708bff5fae4becf1d09a188db25d874d0919d509b90266504eed7","tests/test_fragment.rs":"e90eb5a4418d30002655466c0c4b3125c7fd70a74b6871471eaa172f1def9db8","tests/test_rotation.rs":"fb43c2f2dfa496d151c33bdd46c0fd3252387c23cc71e2cac9ed0234de715a81","tests/test_sample_table.rs":"19b8d0b0f7ed79a857329321b49f5a7f687901cadd4cd22bc6728febd919d3ce","tests/test_workaround_stsc.rs":"7dd419f3d55b9a3a039cac57e58a9240a9c8166bcd4356c24f69f731c3ced83b"},"package":null}
{"files":{"Cargo.toml":"fa0e2b46e9547dba9134da4001b2cd803fac58f9252394aa62653fe99bd220fa","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"f776ed4bbb7b58a5684402a9c5c28dfe1fa02b6b184139b2c2c49384cc1e3723","cbindgen.toml":"f82065edc5be3d2e43db65ac67490194701b3800ce3d42976fc7ad351928a296","examples/dump.rs":"268093925d28d1636e106d93a2f2917fb1d7ddaf04ecd70880e1551fb578de1a","src/lib.rs":"9bec128eb9ac71a79e20a5e2c7125579baab921d285fb897ed04525df4ab9827","tests/test_chunk_out_of_range.rs":"b5da583218d98027ed973a29c67434a91a1306f2d2fb39ec4d640d4824c308ce","tests/test_encryption.rs":"b918f0f10e7708bff5fae4becf1d09a188db25d874d0919d509b90266504eed7","tests/test_fragment.rs":"e90eb5a4418d30002655466c0c4b3125c7fd70a74b6871471eaa172f1def9db8","tests/test_rotation.rs":"fb43c2f2dfa496d151c33bdd46c0fd3252387c23cc71e2cac9ed0234de715a81","tests/test_sample_table.rs":"19b8d0b0f7ed79a857329321b49f5a7f687901cadd4cd22bc6728febd919d3ce","tests/test_workaround_stsc.rs":"7dd419f3d55b9a3a039cac57e58a9240a9c8166bcd4356c24f69f731c3ced83b"},"package":null}

35
third_party/rust/mp4parse_capi/src/lib.rs поставляемый
Просмотреть файл

@ -314,18 +314,25 @@ pub struct Mp4parseParser {
video_track_sample_descriptions: TryHashMap<u32, TryVec<Mp4parseTrackVideoSampleInfo>>,
}
#[repr(C)]
#[derive(Debug)]
pub struct Mp4parseAvifImageItem {
pub coded_data: Mp4parseByteData,
pub bits_per_channel: Mp4parseByteData,
}
#[repr(C)]
#[derive(Debug)]
pub struct Mp4parseAvifImage {
pub primary_item: Mp4parseByteData,
pub primary_image: Mp4parseAvifImageItem,
/// The size of the image; should never be null unless using permissive parsing
pub spatial_extents: *const mp4parse::ImageSpatialExtentsProperty,
pub nclx_colour_information: *const mp4parse::NclxColourInformation,
pub icc_colour_information: Mp4parseByteData,
pub image_rotation: mp4parse::ImageRotation,
pub image_mirror: *const mp4parse::ImageMirror,
/// If no alpha item exists, `.length` will be 0 and `.data` will be null
pub alpha_item: Mp4parseByteData,
/// If no alpha item exists, members' `.length` will be 0 and `.data` will be null
pub alpha_image: Mp4parseAvifImageItem,
pub premultiplied_alpha: bool,
}
@ -1022,8 +1029,8 @@ fn mp4parse_get_track_video_info_safe(
/// pointer points to a valid `Mp4parseAvifParser`, and that the avif_image
/// pointer points to a valid `Mp4parseAvifImage`. If there was not a previous
/// successful call to `mp4parse_avif_read()`, no guarantees are made as to
/// the state of `avif_image`. If `avif_image.alpha_item` is set to a
/// positive `length` and non-null `data`, then the `avif_image` contains an
/// the state of `avif_image`. If `avif_image.alpha_image.coded_data` is set to
/// a positive `length` and non-null `data`, then the `avif_image` contains a
/// valid alpha channel data. Otherwise, the image is opaque.
#[no_mangle]
pub unsafe extern "C" fn mp4parse_avif_get_image(
@ -1047,17 +1054,25 @@ pub fn mp4parse_avif_get_image_safe(
) -> mp4parse::Result<Mp4parseAvifImage> {
let context = parser.context();
let primary_image = Mp4parseAvifImageItem {
coded_data: Mp4parseByteData::with_data(context.primary_item_coded_data()),
bits_per_channel: Mp4parseByteData::with_data(context.primary_item_bits_per_channel()?),
};
// If there is no alpha present, all the `Mp4parseByteData`s will be zero length
let alpha_image = Mp4parseAvifImageItem {
coded_data: Mp4parseByteData::with_data(context.alpha_item_coded_data()),
bits_per_channel: Mp4parseByteData::with_data(context.alpha_item_bits_per_channel()?),
};
Ok(Mp4parseAvifImage {
primary_item: Mp4parseByteData::with_data(context.primary_item()),
primary_image,
spatial_extents: context.spatial_extents_ptr()?,
nclx_colour_information: context.nclx_colour_information_ptr()?,
icc_colour_information: Mp4parseByteData::with_data(context.icc_colour_information()?),
image_rotation: context.image_rotation()?,
image_mirror: context.image_mirror_ptr()?,
alpha_item: context
.alpha_item()
.map(Mp4parseByteData::with_data)
.unwrap_or_default(),
alpha_image,
premultiplied_alpha: context.premultiplied_alpha,
})
}

Просмотреть файл

@ -9,7 +9,7 @@ description = "Shared Rust code for libxul"
geckoservo = { path = "../../../../servo/ports/geckolib" }
kvstore = { path = "../../../components/kvstore" }
lmdb-rkv-sys = { version = "0.11", features = ["mdb_idl_logn_9"] }
mp4parse_capi = { git = "https://github.com/mozilla/mp4parse-rust", rev = "62aa5d4e46289351ebfa2712668077ba8aa81064", features = ["missing-pixi-permitted"] }
mp4parse_capi = { git = "https://github.com/mozilla/mp4parse-rust", rev = "c6ba5afd856c158d9cfc1a447165fcfaaf2b797c", features = ["missing-pixi-permitted"] }
nserror = { path = "../../../../xpcom/rust/nserror" }
nsstring = { path = "../../../../xpcom/rust/nsstring" }
netwerk_helper = { path = "../../../../netwerk/base/rust-helper" }