fix: pixel format

This commit is contained in:
Haibo 2023-09-12 10:11:53 +08:00
parent 4b9f4b11f9
commit 76b3b4fbed
2 changed files with 1299 additions and 1291 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,214 +1,216 @@
// Copyright (c) 2016-2018 Kiwano - Nomango // Copyright (c) 2016-2018 Kiwano - Nomango
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in // The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software. // all copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/core/Resource.h> #include <kiwano/core/Resource.h>
#include <kiwano/render/NativeObject.h> #include <kiwano/render/NativeObject.h>
namespace kiwano namespace kiwano
{ {
KGE_DECLARE_SMART_PTR(Texture); KGE_DECLARE_SMART_PTR(Texture);
/** /**
* \addtogroup Render * \addtogroup Render
* @{ * @{
*/ */
/** /**
* \~chinese * \~chinese
* @brief * @brief
* @details * @details
*/ */
enum class InterpolationMode enum class InterpolationMode
{ {
Linear, ///< 双线性插值,对周围四个像素进行两次线性插值计算,在图像放大时可能会模糊 Linear, ///< 双线性插值,对周围四个像素进行两次线性插值计算,在图像放大时可能会模糊
Nearest ///< 最邻近插值,取最邻近的像素点的颜色值 Nearest ///< 最邻近插值,取最邻近的像素点的颜色值
}; };
/// \~chinese /// \~chinese
/// @brief 像素大小 /// @brief 像素大小
typedef math::Vec2T<uint32_t> PixelSize; typedef math::Vec2T<uint32_t> PixelSize;
/** /**
* \~chinese * \~chinese
* @brief * @brief
* @details * @details
*/ */
enum class PixelFormat enum class PixelFormat
{ {
Bpp32RGB, Bpp32RGB,
Bpp32RGBA, Bpp32RGBA,
}; Bpp32BGR,
Bpp32BGRA,
/** };
* \~chinese
* @brief /**
*/ * \~chinese
class KGE_API Texture : public NativeObject * @brief
{ */
public: class KGE_API Texture : public NativeObject
/// \~chinese {
/// @brief 预加载本地图片 public:
static TexturePtr Preload(const String& file_path); /// \~chinese
/// @brief 预加载本地图片
/// \~chinese static TexturePtr Preload(const String& file_path);
/// @brief 预加载图片资源
static TexturePtr Preload(const Resource& res); /// \~chinese
/// @brief 预加载图片资源
/// \~chinese static TexturePtr Preload(const Resource& res);
/// @brief 从内存加载位图纹理
static TexturePtr Preload(const PixelSize& size, const BinaryData& data, PixelFormat format); /// \~chinese
/// @brief 从内存加载位图纹理
Texture(); static TexturePtr Preload(const PixelSize& size, const BinaryData& data, PixelFormat format);
/// \~chinese Texture();
/// @brief 从本地文件创建纹理
Texture(const String& file_path); /// \~chinese
/// @brief 从本地文件创建纹理
/// \~chinese Texture(const String& file_path);
/// @brief 从资源创建纹理
Texture(const Resource& res); /// \~chinese
/// @brief 从资源创建纹理
virtual ~Texture(); Texture(const Resource& res);
/// \~chinese virtual ~Texture();
/// @brief 加载本地文件
bool Load(const String& file_path); /// \~chinese
/// @brief 加载本地文件
/// \~chinese bool Load(const String& file_path);
/// @brief 加载资源
bool Load(const Resource& res); /// \~chinese
/// @brief 加载资源
/// \~chinese bool Load(const Resource& res);
/// @brief 获取纹理宽度
float GetWidth() const; /// \~chinese
/// @brief 获取纹理宽度
/// \~chinese float GetWidth() const;
/// @brief 获取纹理高度
float GetHeight() const; /// \~chinese
/// @brief 获取纹理高度
/// \~chinese float GetHeight() const;
/// @brief 获取纹理大小
Size GetSize() const; /// \~chinese
/// @brief 获取纹理大小
/// \~chinese Size GetSize() const;
/// @brief 获取像素宽度
uint32_t GetWidthInPixels() const; /// \~chinese
/// @brief 获取像素宽度
/// \~chinese uint32_t GetWidthInPixels() const;
/// @brief 获取像素高度
uint32_t GetHeightInPixels() const; /// \~chinese
/// @brief 获取像素高度
/// \~chinese uint32_t GetHeightInPixels() const;
/// @brief 获取像素大小
PixelSize GetSizeInPixels() const; /// \~chinese
/// @brief 获取像素大小
/// \~chinese PixelSize GetSizeInPixels() const;
/// @brief 获取像素插值方式
InterpolationMode GetBitmapInterpolationMode() const; /// \~chinese
/// \~chinese /// @brief 获取像素插值方式
/// @brief 设置大小 InterpolationMode GetBitmapInterpolationMode() const;
void SetSize(const Size& size); /// \~chinese
/// @brief 设置大小
/// \~chinese void SetSize(const Size& size);
/// @brief 设置像素大小
void SetSizeInPixels(const PixelSize& size); /// \~chinese
/// @brief 设置像素大小
/// \~chinese void SetSizeInPixels(const PixelSize& size);
/// @brief 设置像素插值方式
void SetInterpolationMode(InterpolationMode mode); /// \~chinese
/// @brief 设置像素插值方式
/// \~chinese void SetInterpolationMode(InterpolationMode mode);
/// @brief 拷贝纹理
/// @param copy_from 源纹理 /// \~chinese
void CopyFrom(TexturePtr copy_from); /// @brief 拷贝纹理
/// @param copy_from 源纹理
/// \~chinese void CopyFrom(TexturePtr copy_from);
/// @brief 拷贝纹理
/// @param copy_from 源纹理 /// \~chinese
/// @param src_rect 源纹理裁剪矩形 /// @brief 拷贝纹理
/// @param dest_point 拷贝至目标位置 /// @param copy_from 源纹理
void CopyFrom(TexturePtr copy_from, const Rect& src_rect, const Point& dest_point); /// @param src_rect 源纹理裁剪矩形
/// @param dest_point 拷贝至目标位置
/// \~chinese void CopyFrom(TexturePtr copy_from, const Rect& src_rect, const Point& dest_point);
/// @brief 设置默认的像素插值方式
static void SetDefaultInterpolationMode(InterpolationMode mode); /// \~chinese
/// @brief 设置默认的像素插值方式
/// \~chinese static void SetDefaultInterpolationMode(InterpolationMode mode);
/// @brief 获取默认的像素插值方式
static InterpolationMode GetDefaultInterpolationMode(); /// \~chinese
/// @brief 获取默认的像素插值方式
private: static InterpolationMode GetDefaultInterpolationMode();
Size size_;
PixelSize size_in_pixels_; private:
InterpolationMode interpolation_mode_; Size size_;
PixelSize size_in_pixels_;
static InterpolationMode default_interpolation_mode_; InterpolationMode interpolation_mode_;
};
static InterpolationMode default_interpolation_mode_;
/** @} */ };
inline float Texture::GetWidth() const /** @} */
{
return size_.x; inline float Texture::GetWidth() const
} {
return size_.x;
inline float Texture::GetHeight() const }
{
return size_.y; inline float Texture::GetHeight() const
} {
return size_.y;
inline Size Texture::GetSize() const }
{
return size_; inline Size Texture::GetSize() const
} {
return size_;
inline uint32_t Texture::GetWidthInPixels() const }
{
return size_in_pixels_.x; inline uint32_t Texture::GetWidthInPixels() const
} {
return size_in_pixels_.x;
inline uint32_t Texture::GetHeightInPixels() const }
{
return size_in_pixels_.y; inline uint32_t Texture::GetHeightInPixels() const
} {
return size_in_pixels_.y;
inline PixelSize Texture::GetSizeInPixels() const }
{
return size_in_pixels_; inline PixelSize Texture::GetSizeInPixels() const
} {
return size_in_pixels_;
inline InterpolationMode Texture::GetBitmapInterpolationMode() const }
{
return interpolation_mode_; inline InterpolationMode Texture::GetBitmapInterpolationMode() const
} {
return interpolation_mode_;
inline void Texture::SetSize(const Size& size) }
{
size_ = size; inline void Texture::SetSize(const Size& size)
} {
size_ = size;
inline void Texture::SetSizeInPixels(const PixelSize& size) }
{
size_in_pixels_ = size; inline void Texture::SetSizeInPixels(const PixelSize& size)
} {
size_in_pixels_ = size;
} // namespace kiwano }
} // namespace kiwano