C

Qt Quick Ultralite 图像解码示例

cmake_minimum_required (VERSION 3.21.1)

if (QUL_PLATFORM MATCHES "autosar")
    return()
endif()

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

if(CMAKE_CROSSCOMPILING)
    if(QUL_PLATFORM MATCHES "^stm32")
        # Custom JPG encoder supported
        if(QUL_PLATFORM MATCHES "^stm32f7")
            set(STM32XX "stm32f7")

            qul_add_target(imagedecoder
                QML_PROJECT mcu_imagedecoder.qmlproject
                os/${QUL_OS_LOWERCASE}/main.cpp
                SELECTORS filesystemSupport
            )

            target_sources(imagedecoder PRIVATE
                ../fileloading/3rdparty/FatFs/src/diskio.c
                ../fileloading/3rdparty/FatFs/src/ff.c
                ../fileloading/3rdparty/FatFs/src/ff_gen_drv.c
                ../fileloading/3rdparty/FatFs/src/option/unicode.c
                ../fileloading/3rdparty/FatFs/src/sd_diskio.c
                ${QUL_BOARD_SDK_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_sdmmc.c
                ${QUL_BOARD_SDK_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_sd.c
                ${QUL_BOARD_SDK_DIR}/Drivers/BSP/STM32F769I-Discovery/stm32f769i_discovery_sd.c
                ${QUL_BOARD_SDK_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_jpeg.c
                ${CMAKE_CURRENT_SOURCE_DIR}/stm/${STM32XX}/stm32f7xx_hal_msp.c
            )

            target_include_directories(imagedecoder PRIVATE
                ../fileloading/
                ../fileloading/3rdparty/FatFs/src/
            )

            target_compile_definitions(imagedecoder PRIVATE
                SUPPORT_FILESYSTEM
                FF_FS_READONLY
            )
        elseif(QUL_PLATFORM MATCHES "^stm32h7")
            set(STM32XX "stm32h7")

            qul_add_target(imagedecoder
                QML_PROJECT mcu_imagedecoder_stm32h750b.qmlproject
                os/${QUL_OS_LOWERCASE}/main.cpp
                SELECTORS noFilesystemSupport
            )

            target_sources(imagedecoder PRIVATE
                ${QUL_BOARD_SDK_DIR}/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_jpeg.c
                ${CMAKE_CURRENT_SOURCE_DIR}/stm/${STM32XX}/stm32h7xx_hal_msp.c
            )
        endif()

        target_sources(imagedecoder PRIVATE
            ${CMAKE_CURRENT_SOURCE_DIR}/stm/${STM32XX}/board_config.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/stm/${STM32XX}/buffer_config.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/stm/stmimagedecoder.cpp
            common/jpeg.cpp
            3rdparty/stm/Utilities/JPEG/jpeg_utils.c
        )

        target_include_directories(imagedecoder PRIVATE
            ${QUL_BOARD_SDK_DIR}/Utilities/JPEG
            ${CMAKE_CURRENT_SOURCE_DIR}/stm/${STM32XX}
            ${CMAKE_CURRENT_SOURCE_DIR}/stm
        )

        target_compile_definitions(imagedecoder PRIVATE
            USE_JPEG_DECODER=1
            PLATFORM_OS=${QUL_OS_LOWERCASE}
            USE_DMA_BASED_JPEG_DECODING
        )

        target_link_libraries(imagedecoder PRIVATE Qul::PlatformBSPConfig)

        if(NOT IAR)
            # Required for SDK code to build
            target_compile_options(imagedecoder PRIVATE
                -Wno-unused-parameter
            )
        endif()
    elseif(QUL_PLATFORM MATCHES "tviic2d6m-baremetal")
        # In CI we test with the 500-BGA variant with graphics driver TVII_GRAPHICS_DRIVER_DIR_1_1_0_4M6M
        # (infineon-traveo-t2g-cyt4dn-baremetal-500-bga-windows-ghs-arm)
        # and to be able to build the imagedecoder backend an SDL upgrade is required.
        if(QUL_TVIIC2D6M_BOARD_REVISION STREQUAL "500-BGA")
            return()
        endif()

        if(NOT TVII_JPEG_DRIVER_DIR)
            message(FATAL_ERROR "TVII_JPEG_DRIVER_DIR is not set. Reconfigure the example by providing the path to the JPEG decoder SDK root folder.")
        else()
            if(IAR)
                set(TVII_JPEG_DRIVER_SDK_TOOLCHAIN_DIR "iar")
            else()
                set(TVII_JPEG_DRIVER_SDK_TOOLCHAIN_DIR "arm-none-ghs")
            endif()

            find_library(TVII_JPEG_DRIVER_LIB libjpeg_driver_cm7.a
                PATHS ${TVII_JPEG_DRIVER_DIR}/Bin/${TVII_JPEG_DRIVER_SDK_TOOLCHAIN_DIR}/production/bin
                    NO_CMAKE_SYSTEM_PATH
                    NO_DEFAULT_PATH
                    NO_CMAKE_FIND_ROOT_PATH)

            if(NOT TVII_JPEG_DRIVER_LIB)
                message(STATUS "TVII_JPEG_DRIVER static library not found: building libjpeg_driver_cm7 from sources.")

                set(TVII_JPEG_DRIVER_LIB libjpeg_driver_cm7)
                add_library(${TVII_JPEG_DRIVER_LIB} STATIC)
                set_target_properties(${TVII_JPEG_DRIVER_LIB} PROPERTIES OUTPUT_NAME
                    jpeg_driver_cm7_${QUL_PLATFORM}_${CMAKE_HOST_SYSTEM_NAME}_${QUL_COMPILER_NAME}_$<CONFIG>
                )

                target_sources(${TVII_JPEG_DRIVER_LIB} PRIVATE
                    ${TVII_JPEG_DRIVER_DIR}/Source/jpgdec/lib_src/intjpg_drvif.c
                    ${TVII_JPEG_DRIVER_DIR}/Source/jpgdec/lib_src/intjpg_ctrl.c
                )

                target_include_directories(${TVII_JPEG_DRIVER_LIB} PRIVATE
                    ${TVII_JPEG_DRIVER_DIR}/Source/jpgdec/include
                    ${TVII_JPEG_DRIVER_DIR}/Source/jpgdec/lib_include
                )
                target_link_libraries(${TVII_JPEG_DRIVER_LIB} PRIVATE Qul::PlatformArchitecture Qul::PlatformBSPConfig)
                target_compile_definitions(${TVII_JPEG_DRIVER_LIB} PRIVATE PRODUCTION)

                if(GREENHILLS)
                    target_compile_options(${TVII_JPEG_DRIVER_LIB} PRIVATE
                        "SHELL:-section .bss=.cyjpg_bss"
                        "SHELL:-section .data=.cyjpg_data"
                        "SHELL:-section .rodata=.cyjpg_rodata"
                        "SHELL:-section .text=.cyjpg_text"
                    )
                else()
                    target_compile_options(${TVII_JPEG_DRIVER_LIB} PRIVATE
                        "SHELL:--section .bss=.cyjpg_bss"
                        "SHELL:--section .data=.cyjpg_data"
                        "SHELL:--section .rodata=.cyjpg_rodata"
                        "SHELL:--section .text=.cyjpg_text"
                    )
                endif()

            else()
                message(STATUS "TVII_JPEG_DRIVER library found: ${TVII_JPEG_DRIVER_LIB}")
            endif()

            set(IMAGE_DECODER_SELECTORS noFilesystemSupport)

            qul_add_target(imagedecoder
                QML_PROJECT mcu_imagedecoder_traveo_t2g.qmlproject
                os/${QUL_OS_LOWERCASE}/main.cpp
                SELECTORS ${IMAGE_DECODER_SELECTORS}
            )

            target_sources(imagedecoder PRIVATE
                ${CMAKE_CURRENT_SOURCE_DIR}/traveo-t2g/board_config.cpp
                ${CMAKE_CURRENT_SOURCE_DIR}/traveo-t2g/traveot2gimagedecoder.cpp
                ${CMAKE_CURRENT_SOURCE_DIR}/traveo-t2g/tvii_jpeg.c
                common/jpeg.cpp
            )

            list(APPEND CMAKE_MODULE_PATH ${QUL_PLATFORM_TARGET_DIR}/../common/cmake/modules)
            # Old path needed for platform compatibility checks after UL-5159 (renamed folder from tvii-shared to common)
            list(APPEND CMAKE_MODULE_PATH ${QUL_PLATFORM_TARGET_DIR}/../tvii-shared/cmake/modules)
            find_package(TVII-SDK REQUIRED COMPONENTS basic_graphics util freetype)

            target_include_directories(imagedecoder PRIVATE
                ${CMAKE_CURRENT_SOURCE_DIR}/traveo-t2g/
                ${TVII_JPEG_DRIVER_DIR}/Source/jpgdec/include
                ${TVII_SDK_INCLUDE_DIRS}
            )

            target_link_libraries(imagedecoder PRIVATE Qul::PlatformBSPConfig ${TVII_JPEG_DRIVER_LIB})
            if(GREENHILLS)
                target_link_libraries(imagedecoder PRIVATE -T ${CMAKE_CURRENT_SOURCE_DIR}/traveo-t2g/JPEGDEC_register_map.ld)
            endif()

            if(IAR)
                target_compile_options(imagedecoder PRIVATE --diag_suppress=Pe940) # Pe940 missing return statement at end of non-void function (graphics driver 1.2.1)
            endif()
        endif()
    else()
        return()
    endif()
endif()

app_target_setup_os(imagedecoder)

if (QUL_PLATFORM STREQUAL "qt")
    find_package(Qt6 6.2 COMPONENTS Gui QUIET)
    if(NOT Qt6Gui_FOUND)
        message(FATAL_ERROR "Qt6 is required to build the image decoder example."
                            "Use -DCMAKE_PREFIX_PATH to specify the location to Qt6,"
                            "or check the documentation for this example for more detailed instructions."
                          )
    endif()

    qul_add_target(imagedecoder
        QML_PROJECT mcu_imagedecoder.qmlproject
        os/${QUL_OS_LOWERCASE}/main.cpp
        SELECTORS filesystemSupport
    )

    target_link_libraries(imagedecoder PRIVATE Qt6::Gui)
    target_sources(imagedecoder PRIVATE
                          desktop/desktopimagedecoder.cpp
                          desktop/board_config.cpp
                          ../fileloading/desktop/posixfilesystem.cpp
                  )
    target_compile_features(imagedecoder PRIVATE cxx_std_17)
    target_include_directories(imagedecoder PRIVATE ../fileloading/desktop/)
    if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
        target_compile_options(imagedecoder PRIVATE -Wno-maybe-uninitialized) # desktopimagedecoder.cpp:129ff read into a byte array.
    endif()

    add_custom_command(TARGET imagedecoder POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E
      copy_if_different "${CMAKE_CURRENT_LIST_DIR}/basse-terre-guadeloupe.jpg" "${CMAKE_CURRENT_LIST_DIR}/yosemite-national-park.jpg" "$<TARGET_FILE_DIR:imagedecoder>")
endif()