Skip to content

Commit

Permalink
2.1.0 - full support for the way palettes are stored in Aseprite 1.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
miriti committed May 26, 2024
1 parent e0daa19 commit fafac67
Show file tree
Hide file tree
Showing 54 changed files with 361 additions and 140 deletions.
45 changes: 22 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# ASE

.ase/.aseprite file format reader/writer written in Haxe with no external dependencies.
A `.ase/.aseprite` file format reader/writer written in Haxe with no external dependencies.

Implemented following the official [Aseprite File Format (.ase/.aseprite) Specifications](https://github.com/aseprite/aseprite/blob/master/docs/ase-file-specs.md)
Implemented following the official [Aseprite File Format (.ase/.aseprite) Specifications](https://github.com/aseprite/aseprite/blob/master/docs/ase-file-specs.md).

Note that this library only provides reading and writing of the Aseprite file format. If you need rendering you will have to implement it yourself or use one of the existing rendering libraries:
Note that this library only provides reading and writing of the Aseprite file format. If you need rendering, you will have to implement it yourself or use one of the existing rendering libraries:

- [OpenFL Aseprite](https://github.com/miriti/openfl-aseprite)
- [heaps-aseprite](https://github.com/AustinEast/heaps-aseprite) by [Austin East](https://github.com/AustinEast)
Expand All @@ -20,13 +20,13 @@ Note that this library only provides reading and writing of the Aseprite file fo

### Installation

```
```shell
haxelib install ase
```

### Usage

#### Parsing files
#### Parsing Files

```haxe
import sys.io.File;
Expand All @@ -47,16 +47,13 @@ var spriteColorDepth:ColorDepth = ase.colorDepth;
Palette:

```haxe
for(index in ase.palette.firstIndex...ase.palette.lastIndex+1) {
var entry:PaletteEntry = ase.palette.getEntry(index);
var r:Int = entry.r;
var g:Int = entry.g;
var b:Int = entry.b;
var a:Int = entry.a;
for(index => entry in ase.palette.entries) {
trace('Red: ${entry.red}, Green: ${entry.green}, Blue: ${entry.blue}, Alpha: ${entry.alpha}');
var rgbaColor = ase.palette.getRGBA(index);
var argbColor = ase.palette.getARGB(index);
// Alternatively, get the 32-bit integer RGBA or ARGB value
var rgbaColor:Int = ase.palette.getRGBA(index);
var argbColor:Int = ase.palette.getARGB(index);
trace('RGBA: ${StringTools.hex(rgbaColor, 8)}, ARGB: ${StringTools.hex(argbColor, 8)}');
}
```

Expand All @@ -66,7 +63,7 @@ Layers:
for(layer in ase.layers) {
var layerName:String = layer.name;
var layerEditable:Bool = layer.editable;
var layerVisible = layer.visible;
var layerVisible:Bool = layer.visible;
}
```

Expand All @@ -88,10 +85,9 @@ var celHeight:Int = frame.cel(layerIndex).height;
var celPixelData:Bytes = frame.cel(layerIndex).pixelData;
```

#### Create files
#### Creating Files

```haxe
var spriteWidth:Int = 320;
var spriteHeight:Int = 320;
var colorDepth:ColorDepth = INDEXED;
Expand All @@ -105,16 +101,15 @@ var initialPalette:Array<Int> = [
];
var ase = Ase.create(spriteWidth, spriteHeight, colorDepth);
```

Newly created file always comes with one blank frame. To add some content add at least one layer first:
A newly created file always comes with one blank frame. To add some content, add at least one layer first:

```haxe
ase.addLayer('Background');
```

Now to add some pixels to the sprite create a Cel on the first frame and the newly created layer:
Now, to add some pixels to the sprite, create a Cel on the first frame and the newly created layer:

```haxe
var layerIndex:Int = 0;
Expand All @@ -139,16 +134,20 @@ cel.fillIndex(0); // Fill the cel with color #0 from the palette
cel.fillColor(0xff00ff00); // Fill the cel with ARGB color (for 32bpp mode)
cel.setPixel(20, 20, 0xff0033aa); // Set ARGB color at x and y
cel.setPixel(20, 20, 4); // Set color index at x and y
cel.setPixelData(bytes, 300, 300); // Set bytes of the pixel data (the size must me equal to width x height x bpp)
cel.setPixelData(bytes, 300, 300); // Set bytes of the pixel data (the size must be equal to width x height x bpp)
```

At any time you can get the file representation as bytes and, for example, store them to a file:
At any time, you can get the file representation as bytes and, for example, store them to a file:

```haxe
var bytes = ase.getBytes();
File.saveBytes('my_aseprite_file.aseprite', bytes);
```

## Contributors

See [https://github.com/miriti/ase/graphs/contributors](https://github.com/miriti/ase/graphs/contributors).

## License

This project is licensed under the MIT License - see the LICENSE.md file for details
This project is licensed under the MIT License - see the [LICENSE.md](./LICENSE.md) file for details.
2 changes: 1 addition & 1 deletion documentation/404.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><!-- use theme color or fallback --><!--use textcolor from settings, otherwise create a contrasting color to theme color--><head><meta charset="utf-8"/><link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet"/><link href="./bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet"/><link href="./bootstrap/css/bootstrap-select.min.css" rel="stylesheet"/><link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700,700italic,400italic" rel="stylesheet" type="text/css"/><link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,600,600italic,400" rel="stylesheet" type="text/css"/><link href="https://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.css" rel="stylesheet" type="text/css"/><script src="./jquery-1.9.1.min.js"></script><script src="./bootstrap/js/bootstrap.min.js"></script><script src="./bootstrap/js/bootstrap-select.min.js"></script><link href="./styles.css" rel="stylesheet"/><link href="./extra-styles.css" rel="stylesheet"/><link href="./haxe-nav.css" rel="stylesheet"/><link href="./dark-mode.css" rel="stylesheet"/><script>var dox = {rootPath: "./",platforms: ["all"]};</script><script src="./nav.js"></script><script src="./index.js"></script><link rel="icon" href="./favicon.ico" type="image/x-icon"/><title>File not found</title></head><body><script>/* Here to prevent flash of unstyled content */let systemDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;if ((!localStorage.theme && systemDarkMode) || localStorage.theme == "dark") {document.body.style.backgroundColor = "#111";document.body.style.opacity = "0";document.addEventListener("DOMContentLoaded", function(event) {toggleTheme();document.body.style.backgroundColor = "";document.body.style.opacity = "";});}</script><style>.navbar .brand {display: inline-block;float: none;text-shadow: 0 0 0 transparent;}</style><nav class="nav"><div class="navbar"><div class="navbar-inner" style="background:#FAFAFA; border-bottom:1px solid rgba(0,0,0,.09)"><div class="container"><a class="brand" style="color:#000000" href="./">API Documentation</a><a href="#" id="theme-toggle" class="brand" style="color:#000000" onclick="toggleTheme()" title="Toggle Dark Mode"><i class="fa fa-moon-o"></i></a></div></div></div></nav><div class="container main-content"><div class="row-fluid"><div class="span3"><div class="well sidebar-nav"><form class="form-search" id="searchForm"><div class="input-prepend input-block-level"><span class="add-on"><i class="fa fa-search"></i></span><input id="search" type="text" placeholder="Filter (Ctrl+P)" autocomplete="off"/></div></form></div><div class="well sidebar-nav" id="explorer"><div id="nav"></div></div></div><div class="span9"><script type="text/javascript">$(document).ready(errorSearch);</script><h1><small>404</small> Page not found</h1><p>Page not found, sorry.</p></div></div></div><footer class="section site-footer" style="background:#FAFAFA"><div class="container"><div class="copyright"><p style="color:#000000">&copy; 2023 &nbsp;</p></div></div></footer><script src=".//highlighter.js"></script><link href="./highlighter.css" rel="stylesheet"/></body></html>
<!DOCTYPE html><html lang="en"><!-- use theme color or fallback --><!--use textcolor from settings, otherwise create a contrasting color to theme color--><head><meta charset="utf-8"/><link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet"/><link href="./bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet"/><link href="./bootstrap/css/bootstrap-select.min.css" rel="stylesheet"/><link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700,700italic,400italic" rel="stylesheet" type="text/css"/><link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,600,600italic,400" rel="stylesheet" type="text/css"/><link href="https://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.css" rel="stylesheet" type="text/css"/><script src="./jquery-1.9.1.min.js"></script><script src="./bootstrap/js/bootstrap.min.js"></script><script src="./bootstrap/js/bootstrap-select.min.js"></script><link href="./styles.css" rel="stylesheet"/><link href="./extra-styles.css" rel="stylesheet"/><link href="./haxe-nav.css" rel="stylesheet"/><link href="./dark-mode.css" rel="stylesheet"/><script>var dox = {rootPath: "./",platforms: ["all"]};</script><script src="./nav.js"></script><script src="./index.js"></script><link rel="icon" href="./favicon.ico" type="image/x-icon"/><title>File not found</title></head><body><script>/* Here to prevent flash of unstyled content */let systemDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;if ((!localStorage.theme && systemDarkMode) || localStorage.theme == "dark") {document.body.style.backgroundColor = "#111";document.body.style.opacity = "0";document.addEventListener("DOMContentLoaded", function(event) {toggleTheme();document.body.style.backgroundColor = "";document.body.style.opacity = "";});}</script><style>.navbar .brand {display: inline-block;float: none;text-shadow: 0 0 0 transparent;}</style><nav class="nav"><div class="navbar"><div class="navbar-inner" style="background:#FAFAFA; border-bottom:1px solid rgba(0,0,0,.09)"><div class="container"><a class="brand" style="color:#000000" href="./">API Documentation</a><a href="#" id="theme-toggle" class="brand" style="color:#000000" onclick="toggleTheme()" title="Toggle Dark Mode"><i class="fa fa-moon-o"></i></a></div></div></div></nav><div class="container main-content"><div class="row-fluid"><div class="span3"><div class="well sidebar-nav"><form class="form-search" id="searchForm"><div class="input-prepend input-block-level"><span class="add-on"><i class="fa fa-search"></i></span><input id="search" type="text" placeholder="Filter (Ctrl+P)" autocomplete="off"/></div></form></div><div class="well sidebar-nav" id="explorer"><div id="nav"></div></div></div><div class="span9"><script type="text/javascript">$(document).ready(errorSearch);</script><h1><small>404</small> Page not found</h1><p>Page not found, sorry.</p></div></div></div><footer class="section site-footer" style="background:#FAFAFA"><div class="container"><div class="copyright"><p style="color:#000000">&copy; 2024 &nbsp;</p></div></div></footer><script src=".//highlighter.js"></script><link href="./highlighter.css" rel="stylesheet"/></body></html>
Loading

0 comments on commit fafac67

Please sign in to comment.