Skip to content

Commit 4702524

Browse files
committed
Initial commit
0 parents  commit 4702524

16 files changed

Lines changed: 257 additions & 0 deletions

.ci/aptPackagesToInstall.txt

Whitespace-only changes.

.ci/pythonPackagesToInstallFromGit.txt

Whitespace-only changes.

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = tab
6+
indent_size = 4
7+
insert_final_newline = true
8+
end_of_line = lf
9+
10+
[*.{yml,yaml}]
11+
indent_style = space
12+
indent_size = 2

.github/.templateMarker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KOLANICH/python_project_boilerplate.py

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
allow:
8+
- dependency-type: "all"

.github/workflows/CI.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- name: typical python workflow
13+
uses: KOLANICH-GHActions/typical-python-workflow@master
14+
with:
15+
github_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__pycache__
2+
*.pyc
3+
*.pyo
4+
/*.egg-info
5+
*.srctrlbm
6+
*.srctrldb
7+
build
8+
dist
9+
.eggs
10+
monkeytype.sqlite3
11+
/.ipynb_checkpoints

.gitlab-ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
image: registry.gitlab.com/kolanich-subgroups/docker-images/fixed_python:latest
2+
3+
variables:
4+
DOCKER_DRIVER: overlay2
5+
SAST_ANALYZER_IMAGE_TAG: latest
6+
SAST_DISABLE_DIND: "true"
7+
SAST_CONFIDENCE_LEVEL: 5
8+
CODECLIMATE_VERSION: latest
9+
10+
include:
11+
- template: SAST.gitlab-ci.yml
12+
- template: Code-Quality.gitlab-ci.yml
13+
- template: License-Management.gitlab-ci.yml
14+
15+
build:
16+
tags:
17+
- shared
18+
- linux
19+
stage: build
20+
variables:
21+
GIT_DEPTH: "1"
22+
PYTHONUSERBASE: ${CI_PROJECT_DIR}/python_user_packages
23+
24+
before_script:
25+
- export PATH="$PATH:$PYTHONUSERBASE/bin" # don't move into `variables`
26+
- apt-get update
27+
# todo:
28+
#- apt-get -y install
29+
#- pip3 install --upgrade
30+
#- python3 ./fix_python_modules_paths.py
31+
32+
script:
33+
- python3 -m build -nw bdist_wheel
34+
- mv ./dist/*.whl ./dist/JavaImageTools-0.CI-py3-none-any.whl
35+
- pip3 install --upgrade ./dist/*.whl
36+
- coverage run --source=JavaImageTools -m --branch pytest --junitxml=./rspec.xml ./tests/test.py
37+
- coverage report -m
38+
- coverage xml
39+
40+
coverage: "/^TOTAL(?:\\s+\\d+){4}\\s+(\\d+%).+/"
41+
42+
cache:
43+
paths:
44+
- $PYTHONUSERBASE
45+
46+
artifacts:
47+
paths:
48+
- dist
49+
reports:
50+
junit: ./rspec.xml
51+
cobertura: ./coverage.xml

Code_Of_Conduct.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No codes of conduct!

JavaImageTools/__init__.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import typing
2+
from enum import IntEnum
3+
4+
import numpy as np
5+
from JAbs import ClassesImportSpecT, ClassPathT, SelectedJVMInitializer
6+
from jpype import JInt # ToDo: JPype specific, create an abstraction in JAbs
7+
8+
ji = None # initialized externally
9+
10+
11+
def restack(npArr: np.ndarray, perm: typing.Iterable[int]) -> np.ndarray:
12+
compsSplitted = np.moveaxis(npArr, -1, 0)
13+
permed = []
14+
for el in perm:
15+
permed.append(compsSplitted[el])
16+
return np.dstack(permed)
17+
18+
19+
def convertJavaEnum(namespace, prefix: str, name: str, enumCls: typing.Type[IntEnum] = IntEnum) -> typing.Type[IntEnum]:
20+
return enumCls(name, {el[len(prefix) :]: getattr(namespace, el) for el in dir(namespace) if el.startswith(prefix)})
21+
22+
23+
class JavaImageToolsInitializer:
24+
__slots__ = ("ji", "scalaVersion")
25+
26+
def __init__(self, classPathz: ClassPathT, classes2import: ClassesImportSpecT) -> None:
27+
self.__class__.ji.__set__(self, SelectedJVMInitializer(classPathz, classes2import))
28+
self.loadClasses(("java.awt.image.BufferedImage", "javax.imageio.ImageIO", "java.io.File", "java.awt.image.DataBufferByte"))
29+
self.ji.ImageMode = convertJavaEnum(self.ji.BufferedImage, "TYPE_", "ImageMode")
30+
self.modeRemapping = {
31+
"RGB": (self.ImageMode.INT_RGB, None),
32+
"RGBA": (self.ImageMode["4BYTE_ABGR"], (3, 2, 1, 0)),
33+
"1": (self.ImageMode.BYTE_BINARY, None),
34+
"L": (self.ImageMode.BYTE_GRAY, None),
35+
"I;16": (self.ImageMode.USHORT_GRAY, None),
36+
"BGR;32": (self.ImageMode.INT_BGR, None)
37+
}
38+
39+
def __getattr__(self, k: str) -> typing.Any:
40+
return getattr(self.ji, k)
41+
42+
def __setattr__(self, k: str, v: typing.Any):
43+
setattr(self.ji, k, v)
44+
45+
def pilImg2JavaImg(self, img):
46+
i = np.array(img)
47+
jMode, remap = self.modeRemapping[img.mode]
48+
# t = self.ImageMode()
49+
if remap:
50+
i = restack(i, remap)
51+
iJ = self.ji.BufferedImage(i.shape[1], i.shape[0], jMode)
52+
raster = iJ.getData()
53+
raster.setPixels(0, 0, i.shape[1], i.shape[0], JInt[:](bytes(i.data)))
54+
iJ.setData(raster)
55+
return iJ

0 commit comments

Comments
 (0)