Skip to content

Commit

Permalink
Merge pull request #17 from t0rakka/async_decode
Browse files Browse the repository at this point in the history
Async decode
  • Loading branch information
t0rakka authored Nov 17, 2024
2 parents a18d7f6 + a586d96 commit 491033b
Show file tree
Hide file tree
Showing 52 changed files with 46,354 additions and 28,151 deletions.
2 changes: 1 addition & 1 deletion build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PROJECT(mango CXX C ASM)
# ------------------------------------------------------------------------------

set(MANGO_VERSION_MAJOR 1)
set(MANGO_VERSION_MINOR 4)
set(MANGO_VERSION_MINOR 5)
set(MANGO_VERSION_PATCH 0)
set(MANGO_VERSION_STRING ${MANGO_VERSION_MAJOR}.${MANGO_VERSION_MINOR}.${MANGO_VERSION_PATCH})

Expand Down
22 changes: 11 additions & 11 deletions build/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
project(
'mango', 'c', 'cpp',
meson_version: '>= 0.50.0',
version: '1.4.0',
version: '1.5.0',
default_options : [
'c_std=c11',
'cpp_std=c++17',
Expand Down Expand Up @@ -583,6 +583,16 @@ external_deflate_sources = files(
'../source/external/libdeflate/lib/zlib_decompress.c',
)

if is_arm
external_deflate_sources += files(
'../source/external/libdeflate/lib/arm/cpu_features.c'
)
elif is_x86
external_deflate_sources += files(
'../source/external/libdeflate/lib/x86/cpu_features.c',
)
endif

external_zlib_headers = files(
'../source/external/zlib/crc32.h',
'../source/external/zlib/inffast.h',
Expand Down Expand Up @@ -610,16 +620,6 @@ external_zlib_sources = files(
'../source/external/zlib/uncompr.c',
)

if is_arm
external_deflate_sources += files(
'../source/external/libdeflate/lib/arm/cpu_features.c'
)
elif is_x86
external_deflate_sources += files(
'../source/external/libdeflate/lib/x86/cpu_features.c',
)
endif

external_unrar_headers = files(
'../source/external/unrar/rarvm.hpp',
'../source/external/unrar/suballoc.hpp',
Expand Down
1 change: 1 addition & 0 deletions example/image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_executable(jpeg_reader jpeg_reader/jpeg_reader.cpp)
add_executable(icc_p3_test icc/p3.cpp)
add_executable(blitter blitter/blitter.cpp)
add_executable(palette palette/palette.cpp)
add_executable(async_decode async_decode/async_decode.cpp)

file(COPY icc/DisplayP3-v2-micro.icc DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY blitter/conquer.jpg DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
73 changes: 73 additions & 0 deletions example/image/async_decode/async_decode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
MANGO Multimedia Development Platform
Copyright (C) 2012-2024 Twilight Finland 3D Oy Ltd. All rights reserved.
*/
#include <mango/core/core.hpp>
#include <mango/image/image.hpp>
#include <mango/filesystem/filesystem.hpp>

using namespace mango;
using namespace mango::image;
using namespace mango::filesystem;

void test(const char* filename, int cancel_ms)
{
File file(filename);
ImageDecoder decoder(file, filename);

if (!decoder.isDecoder())
{
return;
}

ImageHeader header = decoder.header();
Bitmap bitmap(header);

u64 time0 = Time::ms();

float progress = 0.0f;
std::mutex mutex;

auto future = decoder.launch([&mutex, &progress] (const ImageDecodeRect& rect)
{
std::lock_guard lock(mutex);
progress += rect.progress;
float percent = std::round(progress * 1000.0f) / 10.0f;
printLine("[+] Update: [{:>5} x {:<5}] ({:>5}, {:>5} ) {:6.1f} %",
rect.width, rect.height, rect.x, rect.y, percent);
}, bitmap);

if (cancel_ms >= 0)
{
Sleep::ms(cancel_ms);
decoder.cancel();
}

future.get();

u64 time1 = Time::ms();
printLine("Decoding: {} ms", time1 - time0);

bitmap.save("test.png");
}

int main(int argc, const char* argv[])
{
if (argc < 2)
{
printLine("Too few arguments. usage: <filename> <cancel:ms>");
exit(1);
}

const char* filename = argv[1];

int cancel_ms = -1;
if (argc == 3)
{
cancel_ms = std::atoi(argv[2]);
}

//printEnable(Print::Info, true);

test(filename, cancel_ms);
}
2 changes: 1 addition & 1 deletion example/image/jpeg_benchmark/jpeg_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ size_t toojpeg_save(const char* filename, const Surface& surface)
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__JPEG

#include "../png_benchmark/wuffs/wuffs-unsupported-snapshot.c"
#include "../png_benchmark/wuffs/wuffs-v0.4.c"

class WuffsCallbacks : public wuffs_aux::DecodeImageCallbacks
{
Expand Down
2 changes: 1 addition & 1 deletion example/image/png_benchmark/png_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ size_t save_fpnge(const Bitmap& bitmap)
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__ZLIB

#include "wuffs/wuffs-unsupported-snapshot.c"
#include "wuffs/wuffs-v0.4.c"

class WuffsCallbacks : public wuffs_aux::DecodeImageCallbacks
{
Expand Down
Loading

0 comments on commit 491033b

Please sign in to comment.