-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH Partial support for reading gray+alpha PNGs
Currently, reading gray+alpha PNGs is only possible by throwing away the alpha channel.
- Loading branch information
Showing
4 changed files
with
33 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2012-2014 Luis Pedro Coelho <[email protected]> | ||
// Copyright 2012-2016 Luis Pedro Coelho <[email protected]> | ||
// License: MIT (see COPYING.MIT file) | ||
|
||
#include "base.h" | ||
|
@@ -109,6 +109,10 @@ std::auto_ptr<Image> PNGFormat::read(byte_source* src, ImageFactory* factory, co | |
// PNGs are in "network" order (ie., big-endian) | ||
if (bit_depth == 16 && !is_big_endian()) png_set_swap(p.png_ptr); | ||
|
||
const bool strip_alpha = get_optional_bool(opts, "strip_alpha", false); | ||
if (strip_alpha) { | ||
png_set_strip_alpha(p.png_ptr); | ||
} | ||
int d = -1; | ||
switch (png_get_color_type(p.png_ptr, p.png_info)) { | ||
case PNG_COLOR_TYPE_PALETTE: | ||
|
@@ -122,6 +126,12 @@ std::auto_ptr<Image> PNGFormat::read(byte_source* src, ImageFactory* factory, co | |
case PNG_COLOR_TYPE_GRAY: | ||
d = -1; | ||
break; | ||
case PNG_COLOR_TYPE_GRAY_ALPHA: | ||
if (!strip_alpha) { | ||
throw CannotReadError("imread.png: Color type (4: grayscale with alpha channel) can only be read when strip_alpha is set to true."); | ||
} | ||
d = -1; | ||
break; | ||
default: { | ||
std::ostringstream out; | ||
out << "imread.png: Color type (" | ||
|