Skip to content

Commit

Permalink
Merge branch 'release/3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Dolski committed May 13, 2016
2 parents 623ce6b + 46811f7 commit 0238f1e
Show file tree
Hide file tree
Showing 81 changed files with 4,181 additions and 413 deletions.
6 changes: 5 additions & 1 deletion build/deploy_website.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
Dir.mktmpdir('website') do |tmp_dir|
puts "Building site in #{tmp_dir}"
`jekyll build -s website -d #{tmp_dir}`
`build/build_javadoc.rb #{tmp_dir}/javadoc`

# switch to the gh-pages branch
if orphan_exists
Expand All @@ -34,12 +33,17 @@
end

# wipe it clean and copy the new website into the place of the old one
puts 'Removing current website'
`git rm -rf .`
puts 'Copying new website into place'
`cp -r #{File.join(tmp_dir, '*')} .`

# commit and push
puts 'Adding files'
`git add *.html */*`
puts 'Committing changes'
`git commit -m 'Update website'`
puts 'Pushing website'
`git push origin gh-pages`
end

Expand Down
28 changes: 23 additions & 5 deletions delegates.rb.sample
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,32 @@ module Cantaloupe
end

##
# Used to define a service in the IIIF Image API 2.0 information endpoint.
# Return nil to avoid.
# Used to add additional keys to the information JSON response. including
# `attribution`, `license`, `logo`, `service`, and custom keys. See
# {http://iiif.io/api/image/2.1/#image-information the Image API
# specification}.
#
# @param identifier [String] Image identifier
# @return [Hash,nil] Hash that will be appended to the `service` key in
# IIIF Image API 2.x information responses, or nil.
# @return [Hash] Hash that will be merged into IIIF Image API 2.x
# information responses. Return an empty hash to add nothing.
#
def self.get_iiif2_service(identifier)
def self.extra_iiif2_information_response_keys(identifier)
=begin
Example:
{
'attribution' => 'Copyright My Great Organization. All rights '\
'reserved.',
'license' => 'http://example.org/license.html',
'logo' => 'http://example.org/logo.png',
'service' => {
'@context' => 'http://iiif.io/api/annex/services/physdim/1/context.json',
'profile' => 'http://iiif.io/api/annex/services/physdim',
'physicalScale' => 0.0025,
'physicalUnits' => 'in'
}
}
=end
{}
end

##
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<artifactId>Cantaloupe</artifactId>
<packaging>war</packaging>
<!-- needs to be kept synchronized with properties/cantaloupe.version -->
<version>3.0.1</version>
<version>3.1</version>
<name>Cantaloupe</name>
<url>https://medusa-project.github.io/cantaloupe/</url>
<inceptionYear>2015</inceptionYear>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<cantaloupe.version>3.0.1</cantaloupe.version>
<cantaloupe.version>3.1</cantaloupe.version>
<restlet.version>2.3.7</restlet.version>
</properties>

Expand Down
36 changes: 21 additions & 15 deletions src/main/java/edu/illinois/library/cantaloupe/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,33 @@ public class Application {
private static Logger logger = LoggerFactory.getLogger(Application.class);

/**
* @return The application version from manifest.mf, or a string like
* "Non-Release" if not running from a jar.
* @return The application version from MANIFEST.MF, or a string like
* "SNAPSHOT" if not running from a jar.
*/
public static String getVersion() {
String versionStr = "Non-Release";
String versionStr = "SNAPSHOT";
Class clazz = Application.class;
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
if (classPath.startsWith("jar")) {
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
"/META-INF/MANIFEST.MF";
try {
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes();
String version = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (version != null) {
versionStr = version;
URL classUrl = clazz.getResource(className);
if (classUrl != null) {
String classPath = clazz.getResource(className).toString();
if (classPath.startsWith("jar")) {
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
"/META-INF/MANIFEST.MF";
try {
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes();
String version = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (version != null) {
versionStr = version;
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
} else {
versionStr = "Unknown";
logger.error("Unable to get the {} resource", className);
}
return versionStr;
}
Expand Down
52 changes: 38 additions & 14 deletions src/main/java/edu/illinois/library/cantaloupe/image/Crop.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
*/
public class Crop implements Operation {

public enum Shape {
ARBITRARY, SQUARE
}

public enum Unit {
PERCENT, PIXELS;
PERCENT, PIXELS
}

private float height = 0.0f;
private boolean isFull = false;
private Shape shape = Shape.ARBITRARY;
private Unit unit = Unit.PIXELS;
private float width = 0.0f;
private float x = 0.0f;
Expand Down Expand Up @@ -70,6 +75,11 @@ public Rectangle getRectangle(Dimension fullSize) {
y = 0;
width = fullSize.width;
height = fullSize.height;
} else if (this.getShape().equals(Shape.SQUARE)) {
final int shortestSide = Math.min(fullSize.width, fullSize.height);
x = (fullSize.width - shortestSide) / 2;
y = (fullSize.height - shortestSide) / 2;
width = height = shortestSide;
} else if (this.getUnit().equals(Unit.PERCENT)) {
x = Math.round(this.getX() * fullSize.width);
y = Math.round(this.getY() * fullSize.height);
Expand All @@ -92,6 +102,10 @@ public Dimension getResultingSize(Dimension fullSize) {
return getRectangle(fullSize).getSize();
}

public Shape getShape() {
return shape;
}

public Unit getUnit() {
return unit;
}
Expand Down Expand Up @@ -159,6 +173,10 @@ public void setHeight(float height) throws IllegalArgumentException {
this.height = height;
}

public void setShape(Shape shape) {
this.shape = shape;
}

public void setUnit(Unit unit) {
this.unit = unit;
}
Expand Down Expand Up @@ -193,9 +211,9 @@ public void setY(float y) throws IllegalArgumentException {
/**
* @param fullSize Full size of the source image on which the operation
* is being applied.
* @return Map with <code>x</code>, <code>y</code>, <code>width</code>, and
* <code>height</code> keys and integer values corresponding to the
* absolute crop coordinates.
* @return Map with <code>operation</code>, <code>x</code>, <code>y</code>,
* <code>width</code>, and <code>height</code> keys and integer
* values corresponding to the absolute crop coordinates.
*/
@Override
public Map<String,Object> toMap(Dimension fullSize) {
Expand All @@ -216,6 +234,8 @@ public Map<String,Object> toMap(Dimension fullSize) {
* <dl>
* <dt>No-op</dt>
* <dd>none</dd>
* <dt>Square</dt>
* <dd>square</dd>
* <dt>Percent</dt>
* <dd>x%,y%,w%,h%</dd>
* <dt>Pixels</dt>
Expand All @@ -231,18 +251,22 @@ public String toString() {
str += "none";
} else {
String x, y, width, height;
if (this.getUnit().equals(Unit.PERCENT)) {
x = NumberUtil.removeTrailingZeroes(this.getX() * 100) + "%";
y = NumberUtil.removeTrailingZeroes(this.getY() * 100) + "%";
width = NumberUtil.removeTrailingZeroes(this.getWidth() * 100) + "%";
height = NumberUtil.removeTrailingZeroes(this.getHeight() * 100) + "%";
if (this.getShape().equals(Shape.SQUARE)) {
str+= "square";
} else {
x = Integer.toString(Math.round(this.getX()));
y = Integer.toString(Math.round(this.getY()));
width = NumberUtil.removeTrailingZeroes(this.getWidth());
height = NumberUtil.removeTrailingZeroes(this.getHeight());
if (this.getUnit().equals(Unit.PERCENT)) {
x = NumberUtil.removeTrailingZeroes(this.getX() * 100) + "%";
y = NumberUtil.removeTrailingZeroes(this.getY() * 100) + "%";
width = NumberUtil.removeTrailingZeroes(this.getWidth() * 100) + "%";
height = NumberUtil.removeTrailingZeroes(this.getHeight() * 100) + "%";
} else {
x = Integer.toString(Math.round(this.getX()));
y = Integer.toString(Math.round(this.getY()));
width = NumberUtil.removeTrailingZeroes(this.getWidth());
height = NumberUtil.removeTrailingZeroes(this.getHeight());
}
str += String.format("%s,%s,%s,%s", x, y, width, height);
}
str += String.format("%s,%s,%s,%s", x, y, width, height);
}
return str;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ class FfmpegProcessor extends AbstractProcessor implements FileProcessor {
ProcessorFeature.MIRRORING,
ProcessorFeature.REGION_BY_PERCENT,
ProcessorFeature.REGION_BY_PIXELS,
ProcessorFeature.REGION_SQUARE,
ProcessorFeature.ROTATION_BY_90S,
ProcessorFeature.SIZE_ABOVE_FULL,
ProcessorFeature.SIZE_BY_DISTORTED_WIDTH_HEIGHT,
ProcessorFeature.SIZE_BY_FORCED_WIDTH_HEIGHT,
ProcessorFeature.SIZE_BY_HEIGHT,
ProcessorFeature.SIZE_BY_PERCENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ class GraphicsMagickProcessor extends AbstractProcessor
ProcessorFeature.MIRRORING,
ProcessorFeature.REGION_BY_PERCENT,
ProcessorFeature.REGION_BY_PIXELS,
ProcessorFeature.REGION_SQUARE,
ProcessorFeature.ROTATION_ARBITRARY,
ProcessorFeature.ROTATION_BY_90S,
ProcessorFeature.SIZE_ABOVE_FULL,
ProcessorFeature.SIZE_BY_DISTORTED_WIDTH_HEIGHT,
ProcessorFeature.SIZE_BY_FORCED_WIDTH_HEIGHT,
ProcessorFeature.SIZE_BY_HEIGHT,
ProcessorFeature.SIZE_BY_PERCENT,
Expand Down Expand Up @@ -291,7 +293,13 @@ private void assembleOperation(IMOperation imOp, OperationList ops,
if (op instanceof Crop) {
Crop crop = (Crop) op;
if (!crop.isNoOp()) {
if (crop.getUnit().equals(Crop.Unit.PERCENT)) {
if (crop.getShape().equals(Crop.Shape.SQUARE)) {
final int shortestSide =
Math.min(fullSize.width, fullSize.height);
int x = (fullSize.width - shortestSide) / 2;
int y = (fullSize.height - shortestSide) / 2;
imOp.crop(shortestSide, shortestSide, x, y);
} else if (crop.getUnit().equals(Crop.Unit.PERCENT)) {
// im4java doesn't support cropping x/y by percentage
// (only width/height), so we have to calculate them.
int x = Math.round(crop.getX() * fullSize.width);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public void write(BufferedImage image,
// JPEG doesn't support alpha, so convert to RGB or else the
// client will interpret as CMYK
image = Java2dUtil.removeAlpha(image);
Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter writer = (ImageWriter) iter.next();
try {
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpeg");
if (writers.hasNext()) {
ImageWriter writer = writers.next();
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(Configuration.getInstance().
Expand All @@ -60,30 +60,40 @@ public void write(BufferedImage image,
ImageOutputStream os = ImageIO.createImageOutputStream(outputStream);
writer.setOutput(os);
IIOImage iioImage = new IIOImage(image, null, null);
writer.write(null, iioImage, param);
} finally {
writer.dispose();
try {
writer.write(null, iioImage, param);
} finally {
writer.dispose();
}
}
break;
case PNG:
writers = ImageIO.getImageWritersByFormatName("png");
if (writers.hasNext()) {
final ImageWriter writer = writers.next();
ImageWriteParam param = writer.getDefaultWriteParam();
ImageOutputStream os = ImageIO.createImageOutputStream(outputStream);
writer.setOutput(os);
IIOImage iioImage = new IIOImage(image, null, null);
try {
writer.write(null, iioImage, param);
} finally {
writer.dispose();
}
}
break;
/*case PNG: // an alternative in case ImageIO.write() ever causes problems
writer = ImageIO.getImageWritersByFormatName("png").next();
ImageOutputStream os = ImageIO.createImageOutputStream(outputStream);
writer.setOutput(os);
writer.write(image);
break;*/
case TIF:
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("TIFF");
writers = ImageIO.getImageWritersByFormatName("tiff");
if (writers.hasNext()) {
writer = writers.next();
final ImageWriter writer = writers.next();
final ImageWriteParam param = writer.getDefaultWriteParam();
final String compressionType = Configuration.getInstance().
getString(Java2dProcessor.TIF_COMPRESSION_CONFIG_KEY);
final ImageWriteParam param = writer.getDefaultWriteParam();
if (compressionType != null) {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType(compressionType);
}

final IIOImage iioImage = new IIOImage(image, null, null);
IIOImage iioImage = new IIOImage(image, null, null);
ImageOutputStream ios =
ImageIO.createImageOutputStream(outputStream);
writer.setOutput(ios);
Expand All @@ -110,7 +120,7 @@ public void write(BufferedImage image,
* @param outputStream Stream to write the image to
* @throws IOException
*/
@SuppressWarnings({ "deprecation" })
@SuppressWarnings({"deprecation"})
public void write(PlanarImage image,
Format outputFormat,
OutputStream outputStream) throws IOException {
Expand Down Expand Up @@ -139,32 +149,6 @@ public void write(PlanarImage image,
}
}
break;
case JP2:
/*
TODO: this doesn't write anything
ImageIO.write(image, outputFormat.getExtension(),
ImageIO.createImageOutputStream(outputStream));
// and this causes an error
writers = ImageIO.getImageWritersByFormatName("JPEG2000");
if (writers.hasNext()) {
ImageWriter writer = writers.next();
J2KImageWriteParam j2Param = new J2KImageWriteParam();
j2Param.setLossless(false);
j2Param.setEncodingRate(Double.MAX_VALUE);
j2Param.setCodeBlockSize(new int[]{128, 8});
j2Param.setTilingMode(ImageWriteParam.MODE_DISABLED);
j2Param.setProgressionType("res");
ImageOutputStream os = ImageIO.
createImageOutputStream(outputStream);
writer.setOutput(os);
IIOImage iioImage = new IIOImage(image, null, null);
try {
writer.write(null, iioImage, j2Param);
} finally {
writer.dispose();
}
} */
break;
case JPG:
Iterator iter = ImageIO.getImageWritersByFormatName("JPEG");
ImageWriter writer = (ImageWriter) iter.next();
Expand Down
Loading

0 comments on commit 0238f1e

Please sign in to comment.