Code Monkey home page Code Monkey logo

korim's People

Contributors

soywiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

korim's Issues

Glow, border and drop shadow effects

Allow to apply glow, border and drop shadow effects to Bitmap32 / maybe Context2D too?
This will enable new use-cases including creating better BitmapFonts at runtime or directly rendering stuff to bitmaps/textures

Image flipping problem, exif rotation and flipping support

There is an image whose width is less than height.
If I read the image and write it back, the image flips 90 °.

"
fun getImmage() {

    val fileName = resourcesVfs["SomeImage.jpg"]
    val image32 = fileName.readBitmap().toBMP32()
    val resfile = resourcesVfs["ResImage.jpg"]
    resfile.writeBytes(image32.encode(PNG))
}

"
11.zip

DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0.

After Upgrading from Korge 1.10.0.0 to 1.12.2.0 my HitKlack Game doesn't run on JS target anymore.
https://github.com/TobseF/HitKlack/tree/UpgradeKorge
Platform: jsWebRun

DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0.

Stacktrace

OpenglAG: Created program BatchBuilder2D.Premultiplied.Tinted with id 3 because contextVersion: -1 != 0
korio-root-korio.js:45410 DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0.
    at HtmlImage.renderHtmlCanvasIntoBitmap_x25gtl$ (http://127.0.0.1:9040/korim-root-korim.js:21434:20)
    at HtmlNativeImage.toNonNativeBmp (http://127.0.0.1:9040/korim-root-korim.js:21507:29)
    at HtmlNativeImage.NativeImage.toBMP32 (http://127.0.0.1:9040/korim-root-korim.js:2393:17)
    at new BitmapFont$Glyph (http://127.0.0.1:9040/korim-root-korim.js:6470:39)
    at Coroutine$readBitmapFontTxt.doResume (http://127.0.0.1:9040/korim-root-korim.js:6799:33)
    at Coroutine$loadImage_ivxn3r$.CoroutineImpl.resumeWith_tl1gpc$ (http://127.0.0.1:9040/kotlin.js:29534:35)
    at CancellableContinuationImpl.DispatchedTask.run (http://127.0.0.1:9040/kotlinx-coroutines-core.js:32877:22)
    at GameWindowCoroutineDispatcher.executePending_p8meis$ (http://127.0.0.1:9040/korgw-root-korgw.js:12387:30)
    at http://127.0.0.1:9040/korgw-root-korgw.js:15364:52
printStackTrace_0 @ korio-root-korio.js:45410
korio-root-korio.js:45411 Error: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0.
    at HtmlImage.renderHtmlCanvasIntoBitmap_x25gtl$ (korim-root-korim.js:21434)
    at HtmlNativeImage.toNonNativeBmp (korim-root-korim.js:21507)
    at HtmlNativeImage.NativeImage.toBMP32 (korim-root-korim.js:2393)
    at new BitmapFont$Glyph (korim-root-korim.js:6470)
    at Coroutine$readBitmapFontTxt.doResume (korim-root-korim.js:6799)
    at Coroutine$loadImage_ivxn3r$.CoroutineImpl.resumeWith_tl1gpc$ (kotlin.js:29534)
    at CancellableContinuationImpl.DispatchedTask.run (kotlinx-coroutines-core.js:32877)
    at GameWindowCoroutineDispatcher.executePending_p8meis$ (korgw-root-korgw.js:12387)
    at korgw-root-korgw.js:15364
printStackTrace_0 @ korio-root-korio.js:45411
kotlinx-coroutines-core.js:35845 DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0.
    at HtmlImage.renderHtmlCanvasIntoBitmap_x25gtl$ (http://127.0.0.1:9040/korim-root-korim.js:21434:20)
    at HtmlNativeImage.toNonNativeBmp (http://127.0.0.1:9040/korim-root-korim.js:21507:29)
    at HtmlNativeImage.NativeImage.toBMP32 (http://127.0.0.1:9040/korim-root-korim.js:2393:17)
    at new BitmapFont$Glyph (http://127.0.0.1:9040/korim-root-korim.js:6470:39)
    at Coroutine$readBitmapFontTxt.doResume (http://127.0.0.1:9040/korim-root-korim.js:6799:33)
    at Coroutine$loadImage_ivxn3r$.CoroutineImpl.resumeWith_tl1gpc$ (http://127.0.0.1:9040/kotlin.js:29534:35)
    at CancellableContinuationImpl.DispatchedTask.run (http://127.0.0.1:9040/kotlinx-coroutines-core.js:32877:22)
    at GameWindowCoroutineDispatcher.executePending_p8meis$ (http://127.0.0.1:9040/korgw-root-korgw.js:12387:30)
    at http://127.0.0.1:9040/korgw-root-korgw.js:15364:52
handleCoroutineExceptionImpl @ kotlinx-coroutines-core.js:35845
kotlin.js:32459 OpenglAG: Created program BatchBuilder2D.NoPremultiplied.Tinted with id 13 because contextVersion: -1 != 0

Image reduction optimization

Hello. Help me, please, with this question: I need
every time I get an image, reduce it to a certain
size (32Kb). I wrote such code. But I would like as much as possible
Optimize loss of quality and border design. Maybe you tell me
the best option? Here is my code:

private suspend fun getImmage32Kb(imageData: Bitmap32): ByteArray? {
var bb: ByteArray? = null
var image32: Bitmap32 = imageData
var image16 = Bitmap16(width = image32.width, height = image32.height, format = RGB_565, premultiplied = false)
val ex = ImageEncodingProps()
bb = image32.encode(PNG, ex)
val AVATAR_SIZE = 32768
if (bb.size <= AVATAR_SIZE) return bb
else bb = null
image32.forEach { _, x, y ->
image16.setRgba(x = x, y = y, v = image32.getRgba(x = x, y = y))
}
image32 = image16.toBMP32()
GlobalScope.launch {
var im_width = image32.width
var im_heigth = image32.height
var koef: Float
val avatar = AVATAR_SIZE.toFloat()
while (bb == null || bb!!.size > AVATAR_SIZE) {
image32.forEach { _, x, y ->
image16.setRgba(x = x, y = y, v = image32.getRgba(x = x, y = y))
}
bb = image16.encode(PNG, ex)
if (bb!!.size <= AVATAR_SIZE) break
val percent = (bb!!.size / avatar)
koef = if (percent >= 2.5F) {
1F
} else {
0.98F
}
if (koef == 1F) {
image32 = image32.mipmap(1)

            } else {
                im_width = (im_width * koef).toInt()
                im_heigth = (im_heigth * koef).toInt()
                image32 = image32.copySliceWithSize(
                    (image32.width - im_width) / 2,
                    (image32.height - im_heigth) / 2,
                    im_width,
                    im_heigth
                )

            }
            im_width = image32.width
            im_heigth = image32.height
            image16 =
                Bitmap16(width = im_width, height = im_heigth, format = RGB_565, premultiplied = false)
        }

    }.join()
    return bb
}

Support KRA format

Could support for reading and writing .KRA (Krita Files) be added?
It shouldn't be that hard (for the veterans among us) as it is a FOSS format.

Fix Context2D semantics

This should draw the circle translated. So we should apply the translation matrix when drawing the points directly.

keep {
    translate(100, 0)
    circle(0, 0, 50)
}
fill()

Bitmap.resized

fun Bitmap.resized(width: Int, height: Int, scale: ScaleMode, anchor: Anchor): Bitmap {
    val bmp = this
    val out = bmp.createWithThisFormat(width, height)
    out.context2d(antialiased = true) {
        val rect = Rectangle(0, 0, width, height).place(bmp.width.toDouble(), bmp.height.toDouble(), anchor, scale)
        drawImage(bmp, rect.x, rect.y, rect.width, rect.height)
    }
    return out
}

Compress image

Hello. Tell me, how can I compress an image to a certain size in bytes? Proportionally reduce the quality and size. Perhaps there is a ready-made functional?

Lots of ttf fonts doesn't load

This one for example:
https://www.dafont.com/es/chunky-wally.font

java.lang.ArrayIndexOutOfBoundsException: Index 13366 out of bounds for length 12088
	at com.soywiz.korim.font.ttf.TtfFont$Glyph.contour(TtfFont.kt:444)
	at com.soywiz.korim.font.ttf.TtfFont$Glyph.contour$default(TtfFont.kt:443)
	at com.soywiz.korim.font.ttf.TtfFont$Glyph.createGraphicsPath(TtfFont.kt:475)
	at com.soywiz.korim.font.ttf.TtfFont$Glyph.fill-6R-LPU4(TtfFont.kt:461)
	at com.soywiz.korim.font.ttf.TtfFont.fillText-szaLBVk(TtfFont.kt:397)
	at com.soywiz.korim.font.ttf.TtfFontKt.fillText-BW0PsmY(TtfFont.kt:676)

Bitmap.clone

Bitmap32.clone is supported, but the base interface Bitmap should support it

BMP Decoding

There is a problem with BMP decoding. The padding is calculated as 4 - (bytesPerRow % 4). Which means when the width is exactly divisible by 4, you have a padding of 4. This messes up the image considerably.

The check should probably be:if (padding != 4) { instead of if (padding != 0){

https://github.com/korlibs/korim/blob/d05eff45d0cb156336cf8dd9557731a3ec9243cb/korim/src/commonMain/kotlin/com/soywiz/korim/format/BMP.kt#L59

https://github.com/korlibs/korim/blob/d05eff45d0cb156336cf8dd9557731a3ec9243cb/korim/src/commonMain/kotlin/com/soywiz/korim/format/BMP.kt#L65

Optimize rasterizer scanline lookup

We have to create a structure that split the lines in buckets. We can create buckets that are variable size. Every top and bottom Y points can define the size of each bucket. Then we can populate those buckets and perform a binary search to locate the bucket and just iterate the points on that bucket per scanline

Native support for resizing images while decoding

Currently the images are decoded at their original resolution.

Even though BitmapExt provides bitmap resizing capabilities, sometimes it doesn't make sense to decode images at original resolution first especially when they're large.

Generate a BitmapFont from a TTF file

What would be the proper way to load a TTF file? As far as I understand, the current implementation of BitmapFontGenerator relies on the font being installed on the system - which might not be the case. I guess we can assume that it's possible to get a VfsFile pointing to a TTF file - it should be possible from there to generate a bitmap font.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.