Ditch FreeImage
minecraft-pi-reborn/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2022-06-13 20:49:09 -04:00
parent f1ec29ec86
commit ca21877000
9 changed files with 114 additions and 64 deletions

View File

@ -1,13 +1,9 @@
project(dependencies) project(dependencies)
# ZLib # ZLib (Needed By libpng)
if(BUILD_ARM_COMPONENTS) add_subdirectory(zlib)
add_subdirectory(zlib)
endif()
# LibPNG # LibPNG
if(BUILD_ARM_COMPONENTS) add_subdirectory(libpng)
add_subdirectory(libpng)
endif()
# Minecraft: Pi Edition # Minecraft: Pi Edition
if(BUILD_ARM_COMPONENTS AND NOT MCPI_OPEN_SOURCE_ONLY) if(BUILD_ARM_COMPONENTS AND NOT MCPI_OPEN_SOURCE_ONLY)
add_subdirectory(minecraft-pi) add_subdirectory(minecraft-pi)

View File

@ -6,16 +6,16 @@ add_compile_options(-w)
## GLFW ## GLFW
# Download # Download
set(BUILD_SHARED_LIBS FALSE) set(BUILD_SHARED_LIBS FALSE CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES FALSE) set(GLFW_BUILD_EXAMPLES FALSE CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS FALSE) set(GLFW_BUILD_TESTS FALSE CACHE BOOL "" FORCE)
set(GLFW_BUILD_DOCS FALSE) set(GLFW_BUILD_DOCS FALSE CACHE BOOL "" FORCE)
set(GLFW_INSTALL FALSE) set(GLFW_INSTALL FALSE CACHE BOOL "" FORCE)
set(GLFW_BUILD_WIN32 FALSE) set(GLFW_BUILD_WIN32 FALSE CACHE BOOL "" FORCE)
set(GLFW_BUILD_COCOA FALSE) set(GLFW_BUILD_COCOA FALSE CACHE BOOL "" FORCE)
set(GLFW_BUILD_X11 TRUE) set(GLFW_BUILD_X11 TRUE CACHE BOOL "" FORCE)
set(GLFW_BUILD_WAYLAND TRUE) set(GLFW_BUILD_WAYLAND TRUE CACHE BOOL "" FORCE)
set(GLFW_LIBRARY_TYPE "STATIC") set(GLFW_LIBRARY_TYPE "STATIC" CACHE BOOL "" FORCE)
add_subdirectory(src EXCLUDE_FROM_ALL) add_subdirectory(src EXCLUDE_FROM_ALL)
# Ensure Build # Ensure Build

View File

@ -5,16 +5,40 @@ add_compile_options(-w)
## LibPNG ## LibPNG
# Options
set(PNG_TESTS FALSE CACHE BOOL "" FORCE)
set(PNG_STATIC ${BUILD_NATIVE_COMPONENTS} CACHE BOOL "" FORCE)
set(PNG_SHARED ${BUILD_ARM_COMPONENTS} CACHE BOOL "" FORCE)
if(BUILD_NATIVE_COMPONENTS)
set(PNG_NO_STDIO FALSE CACHE BOOL "" FORCE)
else()
set(PNG_NO_STDIO TRUE CACHE BOOL "" FORCE)
endif()
# Download # Download
set(ZLIB_LIBRARY zlibstatic) set(ZLIB_LIBRARY zlibstatic)
set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../zlib/src" "${CMAKE_CURRENT_BINARY_DIR}/../zlib/src") set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../zlib/src" "${CMAKE_CURRENT_BINARY_DIR}/../zlib/src")
set(CMAKE_POLICY_DEFAULT_CMP0054 OLD) # Silence Warning set(CMAKE_POLICY_DEFAULT_CMP0054 OLD) # Silence Warning
add_subdirectory(src EXCLUDE_FROM_ALL) add_subdirectory(src EXCLUDE_FROM_ALL)
set(CMAKE_POLICY_DEFAULT_CMP0054 NEW) # Re-Enable New Behavior set(CMAKE_POLICY_DEFAULT_CMP0054 NEW) # Re-Enable New Behavior
set_target_properties(png12 PROPERTIES LINK_OPTIONS "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libpng.vers") # Use Symbol Versioning if(TARGET png12)
set_target_properties(png12 PROPERTIES DEBUG_POSTFIX "") # Fix LibPNG Suffix In Debug Mode set_target_properties(png12 PROPERTIES LINK_OPTIONS "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libpng.vers") # Use Symbol Versioning
set_target_properties(png12 PROPERTIES DEBUG_POSTFIX "") # Fix LibPNG Suffix In Debug Mode
endif()
if(TARGET png12_static)
find_library(M_LIBRARY NAMES m REQUIRED)
target_link_libraries(png12_static "${ZLIB_LIBRARY}" "${M_LIBRARY}")
target_include_directories(png12_static PUBLIC src)
endif()
# Ensure Build # Ensure Build
add_custom_target(png12-build ALL DEPENDS png12) if(TARGET png12)
add_custom_target(png12-build ALL DEPENDS png12)
endif()
if(TARGET png12_static)
add_custom_target(png12_static-build ALL DEPENDS png12_static)
endif()
# Install # Install
install(TARGETS png12 DESTINATION "${MCPI_LIB_DIR}") if(TARGET png12)
install(TARGETS png12 DESTINATION "${MCPI_LIB_DIR}")
endif()

View File

@ -98,12 +98,11 @@ This component contains all MCPI symbols.
## Dependencies ## Dependencies
MCPI-Reborn has several dependencies: MCPI-Reborn has several dependencies:
* MCPI (Bundled) * MCPI (Bundled)
* GLFW (Only In Client Mode) * GLFW (Only In Client Mode; Bundled)
* Open GL ES 1.1 * Open GL ES 2.0
* EGL * EGL
* OpenAL (Only In Client Mode) * OpenAL (Only In Client Mode)
* ZLib (Required By LibPNG; Bundled) * ZLib (Required By LibPNG; Bundled)
* LibPNG (Bundled) * LibPNG (Bundled)
* FreeImage (Only In Client Mode)
* QEMU User Mode (Only On Non-ARM Hosts; Runtime Only) * QEMU User Mode (Only On Non-ARM Hosts; Runtime Only)
* Zenity (Only In Client Mode; Runtime Only) * Zenity (Only In Client Mode; Runtime Only; Bundled)

View File

@ -3,12 +3,10 @@
## Build Dependencies ## Build Dependencies
* Common * Common
* ARM Compiler * ARM Compiler
* Host Compiler (Clang) * Host Compiler
* CMake * CMake
* Host Architecture Dependencies * Host Architecture Dependencies
* Client Mode Only * Client Mode Only
* GLFW
* FreeImage
* OpenAL * OpenAL
## Runtime Dependencies ## Runtime Dependencies
@ -16,11 +14,8 @@
* QEMU User-Mode * QEMU User-Mode
* Host Architecture Dependencies * Host Architecture Dependencies
* Client Mode Only * Client Mode Only
* OpenGL ES 1.1 * OpenGL ES 2.0
* GLFW
* FreeImage
* OpenAL * OpenAL
* Zenity
## Instructions ## Instructions
```sh ```sh

View File

@ -26,12 +26,10 @@ if(TARGET media-layer-core-real)
# Link # Link
target_link_libraries(media-layer-core-real media-layer-headers reborn-util pthread dl) target_link_libraries(media-layer-core-real media-layer-headers reborn-util pthread dl)
if(NOT MCPI_HEADLESS_MODE) if(NOT MCPI_HEADLESS_MODE)
# Find FreeImage
find_library(FREEIMAGE_LIBRARY NAMES freeimage libfreeimage.so.3 REQUIRED)
# OpenAL # OpenAL
find_library(OPENAL_LIBRARY NAMES openal REQUIRED) find_library(OPENAL_LIBRARY NAMES openal REQUIRED)
# Link # Link
target_link_libraries(media-layer-core-real "${FREEIMAGE_LIBRARY}" "${OPENAL_LIBRARY}" m GLESv1_CM glfw) target_link_libraries(media-layer-core-real png12_static "${OPENAL_LIBRARY}" m GLESv1_CM glfw)
endif() endif()
endif() endif()

View File

@ -12,7 +12,7 @@
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <FreeImage.h> #include <png.h>
#include <GLES/gl.h> #include <GLES/gl.h>
#include <media-layer/core.h> #include <media-layer/core.h>
@ -35,6 +35,70 @@ static void ensure_screenshots_folder(char *screenshots) {
#define TIME_SIZE 20 #define TIME_SIZE 20
// Take Screenshot // Take Screenshot
static int save_png(const char *filename, unsigned char *pixels, int line_size, int width, int height) {
// Return value
int ret = 0;
// Variables
png_structp png = NULL;
png_infop info = NULL;
FILE *file = NULL;
png_colorp palette = NULL;
png_bytep rows[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 (file != NULL) {
fclose(file);
}
if (png != NULL) {
png_destroy_write_struct(&png, &info);
}
// Return
return ret;
}
void media_take_screenshot(char *home) { void media_take_screenshot(char *home) {
// Get Directory // Get Directory
char *screenshots = NULL; char *screenshots = NULL;
@ -88,41 +152,18 @@ void media_take_screenshot(char *home) {
unsigned char pixels[size]; unsigned char pixels[size];
glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// Handle Little Endian Systems
#if __BYTE_ORDER == __LITTLE_ENDIAN
// Swap Red And Blue
for (int j = 0; j < width; j++) {
for (int k = 0; k < height; k++) {
int pixel = (k * line_size) + (j * 4);
// Swap
int red = pixels[pixel];
int blue = pixels[pixel + 2];
pixels[pixel] = blue;
pixels[pixel + 2] = red;
}
}
#endif
// Save Image // Save Image
FIBITMAP *image = FreeImage_ConvertFromRawBits(pixels, width, height, line_size, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, 0); if (save_png(file, pixels, line_size, width, height)) {
if (!FreeImage_Save(FIF_PNG, image, file, 0)) {
INFO("Screenshot Failed: %s", file); INFO("Screenshot Failed: %s", file);
} else { } else {
INFO("Screenshot Saved: %s", file); INFO("Screenshot Saved: %s", file);
} }
FreeImage_Unload(image);
// Free // Free
free(file); free(file);
free(screenshots); free(screenshots);
} }
// Init
__attribute__((constructor)) static void init() {
// Init FreeImage
FreeImage_Initialise(0);
}
#else #else
void media_take_screenshot() { void media_take_screenshot() {
// NOP // NOP

View File

@ -28,8 +28,7 @@ run() {
# Host Dependencies Needed For Compile # Host Dependencies Needed For Compile
queue_pkg \ queue_pkg \
libwayland-bin \ libwayland-bin
libfreeimage-dev
# Host Dependencies Needed For Running # Host Dependencies Needed For Running
queue_pkg \ queue_pkg \
@ -44,7 +43,6 @@ run() {
# Dependencies # Dependencies
queue_pkg \ queue_pkg \
libfreeimage3:$1 \
libopenal-dev:$1 libopenal-dev:$1
# GLFW Dependencies # GLFW Dependencies

View File

@ -40,7 +40,6 @@ if (mode === 'client') {
'libgdk-pixbuf2.0-0', 'libgdk-pixbuf2.0-0',
'librsvg2-common', 'librsvg2-common',
'shared-mime-info', 'shared-mime-info',
'libfreeimage3',
'libopenal1' 'libopenal1'
); );
} }