├── .github └── FUNDING.yml ├── bin ├── dqoi.exe └── dqoi.dart ├── testing ├── dice.png ├── dice.qoi ├── kodim10.png ├── kodim10.qoi ├── kodim23.png ├── kodim23.qoi ├── monument.bin ├── monument.qoi ├── qoi_logo.png ├── qoi_logo.qoi ├── testcard.png ├── testcard.qoi ├── testcard_rgba.png ├── testcard_rgba.qoi ├── wikipedia_008.png └── wikipedia_008.qoi ├── GitHubSponsorsImage.jpg ├── example ├── README.md ├── web │ ├── favicon.png │ ├── icons │ │ ├── Icon-192.png │ │ ├── Icon-512.png │ │ ├── Icon-maskable-192.png │ │ └── Icon-maskable-512.png │ ├── manifest.json │ └── index.html ├── assets │ └── images │ │ ├── dice.qoi │ │ ├── kodim23.qoi │ │ └── testcard_rgba.qoi ├── android │ ├── gradle.properties │ ├── app │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── drawable │ │ │ │ │ │ └── launch_background.xml │ │ │ │ │ ├── drawable-v21 │ │ │ │ │ │ └── launch_background.xml │ │ │ │ │ ├── values │ │ │ │ │ │ └── styles.xml │ │ │ │ │ └── values-night │ │ │ │ │ │ └── styles.xml │ │ │ │ ├── kotlin │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── example │ │ │ │ │ │ └── MainActivity.kt │ │ │ │ └── AndroidManifest.xml │ │ │ ├── debug │ │ │ │ └── AndroidManifest.xml │ │ │ └── profile │ │ │ │ └── AndroidManifest.xml │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ ├── .gitignore │ ├── settings.gradle │ └── build.gradle ├── windows │ ├── runner │ │ ├── resources │ │ │ └── app_icon.ico │ │ ├── resource.h │ │ ├── CMakeLists.txt │ │ ├── utils.h │ │ ├── runner.exe.manifest │ │ ├── flutter_window.h │ │ ├── main.cpp │ │ ├── utils.cpp │ │ ├── flutter_window.cpp │ │ ├── Runner.rc │ │ ├── win32_window.h │ │ └── win32_window.cpp │ ├── flutter │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ ├── generated_plugins.cmake │ │ └── CMakeLists.txt │ ├── .gitignore │ └── CMakeLists.txt ├── lib │ ├── load_asset.dart │ └── main.dart ├── .metadata ├── pubspec.yaml ├── .gitignore └── analysis_options.yaml ├── lib ├── dqoi_pure.dart ├── dqoi.dart └── src │ ├── interpreters │ ├── shared.dart │ ├── decode.dart │ └── encode.dart │ ├── flutter_exts.dart │ └── qoi.dart ├── .metadata ├── CHANGELOG.md ├── pubspec.yaml ├── dqoi-test.bat ├── dqoi.iml ├── analysis_options.yaml ├── .gitignore ├── README.md └── LICENSE /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: JaffaKetchup 2 | ko_fi: JaffaKetchup 3 | -------------------------------------------------------------------------------- /bin/dqoi.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/bin/dqoi.exe -------------------------------------------------------------------------------- /testing/dice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/dice.png -------------------------------------------------------------------------------- /testing/dice.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/dice.qoi -------------------------------------------------------------------------------- /testing/kodim10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/kodim10.png -------------------------------------------------------------------------------- /testing/kodim10.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/kodim10.qoi -------------------------------------------------------------------------------- /testing/kodim23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/kodim23.png -------------------------------------------------------------------------------- /testing/kodim23.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/kodim23.qoi -------------------------------------------------------------------------------- /testing/monument.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/monument.bin -------------------------------------------------------------------------------- /testing/monument.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/monument.qoi -------------------------------------------------------------------------------- /testing/qoi_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/qoi_logo.png -------------------------------------------------------------------------------- /testing/qoi_logo.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/qoi_logo.qoi -------------------------------------------------------------------------------- /testing/testcard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/testcard.png -------------------------------------------------------------------------------- /testing/testcard.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/testcard.qoi -------------------------------------------------------------------------------- /GitHubSponsorsImage.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/GitHubSponsorsImage.jpg -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # dqoi_example 2 | 3 | Example application for the 'dqoi' application library. 4 | -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/web/favicon.png -------------------------------------------------------------------------------- /testing/testcard_rgba.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/testcard_rgba.png -------------------------------------------------------------------------------- /testing/testcard_rgba.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/testcard_rgba.qoi -------------------------------------------------------------------------------- /testing/wikipedia_008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/wikipedia_008.png -------------------------------------------------------------------------------- /testing/wikipedia_008.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/testing/wikipedia_008.qoi -------------------------------------------------------------------------------- /example/assets/images/dice.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/assets/images/dice.qoi -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/assets/images/kodim23.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/assets/images/kodim23.qoi -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /example/assets/images/testcard_rgba.qoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/assets/images/testcard_rgba.qoi -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaffaKetchup/dqoi/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/kotlin/com/example/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /example/lib/load_asset.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async' show Future; 2 | import 'dart:typed_data'; 3 | import 'package:flutter/services.dart' show rootBundle; 4 | 5 | Future loadAsset(String path) async => 6 | (await rootBundle.load(path)).buffer.asUint8List(); 7 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip 7 | -------------------------------------------------------------------------------- /lib/dqoi_pure.dart: -------------------------------------------------------------------------------- 1 | /// A Dart implementation of the Quite OK Image Format. 2 | /// 3 | /// This is the library entry-point for use in non-Flutter programs. Used internally for the 'dqoi' CLI, for example. 4 | /// 5 | /// Use standard 'dqoi' library wherever possible in Flutter applications. 6 | library dqoi_pure; 7 | 8 | export 'src/qoi.dart'; 9 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 5464c5bac742001448fe4fc0597be939379f88ea 8 | channel: stable 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /lib/dqoi.dart: -------------------------------------------------------------------------------- 1 | /// A Dart implementation of the Quite OK Image Format. 2 | /// 3 | /// This is the library entry-point for use in Flutter applications by automatically including Flutter-only extensions. 4 | /// 5 | /// See 'dqoi_pure' for 'dqoi' use without Flutter. 6 | library dqoi; 7 | 8 | export 'src/qoi.dart'; 9 | export 'src/flutter_exts.dart'; 10 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 5464c5bac742001448fe4fc0597be939379f88ea 8 | channel: stable 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.3.0 4 | 5 | * Updated license 6 | 7 | ## 1.2.0 8 | 9 | * Updated dependencies 10 | * Added funding links 11 | 12 | ## 1.1.0 13 | 14 | * Improved documentation & added changelog 15 | * Improve performance - made variables immutable 16 | * Internal refactoring 17 | * Updated dependencies 18 | 19 | ## 1.0.0 (stable) 20 | 21 | * Made CLI stable 22 | * Made application library stable 23 | * Added documentation 24 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: dqoi_example 2 | description: Example application for the 'dqoi' application library 3 | 4 | publish_to: "none" 5 | version: 1.0.0 6 | 7 | environment: 8 | sdk: ">=2.16.2 <3.0.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | dqoi: 14 | path: ../ 15 | 16 | dev_dependencies: 17 | flutter_lints: ^1.0.0 18 | 19 | flutter: 20 | uses-material-design: true 21 | assets: 22 | - assets/images/ 23 | -------------------------------------------------------------------------------- /example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | add_executable(${BINARY_NAME} WIN32 5 | "flutter_window.cpp" 6 | "main.cpp" 7 | "utils.cpp" 8 | "win32_window.cpp" 9 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 10 | "Runner.rc" 11 | "runner.exe.manifest" 12 | ) 13 | apply_standard_settings(${BINARY_NAME}) 14 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 15 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 16 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 17 | add_dependencies(${BINARY_NAME} flutter_assemble) 18 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: dqoi 2 | description: A Dart implementation of the "Quite OK Image Format", with a command line interface for console use and a library for use in applications. 3 | version: 1.3.0 4 | repository: https://github.com/JaffaKetchup/dqoi 5 | issue_tracker: https://github.com/JaffaKetchup/dqoi/issues 6 | 7 | funding: 8 | - https://github.com/sponsors/JaffaKetchup 9 | - https://ko-fi.com/jaffaketchup 10 | 11 | environment: 12 | sdk: ">=2.17.0 <3.0.0" 13 | flutter: ">=3.3.0" 14 | 15 | dependencies: 16 | args: ^2.3.0 17 | flutter: 18 | sdk: flutter 19 | image: ^3.2.0 20 | path: ^1.8.2 21 | 22 | dev_dependencies: 23 | lints: ^2.0.0 24 | 25 | executables: 26 | dqoi: 27 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.6.10' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /dqoi-test.bat: -------------------------------------------------------------------------------- 1 | :: TESTS CLI BASED ON TESTING IMAGES 2 | :: DOES NOT TEST APPLICATION LIBRARY 3 | 4 | @echo off 5 | 6 | :: Binary and QOI testing 7 | bin\dqoi -f testing\monument.qoi --bin | more 8 | bin\dqoi -f outputs\testing\monument.bin -w 735 -h 588 --channels 4 --colorspace 1 | more 9 | 10 | move /Y outputs\outputs\testing\monument.qoi outputs\ > nul 11 | rmdir /S /Q outputs\outputs 12 | move /Y outputs\testing\monument.bin outputs\ > nul 13 | rmdir /S /Q outputs\testing 14 | 15 | fc /b testing\monument.qoi outputs\monument.qoi 16 | fc /b testing\monument.bin outputs\monument.bin 17 | 18 | :: PNG and QOI testing 19 | :: Does not test decoding algorithm 20 | bin\dqoi -f testing\testcard_rgba.png | more 21 | move /Y outputs\testing\testcard_rgba.qoi outputs\ > nul 22 | rmdir /S /Q outputs\testing 23 | fc /b testing\testcard_rgba.qoi outputs\testcard_rgba.qoi -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | 43 | # Android Studio will place build artifacts here 44 | /android/app/debug 45 | /android/app/profile 46 | /android/app/release 47 | -------------------------------------------------------------------------------- /dqoi.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /example/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "short_name": "example", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | }, 22 | { 23 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /lib/src/interpreters/shared.dart: -------------------------------------------------------------------------------- 1 | /// Represents a RGBA color pixel 2 | class Color { 3 | final int red; 4 | final int green; 5 | final int blue; 6 | final int alpha; 7 | 8 | /// Create a RGBA color pixel (custom) 9 | Color(this.red, this.green, this.blue, this.alpha); 10 | 11 | /// Create a RGBA color pixel (white transparent) 12 | static Color get zero => Color(0, 0, 0, 0); 13 | 14 | @override 15 | bool operator ==(Object other) { 16 | if (identical(this, other)) return true; 17 | 18 | return other is Color && 19 | other.red == red && 20 | other.green == green && 21 | other.blue == blue && 22 | other.alpha == alpha; 23 | } 24 | 25 | @override 26 | int get hashCode => (red * 3 + green * 5 + blue * 7 + alpha * 11) % 64; 27 | } 28 | 29 | /// Represents a method identification byte found at the start of each compressed block 30 | class IDTag { 31 | static const int rgb = 0xfe; 32 | static const int rgba = 0xff; 33 | static const int run = 0xc0; 34 | static const int index = 0x00; 35 | static const int diff = 0x40; 36 | static const int luma = 0x80; 37 | } 38 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:lints/recommended.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | # linter: 19 | # rules: 20 | # - camel_case_types 21 | 22 | # analyzer: 23 | # exclude: 24 | # - path/to/excluded/files/** 25 | 26 | # For more information about the core and recommended set of lints, see 27 | # https://dart.dev/go/core-lints 28 | 29 | # For additional information about configuring this file, see 30 | # https://dart.dev/guides/language/analysis-options 31 | -------------------------------------------------------------------------------- /lib/src/flutter_exts.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:ui' as ui; 3 | 4 | import 'package:flutter/material.dart'; 5 | 6 | import 'qoi.dart'; 7 | 8 | /// Extends [QOI] with extra methods targeted for Flutter users 9 | /// 10 | /// Automatically exported by `package:dqoi/dqoi.dart`. 11 | extension FlutterQOIExts on QOI { 12 | /// Create an [ui.Image] from this QOI data, in future 13 | /// 14 | /// Alternatively, use [toImageWidget] for a more complete solution using [FutureBuilder] to await the rendering. 15 | Future toImage() { 16 | final c = Completer(); 17 | 18 | ui.decodeImageFromPixels( 19 | toRaw(), 20 | width, 21 | height, 22 | ui.PixelFormat.rgba8888, 23 | c.complete, 24 | ); 25 | return c.future; 26 | } 27 | 28 | /// Using QOI data, create a [FutureBuilder] which will show an [ui.Image] once ready 29 | /// 30 | /// Supply [loadingWidget] to show a custom widget whilst rendering the image. The default is a centered [CircularProgressIndicator]. Note that in the unlikely event of a decoding error, this widget will also be shown. 31 | FutureBuilder toImageWidget({ 32 | Widget? loadingWidget, 33 | }) => 34 | FutureBuilder( 35 | future: toImage(), 36 | builder: (_, img) => img.hasData 37 | ? RawImage(image: img.data) 38 | : (loadingWidget ?? Center(child: CircularProgressIndicator())), 39 | ); 40 | } 41 | -------------------------------------------------------------------------------- /example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.CreateAndShow(L"example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Custom 2 | local/ 3 | .fvm/ 4 | outputs/** 5 | 6 | # Miscellaneous 7 | *.class 8 | *.log 9 | *.pyc 10 | *.swp 11 | .DS_Store 12 | .atom/ 13 | .buildlog/ 14 | .history 15 | .svn/ 16 | 17 | # IntelliJ & VSCode related 18 | *.iml 19 | *.ipr 20 | *.iws 21 | .idea/ 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | **/doc/ 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | build/ 33 | pubspec.lock 34 | 35 | # Android related 36 | **/android/**/gradle-wrapper.jar 37 | **/android/.gradle 38 | **/android/captures/ 39 | **/android/gradlew 40 | **/android/gradlew.bat 41 | **/android/local.properties 42 | **/android/**/GeneratedPluginRegistrant.java 43 | 44 | # iOS/XCode related 45 | **/ios/**/*.mode1v3 46 | **/ios/**/*.mode2v3 47 | **/ios/**/*.moved-aside 48 | **/ios/**/*.pbxuser 49 | **/ios/**/*.perspectivev3 50 | **/ios/**/*sync/ 51 | **/ios/**/.sconsign.dblite 52 | **/ios/**/.tags* 53 | **/ios/**/.vagrant/ 54 | **/ios/**/DerivedData/ 55 | **/ios/**/Icon? 56 | **/ios/**/Pods/ 57 | **/ios/**/.symlinks/ 58 | **/ios/**/profile 59 | **/ios/**/xcuserdata 60 | **/ios/.generated/ 61 | **/ios/Flutter/App.framework 62 | **/ios/Flutter/Flutter.framework 63 | **/ios/Flutter/Flutter.podspec 64 | **/ios/Flutter/Generated.xcconfig 65 | **/ios/Flutter/app.flx 66 | **/ios/Flutter/app.zip 67 | **/ios/Flutter/flutter_assets/ 68 | **/ios/Flutter/flutter_export_environment.sh 69 | **/ios/ServiceDefinitions.json 70 | **/ios/Runner/GeneratedPluginRegistrant.* 71 | !**/ios/**/default.mode1v3 72 | !**/ios/**/default.mode2v3 73 | !**/ios/**/default.pbxuser 74 | !**/ios/**/default.perspectivev3 75 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:flutter/material.dart'; 4 | 5 | import 'package:dqoi/dqoi.dart'; 6 | 7 | import 'load_asset.dart'; 8 | 9 | void main() { 10 | runApp(const DemoAppContainer()); 11 | } 12 | 13 | class DemoAppContainer extends StatelessWidget { 14 | const DemoAppContainer({Key? key}) : super(key: key); 15 | 16 | @override 17 | Widget build(BuildContext context) { 18 | return MaterialApp( 19 | title: 'dqoi Demo Application', 20 | theme: ThemeData( 21 | primarySwatch: Colors.orange, 22 | ), 23 | home: const MainPage(), 24 | ); 25 | } 26 | } 27 | 28 | class MainPage extends StatelessWidget { 29 | const MainPage({Key? key}) : super(key: key); 30 | 31 | @override 32 | Widget build(BuildContext context) { 33 | return Scaffold( 34 | appBar: AppBar( 35 | title: const Text('dqoi Demo Application'), 36 | ), 37 | body: Center( 38 | child: FutureBuilder>( 39 | future: Future.wait([ 40 | loadAsset('assets/images/kodim23.qoi'), 41 | loadAsset('assets/images/dice.qoi'), 42 | loadAsset('assets/images/testcard_rgba.qoi'), 43 | ]), 44 | builder: (context, assets) { 45 | if (!assets.hasData) { 46 | return const CircularProgressIndicator(); 47 | } 48 | 49 | return ListView.builder( 50 | itemBuilder: (context, i) => Container( 51 | child: QOI.fromQOI(assets.data![i]).toImageWidget(), 52 | color: Colors.black.withOpacity(0.5), 53 | ), 54 | itemCount: assets.data!.length, 55 | ); 56 | }, 57 | ), 58 | ), 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | if (target_length == 0) { 52 | return std::string(); 53 | } 54 | std::string utf8_string; 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | return true; 30 | } 31 | 32 | void FlutterWindow::OnDestroy() { 33 | if (flutter_controller_) { 34 | flutter_controller_ = nullptr; 35 | } 36 | 37 | Win32Window::OnDestroy(); 38 | } 39 | 40 | LRESULT 41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 42 | WPARAM const wparam, 43 | LPARAM const lparam) noexcept { 44 | // Give Flutter, including plugins, an opportunity to handle window messages. 45 | if (flutter_controller_) { 46 | std::optional result = 47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 48 | lparam); 49 | if (result) { 50 | return *result; 51 | } 52 | } 53 | 54 | switch (message) { 55 | case WM_FONTCHANGE: 56 | flutter_controller_->engine()->ReloadSystemFonts(); 57 | break; 58 | } 59 | 60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 61 | } 62 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion flutter.compileSdkVersion 30 | 31 | compileOptions { 32 | sourceCompatibility JavaVersion.VERSION_1_8 33 | targetCompatibility JavaVersion.VERSION_1_8 34 | } 35 | 36 | kotlinOptions { 37 | jvmTarget = '1.8' 38 | } 39 | 40 | sourceSets { 41 | main.java.srcDirs += 'src/main/kotlin' 42 | } 43 | 44 | defaultConfig { 45 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 46 | applicationId "com.example.example" 47 | minSdkVersion flutter.minSdkVersion 48 | targetSdkVersion flutter.targetSdkVersion 49 | versionCode flutterVersionCode.toInteger() 50 | versionName flutterVersionName 51 | } 52 | 53 | buildTypes { 54 | release { 55 | // TODO: Add your own signing config for the release build. 56 | // Signing with the debug keys for now, so `flutter run --release` works. 57 | signingConfig signingConfigs.debug 58 | } 59 | } 60 | } 61 | 62 | flutter { 63 | source '../..' 64 | } 65 | 66 | dependencies { 67 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 68 | } 69 | -------------------------------------------------------------------------------- /lib/src/qoi.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:image/image.dart'; 4 | 5 | import 'interpreters/decode.dart' as decoder; 6 | import 'interpreters/encode.dart' as encoder; 7 | 8 | export 'package:image/image.dart' show Channels; 9 | 10 | /// Represents the information found inside a QOI image, whether the image is QOI formatted yet, or not 11 | /// 12 | /// Can be constructed from a: 13 | /// * raw binary file, with the [QOI.fromRaw] constructor 14 | /// * PNG image, with the [QOI.fromPNG] constructor 15 | /// * QOI image, with the [QOI.fromQOI] constructor 16 | /// 17 | /// Can be converted to a: 18 | /// * raw binary file, with the [toRaw] method 19 | /// * PNG image, with the [toPNG] method 20 | /// * QOI image, with the [toQOI] method 21 | class QOI { 22 | //! PROPERTIES !// 23 | 24 | /// Represents any bytes, not necessarily just QOI format bytes 25 | /// 26 | /// Always represents QOI bytes after decoding, and unknown bytes before encoding. 27 | final Uint8List _bytes; 28 | 29 | /// Image width in pixels 30 | final int width; 31 | 32 | /// Image height in pixels 33 | final int height; 34 | 35 | /// Channels in image (RGB or RGBA) 36 | /// 37 | /// Will always be RGBA formatted after decoding. 38 | final Channels _channels; 39 | 40 | /// Colorspace number of image 41 | /// 42 | /// 0 represents sRGB with linear alpha; 1 represents all channels alpha. 43 | final int _colorspace; 44 | 45 | //! DECODERS !// 46 | 47 | /// Constructor that does not do any automatic decoding 48 | /// 49 | /// The input bytes must just be unformatted pixel data (eg. no headers). 50 | QOI.fromRaw({ 51 | required Uint8List bytes, 52 | required this.width, 53 | required this.height, 54 | Channels channels = Channels.rgba, 55 | int colorspace = 0, 56 | }) : _bytes = bytes, 57 | _channels = channels, 58 | _colorspace = colorspace; 59 | 60 | /// Decode from a PNG image, using the [Image] library 61 | static QOI fromPNG( 62 | Uint8List raw, { 63 | Channels? overrideChannels, 64 | int? overrideColorspace, 65 | }) { 66 | final Image image = PngDecoder().decodeImage(raw)!; 67 | 68 | return QOI.fromRaw( 69 | bytes: image.getBytes(), 70 | width: image.width, 71 | height: image.height, 72 | channels: overrideChannels ?? image.channels, 73 | colorspace: overrideColorspace ?? 0, 74 | ); 75 | } 76 | 77 | /// Decode from a QOI image, using the built-in decoder 78 | static QOI fromQOI(Uint8List raw) => decoder.decode(data: raw); 79 | 80 | //! ENCODERS !// 81 | 82 | /// Encode to a QOI image, using the built-in encoder 83 | Uint8List toQOI() => encoder.encode( 84 | data: _bytes, 85 | width: width, 86 | height: height, 87 | channels: _channels == Channels.rgb ? 3 : 4, 88 | colorspace: _colorspace, 89 | ); 90 | 91 | /// Encode to a PNG image, using the [Image] library 92 | Uint8List toPNG() => Uint8List.fromList( 93 | PngEncoder().encodeImage( 94 | Image.fromBytes( 95 | width, 96 | height, 97 | _bytes, 98 | channels: _channels, 99 | ), 100 | ), 101 | ); 102 | 103 | /// Dump to a raw binary image, without any conversions 104 | /// 105 | /// The output just represents the pixel data (eg. no headers). 106 | Uint8List toRaw() => _bytes; 107 | } 108 | -------------------------------------------------------------------------------- /example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #ifdef FLUTTER_BUILD_NUMBER 64 | #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0 67 | #endif 68 | 69 | #ifdef FLUTTER_BUILD_NAME 70 | #define VERSION_AS_STRING #FLUTTER_BUILD_NAME 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "dev.jaffaketchup.dqoi.example" "\0" 93 | VALUE "FileDescription", "example" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 dev.jaffaketchup.dqoi.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "example.exe" "\0" 98 | VALUE "ProductName", "example" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /lib/src/interpreters/decode.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'shared.dart'; 4 | import '../qoi.dart'; 5 | 6 | class Diff { 7 | static const int red = 0x30; 8 | static const int green = 0x0c; 9 | static const int blue = 0x03; 10 | } 11 | 12 | class Luma { 13 | static const int green = 0x3f; 14 | static const int rg = 0xf0; 15 | static const int bg = 0x0f; 16 | } 17 | 18 | QOI decode({ 19 | required Uint8List data, 20 | }) { 21 | final List seenPixels = List.filled(64, Color.zero); 22 | 23 | Color prevColor = Color(0, 0, 0, 255); 24 | int readIndex = 0; 25 | int writeIndex = 0; 26 | 27 | int readByte() => data[readIndex++]; 28 | int read32() => 29 | (readByte() << 24) | (readByte() << 16) | (readByte() << 8) | readByte(); 30 | 31 | if (data.lengthInBytes < 22 || read32() != 0x716f6966) { 32 | throw ArgumentError( 33 | 'Invalid QOI data\nCheck the size and header of the data are correct', 34 | ); 35 | } 36 | 37 | // Retrieve headers 38 | final int width = read32(); 39 | final int height = read32(); 40 | readByte(); 41 | final int channels = 4; // Fix channels to RGBA regardless of headers 42 | final int colorspace = readByte(); 43 | final Uint8List bytes = Uint8List(width * height * channels); 44 | 45 | void writeColor(Color color) { 46 | bytes[writeIndex++] = color.red; 47 | bytes[writeIndex++] = color.green; 48 | bytes[writeIndex++] = color.blue; 49 | bytes[writeIndex++] = color.alpha; 50 | } 51 | 52 | while (readIndex < data.lengthInBytes - 8) { 53 | final int byte = readByte(); 54 | 55 | if (byte == IDTag.rgb || byte == IDTag.rgba) { 56 | prevColor = Color( 57 | readByte(), 58 | readByte(), 59 | readByte(), 60 | byte == IDTag.rgba ? readByte() : prevColor.alpha, 61 | ); 62 | 63 | writeColor(prevColor); 64 | seenPixels[prevColor.hashCode] = prevColor; 65 | continue; 66 | } 67 | 68 | switch (byte & 0xc0) { 69 | case IDTag.run: 70 | for (int i = 0; i <= (byte & 0x3f); i++) { 71 | writeColor(prevColor); 72 | seenPixels[prevColor.hashCode] = prevColor; 73 | } 74 | break; 75 | case IDTag.index: 76 | writeColor(seenPixels[byte & 0x3f]); 77 | prevColor = seenPixels[byte & 0x3f]; 78 | break; 79 | case IDTag.diff: 80 | prevColor = Color( 81 | (prevColor.red + ((byte & Diff.red) >> 4) - 2) & 0xff, 82 | (prevColor.green + ((byte & Diff.green) >> 2) - 2) & 0xff, 83 | (prevColor.blue + (byte & Diff.blue) - 2) & 0xff, 84 | prevColor.alpha, 85 | ); 86 | writeColor(prevColor); 87 | seenPixels[prevColor.hashCode] = prevColor; 88 | break; 89 | case IDTag.luma: 90 | final dg = (byte & Luma.green) - 32; 91 | 92 | final byte2 = readByte(); 93 | final drdg = ((byte2 & Luma.rg) >> 4) - 8; 94 | final dbdg = (byte2 & Luma.bg) - 8; 95 | 96 | prevColor = Color( 97 | (prevColor.red + drdg + dg) & 0xff, 98 | (prevColor.green + dg) & 0xff, 99 | (prevColor.blue + dbdg + dg) & 0xff, 100 | prevColor.alpha, 101 | ); 102 | 103 | writeColor(prevColor); 104 | seenPixels[prevColor.hashCode] = prevColor; 105 | break; 106 | } 107 | } 108 | 109 | return QOI.fromRaw( 110 | width: width, 111 | height: height, 112 | channels: channels == 3 ? Channels.rgb : Channels.rgba, 113 | colorspace: colorspace, 114 | bytes: bytes, 115 | ); 116 | } 117 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates and shows a win32 window with |title| and position and size using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size to will treat the width height passed in to this function 35 | // as logical pixels and scale to appropriate for the default monitor. Returns 36 | // true if the window was created successfully. 37 | bool CreateAndShow(const std::wstring& title, 38 | const Point& origin, 39 | const Size& size); 40 | 41 | // Release OS resources associated with window. 42 | void Destroy(); 43 | 44 | // Inserts |content| into the window tree. 45 | void SetChildContent(HWND content); 46 | 47 | // Returns the backing Window handle to enable clients to set icon and other 48 | // window properties. Returns nullptr if the window has been destroyed. 49 | HWND GetHandle(); 50 | 51 | // If true, closing this window will quit the application. 52 | void SetQuitOnClose(bool quit_on_close); 53 | 54 | // Return a RECT representing the bounds of the current client area. 55 | RECT GetClientArea(); 56 | 57 | protected: 58 | // Processes and route salient window messages for mouse handling, 59 | // size change and DPI. Delegates handling of these to member overloads that 60 | // inheriting classes can handle. 61 | virtual LRESULT MessageHandler(HWND window, 62 | UINT const message, 63 | WPARAM const wparam, 64 | LPARAM const lparam) noexcept; 65 | 66 | // Called when CreateAndShow is called, allowing subclass window-related 67 | // setup. Subclasses should return false if setup fails. 68 | virtual bool OnCreate(); 69 | 70 | // Called when Destroy is called. 71 | virtual void OnDestroy(); 72 | 73 | private: 74 | friend class WindowClassRegistrar; 75 | 76 | // OS callback called by message pump. Handles the WM_NCCREATE message which 77 | // is passed when the non-client area is being created and enables automatic 78 | // non-client DPI scaling so that the non-client area automatically 79 | // responsponds to changes in DPI. All other messages are handled by 80 | // MessageHandler. 81 | static LRESULT CALLBACK WndProc(HWND const window, 82 | UINT const message, 83 | WPARAM const wparam, 84 | LPARAM const lparam) noexcept; 85 | 86 | // Retrieves a class instance pointer for |window| 87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 88 | 89 | bool quit_on_close_ = false; 90 | 91 | // window handle for top level window. 92 | HWND window_handle_ = nullptr; 93 | 94 | // window handle for hosted content. 95 | HWND child_content_ = nullptr; 96 | }; 97 | 98 | #endif // RUNNER_WIN32_WINDOW_H_ 99 | -------------------------------------------------------------------------------- /example/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(example LANGUAGES CXX) 3 | 4 | set(BINARY_NAME "example") 5 | 6 | cmake_policy(SET CMP0063 NEW) 7 | 8 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 9 | 10 | # Configure build options. 11 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 12 | if(IS_MULTICONFIG) 13 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 14 | CACHE STRING "" FORCE) 15 | else() 16 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 17 | set(CMAKE_BUILD_TYPE "Debug" CACHE 18 | STRING "Flutter build mode" FORCE) 19 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 20 | "Debug" "Profile" "Release") 21 | endif() 22 | endif() 23 | 24 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 25 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 26 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 27 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 28 | 29 | # Use Unicode for all projects. 30 | add_definitions(-DUNICODE -D_UNICODE) 31 | 32 | # Compilation settings that should be applied to most targets. 33 | function(APPLY_STANDARD_SETTINGS TARGET) 34 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 35 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 36 | target_compile_options(${TARGET} PRIVATE /EHsc) 37 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 38 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 39 | endfunction() 40 | 41 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 42 | 43 | # Flutter library and tool build rules. 44 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 45 | 46 | # Application build 47 | add_subdirectory("runner") 48 | 49 | # Generated plugin build rules, which manage building the plugins and adding 50 | # them to the application. 51 | include(flutter/generated_plugins.cmake) 52 | 53 | 54 | # === Installation === 55 | # Support files are copied into place next to the executable, so that it can 56 | # run in place. This is done instead of making a separate bundle (as on Linux) 57 | # so that building and running from within Visual Studio will work. 58 | set(BUILD_BUNDLE_DIR "$") 59 | # Make the "install" step default, as it's required to run. 60 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 61 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 62 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 63 | endif() 64 | 65 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 66 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 67 | 68 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 69 | COMPONENT Runtime) 70 | 71 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 72 | COMPONENT Runtime) 73 | 74 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 75 | COMPONENT Runtime) 76 | 77 | if(PLUGIN_BUNDLED_LIBRARIES) 78 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 79 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 80 | COMPONENT Runtime) 81 | endif() 82 | 83 | # Fully re-copy the assets directory on each build to avoid having stale files 84 | # from a previous install. 85 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 86 | install(CODE " 87 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 88 | " COMPONENT Runtime) 89 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 90 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 91 | 92 | # Install the AOT library on non-Debug builds only. 93 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 94 | CONFIGURATIONS Profile;Release 95 | COMPONENT Runtime) 96 | -------------------------------------------------------------------------------- /example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 4 | 5 | # Configuration provided via flutter tool. 6 | include(${EPHEMERAL_DIR}/generated_config.cmake) 7 | 8 | # TODO: Move the rest of this into files in ephemeral. See 9 | # https://github.com/flutter/flutter/issues/57146. 10 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 11 | 12 | # === Flutter Library === 13 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 14 | 15 | # Published to parent scope for install step. 16 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 17 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 18 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 19 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 20 | 21 | list(APPEND FLUTTER_LIBRARY_HEADERS 22 | "flutter_export.h" 23 | "flutter_windows.h" 24 | "flutter_messenger.h" 25 | "flutter_plugin_registrar.h" 26 | "flutter_texture_registrar.h" 27 | ) 28 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 29 | add_library(flutter INTERFACE) 30 | target_include_directories(flutter INTERFACE 31 | "${EPHEMERAL_DIR}" 32 | ) 33 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 34 | add_dependencies(flutter flutter_assemble) 35 | 36 | # === Wrapper === 37 | list(APPEND CPP_WRAPPER_SOURCES_CORE 38 | "core_implementations.cc" 39 | "standard_codec.cc" 40 | ) 41 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 42 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 43 | "plugin_registrar.cc" 44 | ) 45 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 46 | list(APPEND CPP_WRAPPER_SOURCES_APP 47 | "flutter_engine.cc" 48 | "flutter_view_controller.cc" 49 | ) 50 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 51 | 52 | # Wrapper sources needed for a plugin. 53 | add_library(flutter_wrapper_plugin STATIC 54 | ${CPP_WRAPPER_SOURCES_CORE} 55 | ${CPP_WRAPPER_SOURCES_PLUGIN} 56 | ) 57 | apply_standard_settings(flutter_wrapper_plugin) 58 | set_target_properties(flutter_wrapper_plugin PROPERTIES 59 | POSITION_INDEPENDENT_CODE ON) 60 | set_target_properties(flutter_wrapper_plugin PROPERTIES 61 | CXX_VISIBILITY_PRESET hidden) 62 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 63 | target_include_directories(flutter_wrapper_plugin PUBLIC 64 | "${WRAPPER_ROOT}/include" 65 | ) 66 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 67 | 68 | # Wrapper sources needed for the runner. 69 | add_library(flutter_wrapper_app STATIC 70 | ${CPP_WRAPPER_SOURCES_CORE} 71 | ${CPP_WRAPPER_SOURCES_APP} 72 | ) 73 | apply_standard_settings(flutter_wrapper_app) 74 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 75 | target_include_directories(flutter_wrapper_app PUBLIC 76 | "${WRAPPER_ROOT}/include" 77 | ) 78 | add_dependencies(flutter_wrapper_app flutter_assemble) 79 | 80 | # === Flutter tool backend === 81 | # _phony_ is a non-existent file to force this command to run every time, 82 | # since currently there's no way to get a full input/output list from the 83 | # flutter tool. 84 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 85 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 86 | add_custom_command( 87 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 88 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 89 | ${CPP_WRAPPER_SOURCES_APP} 90 | ${PHONY_OUTPUT} 91 | COMMAND ${CMAKE_COMMAND} -E env 92 | ${FLUTTER_TOOL_ENVIRONMENT} 93 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 94 | windows-x64 $ 95 | VERBATIM 96 | ) 97 | add_custom_target(flutter_assemble DEPENDS 98 | "${FLUTTER_LIBRARY}" 99 | ${FLUTTER_LIBRARY_HEADERS} 100 | ${CPP_WRAPPER_SOURCES_CORE} 101 | ${CPP_WRAPPER_SOURCES_PLUGIN} 102 | ${CPP_WRAPPER_SOURCES_APP} 103 | ) 104 | -------------------------------------------------------------------------------- /lib/src/interpreters/encode.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'shared.dart'; 4 | 5 | Uint8List encode({ 6 | required Uint8List data, 7 | required int width, 8 | required int height, 9 | required int channels, 10 | required int colorspace, 11 | }) { 12 | // Fix channels to RGBA regardless of argument 13 | final int fixedRGBA = 4; 14 | 15 | final int lastPixel = data.lengthInBytes - fixedRGBA; 16 | final seenPixels = List.filled(64, Color.zero); 17 | final bytes = Uint8List(width * height * (fixedRGBA + 1) + 18 | 22); // `width * height * (RGBA number of color channels + identification tag byte) + header length + end marker size` 19 | 20 | var prevColor = Color(0, 0, 0, 255); 21 | var run = 0; 22 | var index = 0; 23 | 24 | void write32(int value) { 25 | bytes[index++] = (value & 0xff000000) >> 24; 26 | bytes[index++] = (value & 0x00ff0000) >> 16; 27 | bytes[index++] = (value & 0x0000ff00) >> 8; 28 | bytes[index++] = (value & 0x000000ff) >> 0; 29 | } 30 | 31 | void resetRun() { 32 | bytes[index++] = IDTag.run | (run - 1); 33 | run = 0; 34 | } 35 | 36 | // Write headers to the file 37 | write32(0x716f6966); 38 | write32(width); 39 | write32(height); 40 | bytes[index++] = channels; 41 | bytes[index++] = colorspace; 42 | 43 | for (int offset = 0; offset <= lastPixel; offset += fixedRGBA) { 44 | final Color color = Color( 45 | data[offset + 0], 46 | data[offset + 1], 47 | data[offset + 2], 48 | fixedRGBA == 4 ? data[offset + 3] : prevColor.alpha, 49 | ); 50 | 51 | if (color == prevColor) { 52 | run++; 53 | if (run == 62 || offset == lastPixel) resetRun(); 54 | } else { 55 | if (run > 0) resetRun(); 56 | 57 | if (color == seenPixels[color.hashCode]) { 58 | bytes[index++] = IDTag.index | color.hashCode; 59 | } else { 60 | seenPixels[color.hashCode] = color; 61 | 62 | if (color.alpha == prevColor.alpha) { 63 | int diffRed = (color.red - prevColor.red) & 255; 64 | if (diffRed > 127) diffRed -= 256; 65 | int diffGreen = (color.green - prevColor.green) & 255; 66 | if (diffGreen > 127) diffGreen -= 256; 67 | int diffBlue = (color.blue - prevColor.blue) & 255; 68 | if (diffBlue > 127) diffBlue -= 256; 69 | 70 | final int diffRedGreen = diffRed - diffGreen; 71 | final int diffBlueGreen = diffBlue - diffGreen; 72 | 73 | if (diffRed > -3 && 74 | diffRed < 2 && 75 | diffGreen > -3 && 76 | diffGreen < 2 && 77 | diffBlue > -3 && 78 | diffBlue < 2) { 79 | bytes[index++] = IDTag.diff | 80 | (diffRed + 2) << 4 | 81 | (diffGreen + 2) << 2 | 82 | (diffBlue + 2); 83 | } else if (diffRedGreen > -9 && 84 | diffRedGreen < 8 && 85 | diffGreen > -33 && 86 | diffGreen < 32 && 87 | diffBlueGreen > -9 && 88 | diffBlueGreen < 8) { 89 | bytes[index++] = IDTag.luma | (diffGreen + 32); 90 | bytes[index++] = (diffRedGreen + 8) << 4 | (diffBlueGreen + 8); 91 | } else { 92 | bytes[index++] = IDTag.rgb; 93 | bytes[index++] = color.red; 94 | bytes[index++] = color.green; 95 | bytes[index++] = color.blue; 96 | } 97 | } else { 98 | bytes[index++] = IDTag.rgba; 99 | bytes[index++] = color.red; 100 | bytes[index++] = color.green; 101 | bytes[index++] = color.blue; 102 | bytes[index++] = color.alpha; 103 | } 104 | } 105 | } 106 | 107 | prevColor = color; 108 | } 109 | 110 | for (int byte in Uint8List(8)..[7] = 1) { 111 | bytes[index++] = byte; 112 | } 113 | 114 | return Uint8List.fromList(bytes.getRange(0, index).toList()); 115 | } 116 | -------------------------------------------------------------------------------- /example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | example 33 | 34 | 35 | 36 | 39 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /bin/dqoi.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'dart:typed_data'; 3 | 4 | import 'package:args/args.dart'; 5 | import 'package:path/path.dart' as p; 6 | 7 | import 'package:dqoi/dqoi_pure.dart'; 8 | 9 | void main(List inputArgs) async { 10 | late final ArgResults args; 11 | 12 | try { 13 | final ArgParser parser = ArgParser(); 14 | 15 | parser.addOption( 16 | 'filename', 17 | abbr: 'f', 18 | aliases: ['input'], 19 | help: 20 | 'Path to file (including extension) to encode/decode\nOutput files are created with the same relative path within a \'outputs/\' directory', 21 | allowedHelp: { 22 | '.qoi': 23 | 'Decoded to .png (unless otherwise specified with --bin flag)', 24 | '.bin': 'Encoded to .qoi', 25 | '.png': 'Encoded to .qoi', 26 | '.*': 'Other formats are currently unsupported', 27 | }, 28 | mandatory: true, 29 | ); 30 | parser.addOption( 31 | 'width', 32 | abbr: 'w', 33 | help: 'Image width in pixels\nRequired when encoding .bin format', 34 | ); 35 | parser.addOption( 36 | 'height', 37 | abbr: 'h', 38 | help: 'Image height in pixels\nRequired when encoding .bin format', 39 | ); 40 | parser.addOption( 41 | 'channels', 42 | abbr: 'c', 43 | help: 44 | 'Number of image channels\nMust be either 3 (RGB) or 4 (RGBA)\nRequired when encoding .bin format\nOverrides metadata when encoding .png format', 45 | ); 46 | parser.addOption( 47 | 'colorspace', 48 | help: 49 | 'Number of colorspace\nMust be either 0 (sRGB with linear alpha) or 1 (all channels linear)\nOnly used when encoding', 50 | defaultsTo: '0', 51 | ); 52 | parser.addFlag( 53 | 'bin', 54 | help: 'When decoding, dump to .bin file instead of re-encoding to .png', 55 | negatable: false, 56 | ); 57 | 58 | if (inputArgs.isEmpty || 59 | inputArgs.map((e) => e.toLowerCase()).contains('--help')) { 60 | print(parser.usage); 61 | return; 62 | } 63 | 64 | args = parser.parse(inputArgs); 65 | } catch (e) { 66 | if (e is ArgParserException) { 67 | print(e.message); 68 | } else { 69 | print('Unknown Error: $e'); 70 | } 71 | 72 | return; 73 | } 74 | 75 | final String inputExtension = p.extension(args['filename']); 76 | final String outputExtension = inputExtension != '.qoi' 77 | ? '.qoi' 78 | : args['bin'] 79 | ? '.bin' 80 | : '.png'; 81 | 82 | final bool channelsInvalid = 83 | args['channels'] != '3' && args['channels'] != '4'; 84 | final bool colorspaceInvalid = 85 | args['colorspace'] != '0' && args['colorspace'] != '1'; 86 | 87 | const String assistanceMessage = 88 | '\nFor more assistance, run \'dqoi\' with no arguments'; 89 | 90 | if (inputExtension != '.qoi' && inputExtension == '.bin') { 91 | if (args['width'] == null || args['height'] == null) { 92 | print( 93 | 'You must input a width and height to encode an image from .bin format$assistanceMessage'); 94 | return; 95 | } 96 | if (channelsInvalid) { 97 | print( 98 | 'You must input a valid channel number (3 or 4) to encode an image from .bin format$assistanceMessage'); 99 | return; 100 | } 101 | if (colorspaceInvalid) { 102 | print( 103 | 'You must input a valid colorspace number (0 or 1) to encode an image from .bin format$assistanceMessage'); 104 | return; 105 | } 106 | } 107 | 108 | if (channelsInvalid && args['channels'] != null) { 109 | print( 110 | 'You must input a valid channel number (3 or 4) if you specify it$assistanceMessage'); 111 | return; 112 | } 113 | if (colorspaceInvalid) { 114 | print( 115 | 'You must input a valid colorspace number (0 or 1) if you specify it$assistanceMessage'); 116 | return; 117 | } 118 | 119 | final Uint8List inputData = await File(args['filename']).readAsBytes(); 120 | final File outputFile = File( 121 | p.join( 122 | 'outputs/', 123 | p.withoutExtension(args['filename']) + outputExtension, 124 | ), 125 | ); 126 | 127 | await Directory('outputs/${p.dirname(args['filename'])}') 128 | .create(recursive: true); 129 | 130 | late final Uint8List output; 131 | 132 | if (inputExtension == '.png') { 133 | output = QOI 134 | .fromPNG( 135 | inputData, 136 | overrideChannels: args['channels'] == null 137 | ? null 138 | : int.tryParse(args['channels']) == 3 139 | ? Channels.rgb 140 | : Channels.rgba, 141 | overrideColorspace: int.tryParse(args['colorspace']), 142 | ) 143 | .toQOI(); 144 | } else if (inputExtension == '.bin') { 145 | output = QOI 146 | .fromRaw( 147 | bytes: inputData, 148 | width: int.parse(args['width']), 149 | height: int.parse(args['height']), 150 | channels: 151 | int.parse(args['channels']) == 3 ? Channels.rgb : Channels.rgba, 152 | colorspace: int.tryParse(args['colorspace'])!, 153 | ) 154 | .toQOI(); 155 | } else if (inputExtension == '.qoi') { 156 | final QOI qoi = QOI.fromQOI(inputData); 157 | output = args['bin'] ? qoi.toRaw() : qoi.toPNG(); 158 | } 159 | 160 | await outputFile.writeAsBytes(output); 161 | } 162 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dqoi ('dart_[qoi](https://github.com/phoboslab/qoi)') 2 | 3 | [![Pub](https://img.shields.io/pub/v/dqoi.svg?label=Latest+Stable+Version)](https://pub.dev/packages/dqoi) [![likes](https://img.shields.io/pub/likes/dqoi?label=pub.dev+Likes)](https://pub.dev/packages/dqoi/score) [![pub points](https://img.shields.io/pub/points/dqoi?label=pub.dev+Points)](https://pub.dev/packages/dqoi/score) 4 | [![GitHub stars](https://img.shields.io/github/stars/JaffaKetchup/dqoi.svg?label=GitHub+Stars)](https://GitHub.com/JaffaKetchup/dqoi/stargazers/) [![GitHub issues](https://img.shields.io/github/issues/JaffaKetchup/dqoi.svg?label=Issues)](https://GitHub.com/JaffaKetchup/dqoi/issues/) [![GitHub PRs](https://img.shields.io/github/issues-pr/JaffaKetchup/dqoi.svg?label=Pull%20Requests)](https://GitHub.com/JaffaKetchup/dqoi/pulls/) 5 | 6 | A Dart implementation of the "[Quite OK Image Format](https://qoiformat.org/)", with a command line interface for console use and a library for use in applications. 7 | 8 | Based off of [the official C implementation](https://github.com/phoboslab/qoi/blob/master/qoi.h) and other implementations. 9 | 10 | ## Supporting Me 11 | 12 | I'm an under-18 currently living in the UK, and I am in full-time education. I work on this project and all of my others in my spare time, and I currently have no stable income due to my age - although I aspire to work in software/mobile development in the future. 13 | If you have any change to spare, I'd be grateful for any amount, big or small :D. Every donation gives me 'mental fuel' to continue this project, and lets me know that I'm doing a good job. I'll be happy to give you a place on the documentation website's credits, and a shoutout in every release/CHANGELOG. 14 | 15 | You can read more about me and what I do on my [GitHub Sponsors](https://github.com/sponsors/JaffaKetchup) page, where you can donate as well. 16 | 17 | [![Sponsor Me Via GitHub Sponsors](GitHubSponsorsImage.jpg)](https://github.com/sponsors/JaffaKetchup) 18 | 19 | Alternatively, if you prefer not to use GitHub Sponsors, please feel free to use my [Ko-fi](https://ko-fi.com/jaffaketchup). Note that the PayPal backend will take a small percentage amount of donations made through this method. 20 | 21 | ## Command Line Interface 22 | 23 | An easy to use CLI is provided to get working with QOI! 24 | 25 | ### Setup/Installation 26 | 27 | #### With Dart (recommended) 28 | 29 | If you have Dart installed, you can use the CLI on any operating system! 30 | Just run the command `dart pub global activate dqoi` (with administrator/root privileges), then you can use the command `dqoi` from anywhere on your system! 31 | 32 | #### Without Dart 33 | 34 | ##### Windows 35 | 36 | If you don't have Dart installed, you can use the pre-compiled executable for Windows. 37 | 38 | You can get the .exe by: 39 | 40 | * Cloning this repository with Git, then going to 'bin/dqoi.exe' 41 | * Downloading just the executable from the GitHub repo browser: . 42 | 43 | Note that Windows Defender or your anti-virus may flag the executable malicious or unwanted, as it is not signed. You'll need to make an exception for the program if this happens. 44 | 45 | [Add this file to your system path](https://www.computerhope.com/issues/ch000549.htm#windows10), then you can use the command `dqoi` from anywhere on your system! 46 | 47 | ##### Other Operating Systems 48 | 49 | Unfortunately, I cannot provide executables for other operating systems at this time, as I do not have the appropriate devices. 50 | 51 | The best way to get the executable for your OS is to install Dart, then follow the instructions above for setup with Dart. 52 | 53 | ### CLI Usage 54 | 55 | You can list the available options by just running `dqoi` with no arguments or with '--help'. The program will return helpful messages in the event of an error, which should be self-explanatory. 56 | 57 | On Windows, `dqoi-test.bat` is provided to test the program, comparing the output files with official samples. This is not necessary to run, but may help to verify that the program is working correctly. In the event of a test failure, there will be differences shown in the console. 58 | 59 | ## Application Library 60 | 61 | ### Installation 62 | 63 | There are two included libraries, each of which are very similar: 64 | 65 | * Flutter applications should use the standard `package:dqoi/dqoi.dart` import. 66 | * Non-Flutter programs should use the `package:dqoi/dqoi_pure.dart` import, which excludes some useful Flutter-only methods. 67 | 68 | Note that both export the `Channels` enum from the 'image' package, but you can disable this by using `hide Channels` on the end of the import statement. 69 | Also note that neither uses 'dart:io', so both are fully compatible with Web applications. 70 | 71 | When this documentation refers to the singular "library", it means either library. 72 | 73 | ### Library Usage 74 | 75 | The `QOI` class provides access to conversions between binary, PNG, and QOI formats. 76 | 77 | When extended by `FlutterQOIExts`, it also provides an easy way to render/paint a QOI image in a Flutter app efficiently. 78 | 79 | You can find the full API documentation at . 80 | 81 | ### Examples 82 | 83 | You can build and install the example application, found in the 'example/' directory. However, below are some quick useful snippets to get you started. 84 | 85 | * Convert a PNG file to QOI, and then write to another file: 86 | 87 | ``` dart 88 | await outputFile.writeAsBytes(QOI.fromPNG(await inputFile.readAsBytes()).toQOI()); 89 | ``` 90 | 91 | * Render/paint a QOI file to a widget: 92 | 93 | ```dart 94 | return QOI.fromQOI(await inputFile.readAsBytes()).toImageWidget(loadingWidget: loadingWidget); 95 | ``` 96 | 97 | * Render/paint a QOI asset (bundled) to a widget: 98 | 99 | ```dart 100 | Future loadAsset(String path) async => (await rootBundle.load(path)).buffer.asUint8List(); 101 | return QOI.fromQOI(loadAsset('assetPath.qoi')).toImageWidget(loadingWidget: loadingWidget); 102 | ``` 103 | 104 | ## FAQ 105 | 106 | * How do I pronounce the name of this library? 107 | _It's up to you, but I like "decoy" best._ 108 | * Is this a good implementation? 109 | _The outputted QOI files perfectly match the official C implementation's outputs. Any re-encoded PNGs don't always match byte-for-byte, but the pixels are always correct_ 110 | * Are there any other implementations in different languages? 111 | _Sure there are! You can see all the other available ports on the [official README](https://github.com/phoboslab/qoi#implementations--bindings-of-qoi)._ 112 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.cpp: -------------------------------------------------------------------------------- 1 | #include "win32_window.h" 2 | 3 | #include 4 | 5 | #include "resource.h" 6 | 7 | namespace { 8 | 9 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; 10 | 11 | // The number of Win32Window objects that currently exist. 12 | static int g_active_window_count = 0; 13 | 14 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); 15 | 16 | // Scale helper to convert logical scaler values to physical using passed in 17 | // scale factor 18 | int Scale(int source, double scale_factor) { 19 | return static_cast(source * scale_factor); 20 | } 21 | 22 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. 23 | // This API is only needed for PerMonitor V1 awareness mode. 24 | void EnableFullDpiSupportIfAvailable(HWND hwnd) { 25 | HMODULE user32_module = LoadLibraryA("User32.dll"); 26 | if (!user32_module) { 27 | return; 28 | } 29 | auto enable_non_client_dpi_scaling = 30 | reinterpret_cast( 31 | GetProcAddress(user32_module, "EnableNonClientDpiScaling")); 32 | if (enable_non_client_dpi_scaling != nullptr) { 33 | enable_non_client_dpi_scaling(hwnd); 34 | FreeLibrary(user32_module); 35 | } 36 | } 37 | 38 | } // namespace 39 | 40 | // Manages the Win32Window's window class registration. 41 | class WindowClassRegistrar { 42 | public: 43 | ~WindowClassRegistrar() = default; 44 | 45 | // Returns the singleton registar instance. 46 | static WindowClassRegistrar* GetInstance() { 47 | if (!instance_) { 48 | instance_ = new WindowClassRegistrar(); 49 | } 50 | return instance_; 51 | } 52 | 53 | // Returns the name of the window class, registering the class if it hasn't 54 | // previously been registered. 55 | const wchar_t* GetWindowClass(); 56 | 57 | // Unregisters the window class. Should only be called if there are no 58 | // instances of the window. 59 | void UnregisterWindowClass(); 60 | 61 | private: 62 | WindowClassRegistrar() = default; 63 | 64 | static WindowClassRegistrar* instance_; 65 | 66 | bool class_registered_ = false; 67 | }; 68 | 69 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; 70 | 71 | const wchar_t* WindowClassRegistrar::GetWindowClass() { 72 | if (!class_registered_) { 73 | WNDCLASS window_class{}; 74 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); 75 | window_class.lpszClassName = kWindowClassName; 76 | window_class.style = CS_HREDRAW | CS_VREDRAW; 77 | window_class.cbClsExtra = 0; 78 | window_class.cbWndExtra = 0; 79 | window_class.hInstance = GetModuleHandle(nullptr); 80 | window_class.hIcon = 81 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); 82 | window_class.hbrBackground = 0; 83 | window_class.lpszMenuName = nullptr; 84 | window_class.lpfnWndProc = Win32Window::WndProc; 85 | RegisterClass(&window_class); 86 | class_registered_ = true; 87 | } 88 | return kWindowClassName; 89 | } 90 | 91 | void WindowClassRegistrar::UnregisterWindowClass() { 92 | UnregisterClass(kWindowClassName, nullptr); 93 | class_registered_ = false; 94 | } 95 | 96 | Win32Window::Win32Window() { 97 | ++g_active_window_count; 98 | } 99 | 100 | Win32Window::~Win32Window() { 101 | --g_active_window_count; 102 | Destroy(); 103 | } 104 | 105 | bool Win32Window::CreateAndShow(const std::wstring& title, 106 | const Point& origin, 107 | const Size& size) { 108 | Destroy(); 109 | 110 | const wchar_t* window_class = 111 | WindowClassRegistrar::GetInstance()->GetWindowClass(); 112 | 113 | const POINT target_point = {static_cast(origin.x), 114 | static_cast(origin.y)}; 115 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); 116 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); 117 | double scale_factor = dpi / 96.0; 118 | 119 | HWND window = CreateWindow( 120 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 121 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), 122 | Scale(size.width, scale_factor), Scale(size.height, scale_factor), 123 | nullptr, nullptr, GetModuleHandle(nullptr), this); 124 | 125 | if (!window) { 126 | return false; 127 | } 128 | 129 | return OnCreate(); 130 | } 131 | 132 | // static 133 | LRESULT CALLBACK Win32Window::WndProc(HWND const window, 134 | UINT const message, 135 | WPARAM const wparam, 136 | LPARAM const lparam) noexcept { 137 | if (message == WM_NCCREATE) { 138 | auto window_struct = reinterpret_cast(lparam); 139 | SetWindowLongPtr(window, GWLP_USERDATA, 140 | reinterpret_cast(window_struct->lpCreateParams)); 141 | 142 | auto that = static_cast(window_struct->lpCreateParams); 143 | EnableFullDpiSupportIfAvailable(window); 144 | that->window_handle_ = window; 145 | } else if (Win32Window* that = GetThisFromHandle(window)) { 146 | return that->MessageHandler(window, message, wparam, lparam); 147 | } 148 | 149 | return DefWindowProc(window, message, wparam, lparam); 150 | } 151 | 152 | LRESULT 153 | Win32Window::MessageHandler(HWND hwnd, 154 | UINT const message, 155 | WPARAM const wparam, 156 | LPARAM const lparam) noexcept { 157 | switch (message) { 158 | case WM_DESTROY: 159 | window_handle_ = nullptr; 160 | Destroy(); 161 | if (quit_on_close_) { 162 | PostQuitMessage(0); 163 | } 164 | return 0; 165 | 166 | case WM_DPICHANGED: { 167 | auto newRectSize = reinterpret_cast(lparam); 168 | LONG newWidth = newRectSize->right - newRectSize->left; 169 | LONG newHeight = newRectSize->bottom - newRectSize->top; 170 | 171 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, 172 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE); 173 | 174 | return 0; 175 | } 176 | case WM_SIZE: { 177 | RECT rect = GetClientArea(); 178 | if (child_content_ != nullptr) { 179 | // Size and position the child window. 180 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, 181 | rect.bottom - rect.top, TRUE); 182 | } 183 | return 0; 184 | } 185 | 186 | case WM_ACTIVATE: 187 | if (child_content_ != nullptr) { 188 | SetFocus(child_content_); 189 | } 190 | return 0; 191 | } 192 | 193 | return DefWindowProc(window_handle_, message, wparam, lparam); 194 | } 195 | 196 | void Win32Window::Destroy() { 197 | OnDestroy(); 198 | 199 | if (window_handle_) { 200 | DestroyWindow(window_handle_); 201 | window_handle_ = nullptr; 202 | } 203 | if (g_active_window_count == 0) { 204 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); 205 | } 206 | } 207 | 208 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { 209 | return reinterpret_cast( 210 | GetWindowLongPtr(window, GWLP_USERDATA)); 211 | } 212 | 213 | void Win32Window::SetChildContent(HWND content) { 214 | child_content_ = content; 215 | SetParent(content, window_handle_); 216 | RECT frame = GetClientArea(); 217 | 218 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left, 219 | frame.bottom - frame.top, true); 220 | 221 | SetFocus(child_content_); 222 | } 223 | 224 | RECT Win32Window::GetClientArea() { 225 | RECT frame; 226 | GetClientRect(window_handle_, &frame); 227 | return frame; 228 | } 229 | 230 | HWND Win32Window::GetHandle() { 231 | return window_handle_; 232 | } 233 | 234 | void Win32Window::SetQuitOnClose(bool quit_on_close) { 235 | quit_on_close_ = quit_on_close; 236 | } 237 | 238 | bool Win32Window::OnCreate() { 239 | // No-op; provided for subclasses. 240 | return true; 241 | } 242 | 243 | void Win32Window::OnDestroy() { 244 | // No-op; provided for subclasses. 245 | } 246 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------