image-codecs: borrow the ICC profile and EXIF in the PNG header

The PNG writer copied the caller's ICC profile, and the exported EXIF,
into new buffers before writing the header. Each tagged save allocated a
second profile-sized buffer that could abort the process when memory ran
short. The header now borrows the profile, and borrows the EXIF whenever
export_exif returns it unchanged.
This commit is contained in:
dotCooCoo
2026-11-23 23:58:58 -08:00
parent 249a41bd93
commit d28ad274b3
+2 -2
View File
@@ -1360,12 +1360,12 @@ fn start<W: Write>(
if opts.embed_icc
&& let Some(icc) = icc
{
info.icc_profile = Some(icc.clone().into());
info.icc_profile = Some(std::borrow::Cow::Borrowed(icc.as_slice()));
}
if opts.embed_metadata {
if let Some(exif) = &meta.exif {
// The pixels are written as they are shown: never let a viewer rotate them again.
info.exif_metadata = Some(crate::resolution::export_exif(exif, meta.dpi).into_owned().into());
info.exif_metadata = Some(crate::resolution::export_exif(exif, meta.dpi));
}
if let Some((x, y)) = meta.dpi
&& x > 0.0