Program Listing for File sixtyfps_image.h

Return to documentation for file (/home/runner/work/sixtyfps/sixtyfps/api/sixtyfps-cpp/include/sixtyfps_image.h)

/* LICENSE BEGIN
    This file is part of the SixtyFPS Project -- https://sixtyfps.io
    Copyright (c) 2021 Olivier Goffart <olivier.goffart@sixtyfps.io>
    Copyright (c) 2021 Simon Hausmann <simon.hausmann@sixtyfps.io>

    SPDX-License-Identifier: GPL-3.0-only
    This file is also available under commercial licensing terms.
    Please contact info@sixtyfps.io for more information.
LICENSE END */
#pragma once
#include <string_view>
#include "sixtyfps_image_internal.h"
#include "sixtyfps_string.h"
#include "sixtyfps_sharedvector.h"

namespace sixtyfps {

#if !defined(DOXYGEN)
using cbindgen_private::types::Size;
#else
struct Size
{
    float width;
    float height;
};
#endif

struct Image
{
public:
    Image() : data(Data::None()) { }

    static Image load_from_path(const SharedString &file_path)
    {
        Image img;
        img.data = Data::AbsoluteFilePath(file_path);
        return img;
    }

    /*
    static Image load_from_argb(int width, int height, const SharedVector<uint32_t> &data) {
        Image img;
        img.data = Data::EmbeddedRgbaImage(width, height, data);
        return img;
    }
    */

    Size size() const { return cbindgen_private::types::sixtyfps_image_size(&data); }

    std::optional<sixtyfps::SharedString> path() const
    {
        if (auto *str = cbindgen_private::types::sixtyfps_image_path(&data)) {
            return *str;
        } else {
            return {};
        }
    }

    friend bool operator==(const Image &a, const Image &b) { return a.data == b.data; }
    friend bool operator!=(const Image &a, const Image &b) { return a.data != b.data; }

    explicit Image(cbindgen_private::types::Image inner) : data(inner) { }

private:
    using Tag = cbindgen_private::types::ImageInner::Tag;
    using Data = cbindgen_private::types::Image;
    Data data;
};

}