Skip to content

Commit

Permalink
Merge pull request kitodo#5683 from matthias-ronge/issue-5580c
Browse files Browse the repository at this point in the history
Remove unused part of the image management interface
  • Loading branch information
solth authored Feb 26, 2024
2 parents 22c6cd4 + 846bcfc commit ad2e804
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,6 @@ public interface ImageManagementInterface {
boolean createDerivative(URI imageFileUri, double percent, URI resultFileUri, ImageFileFormat resultFileFormat)
throws IOException;

/**
* Scales an image at a given path and returns it.
*
* @param imageFileUri
* the URI to the image which should be scaled
* @param percent
* the percentage for scaling
* @return the scaled image
* @throws IOException
* if the plug-in is configured incorrectly, the image is
* missing or corrupted, etc.
*/
Image getScaledWebImage(URI imageFileUri, double percent) throws IOException;

/**
* Changes the size (in pixel) of the image.
*
Expand All @@ -77,5 +63,4 @@ boolean createDerivative(URI imageFileUri, double percent, URI resultFileUri, Im
* missing or corrupted, etc.
*/
Image getSizedWebImage(URI imageFileUri, int pixelWidth) throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@ public class Folder extends BaseBean {
@Column(name = "fileGroup")
private String fileGroup;

/**
* If not null, images in this folder can be generated by the function
* {@link ImageManagementInterface#getScaledWebImage(java.net.URI, double)}.
* The value is the factor of scaling for the derivative, a value of 1.0
* indicates the original size.
*/
@Column(name = "imageScale")
private Double imageScale = null;

/**
* If not null, images in this folder can be generated by the function
* {@link ImageManagementInterface#getSizedWebImage(java.net.URI, int)}. The
Expand Down Expand Up @@ -213,17 +204,6 @@ public Collection<String> getFileGroups() {
return fileGroups;
}

/**
* Returns the scale factor to get the contents of the folder as scaled web
* images form the content of another folder, if any. If absent, the
* function is disabled.
*
* @return the scale factor. A value of 1.0 refers to the original size.
*/
public Optional<Double> getImageScale() {
return Optional.ofNullable(imageScale);
}

/**
* Returns the pixel width to get the contents of the folder as sized web
* images form the content of another folder, if any. If absent, the
Expand Down Expand Up @@ -383,18 +363,6 @@ public void setFileGroup(String fileGroup) {
this.fileGroup = fileGroup;
}

/**
* Sets the scale factor to get the contents of the folder as scaled web
* images form the content of another folder. Can be set to {@code null} to
* disable the function.
*
* @param imageScale
* the scale factor. A value of 1.0 refers to the original size.
*/
public void setImageScale(Double imageScale) {
this.imageScale = imageScale;
}

/**
* Returns the pixel width to get the contents of the folder as sized web
* images form the content of another folder, if any. If absent, the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public List<Folder> getContentFolders() {
List<Folder> contentFolders = typeGenerateImages
? process.getProject().getFolders().parallelStream()
.filter(folder -> folder.getDerivative().isPresent() || folder.getDpi().isPresent()
|| folder.getImageScale().isPresent() || folder.getImageSize().isPresent())
|| folder.getImageSize().isPresent())
.collect(Collectors.toList())
: Collections.emptyList();
return contentFolders;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--
-- (c) Kitodo. Key to digital objects e. V. <[email protected]>
--
-- This file is part of the Kitodo project.
--
-- It is licensed under GNU General Public License version 3 or later.
--
-- For the full copyright and license information, please read the
-- GPL3-License.txt file that was distributed with this source code.
--

--
-- Delete column for image generation option "getScaledWebImage"
ALTER TABLE folder DROP COLUMN imageScale;
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,6 @@ public boolean createDerivative(URI sourceUri, double factor, URI resultUri, Ima
return new File(resultUri).exists();
}

/**
* {@inheritDoc}
*
* @see org.kitodo.api.imagemanagement.ImageManagementInterface#getScaledWebImage(java.net.URI,
* double)
*/
@Override
public Image getScaledWebImage(URI sourceUri, double factor) throws IOException {
validateParameters(sourceUri, factor);
return summarize("scaledWebImage-", WEB_IMAGE_FORMAT, sourceUri, lambda -> lambda.resize(factor),
"Generating scaled web image from {} as {}, factor {}%", 100 * factor);
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,6 @@ public static void createTestTiff() throws IOException, InterruptedException, IM
convertCmd.run(operation);
}

@Test
public void testGetScaledWebImage() throws IOException, InfoException {
assert new File(_00000001_TIF).exists();
ImageManagementInterface module = new ImageManagement();
Image scaledWebImage = module.getScaledWebImage(new File(_00000001_TIF).toURI(), 0.3);
assertEquals((int) Math.round(0.3 * new Info(_00000001_TIF, true).getImageWidth()),
scaledWebImage.getWidth(null));
}

@Test
public void testCreateDerivative() throws IOException, InfoException {
assert new File(_00000001_TIF).exists();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ private void generateImages(List<Process> processes, GenerationMode generationMo
for (Folder folder : process.getProject().getFolders()) {
if ((all || folders.contains(folder.getPath())) && !folder.equals(generatorSource)
&& (folder.getDerivative().isPresent() || folder.getDpi().isPresent()
|| folder.getImageScale().isPresent() || folder.getImageSize().isPresent())) {
|| folder.getImageSize().isPresent())) {
outputFolders.add(new Subfolder(process, folder));
ungeneratableFolders.remove(folder.getPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public Folder cloneFolder(Folder source) {
clone.setCreateFolder(source.isCreateFolder());
clone.setDerivative(source.getDerivative().orElse(null));
clone.setDpi(source.getDpi().orElse(null));
clone.setImageScale(source.getImageScale().orElse(null));
clone.setImageSize(source.getImageSize().orElse(null));
clone.setLinkingMode(source.getLinkingMode());
return clone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ private static Stream<Folder> dropOwnSourceFolders(Stream<Project> projects) {
*/
private static Stream<Folder> removeFoldersThatCannotBeGenerated(Stream<Folder> folders) {
return folders.filter(folder -> folder.getDerivative().isPresent() || folder.getDpi().isPresent()
|| folder.getImageScale().isPresent() || folder.getImageSize().isPresent());
|| folder.getImageSize().isPresent());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,9 @@ public void letTheSupervisorDo(Consumer<EmptyTask> action) {
*/
private Image retrieveJavaImage(URI sourceImage, Folder imageProperties) throws IOException {
Optional<Integer> optionalDpi = imageProperties.getDpi();
Optional<Double> optionalImageScale = imageProperties.getImageScale();
Optional<Integer> optionalImageSize = imageProperties.getImageSize();
if (optionalDpi.isPresent()) {
return imageService.changeDpi(sourceImage, optionalDpi.get());
} else if (optionalImageScale.isPresent()) {
return imageService.getScaledWebImage(sourceImage, optionalImageScale.get());
} else if (optionalImageSize.isPresent()) {
return imageService.getSizedWebImage(sourceImage, optionalImageSize.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,6 @@ boolean createDerivative(URI imageFileUri, double percent, URI resultFileUri, Im
return imageManagement.createDerivative(imageFileUri, percent, resultFileUri, resultFileFormat);
}

/**
* Scales an image at a given path and returns it.
*
* @param imageFileUri
* the URI to the image which should be scaled
* @param percent
* the percentage for scaling
* @return the scaled image
* @throws IOException
* if the plug-in is configured incorrectly, the image is
* missing or corrupted, etc.
*/
Image getScaledWebImage(URI imageFileUri, double percent) throws IOException {
return imageManagement.getScaledWebImage(imageFileUri, percent);
}

/**
* Changes the size (in pixel) of the image.
*
Expand Down

0 comments on commit ad2e804

Please sign in to comment.