SDLPainter 0.1.0
QPainter benzeri SDL3 + OpenGL/Vulkan 2D çizim kütüphanesi
Yüklüyor...
Arıyor...
Eşleşme Yok
image.h
1#pragma once
2
3#include "sdl_painter/renderer.h"
4#include "sdl_painter/texture.h"
5
6#include <cstdint>
7#include <memory>
8#include <string>
9
10namespace sdl_painter {
11
12class IRenderer;
13
25class Image {
26 public:
27 Image() = default;
28
30 explicit Image(const std::string& file_path);
31
32 ~Image();
33
34 // Non-copyable, movable
35 Image(const Image&) = delete;
36 Image& operator=(const Image&) = delete;
37 Image(Image&&) noexcept;
38 Image& operator=(Image&&) noexcept;
39
41 [[nodiscard]] bool IsValid() const noexcept { return mRawData != nullptr; }
42
44 [[nodiscard]] int32_t Width() const noexcept { return mWidth; }
45
47 [[nodiscard]] int32_t Height() const noexcept { return mHeight; }
48
50 [[nodiscard]] int32_t Channels() const noexcept { return mChannels; }
51
53 [[nodiscard]] const uint8_t* RawData() const noexcept {
54 return mRawData.get();
55 }
56
60 [[nodiscard]] static Image CreateFromData(const uint8_t* data, int32_t width,
61 int32_t height, int32_t channels);
62
64 TextureHandle Upload(IRenderer& renderer) const;
65
67 [[nodiscard]] TextureHandle GetHandle() const noexcept {
68 return mHandle.Handle();
69 }
70
71 private:
72 struct StbDeleter {
73 void operator()(uint8_t* ptr) const;
74 };
75
76 std::unique_ptr<uint8_t, StbDeleter> mRawData;
77 int32_t mWidth{0};
78 int32_t mHeight{0};
79 int32_t mChannels{0};
80 mutable Texture
81 mHandle;
82};
83
84} // namespace sdl_painter
Backend-agnostik soyut renderer arayüzü.
Definition renderer.h:32
int32_t Width() const noexcept
Görüntü genişliği (piksel).
Definition image.h:44
bool IsValid() const noexcept
Görüntü başarıyla yüklendi mi?
Definition image.h:41
TextureHandle GetHandle() const noexcept
Önceden yüklenmiş texture tanımlayıcısını döner (kInvalidTexture → henüz yüklenmedi).
Definition image.h:67
int32_t Channels() const noexcept
Kanal sayısı (3 = RGB, 4 = RGBA).
Definition image.h:50
static Image CreateFromData(const uint8_t *data, int32_t width, int32_t height, int32_t channels)
Ham piksel verisinden görüntü oluştur (veriler kopyalanır).
const uint8_t * RawData() const noexcept
Ham piksel verisi (stb_image tarafından yüklendi).
Definition image.h:53
int32_t Height() const noexcept
Görüntü yüksekliği (piksel).
Definition image.h:47
Image(const std::string &file_path)
Dosyadan görüntü yükle. Başarısız olursa IsValid() false döner.
TextureHandle Upload(IRenderer &renderer) const
Texture'ı renderer'a yükle; ikinci çağrıda önbelleği döner.