2016-05-04 19:24:41 +02:00
|
|
|
/*****************************************************************************
|
2018-06-15 14:07:34 +02:00
|
|
|
* Copyright (c) 2014-2018 OpenRCT2 developers
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-04 19:24:41 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-01-07 13:10:42 +01:00
|
|
|
#pragma once
|
2015-12-29 15:32:51 +01:00
|
|
|
|
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>
|
2018-05-07 19:45:15 +02:00
|
|
|
#include "../common.h"
|
2018-05-09 00:39:03 +02:00
|
|
|
#include "../drawing/Drawing.h"
|
2017-06-09 00:02:39 +02:00
|
|
|
|
2018-03-13 13:14:02 +01:00
|
|
|
struct rct_drawpixelinfo;
|
|
|
|
struct rct_palette;
|
2015-12-29 17:21:08 +01:00
|
|
|
|
2018-05-09 20:33:08 +02:00
|
|
|
struct PaletteBGRA
|
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
uint8_t Blue{};
|
|
|
|
uint8_t Green{};
|
|
|
|
uint8_t Red{};
|
|
|
|
uint8_t Alpha{};
|
2018-05-09 20:33:08 +02:00
|
|
|
};
|
|
|
|
|
2018-05-07 22:32:24 +02:00
|
|
|
enum class IMAGE_FORMAT
|
|
|
|
{
|
|
|
|
UNKNOWN,
|
|
|
|
AUTOMATIC, // Automatically detect from file extension
|
|
|
|
BITMAP,
|
|
|
|
PNG,
|
|
|
|
PNG_32, // Force load to 32bpp buffer
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Image
|
|
|
|
{
|
|
|
|
// Meta
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t Width{};
|
|
|
|
uint32_t Height{};
|
|
|
|
uint32_t Depth{};
|
2018-05-07 22:32:24 +02:00
|
|
|
|
|
|
|
// Data
|
2018-06-20 17:28:51 +02:00
|
|
|
std::vector<uint8_t> Pixels;
|
2018-05-07 22:32:24 +02:00
|
|
|
std::unique_ptr<rct_palette> Palette;
|
2018-06-20 17:28:51 +02:00
|
|
|
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
|
|
|
|
{
|
2018-05-08 22:41:41 +02:00
|
|
|
IMAGE_FORMAT GetImageFormatFromPath(const std::string_view& path);
|
2018-05-07 22:32:24 +02:00
|
|
|
Image ReadFromFile(const std::string_view& path, IMAGE_FORMAT format = IMAGE_FORMAT::AUTOMATIC);
|
2018-06-20 17:28:51 +02:00
|
|
|
Image ReadFromBuffer(const std::vector<uint8_t>& buffer, IMAGE_FORMAT format = IMAGE_FORMAT::AUTOMATIC);
|
2018-05-07 22:32:24 +02:00
|
|
|
void WriteToFile(const 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);
|
2017-01-07 13:10:42 +01:00
|
|
|
}
|