ppdnode/lib/image_model.h
2024-05-07 20:10:53 -04:00

48 lines
876 B
C++

#include "imgui.h"
#include <sstream>
#include <string_view>
#if defined(__APPLE__)
#include <SDL2/SDL.h>
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <SDL2/SDL_opengles.h>
#else
#include <SDL2/SDL_opengl.h>
#endif
#else
#include <SDL.h>
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <SDL_opengles2.h>
#else
#include <SDL_opengl.h>
#endif
#endif
class ImageBundle {
public:
int width;
int height;
int channels;
ImTextureID texture;
GLuint *glTextureID;
std::string_view raw_buffer;
uint8_t *image;
bool loaded;
std::string fname;
ImageBundle() {
fname = "";
loaded = false;
}
float aspectRatio() { return (float)width / (float)height; }
int calcResizedWidth(int newHeight) {
return (int)((float)newHeight * (1.0 / aspectRatio()));
}
int calcResizedHeight(int newWidth) {
return (int)((float)newWidth * (aspectRatio()));
}
};