ALF-17766: ImageCropOptions Should be Refactored as TransformationSourceOptions

- Moved code in ImageCropOptions to CropSourceOptions
   - Moved crop rendition parameters to CropSourceOptionsSerializer
   - Removed notion of crop options from ImageRenderingEnding as its now handled by the source options processing of AbstractTransformationRenderingEngine and CropSourceOptionsSerializer
   - Removed notion of crop options from ImageTransformationOptions as its now handled by the source options in TransformationOptions
   - Changed ImageMagickContentTransformerWorker to get crop options from the TransformationOptions source options
   - Added CropSourceOptions to imageRenderingEngine's sourceOptionsSerializers in rendition-services-context.xml
   - Deprecated ImageCropOptions
   - Removed unused imports and log declaration in TransformationOptions


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@46218 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ray Gauss
2013-02-05 01:13:53 +00:00
parent e015d94242
commit 7bfed4b0c3
10 changed files with 417 additions and 343 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -22,13 +22,13 @@ package org.alfresco.repo.rendition.executer;
import java.util.Collection;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.transform.magick.ImageCropOptions;
import org.alfresco.repo.content.transform.magick.ImageResizeOptions;
import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.rendition.RenditionService;
import org.alfresco.service.cmr.repository.CropSourceOptions.CropSourceOptionsSerializer;
import org.alfresco.service.cmr.repository.TransformationOptions;
/**
@@ -116,112 +116,6 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine
*/
public static final String PARAM_ALLOW_ENLARGEMENT = "allowEnlargement";
// Crop params
/**
* This optional {@link Integer} or {@link Float} parameter specifies the
* width of the image after cropping. This may be expressed as pixels or it
* may represent a percentage of the original image width, depending on the
* value of the PARAM_IS_PERCENT_CROP parameter. <br>
* If no value is specified for this parameter then the width of the image
* will be unchanged. <br>
* If an image is being cropped and resized then the cropping happens first,
* followed by resizing of the cropped image.
*/
public static final String PARAM_CROP_WIDTH = "crop_width";
/**
* This optional {@link Integer} or {@link Float} parameter specifies the
* height of the image after cropping. This may be expressed as pixels or it
* may represent a percentage of the original image width, depending on the
* value of the PARAM_IS_PERCENT_CROP parameter. <br>
* If no value is specified for this parameter then the width of the image
* will be unchanged. <br>
* If an image is being cropped and resized then the cropping happens first,
* followed by resizing of the cropped image.
*/
public static final String PARAM_CROP_HEIGHT = "crop_height";
/**
* This optional {@link Integer} parameter specifies the horizontal position
* of the start point of the area to be cropped. By default this parameter
* sets the distance, in pixels, from the left-hand edge of the image to the
* start position of the crop area. By default a positive value will shift
* the start-position to the right, while a negative value will shift the
* start position to the left. Setting the PARAM_CROP_GRAVITY parameter may
* change this, however.<br>
* If this parameter is not set it is assumed to be 0.
*/
public static final String PARAM_CROP_X_OFFSET = "crop_x";
/**
* This optional {@link Integer} parameter specifies the vertical position
* of the start point of the area to be cropped. By default this parameter
* sets the distance, in pixels, from the top edge of the image to the start
* position of the crop area. By default a positive value will shift the
* start-position downwards, while a negative value will shift the start
* position upwards. Setting the PARAM_CROP_GRAVITY parameter may change
* this, however.<br>
* If this parameter is not set it is assumed to be 0.
*/
public static final String PARAM_CROP_Y_OFFSET = "crop_y";
/**
* This optional {@link String} parameter determines the 'zero' position
* from which offsets are measured and also determines the direction of
* offsets. The allowed values of gravity are the four cardinal points
* (North, East, etc.), the four ordinal points (NorhtWest, SouthEast, etc)
* and Center. By default NorthWest gravity is used.
* <p>
*
* If an ordinal gravity is set then the point from which offsets originate
* will be the appropriate corner. For example, NorthWest gravity would
* originate at teh top-left corner while SouthWest origin would originate
* at the bottom-left corner. Cardinal gravity sets the origin at the center
* of the appropriate edge. Center origin sets the origin at the center of
* the image.
* <p>
*
* Gravity also affects the direction of offsets and how the offset position
* relates to the cropped image. For example, NorthWest gravity sets
* positive horizontal offset direction to right, positive vertical
* direction to down and sets the cropped image origin to the top-left
* corner. Northerly gavities set the positive vertical direction to down.
* Southerly gavities set teh positive vertical direction to up. Easterly
* gavities set teh positive horizontal positive direction to left. Westerly
* gavities set teh positive horizontal positive direction to right.
* <p>
* Some gravity values do not specify a horizontal or a vertical direction
* explicitly. For example North does not specify a horizontal direction,
* while Center does not specify either horizontal or vertical direction. In
* thse cases the positive horizontal offset direction is always right and
* the positive vertical offset direction is always down.
* <p>
*
* The gravity also affects how the cropped image relates to the offset
* position. For example, NorthWest gravity causes the top-left corner of
* the cropped area to be the offset position, while NorthEast gravity would
* set the top-right corner of the cropped are to the offset position. When
* a direction is not explicitly specified then the center of the cropped
* area is placed at the offset position. For example, with North gravity
* the horizontal position is unspecified so the cropped area would be
* horizontally centered on the offset position, but the top edge of the
* cropped area would be at the offset position. For Center gravity the
* cropped area will be centered over the offset position both horizontally
* and vertically.
*/
public static final String PARAM_CROP_GRAVITY = "crop_gravity";
/**
* This optional {@link Boolean} flag parameter specifies how the
* PARAM_CROP_HEIGHT and PARAM_CROP_WIDTH parameters are interpreted. If
* this parameter is set to <code>true</code> then the cropped image height and
* width are represented as a percentage of the original image height and
* width. If this parameter is set to <code>false</code> then the rendition
* height and width are represented as pixels. This parameter defaults to
* <code>false</code>.
*/
public static final String PARAM_IS_PERCENT_CROP = "percent_crop";
/**
* This optional {@link String} parameter specifies any additional
* ImageMagick commands, that the user wishes to add. These commands are
@@ -261,12 +155,10 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine
String commandOptions = context.getCheckedParam(PARAM_COMMAND_OPTIONS, String.class);
ImageResizeOptions imageResizeOptions = getImageResizeOptions(context);
ImageCropOptions cropOptions = getImageCropOptions(context);
boolean autoOrient = context.getParamWithDefault(PARAM_AUTO_ORIENTATION, true);
imageTransformationOptions.setResizeOptions(imageResizeOptions);
imageTransformationOptions.setCropOptions(cropOptions);
imageTransformationOptions.setAutoOrient(autoOrient);
if (commandOptions != null)
{
@@ -309,31 +201,6 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine
imageResizeOptions.setAllowEnlargement(allowEnlargement);
return imageResizeOptions;
}
private ImageCropOptions getImageCropOptions(RenderingContext context)
{
int newWidth = context.getIntegerParam(PARAM_CROP_WIDTH, -1);
int newHeight = context.getIntegerParam(PARAM_CROP_HEIGHT, -1);
if (newHeight == -1 && newWidth == -1)
{
return null;
}
int xOffset = context.getIntegerParam(PARAM_CROP_X_OFFSET, 0);
int yOffset = context.getIntegerParam(PARAM_CROP_Y_OFFSET, 0);
boolean isPercentCrop = context.getParamWithDefault(PARAM_IS_PERCENT_CROP, false);
String gravity = context.getCheckedParam(PARAM_CROP_GRAVITY, String.class);
ImageCropOptions cropOptions = new ImageCropOptions();
cropOptions.setGravity(gravity);
cropOptions.setHeight(newHeight);
cropOptions.setPercentageCrop(isPercentCrop);
cropOptions.setWidth(newWidth);
cropOptions.setXOffset(xOffset);
cropOptions.setYOffset(yOffset);
return cropOptions;
}
@Override
protected void checkParameterValues(Action action)
@@ -341,8 +208,8 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine
// Some numerical parameters should not be zero or negative.
checkNumericalParameterIsPositive(action, PARAM_RESIZE_WIDTH);
checkNumericalParameterIsPositive(action, PARAM_RESIZE_HEIGHT);
checkNumericalParameterIsPositive(action, PARAM_CROP_HEIGHT);
checkNumericalParameterIsPositive(action, PARAM_CROP_WIDTH);
checkNumericalParameterIsPositive(action, CropSourceOptionsSerializer.PARAM_CROP_HEIGHT);
checkNumericalParameterIsPositive(action, CropSourceOptionsSerializer.PARAM_CROP_WIDTH);
// Target mime type should only be an image MIME type
String mimeTypeParam = (String)action.getParameterValue(PARAM_MIME_TYPE);
@@ -404,18 +271,18 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine
//Crop Params
paramList.add(new ParameterDefinitionImpl(PARAM_CROP_GRAVITY, DataTypeDefinition.TEXT, false,
getParamDisplayLabel(PARAM_CROP_GRAVITY)));
paramList.add(new ParameterDefinitionImpl(PARAM_CROP_HEIGHT, DataTypeDefinition.INT, false,
getParamDisplayLabel(PARAM_CROP_HEIGHT)));
paramList.add(new ParameterDefinitionImpl(PARAM_CROP_WIDTH, DataTypeDefinition.INT, false,
getParamDisplayLabel(PARAM_CROP_WIDTH)));
paramList.add(new ParameterDefinitionImpl(PARAM_CROP_X_OFFSET, DataTypeDefinition.INT, false,
getParamDisplayLabel(PARAM_CROP_X_OFFSET)));
paramList.add(new ParameterDefinitionImpl(PARAM_CROP_Y_OFFSET, DataTypeDefinition.INT, false,
getParamDisplayLabel(PARAM_CROP_Y_OFFSET)));
paramList.add(new ParameterDefinitionImpl(PARAM_IS_PERCENT_CROP, DataTypeDefinition.BOOLEAN, false,
getParamDisplayLabel(PARAM_IS_PERCENT_CROP)));
paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_CROP_GRAVITY, DataTypeDefinition.TEXT, false,
getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_CROP_GRAVITY)));
paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_CROP_HEIGHT, DataTypeDefinition.INT, false,
getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_CROP_HEIGHT)));
paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_CROP_WIDTH, DataTypeDefinition.INT, false,
getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_CROP_WIDTH)));
paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_CROP_X_OFFSET, DataTypeDefinition.INT, false,
getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_CROP_X_OFFSET)));
paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_CROP_Y_OFFSET, DataTypeDefinition.INT, false,
getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_CROP_Y_OFFSET)));
paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_IS_PERCENT_CROP, DataTypeDefinition.BOOLEAN, false,
getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_IS_PERCENT_CROP)));
paramList.add(new ParameterDefinitionImpl(PARAM_COMMAND_OPTIONS, DataTypeDefinition.TEXT, false,
getParamDisplayLabel(PARAM_COMMAND_OPTIONS)));