From 392cea7a6ab042e2b1ec564f91373221a8305e73 Mon Sep 17 00:00:00 2001 From: Ethan Simmons Date: Sun, 5 May 2024 18:02:54 -0500 Subject: [PATCH] Connect ocrs to new ui --- Cargo.lock | 227 ++++++++++++++++++++++------------------- Cargo.toml | 6 +- image.png | Bin 0 -> 4070 bytes src/process_point.rs | 125 +---------------------- src/wayland.rs | 4 +- src/wayland/app.rs | 74 +++++++++----- src/wayland/builder.rs | 49 +++++---- src/wayland/draw.rs | 96 +++++++++++++++-- src/wayland/ui.rs | 19 ++-- 9 files changed, 306 insertions(+), 294 deletions(-) create mode 100644 image.png diff --git a/Cargo.lock b/Cargo.lock index a6ce70a..5c0e7e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "arrayvec" @@ -22,9 +22,9 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bit_field" @@ -40,21 +40,21 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bumpalo" -version = "3.15.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32a994c2b3ca201d9b263612a374263f05e7adde37c4707f693dcd375076d1f" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.14.3" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef034f05691a48569bd920a96c81b9d91bbad1ab5ac7c4616c1f6ef36cb79f" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" dependencies = [ "bytemuck_derive", ] @@ -82,7 +82,7 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fba7adb4dd5aa98e5553510223000e7148f621165ec5f9acd7113f6ca4995298" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "log", "polling", "rustix", @@ -104,12 +104,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] +checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd" [[package]] name = "cfg-if" @@ -125,9 +122,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "concurrent-queue" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" dependencies = [ "crossbeam-utils", ] @@ -272,9 +269,9 @@ dependencies = [ [[package]] name = "downcast-rs" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "dwrote" @@ -290,9 +287,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "errno" @@ -350,9 +347,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ "crc32fast", "miniz_oxide", @@ -379,7 +376,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d50ba02d3a19ab9012a00314ff4d105128cdc7ba223d69d48181f2d257244d51" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "byteorder", "core-foundation", "core-graphics", @@ -448,9 +445,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" dependencies = [ "cfg-if", "libc", @@ -469,14 +466,20 @@ dependencies = [ [[package]] name = "half" -version = "2.3.1" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc52e53916c08643f1b56ec082790d1e86a32e58dc5268f897f313fbae7b4872" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" dependencies = [ "cfg-if", "crunchy", ] +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + [[package]] name = "image" version = "0.24.9" @@ -527,9 +530,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "libloading" @@ -553,7 +556,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libc", ] @@ -565,9 +568,9 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -575,9 +578,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "lyon_geom" @@ -592,9 +595,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "memmap2" @@ -626,9 +629,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", "libm", @@ -636,10 +639,11 @@ dependencies = [ [[package]] name = "ocrs" -version = "0.4.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfd2f495d2171a0e9eb972c2a8568b2dca7d56777e6ec7e54f974f36b532c340" +checksum = "8d730843ad91056514776a5f3a830379d73d93c88cf30424301bf9ba54e5b182" dependencies = [ + "anyhow", "rayon", "rten", "rten-imageproc", @@ -674,9 +678,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pkg-config" @@ -699,12 +703,13 @@ dependencies = [ [[package]] name = "polling" -version = "3.5.0" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24f040dee2588b4963afb4e420540439d126f73fdacf4a9c486a96d840bac3c9" +checksum = "645493cf344456ef24219d02a768cf1fb92ddf8c92161679ae3d91b91a637be3" dependencies = [ "cfg-if", "concurrent-queue", + "hermit-abi", "pin-project-lite", "rustix", "tracing", @@ -713,9 +718,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] @@ -740,9 +745,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -764,9 +769,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.8.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -795,42 +800,49 @@ dependencies = [ [[package]] name = "rten" -version = "0.3.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67842141586c527d25547bbd81ccfd60601940281a792bce14a3f72dc15a3fec" +checksum = "ed8c84990cfa2d35011d40e0a8f5ad6d1a877dd80f513f04a2a070445cdd82f2" dependencies = [ "flatbuffers", "libm", "rayon", "rten-tensor", "rten-vecmath", + "rustc-hash", "smallvec", "wasm-bindgen", ] [[package]] name = "rten-imageproc" -version = "0.3.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9ceab28b8dcb8925ebc6e51f0038fd16e1cd68229e596eadef826ec7794747f" +checksum = "6d26fd4e8299e8c9b37affb04836a6d1ac67fee62a157a7b06b3cdc9d9b66e40" dependencies = [ "rten-tensor", ] [[package]] name = "rten-tensor" -version = "0.3.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00a55ca04d3219957737f87a9fc3f6eee6770e1f1643c2094c032c90c43f0d2" +checksum = "4d2541dfaf69014c2e730f8386fc9647ddc0c3381b1fe21ce1640f0ed4f74357" dependencies = [ "smallvec", ] [[package]] name = "rten-vecmath" -version = "0.3.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ae896b8b5bea024dab45f9c8ee71051dfbf2a20a83b0e4e48cea5c4e7096e84" +checksum = "fc89d64420a5b7a7d74e3b5cc9424029a2ce86906cdaed50491c44e6f1a090f8" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc_version" @@ -843,11 +855,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.31" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", @@ -877,9 +889,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "simd-adler32" @@ -898,9 +910,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smithay-client-toolkit" @@ -908,7 +920,7 @@ version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "922fd3eeab3bd820d76537ce8f582b1cf951eceb5475c28500c7457d9d17f53a" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "bytemuck", "calloop", "calloop-wayland-source", @@ -947,9 +959,9 @@ checksum = "9ac8fb7895b4afa060ad731a32860db8755da3449a47e796d5ecf758db2671d4" [[package]] name = "syn" -version = "2.0.49" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915aea9e586f80826ee59f8453c1101f9d1c4b3964cd2460185ee8e299ada496" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -958,18 +970,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", @@ -1033,9 +1045,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1043,9 +1055,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", @@ -1058,9 +1070,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1068,9 +1080,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", @@ -1081,9 +1093,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wayland-backend" @@ -1105,7 +1117,7 @@ version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "rustix", "wayland-backend", "wayland-scanner", @@ -1117,7 +1129,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "cursor-icon", "wayland-backend", ] @@ -1139,7 +1151,7 @@ version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "wayland-backend", "wayland-client", "wayland-scanner", @@ -1151,7 +1163,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "wayland-backend", "wayland-client", "wayland-protocols", @@ -1243,13 +1255,14 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", + "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", @@ -1258,45 +1271,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "wio" diff --git a/Cargo.toml b/Cargo.toml index 217efee..0edecb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rten-tensor = "0.3.*" -rten = "0.3.1" -ocrs = "0.4.*" +rten-tensor = "0.8.0" +rten = "0.8.0" +ocrs = "0.6.0" image = "0.24.9" anyhow = "1.0.81" smithay-client-toolkit = "0.18.1" diff --git a/image.png b/image.png new file mode 100644 index 0000000000000000000000000000000000000000..524020450afb06f8e294c038b9ff337700d90f62 GIT binary patch literal 4070 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 literal 0 HcmV?d00001 diff --git a/src/process_point.rs b/src/process_point.rs index 9192bbc..3f83764 100644 --- a/src/process_point.rs +++ b/src/process_point.rs @@ -5,51 +5,19 @@ use std::time::Instant; use rten_tensor::{NdTensor, AsView}; use rten::Model; use ocrs::{OcrEngine, OcrEngineParams}; -use image::{ColorType, ImageFormat}; -const MATRIX_LEN: usize = 800; -const TEXT_MATRIX_RATIO: f64 = 0.5; -const LINE_WIDTH: f64 = 10.0; - -const MATRIX_X_SIZE: f64 = MATRIX_LEN as f64; -const TEXT_X_SIZE: f64 = (MATRIX_X_SIZE as f64) * TEXT_MATRIX_RATIO; -const TEXT_X_OFFSET: f64 = (MATRIX_X_SIZE - TEXT_X_SIZE) / 2.0; -const LINE_WIDTH_X_OFFSET: f64 = LINE_WIDTH / 2.0; - -#[derive(Debug)] -pub struct Point { - pub x: f64, - pub y: f64, - pub new_line: bool, -} - -pub fn print_words(points: &Vec) -> Result<(), Box> { +pub fn print_words(image: NdTensor) -> Result<(), Box> { let begin = Instant::now(); - let processed_data = process(points); println!("{:#?}", begin.elapsed()); let begin = Instant::now(); - ocr(processed_data)?; + ocr(image).unwrap(); println!("{:#?}", begin.elapsed()); Ok(()) } -fn process(points: &Vec) -> NdTensor { - - let matrix = to_matrix(points); - let y_len = matrix[0].len(); - let x_len = matrix[0][0].len(); - let image_data: Box<[u8]> = matrix.iter().flatten().flatten().map(|f| if *f > 0.5 { u8::from(0) } else { u8::from(255) }).collect(); - let data: Vec = matrix.into_iter().flatten().flatten().map(|f| f as f32).collect(); - - image::save_buffer_with_format("./image.png", &image_data, x_len as u32, y_len as u32, ColorType::L8, ImageFormat::Png).unwrap(); - - - NdTensor::from_data([1, y_len, x_len], data) -} - fn ocr(data: NdTensor) -> Result<(), Box> { let detection_model_data = fs::read("text-detection.rten")?; @@ -58,7 +26,6 @@ fn ocr(data: NdTensor) -> Result<(), Box> { let detection_model = Model::load(&detection_model_data)?; let rec_model = Model::load(&rec_model_data)?; - let ocr_engine = OcrEngine::new(OcrEngineParams { detection_model: Some(detection_model), recognition_model: Some(rec_model), @@ -87,91 +54,3 @@ fn ocr(data: NdTensor) -> Result<(), Box> { } - -fn line(x: f64, point1: (f64, f64), point2: (f64, f64)) -> f64 { - let slope = (point2.1 - point1.1) / (point2.0 - point1.0); - - let point = slope * (x - point1.0) + point1.1; - - point -} - -fn to_matrix(points: &Vec) -> Vec>> { - - let min_x = points.iter().min_by_key(|p| p.x as i32).unwrap().x; - let min_y = points.iter().min_by_key(|p| p.y as i32).unwrap().y; - let max_x = points.iter().max_by_key(|p| p.x as i32).unwrap().x; - let max_y = points.iter().max_by_key(|p| p.y as i32).unwrap().y; - - let x_len = max_x - min_x; - let y_len = max_y - min_y; - - let y_ratio = y_len / x_len; - - let matrix_y_size = MATRIX_X_SIZE * y_ratio; - let text_y_size = TEXT_X_SIZE * y_ratio; - let text_y_offset = TEXT_X_OFFSET * y_ratio; - let line_width_y_offset = LINE_WIDTH_X_OFFSET * y_ratio; - - let x_scale = MATRIX_X_SIZE / x_len; - let y_scale = matrix_y_size / y_len; - - - let mut matrix: Vec> = vec![ - vec![0.0; MATRIX_LEN]; (matrix_y_size as usize) + 1 - ]; - - let scaled_points: Vec<((f64, f64), bool)> = points - .iter() - .map(|point| { - let x_scaled = ((point.x - min_x) * x_scale) + TEXT_X_OFFSET; - let y_scaled = ((point.y - min_y) * y_scale) + text_y_offset; - - ((x_scaled, y_scaled), point.new_line) - }).collect(); - - let mut last_x = 0.0; - let mut last_y = 0.0; - - for ((current_x, current_y), newline) in scaled_points { - - if !newline { - let curr_x_start = current_x - LINE_WIDTH_X_OFFSET; - let curr_x_end = current_x + LINE_WIDTH_X_OFFSET; - - let last_x_start = last_x - LINE_WIDTH_X_OFFSET; - let last_x_end = last_x + LINE_WIDTH_X_OFFSET; - - let top_y = current_y.max(last_y) + line_width_y_offset; - let bottom_y = current_y.min(last_y) - line_width_y_offset; - - let start_x = (last_x_start.min(curr_x_start)) as usize; - let end_x = (last_x_end.max(curr_x_end)) as usize + 1; - - - for x in start_x..(end_x + 1) { - - let left_line_y = line(x as f64, (last_x_start, last_y), (curr_x_start, current_y)); - let right_line_y = line(x as f64, (last_x_end, last_y), (curr_x_end, current_x)); - - let top_line_y = left_line_y - .max(right_line_y) - .min(top_y) as usize; - let bottom_line_y = left_line_y - .min(right_line_y) - .max(bottom_y) as usize; - - for y in bottom_line_y..(top_line_y + 1) { - matrix[y][x] = 1.0; - } - - } - } - - last_x = current_x; - last_y = current_y; - } - - vec![matrix] - -} diff --git a/src/wayland.rs b/src/wayland.rs index 697722a..6a0b6dd 100644 --- a/src/wayland.rs +++ b/src/wayland.rs @@ -1,6 +1,6 @@ -mod ui; pub mod app; -mod draw; +pub mod draw; +mod ui; mod builder; #[derive(Clone, Copy, Debug)] diff --git a/src/wayland/app.rs b/src/wayland/app.rs index 2652739..111d8b1 100644 --- a/src/wayland/app.rs +++ b/src/wayland/app.rs @@ -32,17 +32,21 @@ use wayland_client::{ use std::time::Duration; +use rten_tensor::NdTensor; + use anyhow::Result; use crate::wayland::{ - draw::DrawPath, + draw::{DrawPath, Draw}, builder::{TextAreaBuilder, DrawAreaBuilder, ButtonBuilder}, - ui::{self, Widget}, + ui::{self, Widget, ButtonType}, Position, }; -const WINDOW_HEIGHT: u32 = 256; -const WINDOW_WIDTH: u32 = 512; +use crate::process_point::print_words; + +const WINDOW_HEIGHT: usize = 256; +const WINDOW_WIDTH: usize = 512; pub(crate) struct SimpleWindow { registry_state: RegistryState, @@ -55,8 +59,8 @@ pub(crate) struct SimpleWindow { pool: SlotPool, window: Window, ui: Option, - width: u32, - height: u32, + width: usize, + height: usize, cursor_down: bool, exit: bool, first_configure: bool, @@ -87,8 +91,8 @@ impl SimpleWindow { window.set_title("A window"); window.set_app_id("simmer.simplewindow"); - window.set_min_size(Some((WINDOW_WIDTH, WINDOW_HEIGHT))); - window.set_max_size(Some((WINDOW_WIDTH, WINDOW_HEIGHT))); + window.set_min_size(Some((WINDOW_WIDTH as u32, WINDOW_HEIGHT as u32))); + window.set_max_size(Some((WINDOW_WIDTH as u32, WINDOW_HEIGHT as u32))); window.commit(); @@ -260,8 +264,8 @@ impl WindowHandler for SimpleWindow { let mut draw_area = DrawAreaBuilder::new(); draw_area.position(0.0, 50.0); - draw_area.width(self.width as f32 - 100.0); - draw_area.height(self.height as f32 - 50.0); + draw_area.width(self.width - 100); + draw_area.height(self.height - 50); draw_area.path(&mut self.draw_path); let draw_area = draw_area.finish(); @@ -273,22 +277,31 @@ impl WindowHandler for SimpleWindow { draw_area, ); - let mut button = ButtonBuilder::new(); + let mut enter_button = ButtonBuilder::new(); - button.position(self.width as f32 - 100.0, 50.0); - button.width(100.0); - button.height(50.0); - let button = button.finish(); + enter_button.button_type(ButtonType::Enter); + enter_button.position(self.width - 100, 60); + enter_button.width(100); + enter_button.height(50); + let enter_button = enter_button.finish(); + let mut clear_button = ButtonBuilder::new(); + + clear_button.button_type(ButtonType::Clear); + clear_button.position(self.width - 100, 120); + clear_button.width(100); + clear_button.height(50); + let clear_button = clear_button.finish(); let mut text_area = TextAreaBuilder::new(); text_area.position(0.0, 0.0); - text_area.width(self.width as f32); - text_area.height(50.0); + text_area.width(self.width); + text_area.height(50); let text_area = text_area.finish(); - window.add_widget(button); + window.add_widget(enter_button); + window.add_widget(clear_button); window.add_widget(text_area); self.ui = Some(window); @@ -354,12 +367,25 @@ impl PointerHandler for SimpleWindow { window.draw_area.path.add_point(pos, true); } - for widget in &window.widgets { - if let Widget::Button(button) = widget { - if button.contains_point(pos) { - window.draw_area.path = DrawPath::default(); - } - } + for button in window.widgets + .iter() + .filter_map(|widget| { + if let Widget::Button(button) = widget { + Some(button) + } else { + None + } + }) + { + match button.button_type { + ButtonType::Clear if button.contains_point(pos) => { + window.draw_area.path = DrawPath::default(); + }, + ButtonType::Enter if button.contains_point(pos) => { + print_words((&window.draw_area).into()).unwrap() + }, + _ => (), + } } } } diff --git a/src/wayland/builder.rs b/src/wayland/builder.rs index 6f622de..6ab1635 100644 --- a/src/wayland/builder.rs +++ b/src/wayland/builder.rs @@ -1,5 +1,5 @@ use crate::wayland::{ - ui::{TextArea, TextAreaColors, Button, ButtonColors, Widget}, + ui::{TextArea, TextAreaColors, Button, ButtonColors, Widget, ButtonType}, draw::{DrawAreaColors, DrawArea, DrawPath}, Position }; @@ -7,8 +7,8 @@ use crate::wayland::{ use raqote::{DrawOptions, PathBuilder}; pub(super) struct TextAreaBuilder { - pub(super) width: Option, - pub(super) height: Option, + pub(super) width: Option, + pub(super) height: Option, pub(super) position: Option, pub(super) colors: Option, pub(super) options: Option, @@ -25,11 +25,11 @@ impl<'a> TextAreaBuilder { } } - pub(super) fn width(&mut self, width: f32) { + pub(super) fn width(&mut self, width: usize) { self.width = Some(width) } - pub(super) fn height(&mut self, height: f32) { + pub(super) fn height(&mut self, height: usize) { self.height = Some(height) } @@ -56,11 +56,12 @@ impl<'a> TextAreaBuilder { } pub(super) struct ButtonBuilder { - pub(super) width: Option, - pub(super) height: Option, + pub(super) width: Option, + pub(super) height: Option, pub(super) position: Option, pub(super) colors: Option, pub(super) options: Option, + pub(super) button_type: Option, } impl ButtonBuilder { @@ -71,25 +72,30 @@ impl ButtonBuilder { position: None, colors: None, options: None, + button_type: None, } } - pub(super) fn width(&mut self, width: f32) { + pub(super) fn width(&mut self, width: usize) { self.width = Some(width) } - pub(super) fn height(&mut self, height: f32) { + pub(super) fn height(&mut self, height: usize) { self.height = Some(height) } - pub(super) fn position(&mut self, x: f32, y: f32) { - self.position = Some(Position::new(x, y)) + pub(super) fn position(&mut self, x: usize, y: usize) { + self.position = Some(Position::new(x as f32, y as f32)) } pub(super) fn colors(&mut self, colors: ButtonColors) { self.colors = Some(colors) } + pub(super) fn button_type(&mut self, button_type: ButtonType) { + self.button_type = Some(button_type) + } + pub(super) fn finish(self) -> Widget { let width = self.width.expect("Button must have a width"); let height = self.height.expect("Button must have a height"); @@ -97,14 +103,15 @@ impl ButtonBuilder { let mut button_path = PathBuilder::new(); button_path.move_to(position.x, position.y); - button_path.line_to(position.x + width, position.y); - button_path.line_to(position.x + width, position.y + height); - button_path.line_to(position.x, position.y + height); + button_path.line_to(position.x + width as f32, position.y); + button_path.line_to(position.x + width as f32, position.y + height as f32); + button_path.line_to(position.x, position.y + height as f32); button_path.line_to(position.x, position.y); let button_path = button_path.finish(); Widget::Button( Button { + button_type: self.button_type.expect("Button must have a type"), width: self.width.expect("Button must have width"), height: self.height.expect("Button must have height"), position: self.position.expect("Button must have a position"), @@ -117,8 +124,8 @@ impl ButtonBuilder { } pub(super) struct DrawAreaBuilder { - pub(super) width: Option, - pub(super) height: Option, + pub(super) width: Option, + pub(super) height: Option, pub(super) position: Option, pub(super) path: Option, pub(super) colors: Option, @@ -137,11 +144,11 @@ impl DrawAreaBuilder { } } - pub(super) fn width(&mut self, width: f32) { + pub(super) fn width(&mut self, width: usize) { self.width = Some(width) } - pub(super) fn height(&mut self, height: f32) { + pub(super) fn height(&mut self, height: usize) { self.height = Some(height) } @@ -168,9 +175,9 @@ impl DrawAreaBuilder { let mut draw_rect_path = PathBuilder::new(); draw_rect_path.move_to(position.x, position.y); - draw_rect_path.line_to(position.x + width, position.y); - draw_rect_path.line_to(position.x + width, position.y + height); - draw_rect_path.line_to(position.x, position.y + height); + draw_rect_path.line_to(position.x + width as f32, position.y); + draw_rect_path.line_to(position.x + width as f32, position.y + height as f32); + draw_rect_path.line_to(position.x, position.y + height as f32); draw_rect_path.line_to(position.x, position.y); let draw_rect_path = draw_rect_path.finish(); diff --git a/src/wayland/draw.rs b/src/wayland/draw.rs index 05092e2..f44bfdc 100644 --- a/src/wayland/draw.rs +++ b/src/wayland/draw.rs @@ -1,6 +1,8 @@ -use raqote::{DrawTarget, Color, StrokeStyle, PathBuilder, Source, DrawOptions}; +use raqote::{DrawTarget, Color, StrokeStyle, PathBuilder, Source, DrawOptions, SolidSource}; +use rten_tensor::NdTensor; use crate::wayland::Position; +use crate::process_point::print_words; pub(super) trait Draw { fn render(&self, area: &mut DrawTarget<&mut [u32]>); @@ -9,20 +11,20 @@ pub(super) trait Draw { type Path = Vec; #[derive(Default)] -pub(super) struct DrawPath { - pub(super) paths: Vec, - pub(super) newline: bool, +pub(crate) struct DrawPath { + pub(crate) paths: Vec, + pub(crate) newline: bool, } impl DrawPath { - pub(super) fn new() -> Self { + pub(crate) fn new() -> Self { Self { paths: Vec::new(), newline: false, } } - pub(super) fn add_point(&mut self, point: Position, newline: bool) { + pub(crate) fn add_point(&mut self, point: Position, newline: bool) { if newline { self.paths.push(vec![point]) } else if self.paths.len() > 0 { @@ -33,15 +35,15 @@ impl DrawPath { } } - pub(super) fn into_iter(self) -> std::vec::IntoIter { + pub(crate) fn into_iter(self) -> std::vec::IntoIter { self.paths.into_iter() } - pub(super) fn iter(&self) -> std::slice::Iter { + pub(crate) fn iter(&self) -> std::slice::Iter { self.paths.iter() } - pub(super) fn iter_mut(&mut self) -> std::slice::IterMut { + pub(crate) fn iter_mut(&mut self) -> std::slice::IterMut { self.paths.iter_mut() } } @@ -63,8 +65,8 @@ impl Default for DrawAreaColors { } pub(super) struct DrawArea { - pub(super) width: f32, - pub(super) height: f32, + pub(super) width: usize, + pub(super) height: usize, pub(super) position: Position, pub(super) path: DrawPath, pub(super) shape: raqote::Path, @@ -89,6 +91,78 @@ impl DrawArea { self.shape.contains_point(0.1, point.x, point.y) } + +} + +impl From<&DrawArea> for NdTensor { + fn from(draw_area: &DrawArea) -> Self { + let mut target = DrawTarget::new(draw_area.width as i32, draw_area.height as i32); + + target.fill_rect( + 0.0, + 0.0, + draw_area.width as f32, + draw_area.height as f32, + &Source::Solid(SolidSource::from_unpremultiplied_argb(0xff, 0xff, 0xff, 0xff)), + &DrawOptions::new(), + ); + + let mut draw_path = PathBuilder::new(); + + for path in draw_area.path.iter() { + if path.len() > 1 { + let mut path = path + .into_iter() + .map(|position| Position::new(position.x - draw_area.position.x, position.y - draw_area.position.y)); + + let first_point = path + .by_ref() + .next(); + + if let Some(point) = first_point { + draw_path.move_to(point.x, point.y); + } else { + break; + } + + for point in path { + draw_path.line_to(point.x, point.y); + } + + } + + } + + let draw_path = draw_path.finish(); + + target.stroke( + &draw_path, + &Source::Solid(SolidSource::from_unpremultiplied_argb(0xff, 0x00, 0x00, 0x00)), + &StrokeStyle {width: 3.0, ..StrokeStyle::default()}, + &DrawOptions::new(), + ); + + let data: Vec = target + .get_data_u8() + .chunks(4) + .into_iter() + .map(|chunk| chunk[0..3].into_iter().map(|byte| *byte as f32).sum::() / 765.0) + .collect(); + + image::save_buffer_with_format( + "./image.png", + &data + .iter() + .map(|num| (num * 255.0).floor() as u8) + .collect::>(), + draw_area.width as u32, + draw_area.height as u32, + image::ColorType::L8, + image::ImageFormat::Png + ).unwrap(); + + NdTensor::from_data([1, draw_area.width as usize, draw_area.height as usize], data) + } } impl Draw for DrawArea { diff --git a/src/wayland/ui.rs b/src/wayland/ui.rs index 900656d..374058e 100644 --- a/src/wayland/ui.rs +++ b/src/wayland/ui.rs @@ -103,9 +103,16 @@ impl Default for ButtonColors { } } +#[derive(PartialEq, Eq)] +pub(super) enum ButtonType { + Clear, + Enter, +} + pub(super) struct Button { - pub(super) width: f32, - pub(super) height: f32, + pub(super) button_type: ButtonType, + pub(super) width: usize, + pub(super) height: usize, pub(super) position: Position, pub(super) shape: raqote::Path, pub(super) colors: ButtonColors, @@ -149,8 +156,8 @@ impl Default for TextAreaColors { } pub(super) struct TextArea { - pub(super) width: f32, - pub(super) height: f32, + pub(super) width: usize, + pub(super) height: usize, pub(super) position: Position, pub(super) colors: TextAreaColors, pub(super) options: DrawOptions, @@ -172,8 +179,8 @@ impl Draw for TextArea { area.fill_rect( self.position.x, self.position.y, - self.width, - self.height, + self.width as f32, + self.height as f32, &self.background_source(), &self.options, );