diff options
| author | Lioncash <mathew1800@gmail.com> | 2015-08-29 22:24:15 -0400 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2015-08-29 22:46:18 -0400 |
| commit | e0aabc5f6ca7ce1ff8a77cf096891534ff0afae7 (patch) | |
| tree | ae19c4f8362114a679e8f1e17b0fb42250572eb0 /Source/Core | |
| parent | 83a179b56a94bb673457910bad4e8448f8d19f99 (diff) | |
MemcardManager: Remove trivial explicit delete and new
Also gets rid of pointer casting.
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/DolphinWX/MemcardManager.cpp | 83 |
1 files changed, 39 insertions, 44 deletions
diff --git a/Source/Core/DolphinWX/MemcardManager.cpp b/Source/Core/DolphinWX/MemcardManager.cpp index e0c1347d1d..a58a5c0c4a 100644 --- a/Source/Core/DolphinWX/MemcardManager.cpp +++ b/Source/Core/DolphinWX/MemcardManager.cpp @@ -2,8 +2,11 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include <algorithm> +#include <array> #include <cstring> #include <string> +#include <vector> #include <wx/bitmap.h> #include <wx/button.h> #include <wx/dialog.h> @@ -29,54 +32,47 @@ #define FIRSTPAGE 0 #define ARROWS slot ? "" : ARROW[slot], slot ? ARROW[slot] : "" -const u8 hdr[] = { - 0x42, 0x4D, - 0x38, 0x30, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x00, - 0x28, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, //W - 0x20, 0x00, 0x00, 0x00, //H - 0x01, 0x00, - 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x30, 0x00, 0x00, //data size - 0x12, 0x0B, 0x00, 0x00, - 0x12, 0x0B, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 -}; - static wxBitmap wxBitmapFromMemoryRGBA(const unsigned char* data, u32 width, u32 height) { - u32 stride = (4*width); - - u32 bytes = (stride*height) + sizeof(hdr); - - bytes = (bytes + 3)&(~3); - - u8 *pdata = new u8[bytes]; - - memcpy(pdata, hdr, sizeof(hdr)); - memset(pdata + sizeof(hdr), 0, bytes - sizeof(hdr)); - - u8 *pixelData = pdata + sizeof(hdr); + static const std::array<u8, 54> header = {{ + 0x42, 0x4D, + 0x38, 0x30, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, // Width + 0x20, 0x00, 0x00, 0x00, // Height + 0x01, 0x00, + 0x20, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x02, 0x30, 0x00, 0x00, // Data size + 0x12, 0x0B, 0x00, 0x00, + 0x12, 0x0B, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + }}; + + u32 stride = (4 * width); + + u32 bytes = (stride * height) + header.size(); + bytes = (bytes + 3) & ~3; + + u32 data_length = bytes - header.size(); + + std::vector<u8> pdata(bytes); + std::copy(header.begin(), header.end(), pdata.begin()); + + u8* const pixelData = &pdata[header.size()]; for (u32 y = 0; y < height; y++) - { - memcpy(pixelData + y*stride, data + (height - y - 1)*stride, stride); - } - - *(u32*)(pdata + 18) = width; - *(u32*)(pdata + 22) = height; - *(u32*)(pdata + 34) = bytes - sizeof(hdr); - - wxMemoryInputStream is(pdata, bytes); - wxBitmap map(wxImage(is, wxBITMAP_TYPE_BMP, -1), -1); + std::memcpy(&pixelData[y * stride], &data[(height - y - 1) * stride], stride); - delete[] pdata; + std::memcpy(&pdata[18], &width, sizeof(u32)); + std::memcpy(&pdata[22], &height, sizeof(u32)); + std::memcpy(&pdata[34], &data_length, sizeof(u32)); - return map; + wxMemoryInputStream is(pdata.data(), bytes); + return wxBitmap(wxImage(is, wxBITMAP_TYPE_BMP)); } BEGIN_EVENT_TABLE(CMemcardManager, wxDialog) @@ -654,7 +650,7 @@ bool CMemcardManager::ReloadMemcard(const std::string& fileName, int card) list->RemoveAll(); u8 nFiles = memoryCard[card]->GetNumFiles(); - int *images = new int[nFiles * 2]; + std::vector<int> images(nFiles * 2); for (u8 i = 0; i < nFiles; i++) { @@ -774,7 +770,6 @@ bool CMemcardManager::ReloadMemcard(const std::string& fileName, int card) } } - delete[] images; // Automatic column width and then show the list for (int i = COLUMN_BANNER; i <= COLUMN_FIRSTBLOCK; i++) { |
