Skip to content

Commit

Permalink
move compressing into separate shell script
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaiR committed Jan 26, 2019
1 parent 07834c9 commit 68f929c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ WORKDIR /render

COPY --from=build /build/render/build/libs/render.jar .
COPY .revisions .
COPY render/src/main/compress.sh .

RUN apk update && \
apk add git pngquant && \
mkdir -p tmp/repo && \
git clone --progress https://github.com/TauCetiStation/TauCetiClassic.git tmp/repo && \
java -Xms1g -Xmx1g -jar render.jar
java -Xms1g -Xmx1g -jar render.jar && \
./compress.sh

FROM oracle/graalvm-ce:1.0.0-rc11 as native
WORKDIR /native
Expand Down
1 change: 0 additions & 1 deletion render/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ application {

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.1.1")
implementation(group = "io.github.spair", name = "byond-dmm-util", version = "1.0.1")
}

Expand Down
14 changes: 14 additions & 0 deletions render/src/main/compress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

echo "Compressing images, this may take several minutes"

count=0
for f in $(find ./data/maps -maxdepth 4 -type f); do count=$((count+1)); done
echo " - Total: $count"

for f in $(find ./data/maps -maxdepth 4 -type f); do
pngquant --ext=.png --force --strip --speed=1 --nofs --posterize=2 "$f"
printf "\r - Remain: %s" "$((count--))"
done

printf "\rAll images compressed!\n"
27 changes: 0 additions & 27 deletions render/src/main/kotlin/io/github/spair/tauwebmap/render.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import io.github.spair.byond.dmm.Dmm
import io.github.spair.byond.dmm.drawer.DmmDrawer
import io.github.spair.byond.dmm.drawer.FilterMode
import io.github.spair.dmm.io.reader.DmmReader
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.awt.Image
import java.awt.image.BufferedImage
import java.awt.image.PixelGrabber
import java.io.File
import java.util.concurrent.atomic.AtomicInteger
import javax.imageio.ImageIO

private const val REVISIONS = ".revisions"
Expand All @@ -29,35 +26,17 @@ private val TYPES_TO_RENDER = mapOf(
)

private val IGNORE_TYPES = arrayOf("/turf/space", "/area", "/obj/effect/landmark")
private val COMPRESSION_ARGS = arrayOf("--ext=.png", "--force", "--strip", "--speed=1", "--nofs", "--posterize=2")

// All values calculated with assumption that map image size is 8160x8160
private val ZOOM_FACTORS = mapOf(3 to 8, 4 to 16, 5 to 32)
private val SCALE_FACTORS = mapOf(3 to 0.3, 4 to 0.6, 5 to 1.0)

private val FILES_TO_COMPRESS = ArrayList<String>(4200)
private val COMPRESS_FILE_COUNTER = AtomicInteger(0)

fun main() {
File(REVISIONS).forEachLine { line ->
val revision = line.split(" ")[1]
ProcessBuilder("git", "checkout", revision).directory(File(REPO_PATH)).start().waitFor()
renderRevision(revision)
}

COMPRESS_FILE_COUNTER.set(FILES_TO_COMPRESS.size)
FILES_TO_COMPRESS.forEach { path ->
GlobalScope.launch {
ProcessBuilder("pngquant", *COMPRESSION_ARGS, path).start().waitFor()
COMPRESS_FILE_COUNTER.decrementAndGet()
}
}

println("Compressing files, this may take several minutes")
while (COMPRESS_FILE_COUNTER.get() > 0) {
print("\r - remains: $COMPRESS_FILE_COUNTER")
}
println("\rImages generation completed!")
}

private fun renderRevision(revision: String) {
Expand All @@ -76,12 +55,6 @@ private fun renderLayer(layerFolderPath: String, typesToUse: Array<String>) {
val zoomFolder = File("$layerFolderPath/$zoom").apply { mkdirs() }
createSubImages(generatedImg, zoomFolder.path, zoomFactor, SCALE_FACTORS.getValue(zoom))
}

File(layerFolderPath).listFiles().forEach { zoomFolder ->
zoomFolder.listFiles().forEach { imgFile ->
FILES_TO_COMPRESS.add(imgFile.path)
}
}
}

internal class Resource
Expand Down

0 comments on commit 68f929c

Please sign in to comment.