Skip to content

Commit

Permalink
Calculate image size
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Nov 9, 2020
1 parent 4efe41a commit 314147b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/ttblit/asset/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ..core.assetbuilder import AssetBuilder
from ..core.palette import Colour, Palette, type_palette
from ..core.struct import struct_blit_image, struct_blit_pixel
from ..core.struct import struct_blit_image


class ImageAsset(AssetBuilder):
Expand Down Expand Up @@ -80,7 +80,6 @@ def to_binary(self, input_data):

return struct_blit_image.build({
'type': 'PK' if self.packed else 'RW',
'size': len(image_data) + (len(self.palette) * 4) + 20,
'width': image.size[0],
'height': image.size[1],
'palette_entries': len(self.palette),
Expand Down
5 changes: 3 additions & 2 deletions src/ttblit/core/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from construct import (Array, Bytes, Checksum, Computed, Const, Int8ul,
Int16ul, Int32ul, Optional, PaddedString, Prefixed,
PrefixedArray, RawCopy, Struct, Adapter, this)
PrefixedArray, RawCopy, Struct, Adapter, Rebuild,
this, len_)


def compute_bit_length(ctx):
Expand Down Expand Up @@ -47,7 +48,7 @@ def _encode(self, obj, context, path):
struct_blit_image = Struct(
'header' / Const(b'SPRITE'),
'type' / PaddedString(2, 'ASCII'),
'size' / Int32ul,
'size' / Rebuild(Int32ul, len_(this.data) + (this.palette_entries * 4) + 18),
'width' / Int16ul,
'height' / Int16ul,
'format' / Const(0x02, Int8ul),
Expand Down

0 comments on commit 314147b

Please sign in to comment.