Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling, issue #149 #171

Merged
merged 5 commits into from
Apr 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,14 @@ public void processChunk(RepInfo info) throws Exception {
_nisoMetadata.setImageLength (height);
int[] bits = { bitDepth };
_nisoMetadata.setBitsPerSample (bits);
_nisoMetadata.setColorSpace(colorTypeToNiso (colorType));
_module.setColorType (colorType);
if (colorType == 1 || colorType == 5 || colorType > 6) {
boolean ctErr = false;
try {
_nisoMetadata.setColorSpace(colorTypeToNiso (colorType));
_module.setColorType (colorType);
} catch (PNGException e) {
ctErr = true;
}
if (ctErr || colorType == 1 || colorType == 5 || colorType > 6) {
ErrorMessage msg =
new ErrorMessage("Invalid color type " + colorType);
info.setMessage(msg);
Expand Down Expand Up @@ -161,7 +166,7 @@ public void processChunk(RepInfo info) throws Exception {
}

/* Convert PNG colour type to NISO color space */
int colorTypeToNiso (int typ) {
private int colorTypeToNiso (int typ) throws PNGException {
int val = 0;
switch (typ) {
case COLOR_GRAYSCALE:
Expand All @@ -176,8 +181,7 @@ int colorTypeToNiso (int typ) {
val = 3;
break;
default:
// This is an error, should report it TODO
break;
throw new PNGException ("Invalid color type");
}
return val;
}
Expand Down