Skip to content

Commit

Permalink
tests + dependencies cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kirilenkobm committed Aug 3, 2023
1 parent da99e35 commit da6a37e
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 80 deletions.
5 changes: 0 additions & 5 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
46 changes: 0 additions & 46 deletions src/main/kotlin/service/ThumbnailGenerationService.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions src/test/kotlin/service/EntityActionsHandlerTest.kt

This file was deleted.

18 changes: 0 additions & 18 deletions src/test/kotlin/service/ThumbnailGenerationServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit da6a37e

Please sign in to comment.