atlas

Asset management for MoonBit: image repositories, atlas allocation, source-image bindings, codec wrappers, and a fetcher abstraction (extracted from kagura)

moon add mizchi/atlas@0.2.0
Download zip
Author
Version
0.2.0
License
Apache-2.0
Last updated
2 months ago
Downloads
29

Dependencies

README

#
AtlasAllocator

pub trait AtlasAllocator {
fn allocate(Self, width : Int, height : Int) -> AtlasRegion?
fn release(Self, region : AtlasRegion) -> Unit
}

#
BytesFetcher

pub(open) trait BytesFetcher {
fn fetch(Self, url : String, on_progress : (FetchProgress) -> Unit, on_complete : (Bytes?) -> Unit) -> FetchHandle
fn cancel(Self, handle : FetchHandle) -> Unit
fn poll(Self) -> Unit
}

#
ImageRepository

pub trait ImageRepository {
fn create_image(Self, key : AssetKey, spec : ImageSpec) ->
ImageHandle
raise
fn get_image(Self, key : AssetKey) ->
ImageHandle
?
fn remove_image(Self, key : AssetKey) -> Unit raise
}

#
MaterialRepository

pub trait MaterialRepository {
fn register_material(Self, key : AssetKey, spec : MaterialSpec) -> Unit raise
fn get_material(Self, key : AssetKey) -> MaterialSpec?
}

#
ShaderRepository

pub trait ShaderRepository {
fn create_shader(Self, key : AssetKey, spec : ShaderSpec) ->
ShaderHandle
raise
fn get_shader(Self, key : AssetKey) ->
ShaderHandle
?
fn remove_shader(Self, key : AssetKey) -> Unit raise
}

#
AssetKey

pub struct AssetKey {
value : String
} derive(
Debug
)

impl Show for AssetKey

#
AtlasCompactResult

pub struct AtlasCompactResult {
removed_page_ids : Array[Int]
removed_page_count : Int
remaining_page_count : Int
} derive(
Debug
)

#
AtlasDrawSource

pub struct AtlasDrawSource {
page_image_id : Int
region : AtlasRegion
u0 : Double
v0 : Double
u1 : Double
v1 : Double
} derive(
Debug
)

#
AtlasPageStats

pub struct AtlasPageStats {
atlas_id : Int
image_count : Int
allocated_region_count : Int
atlas_width : Int
atlas_height : Int
is_empty : Bool
} derive(
Debug
)

#
AtlasRegion

pub struct AtlasRegion {
x : Int
y : Int
width : Int
height : Int
atlas_id : Int
} derive(
Debug
)

impl Show for AtlasRegion

#
DeferredResult

type DeferredResult

#
FetchHandle

pub(all) struct FetchHandle {
id : Int
} derive(
Debug
)

impl Show for FetchHandle

#
FetchProgress

pub(all) struct FetchProgress {
loaded : Int
total : Int
} derive(
Debug
)

#
ImagePalette2x2

pub struct ImagePalette2x2 {
p00 : Rgba
p10 : Rgba
p01 : Rgba
p11 : Rgba
} derive(
Debug
)

#
ImagePaletteBinding

pub struct ImagePaletteBinding {
image_id : Int
palette : ImagePalette2x2
} derive(
Debug
)

#
ImageSpec

pub struct ImageSpec {
width : Int
height : Int
format : String
palette : ImagePalette2x2
pixels_rgba8 : Array[Int]
} derive(
Debug
)

impl Show for ImageSpec

#
MaterialSpec

pub struct MaterialSpec {
shader : AssetKey
blend :
BlendMode

filter :
FilterMode

uniform_keys : Array[String]
} derive(
Debug
)

#
MultiPageAtlasRepository

pub struct MultiPageAtlasRepository {
page_width : Int
page_height : Int
next_page_id : Int
pages : Array[SimpleAtlasImageRepository]
key_page_index : Array[(String, Int)]
}

Multi-page atlas repository that auto-creates new pages when the current page runs out of space.

Ebiten refs:
  • internal/atlas/image.go (multi-backend page management)

#
NativeFetcher

pub struct NativeFetcher {
read_file_fn : (String) -> Bytes?
next_id : Int
deferred : Array[DeferredResult]
}

#
RasterImageFormat

pub enum RasterImageFormat {
Png
Jpeg
Bmp
} derive(Eq,
Debug
)

#
RasterResizeMethod

pub enum RasterResizeMethod {
Nearest
Bilinear
Bicubic
} derive(
Debug
)

#
Rgba

pub struct Rgba {
r : Int
g : Int
b : Int
a : Int
} derive(
Debug
)

impl Show for Rgba

#
ShaderSpec

pub struct ShaderSpec {
debug_name : String
source : String
} derive(
Debug
)

impl Show for ShaderSpec

#
SimpleAtlasAllocator

pub struct SimpleAtlasAllocator {
atlas_width : Int
atlas_height : Int
atlas_id : Int
cursor_x : Int
cursor_y : Int
row_height : Int
allocated : Array[AtlasRegion]
}

#
SimpleAtlasImageEntry

type SimpleAtlasImageEntry derive(
Debug
)

#
SimpleAtlasImageRepository

pub struct SimpleAtlasImageRepository {
atlas_width : Int
atlas_height : Int
atlas_id : Int
next_image_id : Int
allocator : SimpleAtlasAllocator
images : Array[SimpleAtlasImageEntry]
page_generation : Int
page_dirty_rect : SourceImageDirtyRect?
}

Atlas image repository with page-level dirty tracking.

Ebiten refs:
  • internal/atlas/image.go
  • internal/atlas/image.go (writePixels / region updates)

#
SimpleImageEntry

type SimpleImageEntry derive(
Debug
)

#
SimpleImageRepository

pub struct SimpleImageRepository {
next_image_id : Int
images : Array[SimpleImageEntry]
}

#
SimpleMaterialEntry

type SimpleMaterialEntry derive(
Debug
)

#
SimpleMaterialRepository

pub struct SimpleMaterialRepository {
materials : Array[SimpleMaterialEntry]
}

#
SimpleShaderEntry

type SimpleShaderEntry derive(
Debug
)

#
SimpleShaderRepository

pub struct SimpleShaderRepository {
next_shader_id : Int
shaders : Array[SimpleShaderEntry]
}

#
SourceImageBinding

pub struct SourceImageBinding {
image_id : Int
width : Int
height : Int
generation : Int
dirty_rect : SourceImageDirtyRect?
palette : ImagePalette2x2
pixels_rgba8 : Array[Int]
} derive(
Debug
)

#
SourceImageDirtyRect

pub struct SourceImageDirtyRect {
x : Int
y : Int
width : Int
height : Int
} derive(
Debug
)

#
atlas_allocator_is_empty

fn atlas_allocator_is_empty(allocator : SimpleAtlasAllocator) -> Bool

#
atlas_allocator_reset_if_empty

fn atlas_allocator_reset_if_empty(allocator : SimpleAtlasAllocator) -> Bool

#
atlas_page_image_count

fn atlas_page_image_count(repo : SimpleAtlasImageRepository) -> Int

#
atlas_page_is_empty

fn atlas_page_is_empty(repo : SimpleAtlasImageRepository) -> Bool

#
atlas_page_stats

fn atlas_page_stats(repo : SimpleAtlasImageRepository) -> AtlasPageStats

#
checker_palette_from_seed

fn checker_palette_from_seed(seed : Int) -> ImagePalette2x2

#
clamp_channel

fn clamp_channel(channel : Int) -> Int

#
clear_dirty_atlas_page_flags

fn clear_dirty_atlas_page_flags(repo : SimpleAtlasImageRepository) -> Int

#
clear_source_image_dirty_flags

fn clear_source_image_dirty_flags(repo : SimpleImageRepository) -> Int

#
create_atlas_image

fn create_atlas_image(repo : SimpleAtlasImageRepository, key : AssetKey, spec : ImageSpec) ->
ImageHandle
?

#
create_atlas_image_from_raster_bytes

fn create_atlas_image_from_raster_bytes(repository : SimpleAtlasImageRepository, key : AssetKey, bytes : Bytes) ->
ImageHandle
? raise

#
create_image_from_raster_bytes

fn create_image_from_raster_bytes(repository : SimpleImageRepository, key : AssetKey, bytes : Bytes) ->
ImageHandle
? raise

#
decode_bmp_image_spec

fn decode_bmp_image_spec(bytes : Bytes) -> ImageSpec raise
DecodeError

#
decode_image_spec

fn decode_image_spec(bytes : Bytes, format : RasterImageFormat) -> ImageSpec raise
DecodeError

#
decode_image_spec_auto

fn decode_image_spec_auto(bytes : Bytes) -> ImageSpec? raise
DecodeError

#
decode_jpeg_image_spec

fn decode_jpeg_image_spec(bytes : Bytes) -> ImageSpec raise
DecodeError

#
decode_png_image_spec

fn decode_png_image_spec(bytes : Bytes) -> ImageSpec raise
DecodeError

#
default_image_spec

fn default_image_spec(width : Int, height : Int) -> ImageSpec

#
detect_raster_image_format

fn detect_raster_image_format(bytes : Bytes) -> RasterImageFormat?

#
encode_bmp_image_spec

fn encode_bmp_image_spec(spec : ImageSpec) -> Bytes raise
EncodeError

#
encode_image_spec

fn encode_image_spec(spec : ImageSpec, format : RasterImageFormat) -> Bytes raise
EncodeError

#
encode_jpeg_image_spec

fn encode_jpeg_image_spec(spec : ImageSpec, quality? : Int) -> Bytes raise
EncodeError

#
encode_png_image_spec

fn encode_png_image_spec(spec : ImageSpec) -> Bytes raise
EncodeError

#
get_atlas_draw_source

fn get_atlas_draw_source(repo : SimpleAtlasImageRepository, key : AssetKey) -> AtlasDrawSource?

#
get_atlas_image_region

fn get_atlas_image_region(repo : SimpleAtlasImageRepository, key : AssetKey) -> AtlasRegion?

#
get_image_generation_by_id

fn get_image_generation_by_id(repo : SimpleImageRepository, image_id : Int) -> Int

#
get_image_palette_by_id

fn get_image_palette_by_id(repo : SimpleImageRepository, image_id : Int) -> ImagePalette2x2?

#
get_image_pixels_by_id

fn get_image_pixels_by_id(repo : SimpleImageRepository, image_id : Int) -> Array[Int]?

#
image_spec_with_palette

fn image_spec_with_palette(width : Int, height : Int, palette : ImagePalette2x2) -> ImageSpec

#
image_spec_with_rgba8

fn image_spec_with_rgba8(width : Int, height : Int, pixels_rgba8 : Array[Int]) -> ImageSpec

#
list_dirty_atlas_page_bindings

fn list_dirty_atlas_page_bindings(repo : SimpleAtlasImageRepository) -> Array[SourceImageBinding]

#
list_dirty_source_image_bindings

fn list_dirty_source_image_bindings(repo : SimpleImageRepository) -> Array[SourceImageBinding]

#
list_image_palette_bindings

fn list_image_palette_bindings(repo : SimpleImageRepository) -> Array[ImagePaletteBinding]

#
list_source_image_bindings

fn list_source_image_bindings(repo : SimpleImageRepository) -> Array[SourceImageBinding]

#
multi_page_clear_dirty_flags

fn multi_page_clear_dirty_flags(repo : MultiPageAtlasRepository) -> Int

#
multi_page_compact

fn multi_page_compact(repo : MultiPageAtlasRepository) -> AtlasCompactResult

#
multi_page_count

fn multi_page_count(repo : MultiPageAtlasRepository) -> Int

#
multi_page_create_image

fn multi_page_create_image(repo : MultiPageAtlasRepository, key : AssetKey, spec : ImageSpec) ->
ImageHandle
?

#
multi_page_get_draw_source

fn multi_page_get_draw_source(repo : MultiPageAtlasRepository, key : AssetKey) -> AtlasDrawSource?

#
multi_page_get_page_ids

fn multi_page_get_page_ids(repo : MultiPageAtlasRepository) -> Array[Int]

#
multi_page_get_region

fn multi_page_get_region(repo : MultiPageAtlasRepository, key : AssetKey) -> AtlasRegion?

#
multi_page_image_count

fn multi_page_image_count(repo : MultiPageAtlasRepository) -> Int

#
multi_page_list_dirty_bindings

fn multi_page_list_dirty_bindings(repo : MultiPageAtlasRepository) -> Array[SourceImageBinding]

#
multi_page_remove_image

fn multi_page_remove_image(repo : MultiPageAtlasRepository, key : AssetKey) -> Unit

#
multi_page_stats

fn multi_page_stats(repo : MultiPageAtlasRepository) -> Array[AtlasPageStats]

#
multi_page_update_image_spec

fn multi_page_update_image_spec(repo : MultiPageAtlasRepository, key : AssetKey, spec : ImageSpec) ->
ImageHandle
?

#
new_asset_key

fn new_asset_key(value : String) -> AssetKey

#
new_atlas_region

fn new_atlas_region(x : Int, y : Int, width : Int, height : Int, atlas_id : Int) -> AtlasRegion

#
new_image_palette_2x2

fn new_image_palette_2x2(p00 : Rgba, p10 : Rgba, p01 : Rgba, p11 : Rgba) -> ImagePalette2x2

#
new_multi_page_atlas_repository

fn new_multi_page_atlas_repository(page_width : Int, page_height : Int) -> MultiPageAtlasRepository

#
new_native_fetcher

fn new_native_fetcher(read_file_fn : (String) -> Bytes?) -> NativeFetcher

#
new_rgba

fn new_rgba(r : Int, g : Int, b : Int, a : Int) -> Rgba

#
new_simple_atlas_allocator

fn new_simple_atlas_allocator(atlas_width : Int, atlas_height : Int, atlas_id : Int) -> SimpleAtlasAllocator

#
new_simple_atlas_image_repository

fn new_simple_atlas_image_repository(atlas_width : Int, atlas_height : Int, atlas_id : Int) -> SimpleAtlasImageRepository

#
new_simple_image_repository

fn new_simple_image_repository() -> SimpleImageRepository

#
new_simple_material_repository

fn new_simple_material_repository() -> SimpleMaterialRepository

#
new_simple_shader_repository

fn new_simple_shader_repository() -> SimpleShaderRepository

#
new_solid_palette

fn new_solid_palette(color : Rgba) -> ImagePalette2x2

#
new_source_image_binding

fn new_source_image_binding(image_id : Int, width : Int, height : Int, generation : Int, dirty_rect : SourceImageDirtyRect?, palette : ImagePalette2x2, pixels_rgba8 : Array[Int]) -> SourceImageBinding

#
new_source_image_dirty_rect

fn new_source_image_dirty_rect(x : Int, y : Int, width : Int, height : Int) -> SourceImageDirtyRect

#
new_unmanaged_atlas_draw_source

fn new_unmanaged_atlas_draw_source(image_id : Int) -> AtlasDrawSource

#
palette_channel

fn palette_channel(palette : ImagePalette2x2, pixel_index : Int, channel_index : Int) -> Int

#
raster_image_format_bmp

fn raster_image_format_bmp() -> RasterImageFormat

#
raster_image_format_jpeg

fn raster_image_format_jpeg() -> RasterImageFormat

#
raster_image_format_png

fn raster_image_format_png() -> RasterImageFormat

#
raster_resize_bicubic

fn raster_resize_bicubic() -> RasterResizeMethod

#
raster_resize_bilinear

fn raster_resize_bilinear() -> RasterResizeMethod

#
raster_resize_nearest

fn raster_resize_nearest() -> RasterResizeMethod

#
register_precomputed_image

fn register_precomputed_image(repo : SimpleAtlasImageRepository, key : AssetKey, region : AtlasRegion, spec : ImageSpec) ->
ImageHandle

Register an image with a precomputed atlas region (bypasses allocator). Used by sprite_packer to register MaxRects-packed results directly.

#
remove_atlas_image

fn remove_atlas_image(repo : SimpleAtlasImageRepository, key : AssetKey) -> Unit

#
resize_image_spec

fn resize_image_spec(spec : ImageSpec, width : Int, height : Int, resize_method : RasterResizeMethod) -> ImageSpec raise
EncodeError

#
update_atlas_image_from_raster_bytes

fn update_atlas_image_from_raster_bytes(repository : SimpleAtlasImageRepository, key : AssetKey, bytes : Bytes) ->
ImageHandle
? raise

#
update_atlas_image_spec

fn update_atlas_image_spec(repo : SimpleAtlasImageRepository, key : AssetKey, spec : ImageSpec) ->
ImageHandle
?

#
update_image_from_raster_bytes

fn update_image_from_raster_bytes(repository : SimpleImageRepository, key : AssetKey, bytes : Bytes) ->
ImageHandle
? raise

#
update_image_spec

fn update_image_spec(repo : SimpleImageRepository, key : AssetKey, spec : ImageSpec) ->
ImageHandle
?