Skip to content

Commit

Permalink
Added GeoTiff Box
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanOltmann committed Apr 1, 2024
1 parent f65958b commit 9455032
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
40 changes: 40 additions & 0 deletions app/src/commonMain/kotlin/HtmlGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,46 @@ fun ImageMetadata.toXmpHtmlString(): String =
)
}

fun ImageMetadata.toGeoTiffHtmlString(): String =
buildString {

val geoTiffDirectory = exif?.geoTiffDirectory

if (geoTiffDirectory == null) {
append("No GeoTiff data.")
return@buildString
}

append("<table>")

append("<tr>")
append("<th>Name</th>")
append("<th>Value</th>")
append("</tr>")

append("<tr>")
append("<td>Version</td>")
append("<td>${geoTiffDirectory.geoTiffVersionString}")
append("</tr>")

append("<tr>")
append("<td>Model type</td>")
append("<td>${geoTiffDirectory.modelType?.displayName ?: "-/-"}")
append("</tr>")

append("<tr>")
append("<td>Raster type</td>")
append("<td>${geoTiffDirectory.rasterType?.displayName ?: "-/-"}")
append("</tr>")

append("<tr>")
append("<td>Geographic type</td>")
append("<td>${geoTiffDirectory.geographicType?.displayName ?: "-/-"}")
append("</tr>")

append("</table>")
}

fun generateHexHtml(bytes: ByteArray): String {

val format = ImageFormat.detect(bytes) ?: return "Image format was not recognized."
Expand Down
17 changes: 15 additions & 2 deletions app/src/wasmJsMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ private val xmpBox =
private val textBox =
document.getElementById("text-box") as HTMLDivElement

private val geoTiffBox =
document.getElementById("geotiff-box") as HTMLDivElement

private val hexBox =
document.getElementById("hex-box") as HTMLDivElement

Expand All @@ -75,6 +78,9 @@ private val xmpElement =
private val textElement =
document.getElementById("text") as Element

private val geotiffElement =
document.getElementById("geotiff") as Element

private val hexElement =
document.getElementById("hex") as Element

Expand Down Expand Up @@ -180,6 +186,7 @@ private fun processFile(uint8Array: Uint8Array) {
iptcBoxVisible = false,
xmpBoxVisible = false,
textBoxVisible = false,
geotiffBoxVisible = false,
hexBoxVisible = false
)

Expand Down Expand Up @@ -263,6 +270,8 @@ private fun processFile(uint8Array: Uint8Array) {
}
}

updateHtml(geotiffElement, metadata.toGeoTiffHtmlString())

/*
* Set all boxes visible that have meaningful content.
*/
Expand All @@ -272,6 +281,7 @@ private fun processFile(uint8Array: Uint8Array) {
iptcBoxVisible = metadata.iptc != null,
xmpBoxVisible = metadata.xmp != null,
textBoxVisible = displayTextChunk,
geotiffBoxVisible = metadata.exif?.geoTiffDirectory != null,
hexBoxVisible = true
)

Expand All @@ -286,7 +296,7 @@ private fun processFile(uint8Array: Uint8Array) {
* Make all boxes visible even if there is an error or
* the error message would not be shown to the user.
*/
makeAllBoxesVisible()
makeAllRegularBoxesVisible()
}
}

Expand Down Expand Up @@ -403,6 +413,7 @@ private fun setBoxVisibility(
iptcBoxVisible: Boolean,
xmpBoxVisible: Boolean,
textBoxVisible: Boolean,
geotiffBoxVisible: Boolean,
hexBoxVisible: Boolean
) {

Expand All @@ -411,19 +422,21 @@ private fun setBoxVisibility(
iptcBox.style.display = cssDisplayValue(iptcBoxVisible)
xmpBox.style.display = cssDisplayValue(xmpBoxVisible)
textBox.style.display = cssDisplayValue(textBoxVisible)
geoTiffBox.style.display = cssDisplayValue(geotiffBoxVisible)
hexBox.style.display = cssDisplayValue(hexBoxVisible)
}

private fun cssDisplayValue(shouldDisplay: Boolean) =
if (shouldDisplay) "block" else "none"

private fun makeAllBoxesVisible() =
private fun makeAllRegularBoxesVisible() =
setBoxVisibility(
thumbnailBoxVisible = true,
exifBoxVisible = true,
iptcBoxVisible = true,
xmpBoxVisible = true,
textBoxVisible = false,
geotiffBoxVisible = false,
hexBoxVisible = true
)

Expand Down
8 changes: 8 additions & 0 deletions app/src/wasmJsMain/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ <h1>EXIF Viewer</h1>
<div class="box-content" id="text"></div>
</div>

<div id="geotiff-box" class="box">
<div class="box-title" onclick="toggleBoxContent('geotiff-box')">
GeoTiff
<i class="fas fa-chevron-down expand-icon"></i>
</div>
<div class="box-content" id="geotiff"></div>
</div>

<div id="hex-box" class="box">
<div class="box-title" onclick="toggleBoxContent('hex-box')">
File structure (HEX view)
Expand Down

0 comments on commit 9455032

Please sign in to comment.