Skip to content

Commit

Permalink
Merge pull request #1 from Laguna1989/feature/prepareForV0.1
Browse files Browse the repository at this point in the history
Add github action and make zlib buffer way smaller
  • Loading branch information
Laguna1989 authored Oct 10, 2023
2 parents ef11022 + 8e95cdf commit 1b2e37c
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 197 deletions.
136 changes: 136 additions & 0 deletions .github/workflows/test_verification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
Linux_gcc:
runs-on: ubuntu-latest
strategy:
matrix:
gccver: [ 9, 10, 11 ]
steps:
- name: Set up cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.26.x'

- name: Set up gcc
uses: egor-tensin/setup-gcc@v1
with:
version: ${{ matrix.gccver }}
platform: x64

- uses: actions/checkout@v2

- name: ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: ${{ github.job }}-${{ matrix.gccver }}-${{ matrix.os }}
max-size: 100M

- name: CMake
run: |
cmake \
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-B ${{github.workspace}}/build .
- name: Build
working-directory: ${{github.workspace}}/build
run: make aselib aselib_test -j

- name: CopyAssets
run: cp -r ${{github.workspace}}/assets ${{github.workspace}}/build/test/unit_tests/

- name: Test
run: ./aselib_test
working-directory: ${{github.workspace}}/build/test/unit_tests

# Windows:
# runs-on: windows-2019
# steps:
# - name: Set up cmake
# uses: jwlawson/[email protected]
# with:
# cmake-version: '3.26.x'
#
# - uses: actions/checkout@v2
#
# - name: CMake
# run: cmake -B ${{github.workspace}}/build . -DOALPP_STATIC_LIBRARY=ON
#
# - name: Build
# working-directory: ${{github.workspace}}/build
# run: cmake --build .
#
# - name: Test
# working-directory: ${{github.workspace}}/build
# run: test/unit_tests/Debug/OpenALpp_UnitTests.exe --order rand

Web:
runs-on: ubuntu-latest
env:
EMCC_CCACHE: 1
steps:
- name: Set up cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.26.x'

- name: Set up gcc
uses: egor-tensin/setup-gcc@v1
with:
version: 9
platform: x64

- uses: mymindstorm/setup-emsdk@v11

- uses: actions/checkout@v2

- name: ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.type }}
max-size: 100M

- name: CMake
run: |
emcmake cmake -B ${{github.workspace}}/build \
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
.
- name: Build
working-directory: ${{github.workspace}}/build
run: emmake make aselib aselib_test

Mac_clang:
runs-on: macos-latest
steps:
- name: Set up cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.26.x'

- name: Install dependencies
run: |
brew install cmake ninja
- uses: actions/checkout@v2

- name: ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: ${{ github.job }}-${{ matrix.os }}
max-size: 100M

- name: CMake
run: |
cmake \
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-B ${{github.workspace}}/build .
- name: Build
working-directory: ${{github.workspace}}/build
run: make aselib aselib_test -j 4
Binary file added assets/test/unit/miner.aseprite
Binary file not shown.
24 changes: 13 additions & 11 deletions impl/aselib/chunk_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string decompress(const std::string& str)
zs.avail_in = static_cast<uInt>(str.size());

int ret;
char outbuffer[10240];
char outbuffer[256];
std::string outstring;

// get the decompressed bytes blockwise using repeated calls to inflate
Expand Down Expand Up @@ -58,7 +58,7 @@ aselib::ChunkHeader aselib::parseChunkHeader(std::istream& is)

void aselib::parseNextChunk(std::istream& is, ChunksData& data)
{
ChunkHeader hdr = parseChunkHeader(is);
ChunkHeader const hdr = parseChunkHeader(is);

if (hdr.m_chunk_type == 0x2007) {
// color profile chunk
Expand Down Expand Up @@ -130,10 +130,10 @@ void aselib::parseNextChunk(std::istream& is, ChunksData& data)
auto const chunk_header_size = 6;
auto const chunk_data_offset = 20 + chunk_header_size;
auto const data_size = cc.m_header.m_chunk_size - chunk_data_offset;
std::string compressed_data;
std::string compressed_data {};
compressed_data.resize(data_size);
is.read(compressed_data.data(), compressed_data.size());
std::string uncompressed_data = decompress(compressed_data);
std::string const uncompressed_data = decompress(compressed_data);

auto const length = uncompressed_data.length();
if (length != cc.m_cell_height * cc.m_cell_width * 4) {
Expand All @@ -144,12 +144,14 @@ void aselib::parseNextChunk(std::istream& is, ChunksData& data)
for (auto j = 0u; j != cc.m_cell_height; ++j) {
for (auto i = 0u; i != cc.m_cell_width; ++i) {
auto const idx_ofs = (i + j * cc.m_cell_width) * 4;
PixelDataRGBA col {};
col.r = static_cast<Byte_t>(uncompressed_data[idx_ofs + 0]);
col.g = static_cast<Byte_t>(uncompressed_data[idx_ofs + 1]);
col.b = static_cast<Byte_t>(uncompressed_data[idx_ofs + 2]);
col.a = static_cast<Byte_t>(uncompressed_data[idx_ofs + 3]);
cc.m_pixels_rgba.emplace_back(col);
cc.m_pixels_rgba.emplace_back(PixelDataRGBA {
// clang-format off
static_cast<Byte_t>(uncompressed_data[idx_ofs + 0]),
static_cast<Byte_t>(uncompressed_data[idx_ofs + 1]),
static_cast<Byte_t>(uncompressed_data[idx_ofs + 2]),
static_cast<Byte_t>(uncompressed_data[idx_ofs + 3])
// clang-format on
});
}
}

Expand Down Expand Up @@ -189,7 +191,7 @@ void aselib::parseNextChunk(std::istream& is, ChunksData& data)
}
if (udc.m_user_data_flags & 4) {
// TODO implement properties

// Dword_t const numberOfPropertyMaps = parseDword(is);
throw std::invalid_argument { "cannot read properties until now" };
}
Expand Down
58 changes: 58 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
This is a c++17 library to parse `*.aseprite` files. Please check out and
support [this awesome pixelart program](https://www.aseprite.org/)!

# Limitations

* No support for grayscale or indexed image types. Only RGBA files are supported.
* Grayscale and indexed files will not parse.
* Only "Normal" Blend Mode is supported.
* Blend mode is effectively ignored.
* No support of user data properties.
* Files with user data properties will not prase.

# Dependencies

* zlib (for cel chunk decompression)
* catch2 (for testing only)

All dependencies are obtained via cmake.

# How to use this library

## CMake

CMake integration into your own project is done via `FetchContent`.

include in your `CMakeLists.txt`

```cmake
include(FetchContent)
message(STATUS "Fetching aselib")
FetchContent_Declare(
aselib
GIT_REPOSITORY https://github.com/Laguna1989/aseprite_lib.git
GIT_TAG master
)
set(ASE_LIB_ENABLE_UNIT_TESTS OFF)
FetchContent_MakeAvailable(aselib)
## .... Adding your own library and executable projects
FetchContent_GetProperties(aselib)
target_link_libraries(MyTarget aselib)
```

## Build and run tests locally (on linux)

```shell
git clone https://github.com/Laguna1989/aselib.git
cd aselib
mkdir build
cd build
cmake ..
cmake --build .

cd test/unit_test
./aselib_test
```
Loading

0 comments on commit 1b2e37c

Please sign in to comment.