Korim: Kotlin cORoutines IMaging, Bitmap and Vector graphics for Multiplatform Kotlin

Overview

Korim

Korim

Kotlin cORoutines IMaging utilities for Multiplatform Kotlin

Build Status Maven Central Discord

Full Documentation: https://korlibs.soywiz.com/korim/

Use with gradle:

repositories {
    mavenCentral()
}

dependencies {
    compile "com.soywiz.korlibs.korim:korim:$korimVersion"
}

Bitmap classes

Bitmap base class + Bitmap8 and Bitmap32. And other fancy bitmaps: BitmapIndexed as base + Bitmap1, Bitmap2, Bitmap4 and BitmapChannel.

Image Formats

Korim provides utilities for reading and writing some image formats without any kind of additional dependency.

PNG, JPG, TGA, BMP, ICO, PSD(WIP) and DDS (DXT1, DXT2, DXT3, DXT4 and DXT5).

Native Image Formats

Korim also allows to use native image readers from your device for maximum performance for standard image formats.

Color Formats

Korim provides color formats to convert easily and fast and to perform mixing, de/premultiplication and other operations quickly.

Vectorial Image Formats

Korim supports loading, rasterizing and drawing vectorial SVG files.

Native vectorial rendering

Korim provides a single interface for vector rendering so you can use a single interface and leverage JavaScript Canvas, AWT's Graphics2D, Android Canvas or any other rasterizer exposed by korim implementations. It also allows to convert shapes into SVG. Korim includes a feature to draw shapes with fills in contact without artifacts in a portable way by multisampling. Useful for offline rasterizers.

AWT Utilities

Korim provides AWT utilities to convert bitmaps into AWT BufferedImages, and to display them. These are just extensions so they are not referenced from the main code. And if you use native image loading, you can display those images as fast as possible without any conversion at all.

Native Fonts

Korim provides native font rendering. You can rasterize glyph fonts on all targets without actually including any font, using device fonts.

TTF Reading and rendering

Korim provides a pure Kotlin-Common TTF reader, and using native vectorial rendering allows you to render glyphs, texts and to get advanced font metrics.

Korio integration

Korim provides korio integration adding VfsFile.readBitmap() that allows Bitmap reading easily and faster (with native implementations) in some targets like browsers.

Comments
  • Native support for resizing images while decoding

    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.

    optimization 
    opened by sahilbajaj 6
  •  Image reduction optimization

    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
    }
    
    opened by lemkoleg 3
  • Generate a BitmapFont from a TTF file

    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.

    enhancement 
    opened by Kernald 2
  • Best way to load image from iOS CMSampleBuffer or ByteArray?

    Best way to load image from iOS CMSampleBuffer or ByteArray?

    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?

    opened by luca992 1
  • I am getting

    I am getting "kotlin.NotImplementedError" in ImageFormat.kt

    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

    opened by min2222 1
  • Image flipping problem, exif rotation and flipping support

    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

    opened by lemkoleg 1
  • Reading quantization tables of JPEG file on Android

    Reading quantization tables of JPEG file on Android

    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!

    opened by BioGeek 1
  • DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0.

    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
    
    opened by TobseF 1
  • Fixes BitmapIndexed.toBMP32() for bpp < 8

    Fixes BitmapIndexed.toBMP32() for bpp < 8

    BitmapIndexed.toBMP32() throws an java.lang.ArrayIndexOutOfBoundsException for bpp smaller than 8.

    Minimal repro:

    val bpp4 = Bitmap4(2, 1)
    bpp4[0, 0] = 1
    bpp4[1, 0] = 1
    bpp4.palette = RgbaArray(16)
    bpp4.toBMP32()
    
    opened by dandanx 1
  • Glow, border and drop shadow effects

    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

    enhancement 
    opened by soywiz 1
  • Fix Context2D semantics

    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()
    
    bug 
    opened by soywiz 1
Releases(v2.2.2)
Owner
Kotlin cORoutine Libraries for fullstack development - https://bintray.com/korlibs/korlibs - https://github.com/korlibs
null
A general purpose kotlin library that use kotlin coroutines, flows and channels to provide timer features with the most easy and efficient way

Timer Timer is a general purpose kotlin library that use kotlin coroutines, flows and channels to provide timer features with the most easy and effici

Amr Saraya 3 Jul 11, 2022
It is a NBAApp developed by Kotlin. It uses MVVM design pattern, Coroutines, Retrofit and JetPack libraries like Room, Lifecycle, ViewBinding, DataBinding, Hilt and Navigation.

NbaApp It is a NBAApp developed by Kotlin. It uses MVVM design pattern, Coroutines, Retrofit and JetPack libraries like Room, Lifecycle, ViewBinding,

Tuna Ateş Koç 2 Feb 26, 2022
Example of a multimodule project following SOLID principles and MVVM, Hilt, Room, coroutines and testing.

MarvelCharacters David Ferrándiz Features Retrieve Marvel’s characters and show them in a grid. See more information about the character in a new scre

David Ferrandiz 2 Aug 22, 2022
To Do List App is built in Kotlin using Material 3, Data Binding, Navigation Component Graphs, Room persistence library, Kotlin coroutines, LiveData, Dagger Hilt, and Notifications following MVVM Architecture.

ToDoListApp ToDoList App demonstrates modern Android development with Hilt, Coroutines, LiveData, Jetpack (Room, ViewModel), and Material 3 Design bas

Naman Garg 10 Jan 8, 2023
Android News Reader app. Kotlin Coroutines, Retrofit and Realm

News Reader Android News Reader app Code that follows Packt Publishing Kotlin in Practice Video Course Example of Kotlin Coroutine usage, with Realm a

Marko Devcic 22 Oct 3, 2022
Android multimodule project based on Kotlin, MVVM, SOLID, flow, coroutines and paging3.

TVMaze David Ferrándiz Features Retrieve TVMaze shows in a grid. See more information about the show in a new screen Tech Kotlin Retrofit Modularizati

David Ferrandiz 1 Nov 18, 2022
Patter Lock using Hilt, Coroutines, Flow and Custom View Components based on MVVM architecture.

Pattern Lock App Sample project for created Pattern Lock View using custom view. Preview Usage Step 1 Add the PatterLockView in your XML layout file.

Furkan Özcan 5 Aug 22, 2021
The News App has been carried out within the framework of the MVVM architecture, information about news is obtained by consulting an API, it is built usisng Jetpack Copose, Coroutines, Dependency Injection with Hilt and Retrofit

Journalist The News App consists of an application that displays the latest news from EEUU from an API that provides official and updated information.

null 0 Nov 3, 2021
🔥Simple quote app using MVVM, Retrofit, Coroutines and Dagger Hilt 💉

?? simple quote app using MVVM, Retrofit, Coroutines and Dagger Hilt ?? quote.mp4 ?? knowledges and technologies ViewBinding Retrofit Coroutines MVVM

Geovani Amaral 4 Aug 26, 2022
☀️ 🌤 Sample weather app with Retrofit, Hilt and Coroutines ☀️ 🌤

WeatherAppsX app is a sample networking app showing weather forecast of the current day and the average forecast for the next four days.

Akshay Nandwana 6 Nov 3, 2022
An simple image gallery app utilizing Unsplash API to showcase modern Android development architecture (MVVM + Kotlin + Retrofit2 + Hilt + Coroutines + Kotlin Flow + mockK + Espresso + Junit)

Imagine App An simple image gallery app utilizing Unsplash API. Built with ❤︎ by Wajahat Karim and contributors Features Popular photos with paginatio

Wajahat Karim 313 Jan 4, 2023
MVVM + Kotlin + Jetpack Compose +Navigation Compose + Hilt + Retrofit + Unit Testing + Compose Testing + Coroutines + Kotlin Flow + Io mockK

MvvmKotlinJetpackCompose Why do we need an architecture even when you can make an app without it? let's say you created a project without any architec

Sayyed Rizwan 46 Nov 29, 2022
Shreyas Patil 2.1k Dec 30, 2022
Sample news app using Kotlin, Hilt, Coroutines, Coil, Room, Retrofit

Tech stack & News App libraries Navigation component - navigation graph for navigating and replacing screens/fragments DataBinding - allows to more ea

Mina Mikhail 3 Dec 28, 2021
WatchStore Ecommerce app using MVVM, Kotlin, Firebase Firestore, Coroutines, Dagger Hilt

WatchStore Sanple App Like Ecommerce App Developed using Kotlin. Features used: Firebase Firestore Navigation Component. MVVM Architecture RecyclerVie

Ketan Bhangale 20 Oct 26, 2022
Event Bus powered by Kotlin Coroutines Flow

FlowBus FlowBus is a kotlin event bus implementation. Powered by Kotlin Coroutines and Flows Android MainThread-aware Fully operable from Java code Ex

Robert Kosakowski 26 Dec 27, 2022
Samples demonstrating the features and use of Koala Plot, a Compose Multiplatform based charting and plotting library written in Kotlin.

Koala Plot Samples This repository houses samples demonstrating the use and features of Koala Plot libraries. How to run Build koalaplot-core with the

Koala Plot 6 Oct 18, 2022
❤️ A sample Marvel heroes application based on MVVM (ViewModel, Coroutines, LiveData, Room, Repository, Koin) architecture.

MarvelHeroes MarvelHeroes is a demo application based on modern Android application tech-stacks and MVVM architecture. Fetching data from the network

Jaewoong Eum 1.2k Dec 19, 2022