Skip to content

Commit

Permalink
Version 0.9.11: Fixed a bug of Convert.shape_to_pixels causing pixels…
Browse files Browse the repository at this point in the history
…' alpha to be mis-calculated, fixed examples, updated workflows to start testing Python 3.10
  • Loading branch information
CoffeeStraw committed Dec 30, 2021
1 parent 6486041 commit 690a69b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9]
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand All @@ -72,11 +72,11 @@ jobs:
if: matrix.os != 'windows-latest'
run: |
GO111MODULE=on GOBIN=$HOME/.local/bin go get github.com/Crosse/[email protected]
$HOME/.local/bin/font-install https://mirrors.tuna.tsinghua.edu.cn/osdn/mix-mplus-ipa/58720/migu-1p-20130430.zip
$HOME/.local/bin/font-install "https://osdn.net/frs/redir.php?m=gigenet&f=mix-mplus-ipa%2F58720%2Fmigu-1p-20130430.zip"
shell: bash
- name: Install fonts (Windows)
if: matrix.os == 'windows-latest'
run: powershell ./.github/scripts/install-fonts.ps1 https://mirrors.tuna.tsinghua.edu.cn/osdn/mix-mplus-ipa/58720/migu-1p-20130430.zip
run: ./.github/scripts/install-fonts.ps1 'https://osdn.net/frs/redir.php?m=gigenet&f=mix-mplus-ipa%2F58720%2Fmigu-1p-20130430.zip'
shell: pwsh

- name: Cache Python
Expand Down
6 changes: 3 additions & 3 deletions examples/3 - Advanced/2 - Testing Pixels (WIP).py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def romaji(line, l):
x2, y2 = x + random.uniform(-off, off), y + random.uniform(-off, off)
alpha = (
"\\alpha" + Convert.alpha_dec_to_ass(pixel.alpha)
if pixel.alpha != 255
if pixel.alpha != 0
else ""
)

Expand All @@ -72,8 +72,8 @@ def romaji(line, l):
)
x2, y2 = x + 10 * (-1) ** pi, y + 10 * (-1) ** pi
alpha = (
"\\alpha" + Convert.alpha_int_to_ass(pixel.alpha)
if pixel.alpha != 255
"\\alpha" + Convert.alpha_dec_to_ass(pixel.alpha)
if pixel.alpha != 0
else ""
)

Expand Down
2 changes: 1 addition & 1 deletion pyonfx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .shape import Shape
from .utils import Utils, FrameUtility, ColorUtility

__version__ = "0.9.10"
__version__ = "0.9.11"
33 changes: 15 additions & 18 deletions pyonfx/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def text_to_pixels(
It is highly suggested to create a dedicated style for pixels,
because you will write less tags for line in your pixels, which means less size for your .ass file.
| The style suggested is:
| The style suggested (named "p" in the example) is:
| - **an=7 (very important!);**
| - bord=0;
| - shad=0;
Expand All @@ -567,15 +567,14 @@ def text_to_pixels(
Examples:
.. code-block:: python3
line = lines[2].copy()
line.style = "p"
l.style = "p"
p_sh = Shape.rectangle()
for pixel in Convert.text_to_pixels(line):
x, y = math.floor(line.left) + pixel['x'], math.floor(line.top) + pixel['y']
alpha = "\\alpha" + Convert.color_alpha_to_ass(pixel['alpha']) if pixel['alpha'] != 255 else ""
for pixel in Convert.text_to_pixels(l):
x, y = math.floor(l.left) + pixel.x, math.floor(l.top) + pixel.y
alpha = "\\alpha" + Convert.alpha_dec_to_ass(pixel.alpha) if pixel.alpha != 0 else ""
line.text = "{\\p1\\pos(%d,%d)%s}%s" % (x, y, alpha, p_sh)
io.write_line(line)
l.text = "{\\p1\\pos(%d,%d)%s}%s" % (x, y, alpha, p_sh)
io.write_line(l)
"""
shape = Convert.text_to_shape(obj).move(obj.left % 1, obj.top % 1)
return Convert.shape_to_pixels(shape, supersampling)
Expand All @@ -588,7 +587,7 @@ def shape_to_pixels(shape: Shape, supersampling: int = 8) -> List[Pixel]:
It is highly suggested to create a dedicated style for pixels,
because you will write less tags for line in your pixels, which means less size for your .ass file.
| The style suggested is:
| The style suggested (named "p" in the example) is:
| - **an=7 (very important!);**
| - bord=0;
| - shad=0;
Expand All @@ -606,16 +605,14 @@ def shape_to_pixels(shape: Shape, supersampling: int = 8) -> List[Pixel]:
Examples:
.. code-block:: python3
line = lines[2].copy()
line.style = "p"
l.style = "p"
p_sh = Shape.rectangle()
for pixel in Convert.shape_to_pixels(Shape.heart(100)):
# Random circle to pixel effect just to show
x, y = math.floor(line.left) + pixel.x, math.floor(line.top) + pixel.y
alpha = "\\alpha" + Convert.color_alpha_to_ass(pixel.alpha) if pixel.alpha != 255 else ""
x, y = math.floor(l.left) + pixel.x, math.floor(l.top) + pixel.y
alpha = "\\alpha" + Convert.alpha_dec_to_ass(pixel.alpha) if pixel.alpha != 0 else ""
line.text = "{\\p1\\pos(%d,%d)%s\\fad(0,%d)}%s" % (x, y, alpha, l.dur/4, p_sh)
io.write_line(line)
l.text = "{\\p1\\pos(%d,%d)%s}%s" % (x, y, alpha, p_sh)
io.write_line(l)
"""
# Scale values for supersampled rendering
upscale = supersampling
Expand Down Expand Up @@ -743,14 +740,14 @@ def line_x_hline(x, y, vx, vy, y2):
for yy in range(0, upscale):
for xx in range(0, upscale):
if image[(y + yy) * width + (x + xx)]:
opacity = opacity + 255
opacity += 255

if opacity > 0:
pixels.append(
Pixel(
x=(x - shift_x) * downscale,
y=(y - shift_y) * downscale,
alpha=round(opacity * downscale ** 2),
alpha=255 - round(opacity * downscale ** 2),
)
)

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def get_requirements():
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
],
license="GNU LGPL 3.0 or later",
Expand Down

0 comments on commit 690a69b

Please sign in to comment.