2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 23:09:55 -04:00
|
|
|
// 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>
|
2016-10-08 11:54:27 +02:00
|
|
|
#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"
|
2020-11-26 04:36:27 +01:00
|
|
|
#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);
|
2011-03-11 10:21:46 +00:00
|
|
|
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.
|
|
|
|
*/
|
2016-10-08 11:54:27 +02:00
|
|
|
bool TextureToPng(const u8* data, int row_stride, const std::string& filename, int width,
|
2020-11-26 04:36:27 +01:00
|
|
|
int height, bool save_alpha)
|
2013-11-15 13:00:38 +13:00
|
|
|
{
|
|
|
|
if (!data)
|
|
|
|
return false;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2020-11-26 04:36:27 +01:00
|
|
|
if (save_alpha)
|
2014-08-30 16:51:27 -04:00
|
|
|
{
|
2020-11-26 04:36:27 +01:00
|
|
|
return Common::SavePNG(filename, data, Common::ImageByteFormat::RGBA, width, height,
|
|
|
|
row_stride);
|
2013-11-15 13:00:38 +13:00
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2020-11-26 04:36:27 +01:00
|
|
|
std::vector<u8> buffer;
|
|
|
|
buffer.reserve(width * height * 3);
|
2017-06-07 04:11:23 -07:00
|
|
|
|
2020-11-26 04:36:27 +01:00
|
|
|
for (int y = 0; y < height; ++y)
|
2013-11-15 13:00:38 +13:00
|
|
|
{
|
2020-11-26 04:36:27 +01:00
|
|
|
const u8* pos = data + y * row_stride;
|
|
|
|
for (int x = 0; x < width; ++x)
|
2013-11-15 13:00:38 +13:00
|
|
|
{
|
2020-11-26 04:36:27 +01: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
|
|
|
}
|
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2020-11-26 04:36:27 +01:00
|
|
|
return Common::SavePNG(filename, buffer.data(), Common::ImageByteFormat::RGB, width, height);
|
2013-11-15 13:00:38 +13:00
|
|
|
}
|