#include "grabResourceManager.h"

HRESULT grabResourceManager::LoadBitmapFromFile(const char* filename, ID2D1RenderTarget* rendertarget, ID2D1Bitmap** bitmap) {
    D2D1_SIZE_U size;
    int channels;
    HRESULT hr;
    
    stbi_uc* image = stbi_load(filename, (int*)&(size.width), (int*)&(size.height), &channels, 4);
    rendertarget->CreateBitmap(size, D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_R8G8B8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)), bitmap);
    hr = (*bitmap)->CopyFromMemory(NULL, image, 4U * size.width);
    free(image);
    
    return hr;
}

void grabResourceManager::LoadBitmapFromFile(const char* filename, std::string* buf) {
    D2D1_SIZE_U size;
    int channels;

    stbi_uc* image = stbi_load(filename, (int*)&(size.width), (int*)&(size.height), &channels, 4);

    size_t string_size = size.width * size.height * 4;
    buf->resize(string_size);

    memcpy(&((*buf)[0]), image, string_size);

    free(image);
}
