38 lines
852 B
C++
38 lines
852 B
C++
//
|
|
// Image.cpp
|
|
// libscgui
|
|
//
|
|
// Created by Bob Polis at 2020-10-23
|
|
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
|
//
|
|
|
|
#include "Image.hpp"
|
|
#include <SDL2/SDL_image.h>
|
|
#include <stdexcept>
|
|
|
|
using namespace sc::gui;
|
|
|
|
Image::Image(int w, int h) {
|
|
Uint32 rmask, gmask, bmask, amask;
|
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
rmask = 0xff000000;
|
|
gmask = 0x00ff0000;
|
|
bmask = 0x0000ff00;
|
|
amask = 0x000000ff;
|
|
#else
|
|
rmask = 0x000000ff;
|
|
gmask = 0x0000ff00;
|
|
bmask = 0x00ff0000;
|
|
amask = 0xff000000;
|
|
#endif
|
|
SDL_Surface* s {SDL_CreateRGBSurface(0, w, h, 32, rmask, gmask, bmask, amask)};
|
|
_s.reset(s);
|
|
}
|
|
|
|
Image::Image(const std::string& path) {
|
|
// load image from file into surface
|
|
SDL_Surface* loaded = IMG_Load(path.c_str());
|
|
if (!loaded) throw std::runtime_error(IMG_GetError());
|
|
_s.reset(loaded);
|
|
}
|