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

Enable custom Quality in the model #172

Closed
wants to merge 2 commits into from
Closed
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 @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.base.CaseFormat;
import com.google.common.base.Enums;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import de.digitalcollections.iiif.model.MimeType;
Expand Down Expand Up @@ -54,17 +55,78 @@ public String toString() {
}
}

public enum Quality {
COLOR,
GRAY,
BITONAL,
DEFAULT;
/** See https://iiif.io/api/image/3.0/#quality */
public static class Quality {

private enum ImageApiQuality {
COLOR,
GRAY,
BITONAL,
DEFAULT,
OTHER;

@Override
public String toString() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, this.name());
}
}

/** The image is returned with all of its color information. */
public static final Quality COLOR = new Quality(ImageApiQuality.COLOR);

/** The image is returned in grayscale, where each pixel is black, white or any shade of gray in between. */
public static final Quality GRAY = new Quality(ImageApiQuality.GRAY);

/** The image returned is bitonal, where each pixel is either black or white. */
public static final Quality BITONAL = new Quality(ImageApiQuality.BITONAL);

/** The image is returned using the server’s default quality (e.g. color, gray or bitonal) for the image. */
public static final Quality DEFAULT = new Quality(ImageApiQuality.DEFAULT);

private final ImageApiQuality imageApiQuality;
private final String customQuality;

private Quality(ImageApiQuality quality) {
this.imageApiQuality = quality;
this.customQuality = null;
}

@JsonCreator
public Quality(String qualityName) {
if (!Enums.getIfPresent(ImageApiQuality.class, qualityName.toUpperCase()).isPresent()) {
this.imageApiQuality = ImageApiQuality.OTHER;
this.customQuality = qualityName.toUpperCase();
} else {
String name = qualityName.toUpperCase();
this.imageApiQuality = ImageApiQuality.valueOf(name);
this.customQuality = null;
}
}

@JsonValue
@Override
public String toString() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, this.name());
if (this.imageApiQuality == ImageApiQuality.OTHER) {
return this.customQuality.toLowerCase();
} else {
return this.imageApiQuality.toString();
}
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Quality)) {
return false;
}
Quality other = (Quality) obj;
return Objects.equals(this.imageApiQuality, other.imageApiQuality)
&& Objects.equals(this.customQuality, other.customQuality);
}

public static Quality valueOf(String qualityName) {
return new Quality(qualityName);
}

}

public static class Feature {
Expand Down