Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert after reduce #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoortho/flighttrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ def _udp_listen(self):
self.connected = False
log.debug("Socket timeout. Reset.")
RequestDataRefs(self.sock)
time.sleep(2)
continue
except ConnectionResetError:
log.debug("Connection reset.")
time.sleep(2)
continue
except Exception as err:
log.debug(f"Some other error {err}")
time.sleep(5)
continue

if not self.connected:
# We are transitioning states
Expand Down
13 changes: 7 additions & 6 deletions autoortho/getortho.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def write_cache_tile(self, quick_zoom=0):

outfile = os.path.join(self.cache_dir, f"{self.row}_{self.col}_{self.maptype}_{self.zoom}_{zoom}.dds")

new_im = Image.new('RGBA', (256*width,256*height), (250,250,250))
new_im = Image.new('RGB', (256*width,256*height), (250,250,250))
try:
for chunk in self.chunks[zoom]:
ret = chunk.ready.wait()
Expand All @@ -482,7 +482,7 @@ def write_cache_tile(self, quick_zoom=0):
#end_y = int(start_y + chunk.height)

new_im.paste(
Image.open(BytesIO(chunk.data)).convert("RGBA"),
Image.open(BytesIO(chunk.data)),
(
start_x,
start_y
Expand Down Expand Up @@ -611,7 +611,8 @@ def read_dds_bytes(self, offset, length):
log.debug("READ_DDS_BYTES: Read header")
self.get_bytes(0, length)
#elif offset < 32768:
elif offset < 131072:
elif offset < 65536:
#elif offset < 131072:
#elif offset < 262144:
#elif offset < 1048576:
# How far into mipmap 0 do we go before just getting the whole thing
Expand Down Expand Up @@ -707,7 +708,7 @@ def get_img(self, mipmap, startrow=0, endrow=None):
#outfile = os.path.join(self.cache_dir, f"{self.row}_{self.col}_{self.maptype}_{self.zoom}_{self.zoom}.dds")
#new_im = Image.new('RGBA', (256*width,256*height), (250,250,250))
log.debug(f"GET_IMG: Create new image: Zoom: {self.zoom} | {(256*width, 256*height)}")
new_im = Image.new('RGBA', (256*width,256*height), (0,0,0))
new_im = Image.new('RGB', (256*width,256*height), (0,0,0))
#log.info(f"NUM CHUNKS: {len(chunks)}")
for chunk in chunks:
ret = chunk.ready.wait()
Expand All @@ -718,7 +719,7 @@ def get_img(self, mipmap, startrow=0, endrow=None):
start_y = int((chunk.height) * (chunk.row - row))

new_im.paste(
Image.open(BytesIO(chunk.data)).convert("RGBA"),
Image.open(BytesIO(chunk.data)),
(
start_x,
start_y
Expand Down Expand Up @@ -912,7 +913,7 @@ def clean(self):
continue

while len(self.tiles) >= self.cache_tile_lim and cur_mem > self.cache_mem_lim:
log.info("Hit cache limit. Remove oldest 20")
log.debug("Hit cache limit. Remove oldest 20")
with self.tc_lock:
for i in list(self.tiles.keys())[:20]:
t = self.tiles.get(i)
Expand Down
3 changes: 2 additions & 1 deletion autoortho/perftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
TESTIMG = os.path.join("testfiles", "test_tile2.jpg")
TESTIMG_small = os.path.join("testfiles", "test_tile_small.jpg")
testimg = Image.open(TESTIMG)
testimg_rgba = testimg.convert('RGBA')
#testimg_rgba = testimg.convert('RGBA')
testimg_rgba = testimg
smallimg = Image.open(TESTIMG_small)
#wand_img = wand_image.Image(filename=TESTIMG)
#testimg.convert('RGBA')
Expand Down
34 changes: 34 additions & 0 deletions autoortho/profile_pydds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3

import os
import cProfile
from PIL import Image

import pydds

def testgen(img):
for i in range(20):
width, height = img.size
dds = pydds.DDS(width, height)
dds.gen_mipmaps(img)

def main():

#inimg = sys.argv[1]
#outimg = sys.argv[2]


TESTIMG = os.path.join("testfiles", "test_tile2.jpg")
img = Image.open(TESTIMG)
#img = img.convert("RGBA")
#width, height = img.size
#dds = pydds.DDS(width, height)
profile = cProfile.Profile()
#profile.runcall(dds.gen_mipmaps, img, 0, 1)
profile.runcall(testgen, img)
profile.print_stats()
#dds.gen_mipmaps(img)

if __name__ == "__main__":
#cProfile.run("main()")
main()
9 changes: 6 additions & 3 deletions autoortho/pydds.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class DDS(Structure):
]


def __init__(self, width, height, ispc=True, dxt_format="BC3"):
def __init__(self, width, height, ispc=True, dxt_format="BC1"):
self.magic = b"DDS "
self.size = 124
self.flags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_MIPMAPCOUNT | DDSD_LINEARSIZE
Expand Down Expand Up @@ -453,6 +453,9 @@ def gen_mipmaps(self, img, startmipmap=0, maxmipmaps=0):

timg = img.reduce(reduction_ratio)

if timg.mode == "RGB":
timg = timg.convert("RGBA")

imgdata = timg.tobytes()
width, height = timg.size
log.debug(f"MIPMAP: {mipmap} SIZE: {timg.size}")
Expand Down Expand Up @@ -491,8 +494,8 @@ def gen_mipmaps(self, img, startmipmap=0, maxmipmaps=0):


def to_dds(img, outpath):
if img.mode == "RGB":
img = img.convert("RGBA")
#if img.mode == "RGB":
# img = img.convert("RGBA")
width, height = img.size

dds = DDS(width, height)
Expand Down