Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Fixes pixelSpecificationNarrower for the png plugin.
Browse files Browse the repository at this point in the history
Summary: In some cases (e.g when the input image would have a `skipFirst` / `skipLast` alphaInfo) encoding an image to png would fail as the narrowed pixel spec wasn't accepted by the png compressor.

Reviewed By: lambdapioneer

Differential Revision: D13693679

fbshipit-source-id: c8793147a468e676aaa5570d1e148b903cfe6075
  • Loading branch information
cuva authored and facebook-github-bot committed Jan 16, 2019
1 parent f5d365b commit 0727fd5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cpp/spectrum/plugins/png/LibPngTranscodingPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ inline codecs::DecompressorProvider::Factory makeLibPngDecompressorFactory() {

image::pixel::Specification pixelSpecificationNarrower(
const image::pixel::Specification& pixelSpecification) {
if (pixelSpecification == image::pixel::specifications::RGBA) {
// PNGs cannot encode RGBA.
return image::pixel::specifications::ARGB;
if (pixelSpecification.colorModel == image::pixel::colormodels::Gray) {
return image::pixel::specifications::Gray;
} else {
return pixelSpecification;
switch (pixelSpecification.alphaInfo) {
case image::pixel::AlphaInfo::None:
case image::pixel::AlphaInfo::SkipLast:
case image::pixel::AlphaInfo::SkipFirst:
return image::pixel::specifications::RGB;
default:
return image::pixel::specifications::ARGB;
}
}
}

Expand Down

0 comments on commit 0727fd5

Please sign in to comment.