Files
dolphin/Source/Core/VideoCommon/ImageWrite.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.3 KiB
C++
Raw Normal View History

// Copyright 2008 Dolphin Emulator Project
2015-05-18 01:08:10 +02:00
// Licensed under GPLv2+
// Refer to the license.txt file included.
2008-12-08 05:25:12 +00:00
#include <list>
2014-06-03 01:08:54 -04:00
#include <string>
#include <vector>
2008-12-08 05:25:12 +00:00
2016-01-17 16:54:31 -05:00
#include "Common/CommonTypes.h"
2017-01-15 21:46:32 +01:00
#include "Common/File.h"
2014-02-17 05:18:15 -05:00
#include "Common/FileUtil.h"
#include "Common/Image.h"
2008-12-08 05:25:12 +00:00
2015-12-26 16:00:23 -05:00
bool SaveData(const std::string& filename, const std::string& data)
2008-12-08 05:25:12 +00:00
{
2013-02-28 19:33:39 -06:00
std::ofstream f;
2017-01-15 22:46:43 +01:00
File::OpenFStream(f, filename, std::ios::binary);
f << data;
return true;
2008-12-08 05:25:12 +00:00
}
2013-11-15 13:00:38 +13:00
/*
TextureToPng
Inputs:
data : This is an array of RGBA with 8 bits per channel. 4 bytes for each pixel.
row_stride: Determines the amount of bytes per row of pixels.
*/
bool TextureToPng(const u8* data, int row_stride, const std::string& filename, int width,
int height, bool save_alpha)
2013-11-15 13:00:38 +13:00
{
if (!data)
return false;
if (save_alpha)
{
return Common::SavePNG(filename, data, Common::ImageByteFormat::RGBA, width, height,
row_stride);
}
std::vector<u8> buffer;
buffer.reserve(width * height * 3);
for (int y = 0; y < height; ++y)
2014-08-30 16:51:27 -04:00
{
const u8* pos = data + y * row_stride;
for (int x = 0; x < width; ++x)
2013-11-15 13:00:38 +13:00
{
buffer.push_back(pos[x * 4]);
buffer.push_back(pos[x * 4 + 1]);
buffer.push_back(pos[x * 4 + 2]);
2013-11-15 13:00:38 +13:00
}
}
return Common::SavePNG(filename, buffer.data(), Common::ImageByteFormat::RGB, width, height);
2013-11-15 13:00:38 +13:00
}