C

Qt Quick Ultralite image_cache Example

cmake_minimum_required (VERSION 3.15)

project(image_cache VERSION 0.0.1 LANGUAGES C CXX ASM ASM_MASM)
if (NOT TARGET Qul::Core)
    find_package(Qul)
endif()

# All photos have the same width, height and format. We display 4 photo slideshow.
# For user convenience we need UL-3093 and also need to clarify UL-3097.
if(QUL_PLATFORM MATCHES "^ek-ra6m3g")
# Two 480x288 RGB332 images fit to the RAM at the same time
# 138240 is decompressed photo size in bytes (QImage) for 8 bits per pixel
math(EXPR cache_size_in_bytes "138240 * 2")
else()
# 552960 is decompressed photo size in bytes (QImage) for 32 bits per pixel
math(EXPR cache_size_in_bytes "552960 * 4")
endif()

set(QUL_DEFAULT_RESOURCE_CACHE_POLICY "OnDemand")

# Set FreeRTOS heap size (needed for cache entries)
# STM32F769i has a limited amount of available heap memory in SRAM, but a custom
# memory allocator ensures that images are kept in the larger SDRAM area.
if (QUL_OS STREQUAL "FreeRTOS" AND NOT QUL_PLATFORM MATCHES "^stm32f769i")
    if (QUL_PLATFORM STREQUAL "mimxrt1170-evk-freertos")
        # NXP 1170 needs additional 2*3.6MB for the screen layer
        math(EXPR heap_size "8 * 1024 * 1024 + ${cache_size_in_bytes}")
    else()
        math(EXPR heap_size "1024 * 1024 + ${cache_size_in_bytes}")
    endif()
    add_compile_definitions(configTOTAL_HEAP_SIZE=${heap_size})
endif()

# RH850 doesn't have enough internal flash memory
if (QUL_PLATFORM STREQUAL "rh850-d1m1a-baremetal")
    set(QUL_DEFAULT_RESOURCE_COMPRESSION ON)
endif()

qul_add_target(image_cache ImageModel.cpp)
qul_target_qml_sources(image_cache image_cache.qml)

qul_target_generate_interfaces(image_cache ImageModel.h)

app_target_setup_os(image_cache)
app_target_default_entrypoint(image_cache image_cache)
qul_set_maximum_resource_cache_size(image_cache CACHE_SIZE ${cache_size_in_bytes})

set(IMAGES
    "images/basse-terre-guadeloupe.jpg"
    "images/grand-canyon-arizona.jpg"
    "images/grand-canyon-national-park.jpg"
    "images/Jokulsarlon-glacier-lagoon-iceland.jpg"
    "images/reine-lofoten-islands.jpg"
    "images/sequoia-national-park.jpg"
    "images/sogn-og-fjordane.jpg"
    "images/yosemite-national-park.jpg"
)

if(QUL_PLATFORM MATCHES "^ek-ra6m3g")
set_source_files_properties(${IMAGES}
    PROPERTIES
        QUL_RESOURCE_IMAGE_PIXEL_FORMAT RGB332)
endif()

qul_add_resource(image_cache
    FILES
        ${IMAGES}
)