Skip to content

Commit

Permalink
Merge pull request #162 from mriale/develop
Browse files Browse the repository at this point in the history
Merge in bug fixes from develop
  • Loading branch information
mriale authored Sep 11, 2024
2 parents 9312e3f + c0f194b commit 54e8fcf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
5 changes: 3 additions & 2 deletions libs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,9 @@ def recompose(self):
scaleX = config.fontx // 8
scaleY = config.fonty // 12

config.layers.set("canvas", config.pixel_canvas)
config.layers.set("fg", config.stencil, priority=10, visible=config.stencil.enable)

screen_rgb = None
if self.zoom.on:
screen_rgb = pygame.Surface((self.screen_width, self.screen_height),0)
Expand Down Expand Up @@ -1297,8 +1300,6 @@ def recompose(self):

screen_rgb = pygame.Surface((self.screen_width, self.screen_height),0)
screen_rgb.fill((128,128,128)); # out of page bounds
config.layers.set("canvas", config.pixel_canvas)
config.layers.set("fg", config.stencil, priority=10, visible=config.stencil.enable)
config.layers.blit(screen_rgb, (self.screen_offset_x, self.screen_offset_y))

#blit requestor layer
Expand Down
11 changes: 11 additions & 0 deletions libs/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ def get_at(self, coords):
self.blit(image, (0,0))
return tuple(image.get_at(coords))[0:3]

def get_palette(self):
for key in self.layers:
layer = self.layers[key]
if layer.visible and "get_palette" in dir(layer.image) and \
"get_bytesize" in dir(layer.image) and layer.image.get_bytesize() == 1:
pal = layer.image.get_palette()
if not pal is None:
return(pal)
return None

def set_palette(self, pal):
for key in self.layers:
layer = self.layers[key]
Expand All @@ -174,6 +184,7 @@ def draw_indicator(self, screen):

def get_flattened(self, exclude=[]):
pic = config.pixel_canvas.copy()
pic.set_palette(self.get_palette())
self.blit(pic, exclude=exclude)
return pic

Expand Down
35 changes: 27 additions & 8 deletions libs/picio.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def load_anim(filename, config, ifftype, status_func=None):

#initialize anim header
anim_mode, anim_mask, anim_w, anim_h, anim_x, anim_y, anim_abstime, anim_reltime, anim_interleave, anim_pad0, anim_bits, anim_pad8a, anim_pad8b = (0,0,0,0,0,0,0,0,0,0,0,0,0)
dpan_version, dpan_numframes, dpan_global_fps, dpan_global_delay = (0,0,20, 3)
dpan_version, dpan_numframes, dpan_global_fps, dpan_global_delay = (0,0,0,0)

try:
filesize = os.path.getsize(filename)
Expand Down Expand Up @@ -341,6 +341,9 @@ def load_anim(filename, config, ifftype, status_func=None):
#Deluxe Paint specific chunk
dpan_bytes = chunk.read()
(dpan_version, dpan_numframes, dpan_global_fps, d1,d2,d3) = unpack(">HHBBBB", dpan_bytes)
#print(f"{(dpan_version, dpan_numframes, dpan_global_fps, d1,d2,d3)=}")
if dpan_version < 3:
dpan_global_fps = 0
if dpan_global_fps > 0:
dpan_global_delay = 60 // dpan_global_fps
elif chunk.getname() == b'BMHD':
Expand Down Expand Up @@ -386,7 +389,7 @@ def load_anim(filename, config, ifftype, status_func=None):
anhd_bytes = chunk.read()
(anim_mode, anim_mask, anim_w, anim_h, anim_x, anim_y, anim_abstime, anim_reltime, anim_interleave, anim_pad0, anim_bits, anim_pad8a, anim_pad8b) = unpack(">BBHHhhLLBBLQQ", anhd_bytes)
#print(f"{anim_reltime=} {anim_abstime=}")
if anim_abstime == 0:
if anim_abstime == 0 and dpan_global_delay != 0:
anim_reltime = dpan_global_delay
elif chunk.getname() == b'DLTA':
#Read in column pointers
Expand Down Expand Up @@ -499,12 +502,15 @@ def load_anim(filename, config, ifftype, status_func=None):

config.cranges = cranges

#trim final frames of looping animation
if dpan_numframes == 0 and config.anim.num_frames > 2:
dpan_numframes = config.anim.num_frames - 2
while config.anim.num_frames > dpan_numframes:
del config.anim.frame[-1]
config.anim.num_frames -= 1
if dpan_numframes > 0:
#take frame 0 delay from looping frame to be trimmed
if config.anim.num_frames - dpan_numframes == 2:
config.anim.frame[0].delay = config.anim.frame[-2].delay

#trim final frames of looping animation
while config.anim.num_frames > dpan_numframes:
del config.anim.frame[-1]
config.anim.num_frames -= 1

config.anim.global_palette = (num_CMAP == 1)
config.pal = config.anim.frame[0].pal
Expand All @@ -516,6 +522,14 @@ def load_anim(filename, config, ifftype, status_func=None):
newpic.blit(pic, (0,0))
pic = newpic

#crop anim images to actual bitmap size
for i in range(config.anim.num_frames):
pic2 = config.anim.frame[i].image
newpic = pygame.Surface((w, h), 0, pic2)
newpic.set_palette(pic2.get_palette())
newpic.blit(pic2, (0,0))
config.anim.frame[i].image = newpic

return pic

def pal_power_2(palin):
Expand Down Expand Up @@ -786,6 +800,11 @@ def load_pic(filename_in, config, status_func=None, is_anim=False, cmd_load=Fals
else:
config.anim.global_palette = False

if config.anim.num_frames > 1:
# Add layers to all frames
for i in range(len(config.anim.frame)):
config.anim.frame[i].layers.set("canvas", config.anim.frame[i].image, priority=1)

config.color_depth = config.guess_color_depth(config.truepal)
config.truepal = config.quantize_palette(config.truepal, config.color_depth)
config.pal = config.quantize_palette(config.pal, config.color_depth)
Expand Down
4 changes: 4 additions & 0 deletions libs/prim.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ def render_image(self, color):
if self.size == 1:
image = pygame.Surface((1,1),0, config.pixel_canvas)
image.set_palette(config.pal)
if color == 0:
image.set_colorkey(1)
else:
image.set_colorkey(0)
image.fill(color)
else:
image = pygame.Surface((self.size*ax*2+1, self.size*ay*2+1),0, config.pixel_canvas)
Expand Down
4 changes: 2 additions & 2 deletions libs/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
def version_set_config(config_in):
global config
config = config_in
config.version = "2.0.0"
config.copyright = "\xA92023 Mark Riale"
config.version = "2.0.1"
config.copyright = "\xA92024 Mark Riale"

0 comments on commit 54e8fcf

Please sign in to comment.