mirror of
https://github.com/celisej567/mcpe.git
synced 2025-12-31 17:49:17 +03:00
Friendship Ended With LibPNG
This commit is contained in:
committed by
iProgramInCpp
parent
3776dc26f5
commit
4ca50c0fd8
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -7,6 +7,6 @@
|
||||
[submodule "thirdparty/SDL-src"]
|
||||
path = thirdparty/SDL2/src
|
||||
url = https://github.com/libsdl-org/SDL.git
|
||||
[submodule "thirdparty/LibPNG-src"]
|
||||
path = thirdparty/LibPNG/src
|
||||
url = https://github.com/glennrp/libpng.git
|
||||
[submodule "thirdparty/stb_image/include"]
|
||||
path = thirdparty/stb_image/include
|
||||
url = https://github.com/nothings/stb.git
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include "AppPlatform_android.hpp"
|
||||
#include "client/player/input/Mouse.hpp"
|
||||
|
||||
#include "thirdparty/stb_image.h"
|
||||
#include "thirdparty/stb_image_write.h"
|
||||
#include "stb_image.h"
|
||||
#include "stb_image_write.h"
|
||||
|
||||
|
||||
AppPlatform_android::AppPlatform_android()
|
||||
|
||||
@@ -13,13 +13,16 @@ add_library(reminecraftpe SHARED
|
||||
"${MC_ROOT}/platforms/android/android_native_app_glue.c"
|
||||
"${MC_ROOT}/platforms/android/AppPlatform_android.cpp"
|
||||
"${MC_ROOT}/platforms/android/main.cpp"
|
||||
"${MC_ROOT}/thirdparty/stb_image_impl.c"
|
||||
)
|
||||
|
||||
# Core
|
||||
add_subdirectory("${MC_ROOT}/source" source)
|
||||
target_link_libraries(reminecraftpe reminecraftpe-core)
|
||||
|
||||
# stb_image
|
||||
add_subdirectory("${MC_ROOT}/thirdparty/stb_image" stb_image)
|
||||
target_link_libraries(reminecraftpe stb_image)
|
||||
|
||||
# Extra Dependencies
|
||||
target_link_libraries(reminecraftpe android)
|
||||
|
||||
|
||||
@@ -60,21 +60,10 @@ if(NOT ANDROID)
|
||||
target_link_libraries(reminecraftpe reminecraftpe-openal)
|
||||
endif()
|
||||
|
||||
# LibPNG (If Needed)
|
||||
# stb_image (If Needed)
|
||||
if(NOT EMSCRIPTEN)
|
||||
if(ANDROID)
|
||||
# Vendor LibPNG (Android Only)
|
||||
add_subdirectory(../../thirdparty/LibPNG/src libpng EXCLUDE_FROM_ALL)
|
||||
target_link_libraries(reminecraftpe png_static)
|
||||
target_include_directories(reminecraftpe PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../thirdparty/LibPNG/src"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/libpng"
|
||||
)
|
||||
else()
|
||||
# System LibPNG
|
||||
find_package(PNG REQUIRED)
|
||||
target_link_libraries(reminecraftpe PNG::PNG)
|
||||
endif()
|
||||
add_subdirectory(../../thirdparty/stb_image stb_image)
|
||||
target_link_libraries(reminecraftpe stb_image)
|
||||
endif()
|
||||
|
||||
# SDL
|
||||
|
||||
1
platforms/sdl/android/.idea/.name
generated
Normal file
1
platforms/sdl/android/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
||||
ReMinecraftPE
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="SERIAL_NUMBER" />
|
||||
<value value="R5CRB1GE0RY" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-11-03T20:57:27.283440358Z" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1 +1,2 @@
|
||||
rootProject.name = 'ReMinecraftPE'
|
||||
include ':app'
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
#include <sys/stat.h>
|
||||
#include <cerrno>
|
||||
|
||||
#include "thirdparty/LibPNG/png.h"
|
||||
#include "stb_image.h"
|
||||
#include "stb_image_write.h"
|
||||
|
||||
#include "thirdparty/GL/GL.hpp"
|
||||
|
||||
@@ -20,80 +21,11 @@ AppPlatform_sdl::AppPlatform_sdl(std::string storageDir, SDL_Window *window)
|
||||
// Take Screenshot
|
||||
static int save_png(const char *filename, unsigned char *pixels, int line_size, int width, int height)
|
||||
{
|
||||
// Return value
|
||||
int ret = 0;
|
||||
// Setup
|
||||
stbi_flip_vertically_on_write(true);
|
||||
|
||||
// Variables
|
||||
png_structp png = NULL;
|
||||
png_infop info = NULL;
|
||||
FILE *file = NULL;
|
||||
png_colorp palette = NULL;
|
||||
png_bytep *rows = new png_bytep[height];
|
||||
for (int i = 0; i < height; ++i)
|
||||
{
|
||||
rows[height - i - 1] = (png_bytep)(&pixels[i * line_size]);
|
||||
}
|
||||
|
||||
// Init
|
||||
png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png)
|
||||
{
|
||||
ret = 1;
|
||||
goto ret;
|
||||
}
|
||||
info = png_create_info_struct(png);
|
||||
if (!info)
|
||||
{
|
||||
ret = 1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
// Open File
|
||||
file = fopen(filename, "wb");
|
||||
if (!file)
|
||||
{
|
||||
ret = 1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
// Prepare To Write
|
||||
png_init_io(png, file);
|
||||
png_set_IHDR(png, info, width, height, 8 /* Depth */, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
palette = (png_colorp) png_malloc(png, PNG_MAX_PALETTE_LENGTH * sizeof(png_color));
|
||||
if (!palette)
|
||||
{
|
||||
ret = 1;
|
||||
goto ret;
|
||||
}
|
||||
png_set_PLTE(png, info, palette, PNG_MAX_PALETTE_LENGTH);
|
||||
png_write_info(png, info);
|
||||
png_set_packing(png);
|
||||
|
||||
// Write
|
||||
png_write_image(png, rows);
|
||||
png_write_end(png, info);
|
||||
|
||||
ret:
|
||||
// Free
|
||||
if (palette != NULL)
|
||||
{
|
||||
png_free(png, palette);
|
||||
}
|
||||
if (rows != NULL)
|
||||
{
|
||||
delete rows[height];
|
||||
}
|
||||
if (file != NULL)
|
||||
{
|
||||
fclose(file);
|
||||
}
|
||||
if (png != NULL)
|
||||
{
|
||||
png_destroy_write_struct(&png, &info);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
// Write Image
|
||||
return stbi_write_png(filename, width, height, 4, pixels, line_size);
|
||||
}
|
||||
|
||||
// Ensure Screenshots Folder Exists
|
||||
@@ -169,8 +101,8 @@ void AppPlatform_sdl::saveScreenshot(const std::string& filename, int glWidth, i
|
||||
|
||||
// Read Pixels
|
||||
bool fail = false;
|
||||
unsigned char *pixels = (unsigned char *) malloc(size);
|
||||
if (pixels == NULL)
|
||||
unsigned char *pixels = new unsigned char[size];
|
||||
if (!pixels)
|
||||
{
|
||||
fail = true;
|
||||
}
|
||||
@@ -180,7 +112,7 @@ void AppPlatform_sdl::saveScreenshot(const std::string& filename, int glWidth, i
|
||||
}
|
||||
|
||||
// Save Image
|
||||
if (fail || save_png(file.c_str(), pixels, line_size, width, height))
|
||||
if (fail || !save_png(file.c_str(), pixels, line_size, width, height))
|
||||
{
|
||||
LOG_E("Screenshot Failed: %s", file.c_str());
|
||||
}
|
||||
@@ -190,108 +122,54 @@ void AppPlatform_sdl::saveScreenshot(const std::string& filename, int glWidth, i
|
||||
}
|
||||
|
||||
// Free
|
||||
if (pixels != NULL)
|
||||
if (!pixels)
|
||||
{
|
||||
free(pixels);
|
||||
delete[] pixels;
|
||||
}
|
||||
}
|
||||
|
||||
static void png_read_sdl(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
SDL_RWread((SDL_RWops *) png_get_io_ptr(png_ptr), (char *) data, length, 1);
|
||||
}
|
||||
|
||||
static void nop_png_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
{
|
||||
// Do Nothing
|
||||
}
|
||||
|
||||
Texture AppPlatform_sdl::loadTexture(const std::string& path, bool b)
|
||||
{
|
||||
Texture out;
|
||||
out.field_C = 1;
|
||||
out.field_D = 0;
|
||||
|
||||
// Get Full Path
|
||||
std::string realPath = getAssetPath(path);
|
||||
|
||||
// Read File
|
||||
SDL_RWops *io = SDL_RWFromFile(realPath.c_str(), "rb");
|
||||
|
||||
if (!io)
|
||||
{
|
||||
LOG_E("Couldn't find file: %s", path.c_str());
|
||||
return out;
|
||||
}
|
||||
|
||||
png_structp pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, nop_png_warning);
|
||||
if (!pngPtr)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
png_infop infoPtr = png_create_info_struct(pngPtr);
|
||||
if (!infoPtr)
|
||||
{
|
||||
png_destroy_read_struct(&pngPtr, NULL, NULL);
|
||||
return out;
|
||||
}
|
||||
|
||||
png_set_read_fn(pngPtr, (png_voidp) io, png_read_sdl);
|
||||
|
||||
png_read_info(pngPtr, infoPtr);
|
||||
|
||||
png_set_expand(pngPtr);
|
||||
png_set_strip_16(pngPtr);
|
||||
png_set_gray_to_rgb(pngPtr);
|
||||
png_read_update_info(pngPtr, infoPtr);
|
||||
|
||||
out.m_width = png_get_image_width(pngPtr, infoPtr);
|
||||
out.m_height = png_get_image_height(pngPtr, infoPtr);
|
||||
|
||||
int pixelSize = 4;
|
||||
|
||||
png_bytep *rowPtrs = new png_bytep[out.m_height];
|
||||
unsigned char *pixels = new unsigned char[pixelSize * out.m_width * out.m_height];
|
||||
|
||||
int rowStrideBytes = pixelSize * out.m_width;
|
||||
for (int i = 0; i < out.m_height; i++)
|
||||
{
|
||||
rowPtrs[i] = (png_bytep) &pixels[i * rowStrideBytes];
|
||||
}
|
||||
png_read_image(pngPtr, rowPtrs);
|
||||
|
||||
// Convert RGB Images To RGBA
|
||||
bool opaque = png_get_color_type(pngPtr, infoPtr) != PNG_COLOR_TYPE_RGBA;
|
||||
if (opaque)
|
||||
{
|
||||
for (int y = 0; y < out.m_height; y++)
|
||||
{
|
||||
unsigned char *row = &pixels[y * rowStrideBytes];
|
||||
for (int x = out.m_width - 1; x >= 0; x--)
|
||||
{
|
||||
// Find Indexes
|
||||
int rgb = x * 3;
|
||||
int rgba = x * 4;
|
||||
|
||||
// Read RGB Pixel
|
||||
unsigned char a = row[rgb];
|
||||
unsigned char b = row[rgb + 1];
|
||||
unsigned char c = row[rgb + 2];
|
||||
|
||||
// Store RGBA Pixel
|
||||
row[rgba] = a;
|
||||
row[rgba + 1] = b;
|
||||
row[rgba + 2] = c;
|
||||
row[rgba + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.m_pixels = (uint32_t *) pixels;
|
||||
|
||||
png_destroy_read_struct(&pngPtr, &infoPtr, (png_infopp) 0);
|
||||
delete[](png_bytep) rowPtrs;
|
||||
Sint64 size = SDL_RWsize(io);
|
||||
unsigned char *file = new unsigned char[size];
|
||||
SDL_RWread(io, file, size, 1);
|
||||
SDL_RWclose(io);
|
||||
|
||||
// Parse Image
|
||||
int width = 0, height = 0, channels = 0;
|
||||
stbi_uc *img = stbi_load_from_memory(file, size, &width, &height, &channels, STBI_rgb_alpha);
|
||||
delete[] file;
|
||||
if (!img)
|
||||
{
|
||||
// Failed To Parse Image
|
||||
return out;
|
||||
}
|
||||
|
||||
// Copy Image
|
||||
uint32_t *img2 = new uint32_t[width * height];
|
||||
memcpy(img2, img, width * height * sizeof (uint32_t));
|
||||
stbi_image_free(img);
|
||||
|
||||
// Create Texture
|
||||
out.m_width = width;
|
||||
out.m_height = height;
|
||||
out.m_pixels = img2;
|
||||
|
||||
// Return
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,10 +118,11 @@ static void handle_events()
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
// TODO: Shouldn't we be handling this in Keyboard?
|
||||
|
||||
// We really should. We didn't add the f2 key anywhere -iProgramInCpp
|
||||
/*
|
||||
// This really should be handled somewhere else.
|
||||
// Unforunately, there is no global keyboard handler.
|
||||
// Keyboard events are either handled in Screen::keyboardEvent
|
||||
// when a Screen is visible, or in Minecraft::tickInput
|
||||
// when LocalPlayer exists.
|
||||
if (event.key.keysym.sym == SDLK_F2)
|
||||
{
|
||||
if (event.key.state == SDL_PRESSED && g_pAppPlatform != nullptr)
|
||||
@@ -130,7 +131,6 @@ static void handle_events()
|
||||
}
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
// Android Back Button
|
||||
if (event.key.keysym.sym == SDLK_AC_BACK) {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#include "thirdparty/GL/GL.hpp"
|
||||
|
||||
#include "thirdparty/stb_image.h"
|
||||
#include "thirdparty/stb_image_write.h"
|
||||
#include "thirdparty/stb_image/include/stb_image.h"
|
||||
#include "thirdparty/stb_image/include/stb_image_write.h"
|
||||
|
||||
AppPlatform_win32::AppPlatform_win32()
|
||||
{
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
<ClInclude Include="$(MC_ROOT)\platforms\windows\SoundSystemDS.hpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\stb_image_impl.c" />
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\stb_image\src\stb_image_impl.c" />
|
||||
<ClCompile Include="$(MC_ROOT)\platforms\windows\AppPlatform_win32.cpp" />
|
||||
<ClCompile Include="$(MC_ROOT)\platforms\windows\LoggerWin32.cpp" />
|
||||
<ClCompile Include="$(MC_ROOT)\platforms\windows\main.cpp" />
|
||||
@@ -151,4 +151,4 @@
|
||||
<LocalDebuggerWorkingDirectory>$(MC_ROOT)\game</LocalDebuggerWorkingDirectory>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\stb_image_impl.c">
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\stb_image\src\stb_image_impl.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MC_ROOT)\platforms\windows\AppPlatform_win32.cpp">
|
||||
@@ -45,4 +45,4 @@
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -996,7 +996,7 @@
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\raknet\VitaIncludes.cpp" />
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\raknet\WSAStartupSingleton.cpp" />
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\raknet\_FindFirst.cpp" />
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\stb_image_impl.c" />
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\stb_image\src\stb_image_impl.c" />
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\zlib\adler32.c" />
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\zlib\compress.c" />
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\zlib\crc32.c" />
|
||||
@@ -1026,4 +1026,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -2024,7 +2024,7 @@
|
||||
<ClCompile Include="$(MC_ROOT)\source\world\level\levelgen\biome\Biome.cpp">
|
||||
<Filter>source\world\level\levelgen\biome</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\stb_image_impl.c">
|
||||
<ClCompile Include="$(MC_ROOT)\thirdparty\stb_image\src\stb_image_impl.c">
|
||||
<Filter>thirdparty</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MC_ROOT)\compat\GLExt.cpp">
|
||||
@@ -2225,4 +2225,4 @@
|
||||
</None>
|
||||
<None Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
8
thirdparty/LibPNG/png.h
vendored
8
thirdparty/LibPNG/png.h
vendored
@@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma comment(lib, "zlib.lib")
|
||||
#pragma comment(lib, "libpng16.lib")
|
||||
#endif
|
||||
|
||||
#include <png.h>
|
||||
1
thirdparty/LibPNG/src
vendored
1
thirdparty/LibPNG/src
vendored
Submodule thirdparty/LibPNG/src deleted from f135775ad4
7987
thirdparty/stb_image.h
vendored
7987
thirdparty/stb_image.h
vendored
File diff suppressed because it is too large
Load Diff
6
thirdparty/stb_image/CMakeLists.txt
vendored
Normal file
6
thirdparty/stb_image/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.16.0)
|
||||
project(stb_image)
|
||||
|
||||
# Build
|
||||
add_library(stb_image STATIC src/stb_image_impl.c)
|
||||
target_include_directories(stb_image PUBLIC include)
|
||||
1
thirdparty/stb_image/include
vendored
Submodule
1
thirdparty/stb_image/include
vendored
Submodule
Submodule thirdparty/stb_image/include added at beebb24b94
1724
thirdparty/stb_image_write.h
vendored
1724
thirdparty/stb_image_write.h
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user