mirror of
https://github.com/irmen/prog8.git
synced 2026-04-20 11:17:01 +00:00
fix cx16.getlfs() and add diskio.reuse_last_drive()
update cx16images.py to use improved quantization
This commit is contained in:
@@ -29,6 +29,12 @@ diskio {
|
||||
|
||||
ubyte @shared drivenumber = 8 ; user programs can set this to the drive number they want to load/save to!
|
||||
|
||||
|
||||
sub reuse_last_drive() {
|
||||
; set the drivenumber to the last used disk drive
|
||||
void, drivenumber, void = cx16.getlfs()
|
||||
}
|
||||
|
||||
sub reset_read_channel() {
|
||||
void cbm.CHKIN(READ_IO_CHANNEL)
|
||||
}
|
||||
|
||||
@@ -756,10 +756,10 @@ asmsub mouse_get_sprite_offset() clobbers(A,X,Y) -> word @R0, word @R1 {
|
||||
}}
|
||||
}
|
||||
|
||||
asmsub getlfs() -> ubyte @X, ubyte @A, ubyte @Y {
|
||||
asmsub getlfs() -> ubyte @A, ubyte @X, ubyte @Y {
|
||||
; -- return the result of the last call to SETLFS: A=logical, X=device, Y=secondary.
|
||||
%asm {{
|
||||
lda #EXTAPI_mouse_set_position
|
||||
lda #EXTAPI_getlfs
|
||||
jmp cx16.extapi
|
||||
}}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.13 virtualenv at ~/.virtualenvs/py3" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.14 virtualenv at ~/.virtualenvs/py3" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
+11
-3
@@ -8,7 +8,7 @@ Written by Irmen de Jong (irmen@razorvine.net) - Code is in the Public Domain.
|
||||
Requirements: Pillow (pip install pillow)
|
||||
"""
|
||||
|
||||
from PIL import Image
|
||||
from PIL import Image, features
|
||||
from typing import TypeAlias, Tuple, Optional
|
||||
|
||||
RGBList: TypeAlias = list[tuple[int, int, int]]
|
||||
@@ -189,9 +189,17 @@ class BitmapImage:
|
||||
else:
|
||||
raise ValueError("only 8,4,2,1 bpp supported")
|
||||
image = self.img.convert("RGB")
|
||||
palette_image = image.quantize(colors=num_colors, dither=Image.Dither.NONE, method=Image.Quantize.MAXCOVERAGE)
|
||||
quantize_method = Image.Quantize.MEDIANCUT
|
||||
dither_method = Image.Dither.ORDERED
|
||||
if features.check_feature("libimagequant"):
|
||||
quantize_method = Image.Quantize.LIBIMAGEQUANT
|
||||
dither_method = Image.Dither.FLOYDSTEINBERG
|
||||
print("python PIL: yay, libimagequant is available, using it for high quality and fast conversion.")
|
||||
else:
|
||||
print("python PIL: libimagequant not available, using mediancut+kmeans instead. This is a slightly less accurate conversion, and slow.")
|
||||
palette_image = image.quantize(colors=num_colors, dither=dither_method, method=quantize_method, kmeans=10)
|
||||
if len(palette_image.getpalette()) // 3 > num_colors:
|
||||
palette_image = image.quantize(colors=num_colors - 1, dither=Image.Dither.NONE, method=Image.Quantize.MAXCOVERAGE)
|
||||
palette_image = image.quantize(colors=num_colors - 1, dither=dither_method, method=quantize_method, kmeans=10)
|
||||
palette_rgb = flat_palette_to_rgb(palette_image.getpalette())
|
||||
palette_rgb = list(reversed(sorted(set(palette_8to4(palette_rgb)))))
|
||||
if preserve_first_16_colors:
|
||||
|
||||
Reference in New Issue
Block a user