From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- Source/Core/VideoCommon/ImageWrite.cpp | 108 +++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Source/Core/VideoCommon/ImageWrite.cpp (limited to 'Source/Core/VideoCommon/ImageWrite.cpp') diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp new file mode 100644 index 0000000000..193f058541 --- /dev/null +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -0,0 +1,108 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include +#include + +#include "png.h" +#include "ImageWrite.h" +#include "FileUtil.h" + +bool SaveData(const char* filename, const char* data) +{ + std::ofstream f; + OpenFStream(f, filename, std::ios::binary); + f << data; + + return true; +} + + +/* +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(u8* data, int row_stride, const std::string filename, int width, int height, bool saveAlpha) +{ + bool success = false; + + if (!data) + return false; + + char title[] = "Dolphin Screenshot"; + char title_key[] = "Title"; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; + + // Open file for writing (binary mode) + File::IOFile fp(filename, "wb"); + if (!fp.IsOpen()) { + PanicAlert("Screenshot failed: Could not open file %s %d\n", filename.c_str(), errno); + goto finalise; + } + + // Initialize write structure + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (png_ptr == NULL) { + PanicAlert("Screenshot failed: Could not allocate write struct\n"); + goto finalise; + + } + + // Initialize info structure + info_ptr = png_create_info_struct(png_ptr); + if (info_ptr == NULL) { + PanicAlert("Screenshot failed: Could not allocate info struct\n"); + goto finalise; + } + + // Setup Exception handling + if (setjmp(png_jmpbuf(png_ptr))) { + PanicAlert("Screenshot failed: Error during png creation\n"); + goto finalise; + } + + png_init_io(png_ptr, fp.GetHandle()); + + // Write header (8 bit colour depth) + png_set_IHDR(png_ptr, info_ptr, width, height, + 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + png_text title_text; + title_text.compression = PNG_TEXT_COMPRESSION_NONE; + title_text.key = title_key; + title_text.text = title; + png_set_text(png_ptr, info_ptr, &title_text, 1); + + png_write_info(png_ptr, info_ptr); + + // Write image data + for (auto y = 0; y < height; ++y) + { + u8* row_ptr = (u8*)data + y * row_stride; + u8* ptr = row_ptr; + for (auto x = 0; x < row_stride / 4; ++x) + { + if (!saveAlpha) + ptr[3] = 0xff; + ptr += 4; + } + png_write_row(png_ptr, row_ptr); + } + + // End write + png_write_end(png_ptr, NULL); + + success = true; + +finalise: + if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL); + + return success; +} -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/VideoCommon/ImageWrite.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/ImageWrite.cpp') diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp index 193f058541..ad0449dd2f 100644 --- a/Source/Core/VideoCommon/ImageWrite.cpp +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -6,8 +6,8 @@ #include #include "png.h" -#include "ImageWrite.h" -#include "FileUtil.h" +#include "Common/FileUtil.h" +#include "VideoCommon/ImageWrite.h" bool SaveData(const char* filename, const char* data) { -- cgit v1.2.3 From 315a8ba1c04bf8cffd9b04096be898ac462fa89e Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 23 Feb 2014 23:03:39 +0100 Subject: Various changes suggested by cppcheck - remove unused variables - reduce the scope where it makes sense - correct limits (did you know that strcat()'s last parameter does not include the \0 that is always added?) - set some free()'d pointers to NULL --- Source/Core/VideoCommon/ImageWrite.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/ImageWrite.cpp') diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp index ad0449dd2f..a3c9dec86a 100644 --- a/Source/Core/VideoCommon/ImageWrite.cpp +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -26,7 +26,7 @@ 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(u8* data, int row_stride, const std::string filename, int width, int height, bool saveAlpha) +bool TextureToPng(u8* data, int row_stride, const std::string& filename, int width, int height, bool saveAlpha) { bool success = false; -- cgit v1.2.3 From d802d392811be44d34ae9cd23f616db93e54c50f Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 9 Mar 2014 21:14:26 +0100 Subject: clang-modernize -use-nullptr and s/\bNULL\b/nullptr/g for *.cpp/h/mm files not compiled on my machine --- Source/Core/VideoCommon/ImageWrite.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Source/Core/VideoCommon/ImageWrite.cpp') diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp index a3c9dec86a..d16164887c 100644 --- a/Source/Core/VideoCommon/ImageWrite.cpp +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -35,8 +35,8 @@ bool TextureToPng(u8* data, int row_stride, const std::string& filename, int wid char title[] = "Dolphin Screenshot"; char title_key[] = "Title"; - png_structp png_ptr = NULL; - png_infop info_ptr = NULL; + png_structp png_ptr = nullptr; + png_infop info_ptr = nullptr; // Open file for writing (binary mode) File::IOFile fp(filename, "wb"); @@ -46,8 +46,8 @@ bool TextureToPng(u8* data, int row_stride, const std::string& filename, int wid } // Initialize write structure - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (png_ptr == NULL) { + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); + if (png_ptr == nullptr) { PanicAlert("Screenshot failed: Could not allocate write struct\n"); goto finalise; @@ -55,7 +55,7 @@ bool TextureToPng(u8* data, int row_stride, const std::string& filename, int wid // Initialize info structure info_ptr = png_create_info_struct(png_ptr); - if (info_ptr == NULL) { + if (info_ptr == nullptr) { PanicAlert("Screenshot failed: Could not allocate info struct\n"); goto finalise; } @@ -96,13 +96,13 @@ bool TextureToPng(u8* data, int row_stride, const std::string& filename, int wid } // End write - png_write_end(png_ptr, NULL); + png_write_end(png_ptr, nullptr); success = true; finalise: - if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); - if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL); + if (info_ptr != nullptr) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + if (png_ptr != nullptr) png_destroy_write_struct(&png_ptr, (png_infopp)nullptr); return success; } -- cgit v1.2.3 From ce54c1e571a7f79c173dd8f949003255ba95670a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 3 Jun 2014 01:08:54 -0400 Subject: Kill off replaceable usages of s[n]printf. --- Source/Core/VideoCommon/ImageWrite.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/ImageWrite.cpp') diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp index d16164887c..db6cbf69c7 100644 --- a/Source/Core/VideoCommon/ImageWrite.cpp +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -3,13 +3,14 @@ // Refer to the license.txt file included. #include +#include #include #include "png.h" #include "Common/FileUtil.h" #include "VideoCommon/ImageWrite.h" -bool SaveData(const char* filename, const char* data) +bool SaveData(const std::string& filename, const char* data) { std::ofstream f; OpenFStream(f, filename, std::ios::binary); -- cgit v1.2.3 From 4af8d9d2487c58953e919769db33b20bc062d6ea Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 30 Aug 2014 16:51:27 -0400 Subject: VideoCommon: Clean up brace placements --- Source/Core/VideoCommon/ImageWrite.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoCommon/ImageWrite.cpp') diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp index db6cbf69c7..2666c62a8a 100644 --- a/Source/Core/VideoCommon/ImageWrite.cpp +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -41,14 +41,16 @@ bool TextureToPng(u8* data, int row_stride, const std::string& filename, int wid // Open file for writing (binary mode) File::IOFile fp(filename, "wb"); - if (!fp.IsOpen()) { + if (!fp.IsOpen()) + { PanicAlert("Screenshot failed: Could not open file %s %d\n", filename.c_str(), errno); goto finalise; } // Initialize write structure png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); - if (png_ptr == nullptr) { + if (png_ptr == nullptr) + { PanicAlert("Screenshot failed: Could not allocate write struct\n"); goto finalise; @@ -56,13 +58,15 @@ bool TextureToPng(u8* data, int row_stride, const std::string& filename, int wid // Initialize info structure info_ptr = png_create_info_struct(png_ptr); - if (info_ptr == nullptr) { + if (info_ptr == nullptr) + { PanicAlert("Screenshot failed: Could not allocate info struct\n"); goto finalise; } // Setup Exception handling - if (setjmp(png_jmpbuf(png_ptr))) { + if (setjmp(png_jmpbuf(png_ptr))) + { PanicAlert("Screenshot failed: Error during png creation\n"); goto finalise; } -- cgit v1.2.3 From b25e1a2eb4fd20ba84103549a59ea4c4a8639641 Mon Sep 17 00:00:00 2001 From: Stevoisiak Date: Thu, 13 Nov 2014 21:28:27 -0500 Subject: Various formatting and consistency fixes --- Source/Core/VideoCommon/ImageWrite.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/ImageWrite.cpp') diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp index 2666c62a8a..52672612c5 100644 --- a/Source/Core/VideoCommon/ImageWrite.cpp +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -73,7 +73,7 @@ bool TextureToPng(u8* data, int row_stride, const std::string& filename, int wid png_init_io(png_ptr, fp.GetHandle()); - // Write header (8 bit colour depth) + // Write header (8 bit color depth) png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); -- cgit v1.2.3 From cefcb0ace9d363b3679b4e93bcc9ec05f1e5f4f8 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 18 May 2015 01:08:10 +0200 Subject: Update license headers to GPLv2+ --- Source/Core/VideoCommon/ImageWrite.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/ImageWrite.cpp') diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp index 52672612c5..db3a103c48 100644 --- a/Source/Core/VideoCommon/ImageWrite.cpp +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -1,5 +1,5 @@ // Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2+ // Refer to the license.txt file included. #include -- cgit v1.2.3 From 30ebb2459eb97ba544547183854775df8460b475 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:55:12 +0200 Subject: Set copyright year to when a file was created --- Source/Core/VideoCommon/ImageWrite.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/ImageWrite.cpp') diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp index db3a103c48..8c5284eb57 100644 --- a/Source/Core/VideoCommon/ImageWrite.cpp +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -1,4 +1,4 @@ -// Copyright 2013 Dolphin Emulator Project +// Copyright 2008 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -- cgit v1.2.3 From 95a2abc1ce6d0d9304f32725cdf784f2e3d7d1f3 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 15 Mar 2015 16:42:22 +0100 Subject: Use PanicAlertT instead of PanicAlert when appropriate I tried to change messages that contained instructions for users, while avoiding messages that are so technical that most users wouldn't understand them even if they were in the right language. --- Source/Core/VideoCommon/ImageWrite.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'Source/Core/VideoCommon/ImageWrite.cpp') diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp index 8c5284eb57..38ca509c3e 100644 --- a/Source/Core/VideoCommon/ImageWrite.cpp +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -43,7 +43,7 @@ bool TextureToPng(u8* data, int row_stride, const std::string& filename, int wid File::IOFile fp(filename, "wb"); if (!fp.IsOpen()) { - PanicAlert("Screenshot failed: Could not open file %s %d\n", filename.c_str(), errno); + PanicAlertT("Screenshot failed: Could not open file \"%s\" (error %d)", filename.c_str(), errno); goto finalise; } @@ -51,23 +51,22 @@ bool TextureToPng(u8* data, int row_stride, const std::string& filename, int wid png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (png_ptr == nullptr) { - PanicAlert("Screenshot failed: Could not allocate write struct\n"); + PanicAlert("Screenshot failed: Could not allocate write struct"); goto finalise; - } // Initialize info structure info_ptr = png_create_info_struct(png_ptr); if (info_ptr == nullptr) { - PanicAlert("Screenshot failed: Could not allocate info struct\n"); + PanicAlert("Screenshot failed: Could not allocate info struct"); goto finalise; } // Setup Exception handling if (setjmp(png_jmpbuf(png_ptr))) { - PanicAlert("Screenshot failed: Error during png creation\n"); + PanicAlert("Screenshot failed: Error during PNG creation"); goto finalise; } -- cgit v1.2.3