OpenRCT2/src/openrct2/core/Imaging.h

56 lines
1.5 KiB
C
Raw Normal View History

/*****************************************************************************
2020-07-21 15:04:34 +02:00
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2017-01-07 13:10:42 +01:00
#pragma once
2015-12-29 15:32:51 +01:00
2018-06-22 22:58:39 +02:00
#include "../common.h"
#include "../drawing/Drawing.h"
2018-05-09 00:39:03 +02:00
#include <functional>
#include <istream>
2018-05-07 22:32:24 +02:00
#include <memory>
#include <string_view>
#include <vector>
2017-06-09 00:02:39 +02:00
struct rct_drawpixelinfo;
2020-05-19 21:05:56 +02:00
2018-05-07 22:32:24 +02:00
enum class IMAGE_FORMAT
{
UNKNOWN,
2018-06-22 22:58:39 +02:00
AUTOMATIC, // Automatically detect from file extension
2018-05-07 22:32:24 +02:00
BITMAP,
PNG,
2018-06-22 22:58:39 +02:00
PNG_32, // Force load to 32bpp buffer
2018-05-07 22:32:24 +02:00
};
struct Image
{
// Meta
uint32_t Width{};
uint32_t Height{};
uint32_t Depth{};
2018-05-07 22:32:24 +02:00
// Data
std::vector<uint8_t> Pixels;
2020-05-27 21:12:01 +02:00
std::unique_ptr<GamePalette> Palette;
uint32_t Stride{};
2018-05-07 22:32:24 +02:00
};
2018-05-09 00:39:03 +02:00
using ImageReaderFunc = std::function<Image(std::istream&, IMAGE_FORMAT)>;
2018-05-07 22:32:24 +02:00
2017-01-07 13:10:42 +01:00
namespace Imaging
{
IMAGE_FORMAT GetImageFormatFromPath(std::string_view path);
Image ReadFromFile(std::string_view path, IMAGE_FORMAT format = IMAGE_FORMAT::AUTOMATIC);
Image ReadFromBuffer(const std::vector<uint8_t>& buffer, IMAGE_FORMAT format = IMAGE_FORMAT::AUTOMATIC);
void WriteToFile(std::string_view path, const Image& image, IMAGE_FORMAT format = IMAGE_FORMAT::AUTOMATIC);
2018-05-09 00:39:03 +02:00
void SetReader(IMAGE_FORMAT format, ImageReaderFunc impl);
2018-06-22 22:58:39 +02:00
} // namespace Imaging