예제 #1
0
파일: BitmapIO.cpp 프로젝트: Sophrinix/gosu
void Gosu::saveImageFile(const Gosu::Bitmap& bitmap, Gosu::Writer writer,
    const std::wstring& formatHint)
{
    int ok;
    
    if (isExtension(formatHint.c_str(), L"bmp"))
    {
        ok = stbi_write_bmp_to_func(stbiWriteToWriter, &writer,
                                    bitmap.width(), bitmap.height(), 4, bitmap.data());
    }
    else if (isExtension(formatHint.c_str(), L"tga"))
    {
        stbi_write_tga_with_rle = 0;
        ok = stbi_write_tga_to_func(stbiWriteToWriter, &writer,
                                    bitmap.width(), bitmap.height(), 4, bitmap.data());
    }
    else
    {
        ok = stbi_write_png_to_func(stbiWriteToWriter, &writer,
                                    bitmap.width(), bitmap.height(), 4, bitmap.data(), 0);
    }
    
    if (ok == 0)
        throw std::runtime_error("Could not save image data to memory (format hint = '" +
                                 Gosu::wstringToUTF8(formatHint) + "'");
}
예제 #2
0
파일: BitmapIO.cpp 프로젝트: Virolea/gosu
void Gosu::saveImageFile(const Gosu::Bitmap& bitmap, Gosu::Writer writer,
    const std::wstring& formatHint)
{
    unsigned char* rgba =
        const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(bitmap.data()));
    
    // TODO: Use the new *_to_func functions in stb_imagewrite.h instead:
    // https://github.com/nothings/stb/blob/master/stb_image_write.h#L39
    int length;
    unsigned char* png =
        stbi_write_png_to_mem(rgba, 0, bitmap.width(), bitmap.height(), 4, &length);
    
    if (png == 0)
        throw std::runtime_error("Could not save image data to memory");
    
    try
    {
        writer.write(png, length);
    }
    catch (...)
    {
        STBIW_FREE(png);
        throw;
    }
    
    STBIW_FREE(png);
}
예제 #3
0
파일: BitmapIO.cpp 프로젝트: johan--/gosu
void Gosu::saveImageFile(const Gosu::Bitmap& bitmap, Gosu::Writer writer,
    const std::wstring& formatHint)
{
    unsigned char* rgba =
        const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(bitmap.data()));
    
    int length;
    unsigned char* png =
        stbi_write_png_to_mem(rgba, 0, bitmap.width(), bitmap.height(), 4, &length);
    
    if (png == 0)
        throw std::runtime_error("Could not save image data to memory");
    
    try
    {
        writer.write(png, length);
    }
    catch (...)
    {
        STBIW_FREE(png);
        throw;
    }
    
    STBIW_FREE(png);
}
예제 #4
0
파일: BitmapIO.cpp 프로젝트: Virolea/gosu
void Gosu::saveImageFile(const Gosu::Bitmap& bitmap, const std::wstring& filename)
{
    int ok;
    std::string utf8 = Gosu::wstringToUTF8(filename);
    
    if (isExtension(filename.c_str(), L"bmp"))
    {
        ok = stbi_write_bmp(utf8.c_str(), bitmap.width(), bitmap.height(), 4, bitmap.data());
    }
    else if (isExtension(filename.c_str(), L"tga"))
    {
        ok = stbi_write_tga(utf8.c_str(), bitmap.width(), bitmap.height(), 4, bitmap.data());
    }
    else
    {
        ok = stbi_write_png(utf8.c_str(), bitmap.width(), bitmap.height(), 4, bitmap.data(), 0);
    }
    
    if (ok == 0)
        throw std::runtime_error("Could not save image data to file: " + utf8);
}