mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 13:00:36 -05:00
clean up
This commit is contained in:
parent
1b545f980a
commit
977026c332
1 changed files with 103 additions and 100 deletions
|
@ -100,22 +100,22 @@ where
|
||||||
pub(crate) fn premultiply_alpha(
|
pub(crate) fn premultiply_alpha(
|
||||||
image: DynamicImage,
|
image: DynamicImage,
|
||||||
) -> Result<DynamicImage, AnyError> {
|
) -> Result<DynamicImage, AnyError> {
|
||||||
match image.color() {
|
match image {
|
||||||
ColorType::La8 => Ok(DynamicImage::ImageLumaA8(process_premultiply_alpha(
|
DynamicImage::ImageLumaA8(image) => {
|
||||||
image.as_luma_alpha8().unwrap(),
|
Ok(process_premultiply_alpha(&image).into())
|
||||||
))),
|
}
|
||||||
ColorType::La16 => Ok(DynamicImage::ImageLumaA16(
|
DynamicImage::ImageLumaA16(image) => {
|
||||||
process_premultiply_alpha(image.as_luma_alpha16().unwrap()),
|
Ok(process_premultiply_alpha(&image).into())
|
||||||
)),
|
}
|
||||||
ColorType::Rgba8 => Ok(DynamicImage::ImageRgba8(
|
DynamicImage::ImageRgba8(image) => {
|
||||||
process_premultiply_alpha(image.as_rgba8().unwrap()),
|
Ok(process_premultiply_alpha(&image).into())
|
||||||
)),
|
}
|
||||||
ColorType::Rgba16 => Ok(DynamicImage::ImageRgba16(
|
DynamicImage::ImageRgba16(image) => {
|
||||||
process_premultiply_alpha(image.as_rgba16().unwrap()),
|
Ok(process_premultiply_alpha(&image).into())
|
||||||
)),
|
}
|
||||||
ColorType::Rgb32F | ColorType::Rgba32F => {
|
DynamicImage::ImageRgb32F(_) | DynamicImage::ImageRgba32F(_) => {
|
||||||
Err(type_error(image_error_message(
|
Err(type_error(image_error_message(
|
||||||
"processing un-premultiply alpha",
|
"processing premultiply alpha",
|
||||||
NOT_SUPPORTED_BIT_DEPTH,
|
NOT_SUPPORTED_BIT_DEPTH,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -231,36 +231,30 @@ where
|
||||||
pub(crate) fn unpremultiply_alpha(
|
pub(crate) fn unpremultiply_alpha(
|
||||||
image: DynamicImage,
|
image: DynamicImage,
|
||||||
) -> Result<DynamicImage, AnyError> {
|
) -> Result<DynamicImage, AnyError> {
|
||||||
match image.color() {
|
match image {
|
||||||
ColorType::La8 => Ok(DynamicImage::ImageLumaA8(
|
DynamicImage::ImageLumaA8(image) => Ok(if is_premultiplied_alpha(&image) {
|
||||||
if is_premultiplied_alpha(image.as_luma_alpha8().unwrap()) {
|
process_unpremultiply_alpha(&image).into()
|
||||||
process_unpremultiply_alpha(image.as_luma_alpha8().unwrap())
|
} else {
|
||||||
|
image.into()
|
||||||
|
}),
|
||||||
|
DynamicImage::ImageLumaA16(image) => {
|
||||||
|
Ok(if is_premultiplied_alpha(&image) {
|
||||||
|
process_unpremultiply_alpha(&image).into()
|
||||||
} else {
|
} else {
|
||||||
image.into_luma_alpha8()
|
image.into()
|
||||||
},
|
})
|
||||||
)),
|
}
|
||||||
ColorType::La16 => Ok(DynamicImage::ImageLumaA16(
|
DynamicImage::ImageRgba8(image) => Ok(if is_premultiplied_alpha(&image) {
|
||||||
if is_premultiplied_alpha(image.as_luma_alpha16().unwrap()) {
|
process_unpremultiply_alpha(&image).into()
|
||||||
process_unpremultiply_alpha(image.as_luma_alpha16().unwrap())
|
} else {
|
||||||
} else {
|
image.into()
|
||||||
image.into_luma_alpha16()
|
}),
|
||||||
},
|
DynamicImage::ImageRgba16(image) => Ok(if is_premultiplied_alpha(&image) {
|
||||||
)),
|
process_unpremultiply_alpha(&image).into()
|
||||||
ColorType::Rgba8 => Ok(DynamicImage::ImageRgba8(
|
} else {
|
||||||
if is_premultiplied_alpha(image.as_rgba8().unwrap()) {
|
image.into()
|
||||||
process_unpremultiply_alpha(image.as_rgba8().unwrap())
|
}),
|
||||||
} else {
|
DynamicImage::ImageRgb32F(_) | DynamicImage::ImageRgba32F(_) => {
|
||||||
image.into_rgba8()
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
ColorType::Rgba16 => Ok(DynamicImage::ImageRgba16(
|
|
||||||
if is_premultiplied_alpha(image.as_rgba16().unwrap()) {
|
|
||||||
process_unpremultiply_alpha(image.as_rgba16().unwrap())
|
|
||||||
} else {
|
|
||||||
image.into_rgba16()
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
ColorType::Rgb32F | ColorType::Rgba32F => {
|
|
||||||
Err(type_error(image_error_message(
|
Err(type_error(image_error_message(
|
||||||
"processing un-premultiply alpha",
|
"processing un-premultiply alpha",
|
||||||
NOT_SUPPORTED_BIT_DEPTH,
|
NOT_SUPPORTED_BIT_DEPTH,
|
||||||
|
@ -409,71 +403,79 @@ pub(crate) fn to_srgb_from_icc_profile(
|
||||||
Ok(icc_profile) => {
|
Ok(icc_profile) => {
|
||||||
let srgb_icc_profile = Profile::new_srgb();
|
let srgb_icc_profile = Profile::new_srgb();
|
||||||
let color = image.color();
|
let color = image.color();
|
||||||
match color {
|
match image {
|
||||||
ColorType::L8 => {
|
DynamicImage::ImageLuma8(image) => Ok(
|
||||||
Ok(DynamicImage::ImageLuma8(process_icc_profile_conversion(
|
process_icc_profile_conversion(
|
||||||
image.as_luma8().unwrap(),
|
&image,
|
||||||
color,
|
color,
|
||||||
icc_profile,
|
icc_profile,
|
||||||
srgb_icc_profile,
|
srgb_icc_profile,
|
||||||
)))
|
)
|
||||||
}
|
.into(),
|
||||||
ColorType::L16 => {
|
),
|
||||||
Ok(DynamicImage::ImageLuma16(process_icc_profile_conversion(
|
DynamicImage::ImageLuma16(image) => Ok(
|
||||||
image.as_luma16().unwrap(),
|
process_icc_profile_conversion(
|
||||||
|
&image,
|
||||||
color,
|
color,
|
||||||
icc_profile,
|
icc_profile,
|
||||||
srgb_icc_profile,
|
srgb_icc_profile,
|
||||||
)))
|
)
|
||||||
}
|
.into(),
|
||||||
ColorType::La8 => {
|
),
|
||||||
Ok(DynamicImage::ImageLumaA8(process_icc_profile_conversion(
|
DynamicImage::ImageLumaA8(image) => Ok(
|
||||||
image.as_luma_alpha8().unwrap(),
|
process_icc_profile_conversion(
|
||||||
|
&image,
|
||||||
color,
|
color,
|
||||||
icc_profile,
|
icc_profile,
|
||||||
srgb_icc_profile,
|
srgb_icc_profile,
|
||||||
)))
|
)
|
||||||
}
|
.into(),
|
||||||
ColorType::La16 => {
|
),
|
||||||
Ok(DynamicImage::ImageLumaA16(process_icc_profile_conversion(
|
DynamicImage::ImageLumaA16(image) => Ok(
|
||||||
image.as_luma_alpha16().unwrap(),
|
process_icc_profile_conversion(
|
||||||
|
&image,
|
||||||
color,
|
color,
|
||||||
icc_profile,
|
icc_profile,
|
||||||
srgb_icc_profile,
|
srgb_icc_profile,
|
||||||
)))
|
)
|
||||||
}
|
.into(),
|
||||||
ColorType::Rgb8 => {
|
),
|
||||||
Ok(DynamicImage::ImageRgb8(process_icc_profile_conversion(
|
DynamicImage::ImageRgb8(image) => Ok(
|
||||||
image.as_rgb8().unwrap(),
|
process_icc_profile_conversion(
|
||||||
|
&image,
|
||||||
color,
|
color,
|
||||||
icc_profile,
|
icc_profile,
|
||||||
srgb_icc_profile,
|
srgb_icc_profile,
|
||||||
)))
|
)
|
||||||
}
|
.into(),
|
||||||
ColorType::Rgb16 => {
|
),
|
||||||
Ok(DynamicImage::ImageRgb16(process_icc_profile_conversion(
|
DynamicImage::ImageRgb16(image) => Ok(
|
||||||
image.as_rgb16().unwrap(),
|
process_icc_profile_conversion(
|
||||||
|
&image,
|
||||||
color,
|
color,
|
||||||
icc_profile,
|
icc_profile,
|
||||||
srgb_icc_profile,
|
srgb_icc_profile,
|
||||||
)))
|
)
|
||||||
}
|
.into(),
|
||||||
ColorType::Rgba8 => {
|
),
|
||||||
Ok(DynamicImage::ImageRgba8(process_icc_profile_conversion(
|
DynamicImage::ImageRgba8(image) => Ok(
|
||||||
image.as_rgba8().unwrap(),
|
process_icc_profile_conversion(
|
||||||
|
&image,
|
||||||
color,
|
color,
|
||||||
icc_profile,
|
icc_profile,
|
||||||
srgb_icc_profile,
|
srgb_icc_profile,
|
||||||
)))
|
)
|
||||||
}
|
.into(),
|
||||||
ColorType::Rgba16 => {
|
),
|
||||||
Ok(DynamicImage::ImageRgba16(process_icc_profile_conversion(
|
DynamicImage::ImageRgba16(image) => Ok(
|
||||||
image.as_rgba16().unwrap(),
|
process_icc_profile_conversion(
|
||||||
|
&image,
|
||||||
color,
|
color,
|
||||||
icc_profile,
|
icc_profile,
|
||||||
srgb_icc_profile,
|
srgb_icc_profile,
|
||||||
)))
|
)
|
||||||
}
|
.into(),
|
||||||
|
),
|
||||||
_ => Err(type_error(image_error_message(
|
_ => Err(type_error(image_error_message(
|
||||||
"processing un-premultiply alpha",
|
"processing un-premultiply alpha",
|
||||||
NOT_SUPPORTED_BIT_DEPTH,
|
NOT_SUPPORTED_BIT_DEPTH,
|
||||||
|
@ -634,23 +636,24 @@ pub(crate) fn to_srgb_from_icc_profile(
|
||||||
|
|
||||||
// /// Convert the color space of the image from sRGB to Display-P3.
|
// /// Convert the color space of the image from sRGB to Display-P3.
|
||||||
// fn srgb_to_display_p3(image: DynamicImage) -> Result<DynamicImage, AnyError> {
|
// fn srgb_to_display_p3(image: DynamicImage) -> Result<DynamicImage, AnyError> {
|
||||||
// match image.color() {
|
// match image {
|
||||||
// // The conversion of the lumincance color types to the display-p3 color space is meaningless.
|
// // The conversion of the lumincance color types to the display-p3 color space is meaningless.
|
||||||
// ColorType::L8 | ColorType::L16 | ColorType::La8 | ColorType::La16 => {
|
// DynamicImage::ImageLuma8(_)
|
||||||
// Ok(image)
|
// | DynamicImage::ImageLuma16(_)
|
||||||
|
// | DynamicImage::ImageLumaA8(_)
|
||||||
|
// | DynamicImage::ImageLumaA16(_) => Ok(image),
|
||||||
|
// DynamicImage::ImageRgb8(image) => {
|
||||||
|
// Ok(process_srgb_to_display_p3(&image).into())
|
||||||
|
// }
|
||||||
|
// DynamicImage::ImageRgb16(image) => {
|
||||||
|
// Ok(process_srgb_to_display_p3(&image).into())
|
||||||
|
// }
|
||||||
|
// DynamicImage::ImageRgba8(image) => {
|
||||||
|
// Ok(process_srgb_to_display_p3(&image).into())
|
||||||
|
// }
|
||||||
|
// DynamicImage::ImageRgba16(image) => {
|
||||||
|
// Ok(process_srgb_to_display_p3(&image).into())
|
||||||
// }
|
// }
|
||||||
// ColorType::Rgb8 => Ok(DynamicImage::ImageRgb8(process_srgb_to_display_p3(
|
|
||||||
// image.as_rgb8().unwrap(),
|
|
||||||
// ))),
|
|
||||||
// ColorType::Rgb16 => Ok(DynamicImage::ImageRgb16(
|
|
||||||
// process_srgb_to_display_p3(image.as_rgb16().unwrap()),
|
|
||||||
// )),
|
|
||||||
// ColorType::Rgba8 => Ok(DynamicImage::ImageRgba8(
|
|
||||||
// process_srgb_to_display_p3(image.as_rgba8().unwrap()),
|
|
||||||
// )),
|
|
||||||
// ColorType::Rgba16 => Ok(DynamicImage::ImageRgba16(
|
|
||||||
// process_srgb_to_display_p3(image.as_rgba16().unwrap()),
|
|
||||||
// )),
|
|
||||||
// _ => Err(type_error(image_error_message(
|
// _ => Err(type_error(image_error_message(
|
||||||
// "processing ICC color profile conversion to sRGB",
|
// "processing ICC color profile conversion to sRGB",
|
||||||
// NOT_SUPPORTED_BIT_DEPTH,
|
// NOT_SUPPORTED_BIT_DEPTH,
|
||||||
|
|
Loading…
Add table
Reference in a new issue