From da6a37e48e58494bd0615e4c4a8085bf71b48025 Mon Sep 17 00:00:00 2001 From: Bogdan Kirilenko Date: Thu, 3 Aug 2023 15:16:55 +0200 Subject: [PATCH] tests + dependencies cleanup --- NOTICE.md | 5 -- build.gradle.kts | 1 - .../service/ThumbnailGenerationService.kt | 46 ------------------- .../service/EntityActionsHandlerTest.kt | 10 ---- .../service/ThumbnailGenerationServiceTest.kt | 18 -------- 5 files changed, 80 deletions(-) delete mode 100644 src/test/kotlin/service/EntityActionsHandlerTest.kt diff --git a/NOTICE.md b/NOTICE.md index 6c56e34..c6bd974 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -4,11 +4,6 @@ Icons are taken from [Google Material Icons](https://material.io/resources/icons and are licensed under the [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt). You are free to use these icons in your own projects as long as you include a copy of this license. -# Metadata Extractor - -This software includes material from the project Metadata Extractor. -Metadata Extractor Copyright 2002-2022 Drew Noakes and contributors. - # PDF box This product includes software developed at diff --git a/build.gradle.kts b/build.gradle.kts index fccffed..52df248 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,6 @@ dependencies { testImplementation(kotlin("test")) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.5.2") - implementation("com.drewnoakes:metadata-extractor:2.18.0") implementation("com.github.jai-imageio:jai-imageio-jpeg2000:1.3.0") implementation("org.apache.pdfbox:pdfbox:2.0.24") implementation("org.apache.pdfbox:jbig2-imageio:3.0.4") diff --git a/src/main/kotlin/service/ThumbnailGenerationService.kt b/src/main/kotlin/service/ThumbnailGenerationService.kt index 4c189d6..681549b 100644 --- a/src/main/kotlin/service/ThumbnailGenerationService.kt +++ b/src/main/kotlin/service/ThumbnailGenerationService.kt @@ -1,9 +1,6 @@ package service import Constants -import com.drew.imaging.ImageMetadataReader -import com.drew.imaging.ImageProcessingException -import com.drew.metadata.exif.ExifThumbnailDirectory import model.ExplorerFile import kotlinx.coroutines.* import org.apache.pdfbox.pdmodel.PDDocument @@ -15,7 +12,6 @@ import java.awt.RenderingHints import java.awt.image.BufferedImage import java.io.File import java.io.IOException -import java.io.RandomAccessFile import javax.imageio.ImageIO import javax.swing.Icon import javax.swing.ImageIcon @@ -182,13 +178,6 @@ class ThumbnailGenerationService( internal fun createImageThumbnail(): Icon? { try { val file = File(fileEntity.path) - // but worth trying to implement for overall improvement - // For metadata extractor, it's easier to provide file -// val includedThumbnail = extractImageThumbnailIfExists(file) -// if (includedThumbnail != null) { -// println("") -// return resizeThumbnail(includedThumbnail) -// } // This way of extracting data from image suppose to be quicker val imageInputStream = ImageIO.createImageInputStream(file) @@ -236,41 +225,6 @@ class ThumbnailGenerationService( } } - /** - * Check if metadata tree contains a thumbnail. If yes -> just return it. - * The function does not work as expected with JPEG images created - * using Lightroom from Fuji and Canon camera RAWs. - */ - internal fun extractImageThumbnailIfExists(imageFile: File): BufferedImage? { - try { - val metadata = ImageMetadataReader.readMetadata(imageFile) - val directory = metadata.getFirstDirectoryOfType(ExifThumbnailDirectory::class.java) - - if (directory != null && directory.containsTag(ExifThumbnailDirectory.TAG_THUMBNAIL_OFFSET)) { - val offset = directory.getInteger(ExifThumbnailDirectory.TAG_THUMBNAIL_OFFSET) - val length = directory.getInteger(ExifThumbnailDirectory.TAG_THUMBNAIL_LENGTH) - - if (length > 0) { - RandomAccessFile(imageFile, "r").use { raf -> - raf.seek(offset.toLong()) - val thumbnailData = ByteArray(length) - raf.read(thumbnailData) - return ImageIO.read(thumbnailData.inputStream()) - } - } else { - println("Length is 0") - return null - } - } - println("Cannot find directory") - } catch (e: ImageProcessingException) { - e.printStackTrace() - } catch (e: IOException) { - e.printStackTrace() - } - return null - } - /** * Generating PDF previews: just get 1st page and * read as Buffered image using PDDocument library diff --git a/src/test/kotlin/service/EntityActionsHandlerTest.kt b/src/test/kotlin/service/EntityActionsHandlerTest.kt deleted file mode 100644 index a83021b..0000000 --- a/src/test/kotlin/service/EntityActionsHandlerTest.kt +++ /dev/null @@ -1,10 +0,0 @@ -package service - -import org.junit.jupiter.api.Test - -class EntityActionsHandlerTest { - - @Test - fun performEntityAction() { - } -} diff --git a/src/test/kotlin/service/ThumbnailGenerationServiceTest.kt b/src/test/kotlin/service/ThumbnailGenerationServiceTest.kt index 22ce9b5..3fd2379 100644 --- a/src/test/kotlin/service/ThumbnailGenerationServiceTest.kt +++ b/src/test/kotlin/service/ThumbnailGenerationServiceTest.kt @@ -8,29 +8,11 @@ import org.junit.jupiter.api.Assertions.* import state.Settings import view.iconviews.FileIconView import java.awt.image.BufferedImage -import java.io.File import javax.swing.Icon import kotlin.math.max class ThumbnailGenerationServiceTest { - - @Test - fun `extractImageThumbnailIfExists$DirExplorer`() { - // Create instance of the generator service - // exiftool extracts thumbnail from this image, so this function should do it - val pathToImageWithEmbeddedThumbnail = "src/test/resources/imageWithThumbnail.jpg" - val dummyFileEntity = ExplorerFile(pathToImageWithEmbeddedThumbnail) - val dummyIcon = FileIconView(dummyFileEntity) - val generatorInstance = ThumbnailGenerationService(dummyFileEntity, dummyIcon) - - // Create an ImageInputStream - val file = File(pathToImageWithEmbeddedThumbnail) - // Check image with embedded thumbnail - val thumbnail = generatorInstance.extractImageThumbnailIfExists(file) - assertNotNull(thumbnail) - } - @Test fun createImageThumbnailCreatesThumbnail() { val pathToImageWithEmbeddedThumbnail = "src/test/resources/imageWithThumbnail.jpg"