korlibs-archive / korim Goto Github PK
View Code? Open in Web Editor NEWKorim: Kotlin cORoutines IMaging, Bitmap and Vector graphics for Multiplatform Kotlin
Home Page: https://korlibs.soywiz.com/korim/
License: Other
Korim: Kotlin cORoutines IMaging, Bitmap and Vector graphics for Multiplatform Kotlin
Home Page: https://korlibs.soywiz.com/korim/
License: Other
There are still issues on the edges of the vectors.
Check this for example: korlibs/korge@356d28f
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
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
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.
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
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
}
I'm trying to read the quantization tables of a JPEG file on Android.
It seems that JPEGDecoder reads the quantization tables.
But I'm still a beginner with Kotlin so I haven't yet figured out how I go from a string with the path to the JPEG file to printing out the quantization tables.
(Also asked on Stackoverflow)
Thanks in advance!
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.
drawText
has a color
parameter, but it isn't used. The text is always drawn in white.
No suitable image format : MAGIC: (00000300)
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()
Right now there are issues with some angles, and line caps are not properly implemented when at the phase of converting the stroke into fills.
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
}
I've tried going through the docs. But, I'm a bit confused. What would be the best way to load an image from ios's CMSampleBuffer or a CMSampleBuffer dumped into a ByteArray?
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?
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)
Bitmap32.clone is supported, but the base interface Bitmap should support it
Hi I am trying to decompress a .imy file in a game called Criminal Girls and I found this script you made, but when I try to run this script I get "kotlin.NotImplementedError" in ImageFormat.kt How do I fix this?
script : https://github.com/talestra/talestrakt/blob/master/game-criminalgirls/src/com/talestra/criminalgirls/CriminalGirls.kt
error log : https://pastebin.com/NmL4adu2
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){
Implement both winding rules
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fill
fillRule
The algorithm by which to determine if a point is inside or outside the filling region.
Possible values:
"nonzero": The non-zero winding rule. Default rule.
"evenodd": The even-odd winding rule.
https://blogs.adobe.com/webplatform/2013/01/30/winding-rules-in-canvas/
This will be useful for testing or comparing images.
https://en.wikipedia.org/wiki/PSNR
Just copy this: https://github.com/soywiz/kaifu2x/blob/d5b945db26bd003476d284517b1db7f418414648/src/test/kotlin/com/soywiz/kaifu2x/Kaifu2xTest.kt#L61
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
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.
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.
This should improve quality and reduce artifacts
Right now the rasterizer doesn't support clipping
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.